Skip to content

Commit

Permalink
Optolith 1.51
Browse files Browse the repository at this point in the history
  • Loading branch information
Plushtoast committed Dec 2, 2023
1 parent 6d049a3 commit 41c3498
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
notes.md
modules/data/predata
modules/data/moddata
modules/data/test
modules/data/modr20
modules/data/modr20
modules/data/delID
3 changes: 2 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Optolith": {
"hint1": "Importiere einen Optolith Charakter per JSON.",
"hint2": "Dieser Vorgang versucht alle Fähigkeiten und Zauber aus der Bibliothek in den Charakter zu importieren. Der Charakter wird in den Ordner Optolith importiert. Es werden keine Fähigkeiten oder Gegenstände neu erstellt."
"hint2": "Dieser Vorgang versucht alle Fähigkeiten und Zauber aus der Bibliothek in den Charakter zu importieren. Der Charakter wird in den Ordner Optolith importiert. Es werden keine Fähigkeiten oder Gegenstände neu erstellt.",
"notFound": "{type} <b>{name}</b> nicht gefunden. Bitte manuel hinzufügen"
},
"TYPES.Item.none": "Keine Fehler"
}
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Optolith": {
"hint1": "Import a Optolith character via JSON.",
"hint2": "This process tries to import all abilities and spells from the library into the character. The character is imported into the Optolith folder."
"hint2": "This process tries to import all abilities and spells from the library into the character. The character is imported into the Optolith folder.",
"notFound": "{type} <b>{name}</b> not found. Please add manually"
},
"TYPES.Item.none": "No errors"
}
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"title": "The Dark Eye 5th Ed. - Optolith Connector",
"description": "Import heros created with the famous <a href=\"https://optolith.app\" target=\"_blank\">Optolith</a> character generator into Foundry VTT.",
"version": "5.2.1",
"version": "5.2.2",
"url": "https://github.com/Plushtoast/dsa5-optolith",
"manifest": "https://raw.githubusercontent.com/Plushtoast/dsa5-optolith/main/module.json",
"download": "https://github.com/Plushtoast/dsa5-optolith/releases/download/5.2.1/dsa5-optolith-5.2.1.zip",
"download": "https://github.com/Plushtoast/dsa5-optolith/releases/download/5.2.2/dsa5-optolith-5.2.2.zip",
"languages": [{
"lang": "de",
"name": "Deutsch",
Expand Down
2 changes: 1 addition & 1 deletion modules/data/ids/de/odata.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/data/ids/en/odata.json

Large diffs are not rendered by default.

114 changes: 52 additions & 62 deletions modules/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export default class OptolithParser extends Application {
return (await (await fetch(`./modules/dsa5-optolith/modules/data/ids/${game.i18n.lang}/${file}.json`)).json())
}

pushError(errors, type, id) {
if(!errors[type])
errors[type] = []

errors[type].push(game.i18n.format('Optolith.notFound', {
type: game.i18n.localize(`TYPES.Item.${type}`),
name: id
}))
}

async parse() {
const folder = await game.dsa5.apps.DSA5_Utility.getFolderForType("Actor", null, "Optolith")
const errors = {}
Expand Down Expand Up @@ -90,10 +100,7 @@ export default class OptolithParser extends Application {
}
})
} else {
if(!errors["species"])
errors["species"] = []

errors["species"].push(`${species} not found in library. Please add it manually.`)
this.pushError(errors, "species", species)
}

const attrs = ["mu", "kl", "in", "ch", "ff", "ge", "ko", "kk"]
Expand All @@ -116,10 +123,7 @@ export default class OptolithParser extends Application {
}
})
} else {
if(!errors["skill"])
errors["skill"] = []

errors["skill"].push(`${talents[id]} (${id}: ${value}) not found`)
this.pushError(errors, "skill", `${talents[id]} (${id}: ${value})`)
}
}
for(let [id, value] of Object.entries(this.json.ct)) {
Expand All @@ -133,10 +137,7 @@ export default class OptolithParser extends Application {
}
})
} else {
if(!errors["combatskill"])
errors["combatskill"] = []

errors["combatskill"].push(`${combatskills[id]} (${id}: ${value}) not found`)
this.pushError(errors, "combatskill", `${combatskills[id]} (${id}: ${value})`)
}
}

Expand All @@ -158,24 +159,22 @@ export default class OptolithParser extends Application {
}

