Inc release

This commit is contained in:
2021-12-08 13:53:22 +01:00
parent 2b23e9daec
commit 22392fba66
10 changed files with 262 additions and 49 deletions

View File

@ -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");
}
/* -------------------------------------------- */