From b4b41f5c967d698043cb96fd00a1f246922263e5 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Thu, 13 Jan 2022 21:05:55 +0100 Subject: [PATCH] Generic roll and update items --- modules/pegasus-actor-sheet.js | 10 ++++++--- modules/pegasus-create-char.js | 37 ++++++++++++++++++++++++++++++++ modules/pegasus-utility.js | 5 +++-- templates/actor-sheet.html | 9 ++++++++ templates/chat-create-actor.html | 20 ++++++----------- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/modules/pegasus-actor-sheet.js b/modules/pegasus-actor-sheet.js index 42da1a0..2230601 100644 --- a/modules/pegasus-actor-sheet.js +++ b/modules/pegasus-actor-sheet.js @@ -200,15 +200,19 @@ export class PegasusActorSheet extends ActorSheet { this.actor.equipItem( li.data("item-id") ); this.render(true); }); + html.find('.update-field').change(ev => { + const fieldName = $(ev.currentTarget).data("field-name"); + let value = ev.currentTarget.value; + this.actor.update( { [`${fieldName}`]: value } ); + }); html.find('.perk-active').click(ev => { const li = $(ev.currentTarget).parents(".item"); this.actor.activatePerk( li.data("item-id") ); - this.render(true); - + this.render(true); }); } - + /* -------------------------------------------- */ /** @override */ setPosition(options = {}) { diff --git a/modules/pegasus-create-char.js b/modules/pegasus-create-char.js index d723bf8..90480cd 100644 --- a/modules/pegasus-create-char.js +++ b/modules/pegasus-create-char.js @@ -1,6 +1,7 @@ import { PegasusUtility } from "./pegasus-utility.js"; import { PegasusActor } from "./pegasus-actor.js"; import { PegasusActorSheet } from "./pegasus-actor-sheet.js"; +import { PegasusItemSheet } from "./pegasus-item-sheet.js"; export class PegasusActorCreate { @@ -176,6 +177,42 @@ export class PegasusActorCreate { } } + /* -------------------------------------------- */ + async openItemView( event) { + let step = $(event.currentTarget).data("step"); + let itemId = $(event.currentTarget).data("item-id"); + let itemData + + if ( step == 'select-race') { + itemData = this.races.find( item => item._id == itemId ); + } + if ( step == 'select-race-optionnal') { + itemData = this.raceOptionnalAbilities.optionnalabilities.find( item => item._id == itemId ); + } + if ( step == 'select-race-perks') { + itemData = this.perks.find( item => item._id == itemId ); + } + if ( step == 'select-race-perks'){ + itemData = this.racePerks.find( item => item._id == itemId ); + } + if ( step == 'select-role') { + itemData = this.roles.find( item => item._id == itemId ); + } + if ( step == 'select-role-start-spec') { + itemData = this.roleSpecStart.find( item => item._id == itemId ); + } + if (step == 'select-role-spec') { + itemData = this.roleSpec.find( item => item._id == itemId ); + } + if (step == 'select-role-perk') { + itemData = this.rolePerks.find( item => item._id == itemId ); + } + if (itemData) { + let item = await Item.create(itemData, {temporary: true}); + new PegasusItemSheet(item).render(true); + } + } + /* -------------------------------------------- */ manageSelectableStats( race ) { this.raceSelectableStats = { diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 3d507af..bdeec9a 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -128,10 +128,11 @@ export class PegasusUtility { static async chatListeners(html) { html.on("click", '.chat-create-actor', event => { - console.log("Event !") game.system.pegasus.creator.processChatEvent(event); } ); - + html.on("click", '.view-item-from-chat', event => { + game.system.pegasus.creator.openItemView( event) + } ); } /* -------------------------------------------- */ diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 8592010..d2f5534 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -188,6 +188,15 @@
+
    +
  • +

    {{data.nrg.label}}

    + + + +
  • +
+

Basic Actions

diff --git a/templates/chat-create-actor.html b/templates/chat-create-actor.html index 17d0800..3b2a9af 100644 --- a/templates/chat-create-actor.html +++ b/templates/chat-create-actor.html @@ -11,7 +11,7 @@ {{#each races as |race index|}} - + {{/each}} @@ -25,7 +25,7 @@
{{race.name}}{{race.name}} Select it !
{{#each optionnalabilities as |ability index|}} - + {{/each}} @@ -56,19 +56,13 @@
{{ability.name}}{{ability.name}} Select it !
{{/if}} - {{#if (eq step "select-race-perks-all")}} -
Select {{nbperks}} from the Perks Compendium. Once done, click the button below
- Race Perks selected! -
- {{/if}} - {{#if (eq step "select-race-perks")}}
Now select {{nbraceperks}} Perk(s) for your character
{{#each raceperks as |perk index|}} - + {{/each}} @@ -81,7 +75,7 @@
{{perk.name}}{{perk.name}} Select it !
{{#each roles as |role index|}} - + {{/each}} @@ -94,7 +88,7 @@
{{role.name}}{{role.name}} Select it !
{{#each rolestartspec as |spec index|}} - + {{/each}} @@ -120,7 +114,7 @@
{{spec.name}}{{spec.name}} Select it !
{{#each rolespec as |spec index|}} - + {{/each}} @@ -133,7 +127,7 @@
{{spec.name}}{{spec.name}} Select it !
{{#each roleperks as |perk index|}} - + {{/each}}
{{perk.name}}{{perk.name}} Select it !