if(spell) {
const find = (await game.dsa5.itemLibrary.findCompendiumItem(spell, isSpell))
let find = (await game.dsa5.itemLibrary.findCompendiumItem(spell, isSpell))
.find(x => x.type == (isSpell))

if(!find)
find = (await game.dsa5.itemLibrary.findCompendiumItem(spell, "ritual"))
.find(x => x.type == "ritual")

if(find) {
const obj = find.toObject()
obj.system.talentValue.value = value
itemCreations.push(obj)
}else {
if(!errors[isSpell])
errors[isSpell] = []

errors[isSpell].push(`${spell} not found in library. Please add it manually.`)
this.pushError(errors, isSpell, spell)
}
} else {
if(!errors["spell"])
errors["spell"] = []

errors["spell"].push(`${id}: ${value} not found`)
this.pushError(errors, "spell", `${id}: ${value}`)
}
}
}
Expand All @@ -199,16 +198,10 @@ export default class OptolithParser extends Application {
obj.system.talentValue.value = value
itemCreations.push(obj)
}else {
if(!errors["liturgy"])
errors["liturgy"] = []

errors["liturgy"].push(`${spell} not found in library. Please add it manually.`)
this.pushError(errors, "liturgy", spell)
}
} else {
if(!errors["liturgy"])
errors["liturgy"] = []

errors["liturgy"].push(`${id}: ${value} not found`)
this.pushError(errors, "liturgy", `${id}: ${value}`)
}
}
}
Expand All @@ -227,16 +220,10 @@ export default class OptolithParser extends Application {
const obj = find.toObject()
itemCreations.push(obj)
}else {
if(!errors["magictrick"])
errors["magictrick"] = []

errors["magictrick"].push(`${spell} not found in library. Please add it manually.`)
this.pushError(errors, "magictrick", spell)
}
} else {
if(!errors["magictrick"])
errors["magictrick"] = []

errors["magictrick"].push(`${id} not found`)
this.pushError(errors, "magictrick", id)
}
}
}
Expand All @@ -254,16 +241,10 @@ export default class OptolithParser extends Application {
const obj = find.toObject()
itemCreations.push(obj)
}else {
if(!errors["blessing"])
errors["blessing"] = []

errors["blessing"].push(`${spell} not found in library. Please add it manually.`)
this.pushError(errors, "blessing", spell)
}
} else {
if(!errors["blessing"])
errors["blessing"] = []

errors["blessing"].push(`${id} not found`)
this.pushError(errors, "blessing", id)
}
}
}
Expand Down Expand Up @@ -293,6 +274,26 @@ export default class OptolithParser extends Application {
}
}

if(["SA_663", "SA_414"].includes(id)) {
const type = id == "SA_663" ? "liturgyenhancements" : "spellenhancements"
const enhancement = oData[type][val.sid]

if(enhancement) {
const find = (await game.dsa5.itemLibrary.findCompendiumItem(enhancement, "spellextension"))
.find(x => x.type == "spellextension")

if(find) {
const obj = find.toObject()
itemCreations.push(obj)
}else {
this.pushError(errors, "spellextension", enhancement)
}
} else {

}
continue
}

let ability = source[type][searchId]

if(ability) {
Expand All @@ -316,24 +317,15 @@ export default class OptolithParser extends Application {

itemCreations.push(obj)
}else {
if(!errors[type])
errors[type] = []

errors[type].push(`${ability} not found in library. Please add it manually.`)
this.pushError(errors, type, ability)
}

} else {
if(!errors[type])
errors[type] = []

errors[type].push(`${id}: ${val} not found`)
this.pushError(errors, type, `${id}: ${JSON.stringify(val)}`)
}
}
} else {
if(!errors["specialability"])
errors["specialability"] = []

errors["specialability"].push(`${id}: ${value} not found`)
this.pushError(errors, "specialability", `${id}: ${JSON.stringify(value)}`)
}
}
}
Expand All @@ -360,7 +352,8 @@ export default class OptolithParser extends Application {
3: "ammunition",
4: "armor",
21: "poison",
20: "consumable"
20: "consumable",
22: "plant"
}[item.gr] || "equipment"

const find = (await game.dsa5.itemLibrary.findCompendiumItem(item.name, type))
Expand All @@ -371,10 +364,7 @@ export default class OptolithParser extends Application {
obj.system.quantity.value = item.amount
itemCreations.push(obj)
}else {
if(!errors[type])
errors[type] = []

errors[type].push(`${item.name} not found in library. Please add it manually.`)
this.pushError(errors, type, item.name)
}
}

Expand Down

0 comments on commit 41c3498

Please sign in to comment.