diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index dbce6ae..4932b98 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -6,13 +6,19 @@ export class MothershipActorSheet extends ActorSheet { /** @override */ static get defaultOptions() { - return mergeObject(super.defaultOptions, { + var options = { classes: ["mosh", "sheet", "actor", "character"], template: "systems/mosh/templates/actor/actor-sheet.html", width: 820, height: 820, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }] - }); + } + + if (game.release.generation >= 12) { + return foundry.utils.mergeObject(super.defaultOptions, options); + } else { + return mergeObject(super.defaultOptions, options); + } } /* -------------------------------------------- */ @@ -24,7 +30,7 @@ export class MothershipActorSheet extends ActorSheet { data.dtypes = ["String", "Number", "Boolean"]; const superData = data.data.system; - + for (let attr of Object.values(data.data.system.attributes)) { attr.isCheckbox = attr.dtype === "Boolean"; } @@ -41,34 +47,34 @@ export class MothershipActorSheet extends ActorSheet { data.data.system.settings.useCalm = game.settings.get("mosh", "useCalm"); data.data.system.settings.hideWeight = game.settings.get("mosh", "hideWeight"); data.data.system.settings.firstEdition = game.settings.get("mosh", "firstEdition"); - data.data.system.settings.androidPanic = game.settings.get("mosh", "androidPanic"); + data.data.system.settings.androidPanic = game.settings.get("mosh", "androidPanic"); //SKILL XP BUTTONS superData.xp.html = ''; - if(superData.xp.html == ''){ - for(let i = 1; i <= 15; i ++){ - if(i > superData.xp.value){ - if(i % 5){ + if (superData.xp.html == '') { + for (let i = 1; i <= 15; i++) { + if (i > superData.xp.value) { + if (i % 5) { superData.xp.html += '
'; } else { //If a special one let trainLevel = '
Trained
'; - if(i == 10) trainLevel = '
Expert
'; - else if(i == 15) trainLevel = '
Master
'; - superData.xp.html += '
'+trainLevel+'
'; + if (i == 10) trainLevel = '
Expert
'; + else if (i == 15) trainLevel = '
Master
'; + superData.xp.html += '
' + trainLevel + '
'; } } - else{ - if(i % 5){ - superData.xp.html += '
'; - } - else { //If a special one - let trainLevel = '
Trained
'; - if(i == 10) trainLevel = '
Expert
'; - else if(i == 15) trainLevel = '
Master
'; - superData.xp.html += '
'+trainLevel+'
'; - } + else { + if (i % 5) { + superData.xp.html += '
'; + } + else { //If a special one + let trainLevel = '
Trained
'; + if (i == 10) trainLevel = '
Expert
'; + else if (i == 15) trainLevel = '
Master
'; + superData.xp.html += '
' + trainLevel + '
'; + } } } @@ -87,8 +93,8 @@ export class MothershipActorSheet extends ActorSheet { */ _prepareCharacterItems(sheetData) { const actorData = sheetData.data; - console.log(sheetData); - console.log("sheetdata Above"); + //console.log(sheetData); + ///console.log("sheetdata Above"); // Initialize containers. const gear = []; const skills = []; @@ -105,21 +111,21 @@ export class MothershipActorSheet extends ActorSheet { if (i.type === 'item') { gear.push(i); - curWeight+=item.weight*item.quantity; + curWeight += item.weight * item.quantity; } else if (i.type === 'skill') { skills.push(i); } else if (i.type === 'armor') { armors.push(i); - curWeight+=item.weight; + curWeight += item.weight; } else if (i.type === 'weapon') { //We need to update this from the old system. - if(item.ranges.value == "" && item.ranges.medium > 0){ + if (item.ranges.value == "" && item.ranges.medium > 0) { item.ranges.value = item.ranges.short + "/" + item.ranges.medium + "/" + item.ranges.long; item.ranges.medium = 0; } weapons.push(i); - curWeight+=item.weight; + curWeight += item.weight; } else if (i.type === 'condition') { // We'll handle the pip html here. if (item.treatment == null) { @@ -130,10 +136,10 @@ export class MothershipActorSheet extends ActorSheet { } let pipHtml = ""; for (let i = 0; i < 3; i++) { - if (i < item.treatment.value){ + if (i < item.treatment.value) { pipHtml += ''; } - else{ + else { pipHtml += ''; } } @@ -144,19 +150,19 @@ export class MothershipActorSheet extends ActorSheet { } } - if(actorData.system.weight == undefined){ + if (actorData.system.weight == undefined) { actorData.system.weight = { - "current" : 0, - "capacity" : 0 + "current": 0, + "capacity": 0 }; } - if(actorData.system.credits == undefined){ + if (actorData.system.credits == undefined) { actorData.system.credits = { - "value" : 0, + "value": 0, }; } - actorData.system.weight.capacity = Math.ceil((actorData.system.stats.strength.value/10)); //Removed a +3 here because I misunderstood some Traaa.sh stuff. This whole thing can probably be ripped out tbh. + actorData.system.weight.capacity = Math.ceil((actorData.system.stats.strength.value / 10)); //Removed a +3 here because I misunderstood some Traaa.sh stuff. This whole thing can probably be ripped out tbh. actorData.system.weight.current = curWeight; //console.log("Current Weight: " + curWeight + " Capacity: " + actorData.data.weight.capacity); @@ -202,14 +208,20 @@ export class MothershipActorSheet extends ActorSheet { value: attribute.value } - const updateString = "data."+targetName; + const updateString = "data." + targetName; - this.actor.update({[updateString] : updated}); + this.actor.update({ [updateString]: updated }); }); html.on('mousedown', '.treatment-button', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.treatment.value; @@ -230,7 +242,13 @@ export class MothershipActorSheet extends ActorSheet { // Update Inventory Item html.find('.item-equip').click(ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } item.system.equipped = !item.system.equipped; this.actor.updateEmbeddedDocuments('Item', [item]); @@ -249,7 +267,13 @@ export class MothershipActorSheet extends ActorSheet { //Quantity adjuster html.on('mousedown', '.item-quantity', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.quantity; if (event.button == 0) { @@ -264,7 +288,13 @@ export class MothershipActorSheet extends ActorSheet { //Severity adjuster html.on('mousedown', '.severity', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + let amount = item.system.severity; if (event.button == 0) { @@ -279,7 +309,7 @@ export class MothershipActorSheet extends ActorSheet { // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteEmbeddedDocuments("Item",[li.data("itemId")]); + this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")]); li.slideUp(200, () => this.render(false)); }); @@ -309,28 +339,46 @@ export class MothershipActorSheet extends ActorSheet { html.find('.stat-roll').click(ev => { const div = $(ev.currentTarget); const statName = div.data("key"); - this.actor.rollCheck(null,'low',statName,null,null,null); + this.actor.rollCheck(null, 'low', statName, null, null, null); }); // Rollable Skill html.find('.skill-roll').click(ev => { const li = event.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null,null,null,item.name,item.system.bonus,null); + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + this.actor.rollCheck(null, null, null, item.name, item.system.bonus, null); }); // Rollable Weapon html.find('.weapon-roll').click(ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null,'low','combat',null,null,item); + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + this.actor.rollCheck(null, 'low', 'combat', null, null, item); }); // Rollable Damage html.find('.dmg-roll').click(ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null,null,'damage',null,null,item); + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + this.actor.rollCheck(null, null, 'damage', null, null, item); }); // Rollable Item/Anything with a description that we want to click on. @@ -344,7 +392,13 @@ export class MothershipActorSheet extends ActorSheet { //increase ammo html.on('mousedown', '.weapon-ammo', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.ammo; if (event.button == 0) { if (amount >= 0) { @@ -361,7 +415,13 @@ export class MothershipActorSheet extends ActorSheet { //increase shots html.on('mousedown', '.weapon-shots', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } if (event.button == 0) { if (item.system.curShots >= 0 && item.system.curShots < item.system.shots && item.system.ammo > 0) { item.system.curShots = Number(item.system.curShots) + 1; @@ -385,7 +445,13 @@ export class MothershipActorSheet extends ActorSheet { //increase oxygen html.on('mousedown', '.armor-oxy', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.oxygenCurrent; if (event.button == 0) { if (amount < item.system.oxygenMax) { @@ -402,13 +468,13 @@ export class MothershipActorSheet extends ActorSheet { // Calm - Panic Check html.find('.calm-roll').click(ev => { //roll panic check - this.actor.rollTable('panicCheck',null,null,null,null,null,null); + this.actor.rollTable('panicCheck', null, null, null, null, null, null); }); - + // Stress - Panic Check html.find('.stress-roll').click(ev => { //roll panic check - this.actor.rollTable('panicCheck',null,null,null,null,null,null); + this.actor.rollTable('panicCheck', null, null, null, null, null, null); }); // Clicking on Armor @@ -444,7 +510,13 @@ export class MothershipActorSheet extends ActorSheet { // Get the type of item to create. const type = header.dataset.type; // Grab any data associated with this control. - const data = duplicate(header.dataset); + var data; + if (game.release.generation >= 12) { + data = foundry.utils.duplicate(header.dataset); + } else { + data = duplicate(header.dataset); + } + // Initialize a default name. const name = `New ${type.capitalize()}`; // Prepare the item object. @@ -459,7 +531,7 @@ export class MothershipActorSheet extends ActorSheet { // Finally, create the item! - return this.actor.createEmbeddedDocuments("Item",[itemData]); + return this.actor.createEmbeddedDocuments("Item", [itemData]); } /** @@ -473,7 +545,13 @@ export class MothershipActorSheet extends ActorSheet { // Get the type of item to create. const type = header.dataset.type; // Grab any data associated with this control. - const data = duplicate(header.dataset); + var data; + if (game.release.generation >= 12) { + data = foundry.utils.duplicate(header.dataset); + } else { + data = duplicate(header.dataset); + } + //const data = duplicate(header.dataset); // Initialize a default name. const name = `New Skill`; // Prepare the item object. @@ -499,16 +577,16 @@ export class MothershipActorSheet extends ActorSheet { label: "Create", callback: (html) => { var rank = html.find('[id=\"rank\"]')[0].value; - if(rank == "Trained") + if (rank == "Trained") itemData.data.bonus = 10; - if(rank == "Expert") + if (rank == "Expert") itemData.data.bonus = 15; - if(rank == "Master") + if (rank == "Master") itemData.data.bonus = 20; itemData.data.rank = rank; itemData.name = html.find('[id=\"name\"]')[0].value - this.actor.createEmbeddedDocuments("Item",[itemData]); + this.actor.createEmbeddedDocuments("Item", [itemData]); } }, cancel: { @@ -523,7 +601,7 @@ export class MothershipActorSheet extends ActorSheet { d.render(true); // Finally, create the item! - return ; + return; } @@ -549,7 +627,13 @@ export class MothershipActorSheet extends ActorSheet { async _updateObject(event, formData) { const actor = this.object; - const updateData = expandObject(formData); + + var updateData; + if (game.release.generation >= 12) { + updateData = foundry.utils.expandObject(formData); + } else { + updateData = expandObject(formData); + } await actor.update(updateData, { diff: false diff --git a/module/actor/actor.js b/module/actor/actor.js index ea9c88f..317b9c1 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -6,6 +6,7 @@ export class MothershipActor extends Actor { //Augment the basic actor data with additional dynamic data. prepareData() { + //console.log(game.release.generation); super.prepareData(); const actorData = this; @@ -1420,7 +1421,7 @@ export class MothershipActor extends Actor { let woundText = ``; let tableResultEdited = ``; let tableResultFooter = ``; - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) let rollTarget = null; let valueAddress = []; let specialRoll = null; @@ -2164,7 +2165,7 @@ export class MothershipActor extends Actor { let woundEffect = ``; let msgHeader = ``; let msgImgPath = ``; - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()); let firstEdition = game.settings.get('mosh','firstEdition'); let useCalm = game.settings.get('mosh','useCalm'); //customize this roll if its a unique use-case @@ -2777,7 +2778,7 @@ export class MothershipActor extends Actor { let msgFlavor = ``; let msgOutcome = ``; let msgChange = ``; - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) let halfDamage = false; let firstEdition = game.settings.get('mosh','firstEdition'); let useCalm = game.settings.get('mosh','useCalm'); @@ -3087,7 +3088,7 @@ export class MothershipActor extends Actor { let oldValue = 0; let newValue = 0; let flavorText = ``; - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) //find where this item is located //get current compendium let compendium = game.packs; @@ -3249,9 +3250,15 @@ export class MothershipActor extends Actor { let messageTemplate = ``; let messageContent = ``; let msgBody = ``; - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) //dupe item to work with - let item = duplicate(this.getEmbeddedDocument('Item',itemId)); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.getEmbeddedDocument('Item',itemId)); + } else { + item = duplicate(this.getEmbeddedDocument('Item',itemId)); + } + //reload if (!item.system.useAmmo) { //exit function (it should not be possible to get here) @@ -3312,7 +3319,7 @@ export class MothershipActor extends Actor { //make the player take bleeding damage async takeBleedingDamage() { //init vars - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) //determine bleeding amount let healthLost = this.items.getName("Bleeding").system.severity*-1; //run the function for the player's 'Selected Character' @@ -3352,7 +3359,7 @@ export class MothershipActor extends Actor { //make the player take radiation damage async takeRadiationDamage() { //init vars - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) //reduce all stats and saves by 1 this.modifyActor('system.stats.strength.value',-1,null,false); this.modifyActor('system.stats.speed.value',-1,null,false); @@ -3396,7 +3403,7 @@ export class MothershipActor extends Actor { //make the player take radiation damage async takeCryoDamage(rollString) { //init vars - let chatId = randomID(); + let chatId = (game.release.generation >= 12 ? foundry.utils.randomID(): randomID()) //roll the dice //parse the roll string let parsedRollString = this.parseRollString(rollString,'low'); @@ -3906,7 +3913,12 @@ export class MothershipActor extends Actor { // print description printDescription(itemId, options = { event: null }) { - let item = duplicate(this.getEmbeddedDocument('Item',itemId)); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.getEmbeddedDocument('Item',itemId)); + } else { + item = duplicate(this.getEmbeddedDocument('Item',itemId)); + } this.chatDesc(item); } diff --git a/module/actor/creature-sheet.js b/module/actor/creature-sheet.js index dd1a6dd..de9018b 100644 --- a/module/actor/creature-sheet.js +++ b/module/actor/creature-sheet.js @@ -8,13 +8,19 @@ export class MothershipCreatureSheet extends ActorSheet { /** @override */ static get defaultOptions() { - return mergeObject(super.defaultOptions, { + var options = { classes: ["mosh", "sheet", "actor", "creature"], template: "systems/mosh/templates/actor/creature-sheet.html", width: 700, height: 650, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }] - }); + }; + + if (game.release.generation >= 12) { + return foundry.utils.mergeObject(super.defaultOptions, options); + } else { + return mergeObject(super.defaultOptions, options); + } } /** @@ -46,7 +52,13 @@ export class MothershipCreatureSheet extends ActorSheet { async _updateObject(event, formData) { const actor = this.object; - const updateData = expandObject(formData); + var updateData; + if (game.release.generation >= 12) { + updateData = foundry.utils.expandObject(formData); + } else { + updateData = expandObject(formData); + } + await actor.update(updateData, { diff: false @@ -70,12 +82,12 @@ export class MothershipCreatureSheet extends ActorSheet { if (data.data.system.settings == null) { data.data.system.settings = {}; - } - data.data.system.settings.useCalm = game.settings.get("mosh", "useCalm"); - data.data.system.settings.hideWeight = game.settings.get("mosh", "hideWeight"); - data.data.system.settings.firstEdition = game.settings.get("mosh", "firstEdition"); - data.data.system.settings.androidPanic = game.settings.get("mosh", "androidPanic"); - + } + data.data.system.settings.useCalm = game.settings.get("mosh", "useCalm"); + data.data.system.settings.hideWeight = game.settings.get("mosh", "hideWeight"); + data.data.system.settings.firstEdition = game.settings.get("mosh", "firstEdition"); + data.data.system.settings.androidPanic = game.settings.get("mosh", "androidPanic"); + return data.data; } @@ -88,7 +100,7 @@ export class MothershipCreatureSheet extends ActorSheet { */ _prepareCreatureItems(sheetData) { const actorData = sheetData.data; - + // Initialize containers. const abilities = []; const weapons = []; @@ -102,7 +114,7 @@ export class MothershipCreatureSheet extends ActorSheet { if (i.type === 'ability') { abilities.push(i); } else if (i.type === 'weapon') { - if(item.ranges.value == "" && item.ranges.medium > 0){ + if (item.ranges.value == "" && item.ranges.medium > 0) { item.ranges.value = item.ranges.short + "/" + item.ranges.medium + "/" + item.ranges.long; item.ranges.medium = 0; } @@ -126,7 +138,7 @@ export class MothershipCreatureSheet extends ActorSheet { // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteEmbeddedDocuments("Item",[li.data("itemId")]); + this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")]); li.slideUp(200, () => this.render(false)); }); @@ -141,7 +153,7 @@ export class MothershipCreatureSheet extends ActorSheet { html.find('.stat-roll').click(ev => { const div = $(ev.currentTarget); const statName = div.data("key"); - this.actor.rollCheck(null,'low',statName,null,null,null); + this.actor.rollCheck(null, 'low', statName, null, null, null); }); //Weapons @@ -158,22 +170,37 @@ export class MothershipCreatureSheet extends ActorSheet { // Rollable Weapon html.find('.weapon-roll').click(ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null,'low','combat',null,null,item); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + this.actor.rollCheck(null, 'low', 'combat', null, null, item); }); // Rollable Damage html.find('.dmg-roll').click(ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null,null,'damage',null,null,item); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + this.actor.rollCheck(null, null, 'damage', null, null, item); }); //increase ammo html.on('mousedown', '.weapon-ammo', ev => { //dupe item to work on const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.ammo; //increase ammo if (event.button == 0) { @@ -189,24 +216,29 @@ export class MothershipCreatureSheet extends ActorSheet { this.actor.updateEmbeddedDocuments('Item', [item]); }); - //increase shots - html.on('mousedown', '.weapon-shots', ev => { - const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) - if (event.button == 0) { - if (item.system.curShots >= 0 && item.system.curShots < item.system.shots && item.system.ammo > 0) { - item.system.curShots = Number(item.system.curShots) + 1; - item.system.ammo = Number(item.system.ammo) - 1; - } - } else if (event.button == 2) { - if (item.system.curShots > 0) { - item.system.curShots = Number(item.system.curShots) - 1; - item.system.ammo = Number(item.system.ammo) + 1; - } - } - this.actor.updateEmbeddedDocuments('Item', [item]); - }); - + //increase shots + html.on('mousedown', '.weapon-shots', ev => { + const li = ev.currentTarget.closest(".item"); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + if (event.button == 0) { + if (item.system.curShots >= 0 && item.system.curShots < item.system.shots && item.system.ammo > 0) { + item.system.curShots = Number(item.system.curShots) + 1; + item.system.ammo = Number(item.system.ammo) - 1; + } + } else if (event.button == 2) { + if (item.system.curShots > 0) { + item.system.curShots = Number(item.system.curShots) - 1; + item.system.ammo = Number(item.system.ammo) + 1; + } + } + this.actor.updateEmbeddedDocuments('Item', [item]); + }); + //Reload Shots html.on('mousedown', '.weapon-reload', ev => { const li = ev.currentTarget.closest(".item"); @@ -247,7 +279,12 @@ export class MothershipCreatureSheet extends ActorSheet { // Get the type of item to create. const type = header.dataset.type; // Grab any data associated with this control. - const data = duplicate(header.dataset); + var data; + if (game.release.generation >= 12) { + data = foundry.utils.duplicate(header.dataset); + } else { + data = duplicate(header.dataset); + } // Initialize a default name. const name = `New ${type.capitalize()}`; // Prepare the item object. @@ -260,7 +297,7 @@ export class MothershipCreatureSheet extends ActorSheet { delete itemData.data["type"]; // Finally, create the item! - return this.actor.createEmbeddedDocuments("Item",[itemData]); + return this.actor.createEmbeddedDocuments("Item", [itemData]); } diff --git a/module/actor/ship-sheet-sbt.js b/module/actor/ship-sheet-sbt.js index 452f8bb..8f925dd 100644 --- a/module/actor/ship-sheet-sbt.js +++ b/module/actor/ship-sheet-sbt.js @@ -12,16 +12,26 @@ export class MothershipShipSheetSBT extends ActorSheet { /** @override */ static get defaultOptions() { - return mergeObject(super.defaultOptions, { + + var options = { classes: ["mosh", "sheet", "actor", "ship"], template: "systems/mosh/templates/actor/ship-sheet-sbt.html", width: 700, height: 840, tabs: [{ navSelector: "#sheet-tabs", contentSelector: "#sheet-body", initial: "character" }, - { navSelector: "#side-tabs", contentSelector: "#side-body", initial: "close" }], - // { navSelector: "#side-tabs", contentSelector: "#side-body", initial: "crew" }], + { navSelector: "#side-tabs", contentSelector: "#side-body", initial: "close" }], + // { navSelector: "#side-tabs", contentSelector: "#side-body", initial: "crew" }], scrollY: [".sheet-body", "scroll-lock"] - }); + } + + + if (game.release.generation >= 12) { + return foundry.utils.mergeObject(super.defaultOptions, options); + } else { + return mergeObject(super.defaultOptions, options); + } + + } _onOpenDeckplan(event) { @@ -65,7 +75,7 @@ export class MothershipShipSheetSBT extends ActorSheet { data.dtypes = ["String", "Number", "Boolean"]; // console.log(this.actor.getRollTableData('AqGWwoWXzijFs427')); - + // for (let attr of Object.values(data.data.system.attributes)) { // attr.isCheckbox = attr.dtype === "Boolean"; // } @@ -89,7 +99,7 @@ export class MothershipShipSheetSBT extends ActorSheet { let maxHull = superData.supplies.hull.max; - superData.supplies.hull.percentage = " [ "+Math.round(maxHull * 0.25)+" | "+Math.round(maxHull * 0.5)+" | "+Math.round(maxHull * 0.75)+" ]"; + superData.supplies.hull.percentage = " [ " + Math.round(maxHull * 0.25) + " | " + Math.round(maxHull * 0.5) + " | " + Math.round(maxHull * 0.75) + " ]"; //Run Setup @@ -103,12 +113,12 @@ export class MothershipShipSheetSBT extends ActorSheet { // data.data.system.runSetup = false; // } - this._prepareMegadamage(data); + this._prepareMegadamage(superData); return data.data; } - + /** * Organize and classify Items for Character sheets. * @@ -143,13 +153,13 @@ export class MothershipShipSheetSBT extends ActorSheet { cargo.push(i); } else if (i.type === 'module') { modules.push(i); - } else if (i.type == 'repair'){ + } else if (i.type == 'repair') { i.name = i.name.split('.')[0]; - if(i.system.major){ + if (i.system.major) { majorRepairs.push(i); } - else{ + else { minorRepairs.push(i); } } @@ -165,31 +175,30 @@ export class MothershipShipSheetSBT extends ActorSheet { } - async _prepareMegadamage(sheetData){ - const actorData = sheetData.data; - + async _prepareMegadamage(sheetData) { + const actorData = sheetData; //A script to return the data from a table. - let tableId = game.settings.get('mosh','table1eMegadamageEffects'); + let tableId = game.settings.get('mosh', 'table1eMegadamageEffects'); let currentLocation = ''; let tableLocation = ''; //find where this table is located //get current compendium let compendium = game.packs; //loop through each compendium - compendium.forEach(function(pack){ - //is this a pack of rolltables? - if (pack.metadata.type === 'RollTable') { - //log where we are - currentLocation = pack.metadata.id; - //loop through each pack to find the right table - pack.index.forEach(function(table) { - //is this our table? - if (table._id === tableId) { - //grab the table location - tableLocation = currentLocation; + compendium.forEach(function (pack) { + //is this a pack of rolltables? + if (pack.metadata.type === 'RollTable') { + //log where we are + currentLocation = pack.metadata.id; + //loop through each pack to find the right table + pack.index.forEach(function (table) { + //is this our table? + if (table._id === tableId) { + //grab the table location + tableLocation = currentLocation; + } + }); } - }); - } }); //get table data let tableData = await game.packs.get(tableLocation).getDocument(tableId); @@ -197,38 +206,37 @@ export class MothershipShipSheetSBT extends ActorSheet { let megadamageHTML = ""; let entries = Array.from(tableData.results.entries()); - //Prep Megadamage List // if(actorData.system.megadamage.hits.length > 0){ - let index = 0; - for(const entry of entries){ + let index = 0; + for (const entry of entries) { - // Megadamage - Only Active - if(index != 0 && actorData.system.megadamage.hits.includes(index)){ - // megadamageHTML += `  `; - megadamageHTML += `  `; - megadamageHTML += `${index} | ${entry[1].text}

`; - } else if(index != 0) { - // megadamageHTML += `  `; - megadamageHTML += `
 `; - megadamageHTML += `${index} | ${entry[1].text}

`; - } - index++; + // Megadamage - Only Active + if (index != 0 && actorData.megadamage.hits.includes(index)) { + // megadamageHTML += `  `; + megadamageHTML += `  `; + megadamageHTML += `${index} | ${entry[1].text}

`; + } else if (index != 0) { + // megadamageHTML += `  `; + megadamageHTML += `
 `; + megadamageHTML += `${index} | ${entry[1].text}

`; } + index++; + } // } else { - - // megadamageHTML += entries[0][1].text + "

"; + + // megadamageHTML += entries[0][1].text + "

"; // } await this.object.update({ - "data.megadamage.html": megadamageHTML + "system.megadamage.html": megadamageHTML }); - if(actorData.system.page == undefined){ - actorData.system.page = {}; + if (actorData.page == undefined) { + actorData.page = {}; } - actorData.system.page.megadamageMenuClass = ""; + actorData.page.megadamageMenuClass = ""; // if(actorData.system.megadamage.open){ // actorData.system.page.megadamageMenuClass = "sbt-megadamage-open" @@ -236,7 +244,7 @@ export class MothershipShipSheetSBT extends ActorSheet { // actorData.system.page.megadamageMenuClass = "sbt-megadamage-closed" // } - + // await this.object.update({ // "data.megadamage.hits": [] // }); @@ -253,22 +261,22 @@ export class MothershipShipSheetSBT extends ActorSheet { html.on('mousedown', '.megadamage-button', ev => { const data = this.object; - + const div = $(ev.currentTarget); const targetKey = div.data("key"); - if(data.data.system.megadamage.hits.includes(targetKey)){ - const index = data.data.system.megadamage.hits.indexOf(targetKey); - data.data.system.megadamage.hits.splice(index, 1); + if (data.system.megadamage.hits.includes(targetKey)) { + const index = data.system.megadamage.hits.indexOf(targetKey); + data.system.megadamage.hits.splice(index, 1); } else { - data.data.system.megadamage.hits.push(targetKey); + data.system.megadamage.hits.push(targetKey); } - + this.object.update({ - "data.megadamage.hits": data.data.system.megadamage.hits + "system.megadamage.hits": data.system.megadamage.hits }); - this._prepareMegadamage(data); + this._prepareMegadamage(data.system); }); // Create inventory item. @@ -276,7 +284,7 @@ export class MothershipShipSheetSBT extends ActorSheet { // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteEmbeddedDocuments("Item",[li.data("itemId")]); + this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")]); li.slideUp(200, () => this.render(false)); }); @@ -296,7 +304,13 @@ export class MothershipShipSheetSBT extends ActorSheet { //Quantity adjuster html.on('mousedown', '.item-quantity', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.quantity; if (event.button == 0) { @@ -316,7 +330,7 @@ export class MothershipShipSheetSBT extends ActorSheet { html.find('.stat-roll').click(ev => { const div = $(ev.currentTarget); const statName = div.data("key"); - this.actor.rollCheck(null,'low',statName,null,null,null); + this.actor.rollCheck(null, 'low', statName, null, null, null); }); //Weapons @@ -330,11 +344,16 @@ export class MothershipShipSheetSBT extends ActorSheet { }); // Rollable Weapon - not needed since individual ship weapons are not fired - // html.find('.weapon-roll').click(ev => { - // const li = ev.currentTarget.closest(".item"); - // const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - // this.actor.rollCheck(null,'low','combat',null,null,item); - // }); + html.find('.weapon-roll').click(ev => { + // const li = ev.currentTarget.closest(".item"); + // const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + // this.actor.rollCheck(null,'low','combat',null,null,item); + + const li = ev.currentTarget.closest(".item"); + this.actor.printDescription(li.dataset.itemId, { + event: ev + }); + }); // Distress Signal html.find('.distress-button').click(ev => { @@ -393,7 +412,13 @@ export class MothershipShipSheetSBT extends ActorSheet { html.on('mousedown', '.weapon-ammo', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) let amount = item.system.ammo; if (event.button == 0) { @@ -454,7 +479,13 @@ export class MothershipShipSheetSBT extends ActorSheet { // Grab any data associated with this control. - const data = duplicate(header.dataset); + var data; + if (game.release.generation >= 12) { + data = foundry.utils.duplicate(header.dataset); + } else { + data = duplicate(header.dataset); + } + // Initialize a default name. const name = `New ${type.capitalize()}`; // Prepare the item object. @@ -462,18 +493,18 @@ export class MothershipShipSheetSBT extends ActorSheet { name: name, type: type, data: data, - system : {} + system: {} }; - if(type == "repair"){ - itemData.system.major = (header.dataset.subtype == "major"); + if (type == "repair") { + itemData.system.major = (header.dataset.subtype == "major"); } // Remove the type from the dataset since it's in the itemData.type prop. delete itemData.data["type"]; // Finally, create the item! - return this.actor.createEmbeddedDocuments("Item",[itemData]); + return this.actor.createEmbeddedDocuments("Item", [itemData]); } @@ -488,7 +519,7 @@ export class MothershipShipSheetSBT extends ActorSheet { const dataset = element.dataset; if (dataset.roll) { - let roll = new Roll(dataset.roll, this.actor.data.data); + let roll = new Roll(dataset.roll, this.actor.data.system); let label = dataset.label ? `Rolling ${dataset.label} to score under ${dataset.target}` : ''; roll.roll().toMessage({ speaker: ChatMessage.getSpeaker({ actor: this.actor }), diff --git a/module/actor/ship-sheet.js b/module/actor/ship-sheet.js index a1b13ff..af1bd37 100644 --- a/module/actor/ship-sheet.js +++ b/module/actor/ship-sheet.js @@ -22,7 +22,7 @@ export class MothershipShipSheet extends ActorSheet { const data = super.getData(); data.dtypes = ["String", "Number", "Boolean"]; - + // for (let attr of Object.values(data.data.system.attributes)) { // attr.isCheckbox = attr.dtype === "Boolean"; // } @@ -45,7 +45,7 @@ export class MothershipShipSheet extends ActorSheet { let maxHull = superData.supplies.hull.max; - superData.supplies.hull.percentage = " [ "+Math.round(maxHull * 0.25)+" | "+Math.round(maxHull * 0.5)+" | "+Math.round(maxHull * 0.75)+" ]"; + superData.supplies.hull.percentage = " [ " + Math.round(maxHull * 0.25) + " | " + Math.round(maxHull * 0.5) + " | " + Math.round(maxHull * 0.75) + " ]"; return data.data; } @@ -103,7 +103,7 @@ export class MothershipShipSheet extends ActorSheet { // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteEmbeddedDocuments("Item",[li.data("itemId")]); + this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")]); li.slideUp(200, () => this.render(false)); }); @@ -123,7 +123,12 @@ export class MothershipShipSheet extends ActorSheet { //Quantity adjuster html.on('mousedown', '.item-quantity', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.quantity; if (event.button == 0) { @@ -143,7 +148,7 @@ export class MothershipShipSheet extends ActorSheet { html.find('.stat-roll').click(ev => { const div = $(ev.currentTarget); const statName = div.data("key"); - this.actor.rollCheck(null,'low',statName,null,null,null); + this.actor.rollCheck(null, 'low', statName, null, null, null); }); //Weapons @@ -158,13 +163,23 @@ export class MothershipShipSheet extends ActorSheet { // Rollable Weapon html.find('.weapon-roll').click(ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null,'low','combat',null,null,item); + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } + this.actor.rollCheck(null, 'low', 'combat', null, null, item); }); html.on('mousedown', '.weapon-ammo', ev => { const li = ev.currentTarget.closest(".item"); - const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)) + var item; + if (game.release.generation >= 12) { + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } else { + item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + } let amount = item.system.ammo; if (event.button == 0) { @@ -220,7 +235,13 @@ export class MothershipShipSheet extends ActorSheet { // Get the type of item to create. const type = header.dataset.type; // Grab any data associated with this control. - const data = duplicate(header.dataset); + var data; + if (game.release.generation >= 12) { + data = foundry.utils.duplicate(header.dataset); + } else { + data = duplicate(header.dataset); + } + // Initialize a default name. const name = `New ${type.capitalize()}`; // Prepare the item object. @@ -233,7 +254,7 @@ export class MothershipShipSheet extends ActorSheet { delete itemData.data["type"]; // Finally, create the item! - return this.actor.createEmbeddedDocuments("Item",[itemData]); + return this.actor.createEmbeddedDocuments("Item", [itemData]); } diff --git a/module/item/item-sheet.js b/module/item/item-sheet.js index e6b7024..fd53040 100644 --- a/module/item/item-sheet.js +++ b/module/item/item-sheet.js @@ -6,12 +6,18 @@ export class MothershipItemSheet extends ItemSheet { /** @override */ static get defaultOptions() { - return mergeObject(super.defaultOptions, { + var options = { classes: ["mosh", "sheet", "item"], width: 600, height: 500, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }] - }); + }; + + if (game.release.generation >= 12) { + return foundry.utils.mergeObject(super.defaultOptions, options); + } else { + return mergeObject(super.defaultOptions, options); + } } /** @override */ @@ -32,8 +38,8 @@ export class MothershipItemSheet extends ItemSheet { const data = super.getData(); const superData = data.system; - if(data.type == "weapon"){ - if(superData.ranges.value == "" && superData.ranges.medium > 0){ + if (data.type == "weapon") { + if (superData.ranges.value == "" && superData.ranges.medium > 0) { superData.ranges.value = superData.ranges.short + "/" + superData.ranges.medium + "/" + superData.ranges.long; superData.ranges.medium = 0; } @@ -45,7 +51,7 @@ export class MothershipItemSheet extends ItemSheet { data.data.system.settings.useCalm = game.settings.get("mosh", "useCalm"); data.data.system.settings.hideWeight = game.settings.get("mosh", "hideWeight"); data.data.system.settings.firstEdition = game.settings.get("mosh", "firstEdition"); - data.data.system.settings.androidPanic = game.settings.get("mosh", "androidPanic"); + data.data.system.settings.androidPanic = game.settings.get("mosh", "androidPanic"); return data.data; } diff --git a/module/mosh.js b/module/mosh.js index 462334c..a58b5b1 100644 --- a/module/mosh.js +++ b/module/mosh.js @@ -102,6 +102,7 @@ Hooks.once('init', async function () { Hooks.once("ready", async function () { + // Wait to register hotbar drop hook on ready so that modules could register earlier if they want to Hooks.on("hotbarDrop", (bar, data, slot) => createMothershipMacro(data, slot)); //Calm & 1e/0e character updates diff --git a/templates/actor/ship-sheet-sbt.html b/templates/actor/ship-sheet-sbt.html index d5ac431..75d0498 100644 --- a/templates/actor/ship-sheet-sbt.html +++ b/templates/actor/ship-sheet-sbt.html @@ -29,7 +29,7 @@
{{{system.megadamage.html}}}
-
+