From a97732833f03d80e3fd7c36481bd84b7800aeb77 Mon Sep 17 00:00:00 2001 From: Melon-PieldeSapo Date: Wed, 11 Dec 2024 16:17:17 +0100 Subject: [PATCH] WIP: create class-shet.js and first aproach for skills on class --- lang/en.json | 13 ++- module/actor/actor-sheet.js | 2 +- module/item/class-sheet.js | 85 +++++++++++++++++++ module/mosh.js | 15 +++- module/windows/actor-generator.js | 39 +++++---- templates/dialogs/actor-generator-dialog.html | 12 ++- templates/item/item-class-sheet.html | 66 +++++++++----- 7 files changed, 188 insertions(+), 44 deletions(-) create mode 100644 module/item/class-sheet.js diff --git a/lang/en.json b/lang/en.json index 7fce549..277f8f9 100644 --- a/lang/en.json +++ b/lang/en.json @@ -20,9 +20,14 @@ "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.CharacterGenerator.name": "Character Generator", +"Mosh.CharacterGenerator.StatOption":"Stats & Saves", +"Mosh.CharacterGenerator.StatOptionPopupTitle": "Class Attribute and Saves option", +"Mosh.CharacterGenerator.StatOptionPopupText":"Choose where to apply the bonus of:", +"Mosh.CharacterGenerator.Tables":"Tables", +"Mosh.CharacterGenerator.Table.Loadout":"Loadout Table", +"Mosh.CharacterGenerator.Table.Patch":"Patch Table", +"Mosh.CharacterGenerator.Table.Trinket":"Trinket Table", "Mosh.CLASS": "CLASS", "Mosh.Combat": "Combat", "Mosh.Condition": "Condition", @@ -110,6 +115,8 @@ "Mosh.SkillName": "Skill Name", "Mosh.SkillRank": "Skill Rank", "Mosh.Skills": "Skills", +"Mosh.SkillsFixed": "Fixed Skills", +"Mosh.SkillsOptional": "Optional Skills", "Mosh.SkillTraining": "Skill Training", "Mosh.SpecialAbilities": "Special Abilities", "Mosh.Speed": "Speed", diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index b15cde2..29f33eb 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: game.i18n.localize("Mosh.CharacterGenerator"), + label: game.i18n.localize("Mosh.CharacterGenerator.name"), class: 'configure-actor', icon: 'fas fa-cogs', onclick: (ev) => this._onConfigureCreature(ev), diff --git a/module/item/class-sheet.js b/module/item/class-sheet.js new file mode 100644 index 0000000..a1cdfa0 --- /dev/null +++ b/module/item/class-sheet.js @@ -0,0 +1,85 @@ +/** + * Extend the basic MothershipItemSheet with class modification + * @extends {MothershipItemSheet} + */ +import { MothershipItemSheet } from "./item-sheet.js"; +export class MothershipClassSheet extends MothershipItemSheet { + + /** @override */ + static get defaultOptions() { + var options = { + classes: ["mosh", "sheet", "item"], + width: 820, + height: 820, + tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }] + }; + options.dragDrop = [{dragSelector: null, dropSelector: ".dropitem"}]; + + if (game.release.generation >= 12) { + return foundry.utils.mergeObject(super.defaultOptions, options); + } else { + return mergeObject(super.defaultOptions, options); + } + } + + + /** @override */ + getData() { + const data = super.getData(); + if (typeof data.system.base_adjustment.skills_granted == 'undefined'){ + data.system.base_adjustment.skills_granted=[]; + } + return data; + } + + async _onDrop(event){ + await super._onDrop(event); + const droppedUuid = TextEditor.getDragEventData(event); + if (droppedUuid.type != "Item"){ + return; + } + const droppedObject = await fromUuid(droppedUuid.uuid); + if (droppedObject.type == "skill"){ + //this.object.system.base_adjustment.skills_granted.push(droppedObject); + let skills = this.object.system.base_adjustment.skills_granted; + skills.push(droppedObject); + this.object.update({"system.base_adjustment.skills_granted":skills}); + return this.render(false); + } + } + + + /** @override */ + activateListeners(html) { + super.activateListeners(html); + + // Delete Inventory Item + html.find('.item-delete').click(ev => { + const li = $(ev.currentTarget).parents(".item"); + + let skills = this.object.system.base_adjustment.skills_granted.filter(function( obj ) { + return obj._id !== li.data("itemId"); + }); + this.object.update({"system.base_adjustment.skills_granted":skills}); + return this.render(false); + }); + + + } + /**** + async _updateObject(event, formData) { + const item = this.object; + + var updateData; + if (game.release.generation >= 12) { + updateData = foundry.utils.expandObject(formData); + } else { + updateData = expandObject(formData); + } + + await item.update(updateData, { + diff: false + }); + }*/ +} + diff --git a/module/mosh.js b/module/mosh.js index fac2334..dba7210 100644 --- a/module/mosh.js +++ b/module/mosh.js @@ -7,6 +7,8 @@ import { MothershipShipSheetSBT } from "./actor/ship-sheet-sbt.js"; import { MothershipItem } from "./item/item.js"; import { MothershipItemSheet } from "./item/item-sheet.js"; +import { MothershipClassSheet } from "./item/class-sheet.js"; + import { registerSettings } from "./settings.js"; @@ -65,7 +67,18 @@ Hooks.once('init', async function () { }); Items.unregisterSheet("core", ItemSheet); - Items.registerSheet("mosh", MothershipItemSheet, { makeDefault: true }); + Items.registerSheet("mosh", MothershipClassSheet, {types: ['class'], makeDefault: true }); + Items.registerSheet("mosh", MothershipItemSheet, { + types: ["item", + "skill", + "weapon", + "armor", + "ability", + "module", + "condition", + "crew", + "repair",], + makeDefault: true }); // If you need to add Handlebars helpers, here are a few useful examples: Handlebars.registerHelper('concat', function () { diff --git a/module/windows/actor-generator.js b/module/windows/actor-generator.js index df8dc22..7fb2587 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}: ${game.i18n.localize("Mosh.CharacterGenerator")}`; + return `${this.object.name}: ${game.i18n.localize("Mosh.CharacterGenerator.name")}`; } /* -------------------------------------------- */ @@ -189,7 +189,8 @@ export class DLActorGenerator extends FormApplication { this.patchTable = droppedObject.system.roll_tables.patch; this.loadoutTable = droppedObject.system.roll_tables.loadout; - try{ + // Skills + //try{ //let skills = JSON.parse(droppedObject.system.skills.replaceAll("

","").replaceAll("

","").replaceAll("
","").replaceAll("
","").replaceAll(" ","")); let skillsUuid = []; @@ -197,28 +198,31 @@ export class DLActorGenerator extends FormApplication { 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 skill = fixed_skills[i]; + /**we need to keep only the Uuid of the item, not the complete string (for now) */ + skillsUuid.push(skill._id); + let li_html = `
  • ${await TextEditor.enrichHTML(skill.name, {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."); - } + //}catch{ + // ui.notifications.error("Class has invalid skills configuration."); + //} - try{ + //Stats + ///try{ //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 sets all the bonuses of base_adjustment including max_wounds this._element.find(`input[name="system.stats.${key}.bonus"]`).prop("value",value); }); @@ -233,8 +237,8 @@ export class DLActorGenerator extends FormApplication { }; } let d = new Dialog({ - title: game.i18n.localize("Mosh.CharacterGeneratorStatOptionPopupTitle"), - content: `

    ${ game.i18n.localize("Mosh.CharacterGeneratorStatOptionPopupTitle")} (${option_stats_and_saves.modification})

    `, + title: game.i18n.localize("Mosh.CharacterGenerator.StatOptionPopupTitle"), + content: `

    ${ game.i18n.localize("Mosh.CharacterGenerator.StatOptionPopupText")} (${option_stats_and_saves.modification})

    `, buttons: buttons_options, default: "1", //render: html => console.log("Register interactivity in the rendered dialog"), @@ -269,9 +273,9 @@ export class DLActorGenerator extends FormApplication { d.render(true); } }*/ - }catch{ - ui.notifications.error("Class has invalid stats and saves configuration."); - } + //}catch{ + // ui.notifications.error("Class has invalid stats and saves configuration."); + //} //todo: add robotic flag. return; } @@ -456,7 +460,6 @@ export class DLActorGenerator extends FormApplication { if(formData["system.removepreviousitems"]){ - let itemTypesToDelete = ["item", "armor", "weapon","skill","condition"]; let itemsToDelete = this.object.items.filter(item => itemTypesToDelete.includes(item.type)); await this.object.deleteEmbeddedDocuments("Item", itemsToDelete.map(item => item.id)); diff --git a/templates/dialogs/actor-generator-dialog.html b/templates/dialogs/actor-generator-dialog.html index bfc7a9c..8891279 100644 --- a/templates/dialogs/actor-generator-dialog.html +++ b/templates/dialogs/actor-generator-dialog.html @@ -29,9 +29,17 @@ + +
    +
    {{ localize 'Mosh.Wounds'}}
    +
    + +
    +
    -
    Credits
    +
    {{ localize 'Mosh.Credits' }}
    roll @@ -124,7 +132,7 @@
    +
    - +
    diff --git a/templates/item/item-class-sheet.html b/templates/item/item-class-sheet.html index 1f54edd..6c3d42e 100644 --- a/templates/item/item-class-sheet.html +++ b/templates/item/item-class-sheet.html @@ -30,7 +30,6 @@
    -
    +
    @@ -42,7 +41,6 @@ -
    +
    @@ -54,7 +52,6 @@ -
    +
    @@ -66,7 +63,6 @@ -
    +
    @@ -101,7 +97,6 @@ -
    +
    @@ -113,7 +108,6 @@ -
    +
    @@ -125,7 +119,6 @@ -
    +
    @@ -143,10 +136,11 @@ {{!-- Sheet Tab Navigation --}} {{!-- Sheet Body --}} @@ -158,19 +152,53 @@ {{!-- stats&saves Tab --}}
    - - {{editor system.base_adjustmentandsaves target="system.base_adjustmentandsaves" button=true owner=owner editable=true}} - +
    +
    + {{ localize 'Mosh.Value' }} +
    + +
    +
    + todo: editor to add or SELECT the optional stats +
    {{!-- skills Tab --}} -
    - {{editor enriched.skills target="system.skills" button=true owner=owner editable=true}} +
    + + +
      +
    1. +
      +
      {{ localize 'Mosh.SkillName' }}
      +
      {{ localize 'Mosh.SkillRank' }}
      +
      {{ localize 'Mosh.SkillBonus' }}
      +
      +
      +
    2. + {{#each system.base_adjustment.skills_granted as |skill id|}} +
    3. +
      +
      {{skill.name}}
      +
      {{skill.system.rank}}
      +
      {{skill.system.bonus}}
      +
      + +
      +
    4. + {{/each}} +
    + +
    +
    + +
    - +
    - +
    - +