Skip to content

Commit

Permalink
Fix Warscroll Allegiance detection
Browse files Browse the repository at this point in the history
Fixes #1061
  • Loading branch information
daviseford committed Nov 7, 2020
1 parent b15b879 commit 377b2e0
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 55 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "aos-reminders",
"version": "3.2.5",
"version": "3.2.6",
"private": true,
"homepage": "./",
"dependencies": {
"@auth0/auth0-react": "1.1.0",
"@reduxjs/toolkit": "1.4.0",
"@stripe/react-stripe-js": "1.1.2",
"@stripe/stripe-js": "1.10.0",
"@stripe/stripe-js": "1.11.0",
"bootstrap": "4.4.1",
"core-js": "3.6.5",
"core-js": "3.7.0",
"jspdf": "1.5.3",
"lodash": "4.17.20",
"luxon": "1.25.0",
Expand All @@ -21,7 +21,7 @@
"react-beautiful-dnd": "13.0.0",
"react-copy-to-clipboard": "5.0.2",
"react-dom": "17.0.1",
"react-dropzone": "11.2.2",
"react-dropzone": "11.2.3",
"react-ga": "3.2.0",
"react-icons": "3.11.0",
"react-modal": "3.11.2",
Expand Down Expand Up @@ -77,20 +77,20 @@
"devDependencies": {
"@types/jest": "26.0.15",
"@types/jspdf": "1.3.3",
"@types/lodash": "4.14.162",
"@types/lodash": "4.14.165",
"@types/luxon": "1.25.0",
"@types/node": "14.14.5",
"@types/node": "14.14.6",
"@types/parse5": "5.0.3",
"@types/pdfjs-dist": "2.1.5",
"@types/pdfjs-dist": "2.1.6",
"@types/qs": "6.9.5",
"@types/react": "16.9.54",
"@types/react": "16.9.56",
"@types/react-beautiful-dnd": "13.0.0",
"@types/react-copy-to-clipboard": "4.3.0",
"@types/react-dom": "16.9.9",
"@types/react-modal": "3.10.6",
"@types/react-redux": "7.1.9",
"@types/react-redux": "7.1.11",
"@types/react-router-dom": "5.1.6",
"@types/react-select": "3.0.22",
"@types/react-select": "3.0.23",
"@types/superagent": "4.1.10",
"@types/webpack-env": "1.15.3",
"babel-jest": "24.9.0",
Expand Down
Binary file added src/tests/fixtures/warscroll/pdf/Tzeentch1.pdf
Binary file not shown.
11 changes: 10 additions & 1 deletion src/tests/warscroll/warscrollPdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const getFile = (filename: string) => {
}

describe('getWarscrollArmyFromPdf', () => {
it('should correctly read Tzeentch1', () => {
const pdfText = getFile('Tzeentch1')
const parsedText = parsePdf(pdfText)
const res = getWarscrollArmyFromPdf(parsedText)
expect(res.selections.allegiances).toContain('Eternal Conflagration')
expect(res.errors).toEqual([])
})

it('should correctly read SoB3', () => {
const pdfText = getFile('SoB3')
const parsedText = parsePdf(pdfText)
Expand Down Expand Up @@ -519,7 +527,8 @@ describe('getWarscrollArmyFromPdf', () => {
})
})

it('reads Fyreslayers battalions properly', () => {
// TODO: Fix
xit('reads Fyreslayers battalions properly', () => {
const pdfText = getFile('3droth2k')
const parsedText = parsePdf(pdfText)
const res = getWarscrollArmyFromPdf(parsedText)
Expand Down
1 change: 1 addition & 0 deletions src/utils/import/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const warscrollTypoMap: TNameMap = {
'Dabbling in Sorcery': 'Dabblings in Sorcery (Anvilgard Battle Trait)',
'Dark Wizardy': 'Dark Wizardry (Royalty)',
'Devoted Desciples': 'Devoted Disciples',
'Eternal Conflaguration': 'Eternal Conflagration',
'Ethereal Blessing': 'Etheral Blessings',
'Evocators on Dracolines': 'Evocators on Celestial Dracolines',
'Exalted Deathbringer with Impaling Spear': 'Exalted Deathbringer',
Expand Down
32 changes: 24 additions & 8 deletions src/utils/warscroll/getWarscrollArmy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import GenericScenery from 'army/generic/scenery'
import { SeraphonConstellations } from 'army/seraphon/allegiances'
import CommonSonsOfBehematData from 'army/sons_of_behemat/common'
import { last, uniq } from 'lodash'
import { getArmyList } from 'meta/army_list'
import { TSupportedFaction } from 'meta/factions'
import { IImportedArmy, WARSCROLL_BUILDER } from 'types/import'
import { importErrorChecker } from 'utils/import'
Expand All @@ -15,6 +16,12 @@ export const getWarscrollArmyFromPdf = (pdfText: string[]): IImportedArmy => {
return errorChecked
}

const getAllegianceTypes = () => {
return Object.values(getArmyList())
.map(v => (v.Army?.AllegianceType || '').replace(/s$/, '')) // Remove trailing s
.filter(x => !!x)
}

const unitIndicatorsPdf = [
'Artillery',
'Leaders',
Expand All @@ -31,6 +38,8 @@ const getInitialWarscrollArmyPdf = (pdfText: string[]): IImportedArmy => {
const cleanedText = cleanWarscrollText(pdfText)
const genericScenery = GenericScenery.map(x => x.name)

const allegianceTypes = getAllegianceTypes()

let allyUnits: string[] = []
let factionName = ''
let origin_realm: string | null = null
Expand Down Expand Up @@ -116,14 +125,6 @@ const getInitialWarscrollArmyPdf = (pdfText: string[]): IImportedArmy => {
return accum
}

if (txt.startsWith('- Lodge: ')) {
const allegiance = txt.replace('- Lodge: ', '').trim()
if (allegiance) {
accum.allegiances = accum.allegiances.concat(allegiance)
return accum
}
}

if (txt.startsWith('- Additional Footnote: ')) {
const trait = txt.replace('- Additional Footnote: ', '').trim()
if (trait) {
Expand Down Expand Up @@ -221,6 +222,21 @@ const getInitialWarscrollArmyPdf = (pdfText: string[]): IImportedArmy => {
accum.traits = accum.traits.concat(trait)
return accum
}

// Handle allegiances programmatically
let stop = false
allegianceTypes.forEach(t => {
if (!stop) return
if (txt.startsWith(`- ${t}: `)) {
const allegiance = txt.replace(`- ${t}: `, '').trim()
if (allegiance && allegiance !== 'None') {
accum.allegiances = accum.allegiances.concat(allegiance)
stop = true
}
}
})
if (stop) return accum

if (txt.startsWith('- Artefact : ')) {
const { trait: artifact, spell } = getTraitWithSpell('Artefact', txt)
accum.artifacts = accum.artifacts.concat(artifact)
Expand Down
77 changes: 41 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,10 @@
dependencies:
prop-types "^15.7.2"

"@stripe/stripe-js@1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@stripe/stripe-js/-/stripe-js-1.10.0.tgz#d93c2431c9253cb676219c8442f705416c374a19"
integrity sha512-NMizRRaZNwIP6LIUA13Ow8D63v7m0CeSJrxE5JUdC6A1PGRHRKW5zkS22sMAY3l6n0sqlnoVesZ3xJQC7/rF3w==
"@stripe/stripe-js@1.11.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@stripe/stripe-js/-/stripe-js-1.11.0.tgz#00e812d72a7760dae08237875066d263671478ee"
integrity sha512-SDNZKuETBEVkernd1tq8tL6wNfVKrl24Txs3p+4NYxoaIbNaEO7mrln/2Y/WRcQBWjagvhDIM5I6+X1rfK0qhQ==

"@svgr/babel-plugin-add-jsx-attribute@^4.2.0":
version "4.2.0"
Expand Down Expand Up @@ -1857,10 +1857,10 @@
resolved "https://registry.yarnpkg.com/@types/jspdf/-/jspdf-1.3.3.tgz#6940e892da69fdbe0969b742c6bdd9e4c5da320b"
integrity sha512-DqwyAKpVuv+7DniCp2Deq1xGvfdnKSNgl9Agun2w6dFvR5UKamiv4VfYUgcypd8S9ojUyARFIlZqBrYrBMQlew==

"@types/[email protected].162":
version "4.14.162"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.162.tgz#65d78c397e0d883f44afbf1f7ba9867022411470"
integrity sha512-alvcho1kRUnnD1Gcl4J+hK0eencvzq9rmzvFPRmP5rPHx9VVsJj6bKLTATPVf9ktgv4ujzh7T+XWKp+jhuODig==
"@types/[email protected].165":
version "4.14.165"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.165.tgz#74d55d947452e2de0742bad65270433b63a8c30f"
integrity sha512-tjSSOTHhI5mCHTy/OOXYIhi2Wt1qcbHmuXD1Ha7q70CgI/I71afO4XtLb/cVexki1oVYchpul/TOuu3Arcdxrg==

"@types/[email protected]":
version "1.25.0"
Expand All @@ -1877,10 +1877,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1"
integrity sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==

"@types/[email protected].5":
version "14.14.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.5.tgz#e92d3b8f76583efa26c1a63a21c9d3c1143daa29"
integrity sha512-H5Wn24s/ZOukBmDn03nnGTp18A60ny9AmCwnEcgJiTgSGsCO7k+NWP7zjCCbhlcnVCoI+co52dUAt9GMhOSULw==
"@types/[email protected].6":
version "14.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==

"@types/parse-json@^4.0.0":
version "4.0.0"
Expand All @@ -1892,10 +1892,10 @@
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-5.0.3.tgz#e7b5aebbac150f8b5fdd4a46e7f0bd8e65e19109"
integrity sha512-kUNnecmtkunAoQ3CnjmMkzNU/gtxG8guhi+Fk2U/kOpIKjIMKnXGp4IJCgQJrXSgMsWYimYG4TGjz/UzbGEBTw==

"@types/[email protected].5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@types/pdfjs-dist/-/pdfjs-dist-2.1.5.tgz#98d7c8796919828bbdcdf364ca6bf82105b9246e"
integrity sha512-/vs9nLI/BYNo1pobKR5oEucEEcMgd8Mx1nByPNR3QhTboBwdDreQ0fHYXrGRtK3cShDDrVdApL0KhMckMuKSHw==
"@types/[email protected].6":
version "2.1.6"
resolved "https://registry.yarnpkg.com/@types/pdfjs-dist/-/pdfjs-dist-2.1.6.tgz#58e2372d6e65f1d59b1ec3632eb2ac34e36622f7"
integrity sha512-atQ3Dqgc3uKjNu9lCW/G7jhl875iXVErkSWoH8gEqMEpHP+GSuhkxAEaEImZCefeolz1tvWNGcZ/0/jCaVM9EQ==

"@types/prop-types@*":
version "15.7.3"
Expand Down Expand Up @@ -1947,10 +1947,10 @@
dependencies:
"@types/react" "*"

"@types/[email protected].9":
version "7.1.9"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.9.tgz#280c13565c9f13ceb727ec21e767abe0e9b4aec3"
integrity sha512-mpC0jqxhP4mhmOl3P4ipRsgTgbNofMRXJb08Ms6gekViLj61v1hOZEKWDCyWsdONr6EjEA6ZHXC446wdywDe0w==
"@types/[email protected].11":
version "7.1.11"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.11.tgz#a18e8ab3651e8e8cc94798934927937c66021217"
integrity sha512-OjaFlmqy0CRbYKBoaWF84dub3impqnLJUrz4u8PRjDzaa4n1A2cVmjMV81shwXyAD5x767efhA8STFGJz/r1Zg==
dependencies:
"@types/hoist-non-react-statics" "^3.3.0"
"@types/react" "*"
Expand All @@ -1974,10 +1974,10 @@
"@types/history" "*"
"@types/react" "*"

"@types/[email protected].22":
version "3.0.22"
resolved "https://registry.yarnpkg.com/@types/react-select/-/react-select-3.0.22.tgz#b88306365e99fa86809a5c0ce0f1b4e8d0b626bf"
integrity sha512-fqgmC979JPr/6476Pau6QnmI9zVV664R7Q92Ld1rgTn+umtUXT5X3+PO/x6O4imCZnh7XCqZcouabWAlAQJNpQ==
"@types/[email protected].23":
version "3.0.23"
resolved "https://registry.yarnpkg.com/@types/react-select/-/react-select-3.0.23.tgz#67fa25e3305e682d680058542a634964ef44af94"
integrity sha512-WrXjixjHlDfG4kSwasQZvZXD+hPamNTvJYWYb5TAt3hwhVg+4imNMPdUTDQhrGrCHIeKUc5h+syGCylnw30Suw==
dependencies:
"@types/react" "*"
"@types/react-dom" "*"
Expand All @@ -1998,10 +1998,10 @@
"@types/prop-types" "*"
csstype "^3.0.2"

"@types/[email protected].54":
version "16.9.54"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.54.tgz#140280c31825287ee74e9da95285b91c5a2e471d"
integrity sha512-GhawhYraQZpGFO2hVMArjPrYbnA/6+DS8SubK8IPhhVClmKqANihsRenOm5E0mvqK0m/BKoqVktA1O1+Xvlz9w==
"@types/[email protected].56":
version "16.9.56"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.56.tgz#ea25847b53c5bec064933095fc366b1462e2adf0"
integrity sha512-gIkl4J44G/qxbuC6r2Xh+D3CGZpJ+NdWTItAPmZbR5mUS+JQ8Zvzpl0ea5qT/ZT3ZNTUcDKUVqV3xBE8wv/DyQ==
dependencies:
"@types/prop-types" "*"
csstype "^3.0.2"
Expand Down Expand Up @@ -3861,16 +3861,21 @@ core-js-pure@^3.0.0:
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.6.5.tgz#c79e75f5e38dbc85a662d91eea52b8256d53b813"
integrity sha512-lacdXOimsiD0QyNf9BC/mxivNJ/ybBGJXQFKzRekp1WTHoVUWsUHEn+2T8GJAzzIhyOuXA+gOxCVN3l+5PLPUA==

core-js@3.6.5, core-js@^3.5.0, core-js@^3.6.5:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==
core-js@3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.7.0.tgz#b0a761a02488577afbf97179e4681bf49568520f"
integrity sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA==

core-js@^2.4.0:
version "2.6.11"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c"
integrity sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==

core-js@^3.5.0, core-js@^3.6.5:
version "3.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==

[email protected], core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -9998,10 +10003,10 @@ [email protected]:
object-assign "^4.1.1"
scheduler "^0.20.1"

[email protected].2:
version "11.2.2"
resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-11.2.2.tgz#7324620b8b5a7f18a455a169af7339b896f26ce1"
integrity sha512-KmnJVhrg4sOmp8nE+5j7SKwoAhUyvk2i2PcEdPaQKGTAq3k5shn/V36/hRX96iKo5fWVHUQNeRWB6DlHrpSp1Q==
[email protected].3:
version "11.2.3"
resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-11.2.3.tgz#8a49e9fc7ab75eaccf748c382a790092c035cef1"
integrity sha512-D99BhHm7H1h7ztUH/FLDo4wDy7VzXMbHoS/tUZHtoaY37Y55uadq0kUKqoaJ8PXl+niqdb5t6GankuEaAL6Vwg==
dependencies:
attr-accept "^2.2.1"
file-selector "^0.2.2"
Expand Down

0 comments on commit 377b2e0

Please sign in to comment.