diff --git a/lang/en.json b/lang/en.json index 38515df..7fce549 100644 --- a/lang/en.json +++ b/lang/en.json @@ -20,6 +20,9 @@ "Mosh.Calm": "Calm", "Mosh.Cargo": "Cargo", "Mosh.CarryingCapacity": "Carrying Capacity", +"Mosh.CharacterGenerator": "Character Generator", +"Mosh.CharacterGeneratorStatOptionPopupTitle": "Class Attribute and Saves option", +"Mosh.CharacterGeneratorStatOptionPopupText":"Choose where to apply the bonus of:", "Mosh.CLASS": "CLASS", "Mosh.Combat": "Combat", "Mosh.Condition": "Condition", @@ -28,6 +31,7 @@ "Mosh.CreateItem": "Create Item", "Mosh.CreateSkill": "Create Skill", "Mosh.CreateWeapon": "Create Weapon", +"Mosh.CreatureSettings": "Creature Settings", "Mosh.Credits": "Credits", "Mosh.Crew": "Crew", "Mosh.CriticalDamage": "Critical Damage", diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index c3a6679..b15cde2 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -643,7 +643,7 @@ export class MothershipActorSheet extends ActorSheet { const canConfigure = game.user.isGM || this.actor.isOwner; if (this.options.editable && canConfigure) { buttons = [{ - label: 'Character Generator', + label: game.i18n.localize("Mosh.CharacterGenerator"), class: 'configure-actor', icon: 'fas fa-cogs', onclick: (ev) => this._onConfigureCreature(ev), diff --git a/module/actor/creature-sheet.js b/module/actor/creature-sheet.js index de9018b..6ecdb21 100644 --- a/module/actor/creature-sheet.js +++ b/module/actor/creature-sheet.js @@ -32,7 +32,7 @@ export class MothershipCreatureSheet extends ActorSheet { const canConfigure = game.user.isGM || this.actor.isOwner; if (this.options.editable && canConfigure) { buttons = [{ - label: 'Creature Settings', + label: game.i18n.localize("Mosh.CreatureSettings"), class: 'configure-actor', icon: 'fas fa-tasks', onclick: (ev) => this._onConfigureCreature(ev), diff --git a/module/windows/actor-generator.js b/module/windows/actor-generator.js index 7c37418..51c2b40 100644 --- a/module/windows/actor-generator.js +++ b/module/windows/actor-generator.js @@ -15,7 +15,7 @@ export class DLActorGenerator extends FormApplication { * @type {String} */ get title() { - return `${this.object.name}: Character Generator`; + return `${this.object.name}: ${game.i18n.localize("Mosh.CharacterGenerator")}`; } /* -------------------------------------------- */ @@ -23,12 +23,29 @@ export class DLActorGenerator extends FormApplication { * Construct and return the data object used to render the HTML template for this form application. * @return {Object} */ - getData() { + async getData() { //if (this.object.system.class.uuid != null){ // this.updateClass(this.object.system.class.uuid); //} let data=this.object; data.class_options = game.items.filter(i => i.type=="class"); + + let compendium = game.packs; + //loop through each compendium + //TODO: this is not working, the page is rendered before this data is retrieved. + //maybe have it as a triget on ready and manualy/hard replace the html selector ¿? + await compendium.forEach(async function(pack){ + //is this a pack of items? + if (pack.metadata.type === 'Item') { + //get classes: + let classes = await pack.getDocuments({ type: "class" }) + //loop through class + classes.forEach(function(item) { + data.class_options.push(item); + }); + } + }); + data.system.class.value = ""; return data; } @@ -184,40 +201,64 @@ export class DLActorGenerator extends FormApplication { } this._element.find(`input[id="system.class.uuid"]`).prop("value", classUuid); - this._element.find(`input[id="system.class.traumaresponse"]`).prop("value", droppedObject.system.trauma); - this.trinketTable = droppedObject.system.TrinketTable; - this.patchTable = droppedObject.system.PatchTable; - this.loadoutTable = droppedObject.system.loadoutTable; + this._element.find(`input[id="system.class.traumaresponse"]`).prop("value", droppedObject.system.trauma_response); + this.trinketTable = droppedObject.system.roll_tables.trinket; + this.patchTable = droppedObject.system.roll_tables.patch; + this.loadoutTable = droppedObject.system.roll_tables.loadout; try{ - let skills = JSON.parse(droppedObject.system.skills.replaceAll("

","").replaceAll("

","").replaceAll("
","").replaceAll("
","").replaceAll(" ","")); + //let skills = JSON.parse(droppedObject.system.skills.replaceAll("

","").replaceAll("

","").replaceAll("
","").replaceAll("
","").replaceAll(" ","")); let skillsUuid = []; this._element.find(`ul[id="system.class.skils.text"]`).empty(); - if(skills.hasOwnProperty("fixed")){ - for (let i = 0;i${await TextEditor.enrichHTML(skillUuid, {async: true})}`; - this._element.find(`ul[id="system.class.skils.text"]`).append(li_html); - } - } - if(skills.hasOwnProperty("options")){ - for (let k in skills["options"]){ - //todo: instead of a reminder, render a selection pop-up loaded with all skils available found (compendium and items) - let li_html = skills["options"][k].join(` ${k} `); - this._element.find(`ul[id="system.class.skils.text"]`).append(`
  • ${li_html}
  • `); - } + + let fixed_skills = droppedObject.system.base_adjustment.skills_granted; + for (let i = 0;i${await TextEditor.enrichHTML(skillUuid, {async: true})}`; + this._element.find(`ul[id="system.class.skils.text"]`).append(li_html); } + + let option_skills_1 = droppedObject.system.selected_adjustment.choose_skill_and; + let option_skills_2 = droppedObject.system.selected_adjustment.choose_skill_or; + //todo: add popups to choose skils from (following the skill tree and type) + this._element.find(`input[id="system.class.skills.uuid"]`).prop("value", skillsUuid); }catch{ ui.notifications.error("Class has invalid skills configuration."); } try{ - let statsandsaves = JSON.parse(droppedObject.system.statsandsaves.replaceAll("

    ","").replaceAll("

    ","").replaceAll("
    ","").replaceAll("
    ","").replaceAll(" ","")); - + //let statsandsaves = JSON.parse(droppedObject.system.statsandsaves.replaceAll("

    ","").replaceAll("

    ","").replaceAll("
    ","").replaceAll("
    ","").replaceAll(" ","")); + let fix_stats_and_saves = droppedObject.system.base_adjustment; + delete fix_stats_and_saves["skills_granted"]; + + Object.entries(fix_stats_and_saves).forEach(([key, value]) => { + this._element.find(`input[name="system.stats.${key}.bonus"]`).prop("value",value); + }); + + //stats options + let option_stats_and_saves = droppedObject.system.selected_adjustment.choose_stat; + let buttons_options = {}; + for(let j = 0; j < option_stats_and_saves.stats.length; j++) { + buttons_options[j] = { + icon: '', + label: option_stats_and_saves.stats[j],//.replace(/\.bonus/i,"").replace(/(.*)\.+/i,""), + callback: () => this._element.find(`input[name="system.stats.${obj.options[j]}.bonus"]`).prop("value",option_stats_and_saves.modification) + }; + } + let d = new Dialog({ + title: game.i18n.localize("Mosh.CharacterGeneratorStatOptionPopupTitle"), + content: `

    ${ game.i18n.localize("Mosh.CharacterGeneratorStatOptionPopupTitle")} (${obj.value})

    `, + buttons: buttons_options, + default: "1", + //render: html => console.log("Register interactivity in the rendered dialog"), + //close: html => console.log("This always is logged no matter which option is chosen") + }); + d.render(true); + /* for(let i = 0; i < statsandsaves.length; i++) { let obj = statsandsaves[i]; @@ -244,10 +285,11 @@ export class DLActorGenerator extends FormApplication { }); d.render(true); } - } + }*/ }catch{ ui.notifications.error("Class has invalid stats and saves configuration."); } + //todo: add robotic flag. return; } @@ -366,8 +408,10 @@ export class DLActorGenerator extends FormApplication { "system.stats.fear.value": formData["system.stats.fear.value"] + (formData["system.stats.fear.bonus"] || 0), "system.stats.body.value": formData["system.stats.body.value"] + (formData["system.stats.body.bonus"] || 0), } - if (formData["system.hits.bonus"]){ - data["system.hits.max"] = 2+formData["system.hits.bonus"]; + if (formData["system.stats.max_wounds.bonus"]){ + //todo: check if max_wounds represent the total ammount or just the bonus, + //I am going to asume is the total ammount, so for android is gona be a 3, + data["system.hits.max"] = formData["system.stats.max_wounds.bonus"]; } else{ data["system.hits.max"] = 2; @@ -393,7 +437,7 @@ export class DLActorGenerator extends FormApplication { Body: ${data["system.stats.body.value"]} = ${formData["system.stats.body.value"]}+${formData["system.stats.body.bonus"]}

    Health: ${data["system.health.max"]}
    - Extra wounds: ${formData["system.hits.bonus"]}
    + Extra wounds: ${formData["system.stats.max_wounds.bonus"]}
    Credits: ${data["system.credits.value"]}

    Trinket roll:
    diff --git a/templates/dialogs/actor-generator-dialog.html b/templates/dialogs/actor-generator-dialog.html index 6968b85..e49093a 100644 --- a/templates/dialogs/actor-generator-dialog.html +++ b/templates/dialogs/actor-generator-dialog.html @@ -21,7 +21,8 @@ {{#each class_options as |class_option id|}} - + {{id}} + {{/each}} @@ -127,7 +128,7 @@
    +
    - +