From b3e89cf135b898701aee656639b4ff75bcdbb265 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Mon, 29 Aug 2022 17:39:19 +0200 Subject: [PATCH] Add NPC sheet --- modules/crucible-actor-sheet.js | 6 +- modules/crucible-npc-sheet.js | 149 ++++++-- system.json | 4 +- template.json | 2 +- templates/npc-sheet.html | 607 +++++++++++++++++++++++--------- 5 files changed, 561 insertions(+), 207 deletions(-) diff --git a/modules/crucible-actor-sheet.js b/modules/crucible-actor-sheet.js index afecd48..2ffefc9 100644 --- a/modules/crucible-actor-sheet.js +++ b/modules/crucible-actor-sheet.js @@ -119,7 +119,6 @@ export class CrucibleActorSheet extends ActorSheet { let actorId = li.data("actor-id"); this.actor.delSubActor(actorId); }); - html.find('.quantity-minus').click(event => { const li = $(event.currentTarget).parents(".item"); this.actor.incDecQuantity( li.data("item-id"), -1 ); @@ -143,10 +142,11 @@ export class CrucibleActorSheet extends ActorSheet { this.actor.rollAbility(abilityKey); }); html.find('.roll-skill').click((event) => { - const li = $(event.currentTarget).parents(".item"); + const li = $(event.currentTarget).parents(".item") const skillId = li.data("item-id") this.actor.rollSkill(skillId) - }); + }); + html.find('.roll-weapon').click((event) => { const li = $(event.currentTarget).parents(".item"); const skillId = li.data("item-id") diff --git a/modules/crucible-npc-sheet.js b/modules/crucible-npc-sheet.js index 0feb10a..1b22f8e 100644 --- a/modules/crucible-npc-sheet.js +++ b/modules/crucible-npc-sheet.js @@ -24,24 +24,37 @@ export class CrucibleNPCSheet extends ActorSheet { /* -------------------------------------------- */ async getData() { - const objectData = CrucibleUtility.data(this.object); - - this.actor.prepareTraitsAttributes(); - let actorData = duplicate(CrucibleUtility.templateData(this.object)); + const objectData = this.object.system + let actorData = duplicate(objectData) let formData = { title: this.title, - id: objectData.id, - type: objectData.type, - img: objectData.img, - name: objectData.name, + id: this.actor.id, + type: this.actor.type, + img: this.actor.img, + name: this.actor.name, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", data: actorData, - effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)), limited: this.object.limited, - equipments: this.actor.getEquipments(), - weapons: this.actor.getWeapons(), + skills: this.actor.getSkills( ), + weapons: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getWeapons()) ), + armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())), + shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields())), + spells: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getLore())), + equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipmentsOnly()) ), + equippedWeapons: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquippedWeapons()) ), + equippedArmor: this.actor.getEquippedArmor(), + equippedShield: this.actor.getEquippedShield(), + feats: duplicate(this.actor.getFeats()), + subActors: duplicate(this.actor.getSubActors()), + race: duplicate(this.actor.getRace()), + moneys: duplicate(this.actor.getMoneys()), + encCapacity: this.actor.getEncumbranceCapacity(), + saveRolls: this.actor.getSaveRoll(), + conditions: this.actor.getConditions(), + containersTree: this.actor.containersTree, + encCurrent: this.actor.encCurrent, options: this.options, owner: this.document.isOwner, editScore: this.options.editScore, @@ -49,7 +62,7 @@ export class CrucibleNPCSheet extends ActorSheet { } this.formData = formData; - console.log("NPC : ", formData, this.object); + console.log("PC : ", formData, this.object); return formData; } @@ -60,43 +73,97 @@ export class CrucibleNPCSheet extends ActorSheet { // Everything below here is only needed if the sheet is editable if (!this.options.editable) return; + + html.bind("keydown", function(e) { // Ignore Enter in actores sheet + if (e.keyCode === 13) return false; + }); // Update Inventory Item html.find('.item-edit').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - let itemId = li.data("item-id"); + const li = $(ev.currentTarget).parents(".item") + let itemId = li.data("item-id") const item = this.actor.items.get( itemId ); item.sheet.render(true); }); // Delete Inventory Item html.find('.item-delete').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - FraggedKingdomUtility.confirmDelete(this, li); - }); + const li = $(ev.currentTarget).parents(".item") + CrucibleUtility.confirmDelete(this, li) + }) + html.find('.item-add').click(ev => { + let dataType = $(ev.currentTarget).data("type") + this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true }) + }) + + html.find('.equip-activate').click(ev => { + const li = $(ev.currentTarget).parents(".item") + let itemId = li.data("item-id") + this.actor.equipActivate( itemId) + }); + html.find('.equip-deactivate').click(ev => { + const li = $(ev.currentTarget).parents(".item") + let itemId = li.data("item-id") + this.actor.equipDeactivate( itemId) + }); - html.find('.trait-link').click((event) => { - const itemId = $(event.currentTarget).data("item-id"); - const item = this.actor.getOwnedItem(itemId); - item.sheet.render(true); - }); - - html.find('.competence-label a').click((event) => { - const li = $(event.currentTarget).parents(".item"); - const competenceId = li.data("item-id"); - this.actor.rollSkill(competenceId); + html.find('.subactor-edit').click(ev => { + const li = $(ev.currentTarget).parents(".item"); + let actorId = li.data("actor-id"); + let actor = game.actors.get( actorId ); + actor.sheet.render(true); }); - html.find('.weapon-label a').click((event) => { + + html.find('.subactor-delete').click(ev => { + const li = $(ev.currentTarget).parents(".item"); + let actorId = li.data("actor-id"); + this.actor.delSubActor(actorId); + }); + html.find('.quantity-minus').click(event => { const li = $(event.currentTarget).parents(".item"); - const armeId = li.data("item-id"); - const statId = li.data("stat-id"); - this.actor.rollWeapon(armeId, statId); + this.actor.incDecQuantity( li.data("item-id"), -1 ); + } ); + html.find('.quantity-plus').click(event => { + const li = $(event.currentTarget).parents(".item"); + this.actor.incDecQuantity( li.data("item-id"), +1 ); + } ); + + html.find('.ammo-minus').click(event => { + const li = $(event.currentTarget).parents(".item") + this.actor.incDecAmmo( li.data("item-id"), -1 ); + } ); + html.find('.ammo-plus').click(event => { + const li = $(event.currentTarget).parents(".item") + this.actor.incDecAmmo( li.data("item-id"), +1 ) + } ); + + html.find('.roll-ability').click((event) => { + const abilityKey = $(event.currentTarget).data("ability-key"); + this.actor.rollAbility(abilityKey); + }); + html.find('.roll-skill').click((event) => { + const li = $(event.currentTarget).parents(".item") + const skillId = li.data("item-id") + this.actor.rollSkill(skillId) }); - html.find('.npc-fight-roll').click((event) => { - this.actor.rollNPCFight(); - }); - html.find('.npc-skill-roll').click((event) => { - this.actor.rollGenericSkill(); - }); + + html.find('.roll-weapon').click((event) => { + const li = $(event.currentTarget).parents(".item"); + const skillId = li.data("item-id") + this.actor.rollWeapon(skillId) + }); + html.find('.roll-armor-die').click((event) => { + this.actor.rollArmorDie() + }); + html.find('.roll-shield-die').click((event) => { + this.actor.rollShieldDie() + }); + + html.find('.roll-save').click((event) => { + const saveKey = $(event.currentTarget).data("save-key") + this.actor.rollSave(saveKey) + }); + + html.find('.lock-unlock-sheet').click((event) => { this.options.editScore = !this.options.editScore; this.render(true); @@ -109,9 +176,15 @@ export class CrucibleNPCSheet extends ActorSheet { html.find('.item-equip').click(ev => { const li = $(ev.currentTarget).parents(".item"); this.actor.equipItem( li.data("item-id") ); - this.render(true); + this.render(true); }); + html.find('.update-field').change(ev => { + const fieldName = $(ev.currentTarget).data("field-name"); + let value = Number(ev.currentTarget.value); + this.actor.update( { [`${fieldName}`]: value } ); + }); + } /* -------------------------------------------- */ diff --git a/system.json b/system.json index 3dcc8de..34d7d93 100644 --- a/system.json +++ b/system.json @@ -199,7 +199,7 @@ "styles": [ "styles/simple.css" ], - "version": "10.0.7", + "version": "10.0.8", "compatibility": { "minimum": "10", "verified": "10.279", @@ -207,7 +207,7 @@ }, "title": "Crucible RPG", "manifest": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/raw/master/system.json", - "download": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/archive/fvtt-crucible-rpg-v10.0.7.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/archive/fvtt-crucible-rpg-v10.0.8.zip", "url": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg", "background": "images/ui/crucible_welcome_page.webp", "id": "fvtt-crucible-rpg" diff --git a/template.json b/template.json index 2bb3efd..88d86a4 100644 --- a/template.json +++ b/template.json @@ -98,7 +98,7 @@ "templates": [ "biodata", "core" ] }, "npc": { - "templates": [ "npccore" ] + "templates": [ "biodata", "core" ] } }, "Item": { diff --git a/templates/npc-sheet.html b/templates/npc-sheet.html index 6bfa5f1..970aeca 100644 --- a/templates/npc-sheet.html +++ b/templates/npc-sheet.html @@ -1,184 +1,465 @@
- {{!-- Sheet Header --}} -
-
-
- -

-
-
-
- - {{!-- Sheet Tab Navigation --}} - - - {{!-- Sheet Body --}} -
- - {{!-- Carac Tab --}} -
- Unlocked/Locked{{#if editScore}}Unlocked{{else}}Locked{{/if}} - -
-
- -

Type

-
- - - -
-

Traits List

-
    - {{#each traits as |trait key|}} -
  • - - {{trait.name}} - {{trait.data.data.type}} -
    - - -
    -
  • - {{/each}} -
-
- -
- -
-

Stats & Numbers

-
    - {{#each data.spec as |spec key|}} -
  • - {{spec.label}} - -
  • - {{/each}} -
-
- -
-
- - - {{!-- Defence Tab --}} -
+ {{!-- Sheet Header --}} +
+
+

+
+
-
- {{#each data.fight as |fight key|}} -
    -
  • - {{fight.label}} - -
  • - {{#each fight.derivated as |derivated keydev|}} -
  • - {{derivated.label}} - -
  • - {{/each}} -
- {{/each}} -
+
+
+
    + {{#each data.abilities as |ability key|}} + {{#if (eq ability.col 1)}} + {{> systems/fvtt-crucible-rpg/templates/partial-actor-ability-block.html ability=ability key=key}} + {{/if}} + {{/each}} +
+ +
  • + +

    Class

    +
    + +
  • + +
    + +
    +
      + {{#each data.abilities as |ability key|}} + {{#if (eq ability.col 2)}} + {{> systems/fvtt-crucible-rpg/templates/partial-actor-ability-block.html ability=ability key=key}} + {{/if}} + {{/each}} + + {{#if equippedArmor}} +
    • + + +

      {{equippedArmor.name}}

      +
      +
    • + {{/if}} + {{#if equippedShield}} +
    • + + +

      {{equippedShield.name}}

      +
      +
    • + {{/if}} + +
    +
    + +
    + {{> systems/fvtt-crucible-rpg/templates/partial-actor-status.html}} +
    + +
    +
    +
    +
    +
    + + {{!-- Sheet Tab Navigation --}} + + + {{!-- Sheet Body --}} +
    + + {{!-- Skills Tab --}} +
    + +
      +
    • + +

      +
      + + + + + + + + + +
    • + {{#each skills as |skill key|}} +
    • + + {{skill.name}} + {{upper skill.system.ability}} + {{skill.system.skilldice}} +  -  +
       
      +
      + +
      +
    • + {{/each}} +
    + +
      +
    • + +

      +
      + + + + + + +
    • + {{#each equippedWeapons as |weapon key|}} +
    • + + {{weapon.name}} + + {{weapon.system.ability}} + + {{perk.system.range}} + +
       
      +
      + +
      +
    • + {{/each}} +
    + +
      +
    • + +

      +
      + + + + + + + + + +
    • + {{#each feats as |feat key|}} +
    • + + {{feat.name}} + + {{upperFirst feat.system.isfeatdie}} + {{upperFirst feat.system.issl}} + {{feat.system.sl}} + +
       
      +
      + +
      +
    • + {{/each}} +
    -

    Weapons

      - {{#each weapons as |weapon key|}} -
    • - - {{weapon.name}} -
    • + +

      +
      +
    • + {{#each conditions as |condition key|}} +
    • + + {{condition.name}} +
       
      {{!-- Equipement Tab --}} +
      + +
      +

      Encumbrance

      + Current : {{encCurrent}} + Capacity : {{encCapacity}} +
      + +
        +
      • + +

        +
        + + + + + + + + + +
         
        +
        + +
        +
      • + {{#each moneys as |money key|}} +
      • + + {{money.name}} + + + + + + + + {{#if money.system.idrDice}} + {{money.system.idrDice}} + {{else}} +  -  + {{/if}} + + +
         
        +
        + +
        +
      • + {{/each}} +
      + + +
      + + +
    • -
    • - {{#each weapon.data.data.weaponstats as |weaponstat statkey|}} -
        -
      • Attack with {{weaponstat.name}} -
      • -
      • {{> "systems/fvtt-fragged-kingdom/templates/weapon-stats-section.html" stats=weaponstat.data.statstotal isfinal=false header=true}} -
      • -
      - {{/each}} + {{/each}} +
    + +
      +
    • + +

      +
      + + + + + + +
      + +
    • - {{/each}} -
    - -
    -
    - - {{!-- Traits Tab --}} -
    - + {{#each weapons as |weapon key|}} +
  • + + {{weapon.name}} + + + +
     
    + +
  • + {{/each}} + + +
      +
    • + +

      +
      + + + + + + + +
       
      +
      + +
      +
    • + {{#each armors as |armor key|}} +
    • + + {{armor.name}} + {{upper armor.system.armortype}} + {{armor.system.absorprionroll}} + +
       
      + +
    • + {{/each}} +
    + + + +
      +
    • + +

      +
      + + + +
       
      +
      + +
      + +
    • + {{#each containersTree as |equip key|}} + {{> systems/fvtt-crucible-rpg/templates/partial-actor-equipment.html equip=equip level=1}} +
        + {{#each equip.data.contents as |subgear key|}} + {{> systems/fvtt-crucible-rpg/templates/partial-actor-equipment.html equip=subgear level=2}} + {{/each}} +
      + {{/each}} +
    +
    - {{!-- Features Tab --}} -
    -
    - -

    Equipment

    + {{!-- Biography Tab --}} +
    +
    +
      -
    • - Name - Type -
      -   -   -   -
      +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    +
    +
    +
      +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • +
    • + + +
    • - {{#each equipments as |equip key|}} -
    • - - {{equip.name}} - {{equip.type}} - -
    • - {{/each}}
    -
    - {{!-- Notes Tab --}} -
    -
    -

    Description :

    -
    - {{editor content=data.description target="data.description" button=true owner=owner editable=editable}} -
    -
    -

    Notes :

    -
    - {{editor content=data.notes target="data.notes" button=true owner=owner editable=editable}} -
    -
    - {{>"systems/fvtt-fragged-kingdom/templates/editor-notes-gm.html"}} -
    + +
    +

    Background :

    +
    + {{editor data.biodata.description target="system.biodata.description" button=true owner=owner + editable=editable}}
    +
    +

    Notes :

    +
    + {{editor data.biodata.notes target="system.biodata.notes" button=true owner=owner editable=editable}} +
    +
    + +
    -
    -
    - + + \ No newline at end of file