diff --git a/modules/pegasus-actor-sheet.js b/modules/pegasus-actor-sheet.js index 8320464..2fcc6a5 100644 --- a/modules/pegasus-actor-sheet.js +++ b/modules/pegasus-actor-sheet.js @@ -162,8 +162,7 @@ export class PegasusActorSheet 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('.perk-active').click(ev => { const li = $(ev.currentTarget).parents(".item"); diff --git a/modules/pegasus-item-sheet.js b/modules/pegasus-item-sheet.js index 15821a5..c6d8367 100644 --- a/modules/pegasus-item-sheet.js +++ b/modules/pegasus-item-sheet.js @@ -109,6 +109,45 @@ export class PegasusItemSheet extends ItemSheet { }); } + /* -------------------------------------------- */ + async viewSubitem(ev) { + let field = $(ev.currentTarget).data('type'); + let idx = Number($(ev.currentTarget).data('index')); + let itemData = this.object.data.data[field][idx]; + if ( itemData.name != 'None') { + let spec = await Item.create(itemData, {temporary: true}); + spec.data.origin = "embeddedItem"; + new PegasusItemSheet(spec).render(true); + } + } + + /* -------------------------------------------- */ + async deleteSubitem(ev) { + let field = $(ev.currentTarget).data('type'); + let idx = Number($(ev.currentTarget).data('index')); + let oldArray = this.object.data.data[field]; + let itemData = this.object.data.data[field][idx]; + if ( itemData.name != 'None') { + let newArray = []; + for( var i = 0; i < oldArray.length; i++) { + if ( i != idx) { + newArray.push( oldArray[i]); + } + } + this.object.update( { [`data.${field}`]: newArray} ); + } + } + + /* -------------------------------------------- */ + async manageSpec( ) { + let itemData = this.object.data.data.specialisation[0]; + if ( itemData.name != 'None') { + let spec = await Item.create(itemData, {temporary: true}); + spec.data.origin = "embeddedItem"; + new PegasusItemSheet(spec).render(true); + } + } + /* -------------------------------------------- */ /** @override */ activateListeners(html) { @@ -124,44 +163,115 @@ export class PegasusItemSheet extends ItemSheet { const item = this.object.options.actor.getOwnedItem(li.data("item-id")); item.sheet.render(true); }); + + html.find('.delete-spec').click( ev => { + this.object.update( {"data.specialisation": [ { name: 'None'} ]} ); + }); + + html.find('.delete-subitem').click( ev => { + this.deleteSubitem( ev ); + }); + + html.find('.stat-choice-flag').click( ev => { + let idx = $(ev.currentTarget).data("stat-idx"); + let array = duplicate(this.object.data.data.statincreasechoice); + array[Number(idx)].flag = !array[Number(idx)].flag; + this.object.update( {"data.statincreasechoice": array} ); + }); // Update Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); let itemId = li.data("item-id"); let itemType = li.data("item-type"); - let array = duplicate(this.object.data.data[itemType]); - let newArray = array.filter( item => item._id != itemId); - if ( itemType == 'variations') { - this.object.update( {"data.variations": newArray} ); - } else if (itemType == "modifications") { - this.object.update( { "data.modifications": newArray} ); - } else { - this.object.update( { "data.traits": newArray} ); - } }); - html.find('.trait-name').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - let itemId = li.data("item-id"); - this.manageTrait( itemId); + html.find('.view-subitem').click(ev => { + this.viewSubitem( ev ); }); - html.find('.variation-name').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - let itemId = li.data("item-id"); - this.manageVariation( itemId); - }); - html.find('.modification-name').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - let itemId = li.data("item-id"); - this.manageModification( itemId); + + html.find('.view-spec').click(ev => { + this.manageSpec( ); }); } /* -------------------------------------------- */ - async _onDrop(event) { + async searchItem( dataItem) { + let item; + if (dataItem.pack) { + item = await fromUuid(dataItem.id); + } else { + item = game.items.get(dataItem.id ) + } + return item; + } + /* -------------------------------------------- */ + async addSpecialisation(item, dataItem) { + let newItem = duplicate(item.data); + newItem._id = randomID( dataItem.id.length ); + let specArray = [ newItem ]; + await this.object.update( { 'data.specialisation': specArray} ); + } + + /* -------------------------------------------- */ + async addRoleSpecialisation(event, item, dataItem) { + let newItem = duplicate(item.data); + newItem._id = randomID( dataItem.id.length ); + console.log("Add spec", event, newItem); + if ( event.toElement.className == 'drop-spec1') { + let specArray = duplicate(this.object.data.data.specialisationsplus1); + specArray.push( newItem ); + await this.object.update( { 'data.specialisationsplus1': specArray} ); + } + if ( event.toElement.className == 'drop-spec2') { + let specArray = duplicate(this.object.data.data.specincrease); + specArray.push( newItem ); + await this.object.update( { 'data.specincrease': specArray} ); + } + } + + /* -------------------------------------------- */ + async addRolePerk(event, item, dataItem) { + let newItem = duplicate(item.data); + newItem._id = randomID( dataItem.id.length ); + console.log("Add spec", event, newItem); + if ( event.toElement.className == 'drop-perk2') { + let perkArray = duplicate(this.object.data.data.perks); + perkArray.push( newItem ); + await this.object.update( { 'data.perks': perkArray} ); + } + } + + /* -------------------------------------------- */ + async _onDrop(event) { + console.log(event); + if (this.object.type == 'perk' || this.object.type == 'ability') { + let data = event.dataTransfer.getData('text/plain'); + if (data) { + let dataItem = JSON.parse( data ); + let item = await this.searchItem( dataItem); + if ( item.data.type == 'specialisation') { + return this.addSpecialisation( item, dataItem); + } + } + } + if (this.object.type == 'role' ) { + let data = event.dataTransfer.getData('text/plain'); + if (data) { + let dataItem = JSON.parse( data ); + let item = await this.searchItem( dataItem); + if ( item.data.type == 'specialisation') { + return this.addRoleSpecialisation( event, item, dataItem); + } + if ( item.data.type == 'perk') { + return this.addRolePerk( event, item, dataItem); + } + } + } + + ui.notifications.warn("This item can not be dropped over another item"); } /* -------------------------------------------- */ diff --git a/modules/pegasus-item.js b/modules/pegasus-item.js index 5186c36..240c283 100644 --- a/modules/pegasus-item.js +++ b/modules/pegasus-item.js @@ -1,15 +1,12 @@ import { PegasusUtility } from "./pegasus-utility.js"; export const defaultItemImg = { - skill: "systems/fvtt-pegasus-rpg/images/icons/icon_skill.webp", - advantage: "systems/fvtt-pegasus-rpg/images/icons/icon_advantage.webp", - disadvantage: "systems/fvtt-pegasus-rpg/images/icons/icon_disadvantage.webp", - technique: "systems/fvtt-pegasus-rpg/images/icons/icon_technique.webp", + specialisation: "systems/fvtt-pegasus-rpg/images/icons/icon_spec.webp", + perk: "systems/fvtt-pegasus-rpg/images/icons/icon_perk.webp", + ability: "systems/fvtt-pegasus-rpg/images/icons/icon_ability.webp", armor: "systems/fvtt-pegasus-rpg/images/icons/icon_armor.webp", - art: "systems/fvtt-pegasus-rpg/icons/images/icon_art.webp", weapon: "systems/fvtt-pegasus-rpg/images/icons/icon_weapon.webp", equipment: "systems/fvtt-pegasus-rpg/images/icons/icon_equipment.webp", - style: "systems/fvtt-pegasus-rpg/images/icons/icon_style.webp", } /** diff --git a/styles/simple.css b/styles/simple.css index eb4fc03..17bc6dd 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1143,6 +1143,19 @@ ul, li { font-weight: bold; } +.ul-level1 { + padding-left: 2rem; +} + +.drop-perk2, +.drop-spec1 , +.drop-spec2 { + background: linear-gradient(to bottom, #6c95b9fc 5%, #105177ab 100%); + background-color: #7d5d3b00; + border-radius: 3px; + border: 2px ridge #846109; +} + /*************************************************************/ #pause { diff --git a/system.json b/system.json index 3eb36b5..e91019c 100644 --- a/system.json +++ b/system.json @@ -40,9 +40,9 @@ "styles": [ "styles/simple.css" ], - "templateVersion": 9, + "templateVersion": 13, "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "0.0.9", + "version": "0.0.13", "background" : "./images/ui/pegasus_welcome_page.webp" } \ No newline at end of file diff --git a/template.json b/template.json index 8a5c2d8..6bf80fa 100644 --- a/template.json +++ b/template.json @@ -133,13 +133,21 @@ "environment": "", "society_culture": "", "outlook": "", - "abilities": "", + "abilities": [], "statistics": "" }, "role": { - "description": "", - "abilities": "", - "statistics": "" + "statincrease1": "", + "statincrease2": "", + "specialisationsplus1": [], + "powers1": [], + "specialperk": [], + "statincreasechoice": [ { "name":"AGI", "flag":false }, {"name":"MND", "flag":false }, {"name":"SOC", "flag":false }, {"name":"STR", "flag":false }, + {"name":"PHY", "flag":false }, {"name":"COM", "flag":false }, {"name":"DEF", "flag":false }, {"name":"STL", "flag":false }, + {"name":"PER", "flag":false }, {"name":"FOC", "flag":false } ], + "specincrease": [], + "perks": [], + "description": "" }, "ability": { "affectedstat": "", @@ -150,7 +158,7 @@ "statusaffected": "", "statusmodifier": 0, "powergained": 0, - "specgained": "", + "specialisation": [ {"name": "None"}], "aoe": "", "description": "" }, @@ -167,7 +175,7 @@ "gainstatdice": "", "gainbonusdice": 0, "gainotherdice": 0, - "specialisation": "", + "specialisation": [ {"name": "None"}], "range": "", "aoe": "", "nbtargets": 0, diff --git a/templates/item-ability-sheet.html b/templates/item-ability-sheet.html index 73eab80..93d718a 100644 --- a/templates/item-ability-sheet.html +++ b/templates/item-ability-sheet.html @@ -72,7 +72,12 @@
  • - + {{#each data.specialisation as |spec idx|}} + +
    + +
    + {{/each}}
  • diff --git a/templates/item-perk-sheet.html b/templates/item-perk-sheet.html index 0a82d12..dc24e6a 100644 --- a/templates/item-perk-sheet.html +++ b/templates/item-perk-sheet.html @@ -59,7 +59,12 @@
  • - + {{#each data.specialisation as |spec idx|}} + +
    + +
    + {{/each}}
  • + {{#select data.statincrease1}} + {{> systems/fvtt-pegasus-rpg/templates/partial-options-statistics.html notapplicable=false mr=false}} + {{/select}} + +
  • +
  • + +
  • +
  • +
  • + +
  • + {{#each data.specialperk as |perk idx|}} + +
    + +
    + {{/each}} +
  • +
  • +
  • + +
  • +
  • + + +
  • +
  • + + +
    {{editor content=data.description target="data.description" button=true owner=owner editable=editable}}
    - -
    - {{editor content=data.abilities target="data.abilities" button=true owner=owner editable=editable}} -
    - -
    - {{editor content=data.statistics target="data.statistics" button=true owner=owner editable=editable}} -