diff --git a/module/actor-sheet.js b/module/actor-sheet.js index a47920e..d3f261e 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -23,34 +23,48 @@ export class SoSActorSheet extends ActorSheet { /* -------------------------------------------- */ getData() { - let data = super.getData(); - + const objectData = SoSUtility.data(this.object); + let formData = { + title: this.title, + id: objectData.id, + type: objectData.type, + img: objectData.img, + name: objectData.name, + editable: this.isEditable, + cssClass: this.isEditable ? "editable" : "locked", + data: foundry.utils.deepClone(this.object.data), + effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)), + limited: this.object.limited, + options: this.options, + owner: this.document.isOwner + }; + this.actor.checkDeck(); - data.data.edgecard = this.actor.getEdgesCard(); - data.data.deckSize = this.actor.getDeckSize(); + formData.edgecard = this.actor.getEdgesCard(); + formData.deckSize = this.actor.getDeckSize(); - data.data.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => { + formData.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => { if ( a.name > b.name ) return 1; return -1; }); - - data.data.skill1 = data.data.skills.slice(0, Math.ceil(data.data.skills.length/2) ) - data.data.skill2 = data.data.skills.slice(Math.ceil(data.data.skills.length/2), data.data.skills.length ) - data.data.consequences = this.actor.data.items.filter( item => item.type == 'consequence').sort( (a, b) => { + + formData.skill1 = formData.skills.slice(0, Math.ceil(formData.skills.length/2) ) + formData.skill2 = formData.skills.slice(Math.ceil(formData.skills.length/2), formData.skills.length ) + formData.consequences = this.actor.data.items.filter( item => item.type == 'consequence').sort( (a, b) => { if ( a.name > b.name ) return 1; return -1; }); - data.data.gears = this.actor.data.items.filter( item => item.type == 'gear').concat( this.actor.data.items.filter( item => item.type == 'container') ); + formData.gears = this.actor.data.items.filter( item => item.type == 'gear').concat( this.actor.data.items.filter( item => item.type == 'container') ); // Build the gear tree - data.data.gearsRoot = data.data.gears.filter(item => item.data.containerid == ""); - for ( let container of data.data.gearsRoot) { + formData.gearsRoot = formData.gears.filter(item => item.data.containerid == ""); + for ( let container of formData.gearsRoot) { if ( container.type == 'container') { container.data.contains = [] container.data.containerEnc = 0; for (let gear of data.data.gears) { - if ( gear.data.containerid == container._id) { + if ( gear.data.containerid == container.id) { container.data.contains.push( gear ); if ( !gear.data.neg && !gear.data.software ) { container.data.containerEnc += (gear.big > 0) ? gear.big : 1; @@ -60,25 +74,25 @@ export class SoSActorSheet extends ActorSheet { } } - data.data.weapons = this.actor.data.items.filter( item => item.type == 'weapon'); - data.data.armors = this.actor.data.items.filter( item => item.type == 'armor'); - data.data.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.data.items); - data.data.wounds = duplicate(this.actor.data.data.wounds); - data.data.isGM = game.user.isGM; - data.data.currentWounds = this.actor.computeCurrentWounds(); - data.data.totalWounds = this.actor.data.data.scores.wound.value; + formData.weapons = this.actor.data.items.filter( item => item.type == 'weapon'); + formData.armors = this.actor.data.items.filter( item => item.type == 'armor'); + formData.totalEncumbrance = SoSUtility.computeEncumbrance(this.actor.data.items); + formData.wounds = duplicate(this.actor.data.data.wounds); + formData.isGM = game.user.isGM; + formData.currentWounds = this.actor.computeCurrentWounds(); + formData.totalWounds = this.actor.data.data.scores.wound.value; - data.data.subcultureList = this.actor.data.items.filter( item => item.type == 'subculture'); - if ( data.data.subculture != "" ) { // background.subculture contains the main subculture ID - data.data.mainSubculture = data.data.subcultureList.find( subc => subc._id == data.data.subculture); + formData.subcultureList = this.actor.data.items.filter( item => item.type == 'subculture'); + if ( formData.subculture != "" ) { // background.subculture contains the main subculture ID + formData.mainSubculture = formData.subcultureList.find( subc => subc._id == data.data.subculture); } - data.data.languageList = this.actor.data.items.filter( item => item.type == 'language'); - data.data.weaknessList = this.actor.data.items.filter( item => item.type == 'weakness'); - data.data.geneline = this.actor.data.items.find( item => item.type == 'geneline'); - data.data.editStatSkill = this.options.editStatSkill; - //console.log("stats", data); + formData.languageList = this.actor.data.items.filter( item => item.type == 'language'); + formData.weaknessList = this.actor.data.items.filter( item => item.type == 'weakness'); + formData.geneline = this.actor.data.items.find( item => item.type == 'geneline'); + formData.editStatSkill = this.options.editStatSkill; - return data; + console.log("stats", formData); + return formData; } /* -------------------------------------------- */ @@ -94,7 +108,7 @@ export class SoSActorSheet extends ActorSheet { // Update Inventory Item html.find('.item-edit').click(ev => { const li = $(ev.currentTarget).parents(".item"); - const item = this.actor.getOwnedItem(li.data("item-id")); + const item = this.actor.items.get(li.data("item-id")); item.sheet.render(true); }); html.find('.item-equip').click(ev => { @@ -163,7 +177,7 @@ export class SoSActorSheet extends ActorSheet { const li = $(event.currentTarget).parents(".item"); const item = this.actor.getOwnedItem(li.data("item-id")); let severity = $(event.currentTarget).val(); - this.actor.updateOwnedItem( { _id: item._id, 'data.severity': severity}); + this.actor.updateOwnedItem( { id: item.id, 'data.severity': severity}); this.render(true); }); html.find('.lock-unlock-sheet').click((event) => { diff --git a/module/actor.js b/module/actor.js index f0ffc54..ce86f31 100644 --- a/module/actor.js +++ b/module/actor.js @@ -34,17 +34,19 @@ export class SoSActor extends Actor { return actor; } - data.items = []; + let items = []; let compendiumName = "foundryvtt-shadows-over-sol.skills"; if ( compendiumName ) { let skills = await SoSUtility.loadCompendium(compendiumName); - data.items = data.items.concat( skills ); + items = skills.map(i => i.toObject()); } compendiumName = "foundryvtt-shadows-over-sol.consequences"; if ( compendiumName ) { let consequences = await SoSUtility.loadCompendium(compendiumName) - data.items = data.items.concat(consequences); + items = items.concat( consequences.map(i => i.toObject()) ); } + data.items = items; + console.log(data); return super.create(data, options); } diff --git a/module/sos-main.js b/module/sos-main.js index 35fd287..d33610a 100644 --- a/module/sos-main.js +++ b/module/sos-main.js @@ -56,8 +56,8 @@ Hooks.once("init", async function () { /* -------------------------------------------- */ // Define custom Entity classes - CONFIG.Actor.entityClass = SoSActor; - CONFIG.Combat.entityClass = SoSCombat; + CONFIG.Actor.documentClass = SoSActor; + CONFIG.Combat.documentClass = SoSCombat; CONFIG.SoS = { } @@ -83,8 +83,8 @@ Hooks.once("init", async function () { function welcomeMessage() { //ChatUtility.removeMyChatMessageContaining('
'); ChatMessage.create({ - user: game.user._id, - whisper: [game.user._id], + user: game.user.id, + whisper: [game.user.id], content: `
Welcome !
` }); } diff --git a/module/sos-utility.js b/module/sos-utility.js index e5841d4..d1ccefb 100644 --- a/module/sos-utility.js +++ b/module/sos-utility.js @@ -8,7 +8,7 @@ const severity2malus = { "none": 0, "light": -1, "moderate": -2, "severe": -3, " const severity2bonus = { "none": 0, "light": 1, "moderate": 2, "severe": 3, "critical": 4}; /* -------------------------------------------- */ -export class SoSUtility extends Entity { +export class SoSUtility { /* -------------------------------------------- */ static async preloadHandlebarsTemplates() { @@ -55,6 +55,32 @@ export class SoSUtility extends Entity { } } + /* -------------------------------------------- */ + static data(it) { + if (it instanceof Actor || it instanceof Item || it instanceof Combatant) { + return it.data; + } + return it; + } + + + /* -------------------------------------------- */ + static templateData(it) { + return SoSUtility.data(it)?.data ?? {} + } + + /* -------------------------------------------- */ + static async loadCompendiumData(compendium) { + const pack = game.packs.get(compendium); + return await pack?.getDocuments() ?? []; + } + + /* -------------------------------------------- */ + static async loadCompendium(compendium, filter = item => true) { + let compendiumData = await SoSUtility.loadCompendiumData(compendium); + return compendiumData.filter(filter); + } + /* -------------------------------------------- */ static async loadCompendiumNames(compendium) { const pack = game.packs.get(compendium); @@ -64,13 +90,13 @@ export class SoSUtility extends Entity { } /* -------------------------------------------- */ - static async loadCompendium(compendium, filter = item => true) { + /*static async loadCompendium(compendium, filter = item => true) { let compendiumItems = await SoSUtility.loadCompendiumNames(compendium); const pack = game.packs.get(compendium); let list = []; for (let compendiumItem of compendiumItems) { - await pack.getEntity(compendiumItem._id).then(it => { + await pack.getEntity(compendiumItem.id).then(it => { const item = it.data; if (filter(item)) { list.push(item); @@ -78,7 +104,7 @@ export class SoSUtility extends Entity { }); }; return list; - } + }*/ /* -------------------------------------------- */ static updateCombat(combat, round, diff, id) { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 63126aa..1b441f9 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -5,8 +5,8 @@
- -

+ +

@@ -28,8 +28,8 @@
lock/unlock{{#if data.editStatSkill}}Lock{{else}}Unlock{{/if}} + src="systems/foundryvtt-shadows-over-sol/img/icons/{{#if editStatSkill}}unlocked.svg{{else}}locked.svg{{/if}}" alt="lock/unlock" + >{{#if editStatSkill}}Lock{{else}}Unlock{{/if}}
  • Stat name @@ -37,7 +37,7 @@ XP
  • - {{#each data.stats as |stat key|}} + {{#each data.data.stats as |stat key|}} {{#if stat.isLevelUp}}
  • @@ -48,12 +48,12 @@
  • {{/if}} {{localize stat.label}} - {{#select stat.value}} {{>"systems/foundryvtt-shadows-over-sol/templates/stat-option-list.html"}} {{/select}} - +
  • {{/each}} @@ -66,14 +66,14 @@ Value Bonus/Malus - {{#each data.scores as |score key|}} + {{#each data.data.scores as |score key|}}
  • {{localize score.label}} - + {{#if (eq key 'defense')}} - + {{/if}} - +
  • {{/each}}
@@ -81,7 +81,7 @@
-

Current deck size : {{data.deckSize}} cards

+

Current deck size : {{deckSize}} cards

Reset full deck and edges Draw a new Edge card @@ -90,7 +90,7 @@

Edge cards :

- {{#each data.edgecard as |card key|}} + {{#each edgecard as |card key|}}
Discard @@ -106,8 +106,8 @@
lock/unlock{{#if data.editStatSkill}}Lock{{else}}Unlock{{/if}} + src="systems/foundryvtt-shadows-over-sol/img/icons/{{#if editStatSkill}}unlocked.svg{{else}}locked.svg{{/if}}" alt="lock/unlock" + >{{#if editStatSkill}}Lock{{else}}Unlock{{/if}}
Skills @@ -115,11 +115,11 @@
    - {{#each data.skill1 as |skill key|}} + {{#each skill1 as |skill key|}} {{#if skill.data.isLevelUp}} -
  • +
  • {{else}} -
  • +
  • {{/if}} {{#if skill.data.isLevelUp}} @@ -143,11 +143,11 @@
      - {{#each data.skill2 as |skill key|}} + {{#each skill2 as |skill key|}} {{#if skill.data.isLevelUp}} -
    • +
    • {{else}} -
    • +
    • {{/if}} {{#if skill.data.isLevelUp}} @@ -174,24 +174,24 @@ {{!-- Consequences Tab --}}
      lock/unlock{{#if data.editStatSkill}}Lock{{else}}Unlock{{/if}} + src="systems/foundryvtt-shadows-over-sol/img/icons/{{#if editStatSkill}}unlocked.svg{{else}}locked.svg{{/if}}" alt="lock/unlock" + >{{#if editStatSkill}}Lock{{else}}Unlock{{/if}}

      Wounds & Conséquences

      • Wounds :

      • Light : - +
      • Moderate : - +
      • Severe : - +
      • Critical : - +
      • Total : {{data.currentWounds}} / {{data.totalWounds}} @@ -200,8 +200,8 @@
        - {{#each data.consequences as |conseq key|}} -
      • + {{#each consequences as |conseq key|}} +
      • {{conseq.name}} - {{#select data.subculture}} - {{#each data.subcultureList as |subculture key|}} + {{#select subculture}} + {{#each subcultureList as |subculture key|}} {{/each}} {{/select}} @@ -339,8 +339,8 @@
        Familiar Subcultures
          - {{#each data.subcultureList as |subculture key|}} -
        • + {{#each subcultureList as |subculture key|}} +
        • {{subculture.name}}
          @@ -354,8 +354,8 @@
          Known Languages
            - {{#each data.languageList as |language key|}} -
          • + {{#each languageList as |language key|}} +
          • {{language.name}}
            @@ -369,8 +369,8 @@
            Weaknesses
              - {{#each data.weaknessList as |weakness key|}} -
            • + {{#each weaknessList as |weakness key|}} +
            • {{weakness.name}}