From 49e5b47fe184932b206be26c7b8052c616f9135e Mon Sep 17 00:00:00 2001 From: bithir Date: Wed, 13 Oct 2021 13:06:10 +0100 Subject: [PATCH 1/3] More defensive code for system guide, plus our own logging --- script/common/actor.js | 2 +- script/common/devmsg.js | 2 +- script/common/dialog.js | 2 +- script/common/hooks.js | 44 ++++++++++++++++++++++---------------- script/common/item.js | 4 ++-- script/common/migration.js | 43 ++++++++++++++++++------------------- script/common/roll.js | 6 +++--- 7 files changed, 55 insertions(+), 48 deletions(-) diff --git a/script/common/actor.js b/script/common/actor.js index af6e6c8d..1e670555 100644 --- a/script/common/actor.js +++ b/script/common/actor.js @@ -14,7 +14,7 @@ export class SymbaroumActor extends Actor { // console.log("Init data - complete"); this.data.numRituals = 0; // console.log("Compute items"); - console.log("original items",this.data.items); + game.symbaroum.log("original items",this.data.items); let items = this.data.items.contents.sort( (a, b) => { if(a.data.type == b.data.type) { return a.data.name == b.data.name ? 0 : a.data.name < b.data.name ? -1:1; diff --git a/script/common/devmsg.js b/script/common/devmsg.js index 99482851..1c45e848 100644 --- a/script/common/devmsg.js +++ b/script/common/devmsg.js @@ -26,7 +26,7 @@ export function sendDevMessage() } latestVersion = Math.max(latestVersion, msgenvelope.version); } - console.info("latestVersion after "+latestVersion); + game.symbaroum.info("latestVersion after "+latestVersion); game.settings.set('symbaroum', 'symbaroumDevMessageVersionNumber', latestVersion); }) .fail(function(data) { diff --git a/script/common/dialog.js b/script/common/dialog.js index f1c02f86..d42716ed 100644 --- a/script/common/dialog.js +++ b/script/common/dialog.js @@ -101,7 +101,7 @@ export async function prepareRollAttribute(actor, attributeName, armor, weapon) } attri_defaults.impeding = html.find("#impeding")[0].checked ? "checked":""; } - // console.log("Damage bonus",damModifier); + // game.symbaroum.log("Damage bonus",damModifier); await rollAttribute(actor, attributeName, getTarget(), targetAttributeName, favour, modifier, armor, weapon, advantage, damModifier); }, }, diff --git a/script/common/hooks.js b/script/common/hooks.js index 0ff0ba01..b1851b0a 100644 --- a/script/common/hooks.js +++ b/script/common/hooks.js @@ -45,6 +45,18 @@ Hooks.once('init', () => { config: SYMBAROUM, SymbaroumConfig, }; + game.symbaroum.debug = (...args) => { + console.debug("Symbaroum |", ...args); + }; + game.symbaroum.error = (...args) => { + console.error("Symbaroum |", ...args); + }; + game.symbaroum.info = (...args) => { + console.info("Symbaroum |", ...args); + }; + game.symbaroum.log = (...args) => { + console.log("Symbaroum |", ...args); + }; game.settings.register('symbaroum', 'worldTemplateVersion', { // worldTemplateVersion is deprecated - not to use anymore @@ -417,7 +429,7 @@ Hooks.on('renderChatMessage', async (chatItem, html, data) => { functionStuff.actor = tok.actor; functionStuff.targetData.token = targetToken; functionStuff.targetData.actor = targetToken.actor; - console.log("from hook: ", functionStuff); + // game.symbaroum.log("from hook: ", functionStuff); buildRolls(functionStuff); await chatItem.unsetFlag(game.system.id, 'resistRoll'); return; @@ -470,17 +482,25 @@ async function showReleaseNotes() { let newReleasePack = game.packs.find((p) => p.metadata.label === releasePackLabel); if (newReleasePack === null || newReleasePack === undefined) { - console.error('No pack found'); + let err = "No pack found for the system guide in this release"; + game.symbaroum.error(err); + ui.notifications.error(err); // This is bad - the symbaroum pack does not exist in the system packages return; } await newReleasePack.getIndex(); let newReleaseNotes = newReleasePack.index.find((j) => j.name === releaseNoteName); - // console.log("Found new release notes in the compendium pack"); + // game.symbaroum.log("Found new release notes in the compendium pack"); + if( newReleaseNotes === undefined || newReleaseNotes === null ) { + let err = "No system guide found in this release"; + game.symbaroum.error(err); + ui.notifications.error(err); + return; + } // Don't delete until we have new release Pack - if (newReleaseNotes !== undefined && newReleaseNotes !== null && oldReleaseNotes !== null && oldReleaseNotes !== undefined) { + if (oldReleaseNotes !== null && oldReleaseNotes !== undefined) { await oldReleaseNotes.delete(); } @@ -489,28 +509,16 @@ async function showReleaseNotes() { await newReleaseJournal.setFlag('symbaroum', 'ver', newVer); - // Before we show final - tidy up release prior to this - tidyReleaseNotes11(); - // Show journal await newReleaseJournal.sheet.render(true, { sheetMode: 'text' }); } catch (error) { - console.error(error); + game.symbaroum.error(error); } // end of try } // end of if(isgm) } // end of function -async function tidyReleaseNotes11() { - const releaseNoteName = 'Symbaroum System guide EN (1.1)'; - let old11ReleaseNotes = game.journal.getName(releaseNoteName); - // Delete Delete Delete - if (old11ReleaseNotes !== undefined && old11ReleaseNotes !== null) { - await old11ReleaseNotes.delete(); - } -} - async function setupEmit() { - console.info('Setting up Symbaroum emit system'); + game.symbaroum.info('Setting up Symbaroum emit system'); SymbaroumCommsListener.ready(); } diff --git a/script/common/item.js b/script/common/item.js index 08f870ad..45a1aa9c 100644 --- a/script/common/item.js +++ b/script/common/item.js @@ -157,7 +157,7 @@ export class SymbaroumItem extends Item { data.data.isDistance = false; } let baseDamage = data.data.baseDamage; - // console.log("baseDamage["+baseDamage+"]"); + // game.symbaroum.log("baseDamage["+baseDamage+"]"); if( baseDamage === null || baseDamage === undefined || baseDamage === "" ) { baseDamage = "1d8"; } @@ -2051,7 +2051,7 @@ async function standardPowerResult(rollData, functionStuff){ } if(healResult){ - // console.log(healResult) + // game.symbaroum.log(healResult) templateData.hasDamage = healResult.hasDamage; templateData.damageText = healResult.damageText; templateData.dmgFormula = healResult.dmgFormula; diff --git a/script/common/migration.js b/script/common/migration.js index 25f30228..0343b281 100644 --- a/script/common/migration.js +++ b/script/common/migration.js @@ -5,15 +5,14 @@ export const migrateWorld = async () => { let worldTemplateVersion; try{ worldTemplateVersion = Number(game.settings.get("symbaroum", "worldTemplateVersion")); - console.info(`Detected worldTemplateVersion: ${worldTemplateVersion}`); + game.symbaroum.info(`Detected worldTemplateVersion: ${worldTemplateVersion}`); } catch(e){ - console.error(e); + game.symbaroum.error(e); worldTemplateVersion = 1; - console.info("No template version detected... Default to 1") + game.symbaroum.info("No template version detected... Default to 1") } if(worldTemplateVersion && (worldTemplateVersion < 3.3) && game.user.isGM){ //the world hasn't been properly migrated since foundryVTT0.8 -// if((worldTemplateVersion < 3.3) && game.user.isGM){ //the world hasn't been properly migrated since foundryVTT0.8 migrateOldWorld(worldTemplateVersion) } let systemVersion = game.system.data.version; @@ -21,15 +20,15 @@ export const migrateWorld = async () => { try{ worldSystemVersion = game.settings.get('symbaroum', 'systemMigrationVersion') }catch (e) { - console.error(e); + game.symbaroum.error(e); worldSystemVersion = '0'; } - console.info(`Last migration on this world: ${worldSystemVersion}`); + game.symbaroum.info(`Last migration on this world: ${worldSystemVersion}`); // the NEEDS_MIGRATION_VERSION have to be increased for migration to happen const NEEDS_MIGRATION_VERSION = '3.0.8'; const COMPATIBLE_MIGRATION_VERSION = '0' || isNaN('NaN'); let needMigration = foundry.utils.isNewerVersion(NEEDS_MIGRATION_VERSION, worldSystemVersion); - console.warn('needMigration', needMigration, systemVersion); + game.symbaroum.info('needMigration', needMigration, systemVersion); if(needMigration && game.user.isGM){ // Perform the migration @@ -45,24 +44,24 @@ export const migrateWorld = async () => { try { const updateData = migrateActorData(actor.toObject(), worldSystemVersion); if (!foundry.utils.isObjectEmpty(updateData)) { - console.info(`Migrating Actor entity ${actor.name}`); + game.symbaroum.info(`Migrating Actor entity ${actor.name}`); await actor.update(updateData, {enforceTypes: false}); } } catch (e) { e.message = `Failed migration for Actor ${actor.name}: ${e.message}`; - console.error(e); + game.symbaroum.error(e); } } for (let item of game.items) { try { const updateData = migrateItemData(item.toObject(), worldSystemVersion); if (!foundry.utils.isObjectEmpty(updateData)) { - console.info(`Migrating Item entity ${item.name}`); + game.symbaroum.info(`Migrating Item entity ${item.name}`); await item.update(updateData, {enforceTypes: false}); } } catch (e) { e.message = `Failed migration for Item ${item.name}: ${e.message}`; - console.error(e); + game.symbaroum.error(e); } } for (let scene of game.scenes) { @@ -75,7 +74,7 @@ export const migrateWorld = async () => { } } catch (err) { err.message = `Failed migration for Scene ${scene.name}: ${err.message}`; - console.error(err); + game.symbaroum.error(err); } } for (let pack of game.packs.filter((p) => p.metadata.package === "world" && ["Actor", "Item", "Scene"].includes(p.metadata.entity))) { @@ -105,24 +104,24 @@ const migrateOldWorld = async (worldTemplateVersion) => { try { const updateData = migrateOldActorData(actor.toObject(), worldTemplateVersion); if (!foundry.utils.isObjectEmpty(updateData)) { - console.info(`Migrating Actor entity ${actor.name}`); + game.symbaroum.info(`Migrating Actor entity ${actor.name}`); await actor.update(updateData, {enforceTypes: false}); } } catch (e) { e.message = `Failed migration for Actor ${actor.name}: ${e.message}`; - console.error(e); + game.symbaroum.error(e); } } for (let item of game.items) { try { const updateData = migrateOldItemData(item.toObject(), worldTemplateVersion); if (!foundry.utils.isObjectEmpty(updateData)) { - console.info(`Migrating Item entity ${item.name}`); + game.symbaroum.info(`Migrating Item entity ${item.name}`); await item.update(updateData, {enforceTypes: false}); } } catch (e) { e.message = `Failed migration for Item ${item.name}: ${e.message}`; - console.error(e); + game.symbaroum.error(e); } } for (let scene of game.scenes) { @@ -135,7 +134,7 @@ const migrateOldWorld = async (worldTemplateVersion) => { } } catch (err) { err.message = `Failed migration for Scene ${scene.name}: ${err.message}`; - console.error(err); + game.symbaroum.error(err); } } game.settings.set("symbaroum", "worldTemplateVersion", 4); @@ -240,11 +239,11 @@ export const migrateCompendium = async function (pack, worldSystemVersion) { // Save the entry, if data was changed if ( foundry.utils.isObjectEmpty(updateData) ) continue; await ent.update(updateData); - console.info(`Migrated ${entity} entity ${ent.name} in Compendium ${pack.collection}`); + game.symbaroum.info(`Migrated ${entity} entity ${ent.name} in Compendium ${pack.collection}`); } catch(err) { err.message = `Failed system migration for entity ${ent.name} in pack ${pack.collection}: ${err.message}`; - console.error(err); + game.symbaroum.error(err); } } }; @@ -284,7 +283,7 @@ const migrateOldActorData = (actor, worldTemplateVersion) => { }; let itemsChanged = false; - // console.log(actor); + // game.symbaroum.log(actor); const items = actor.items.map((item) => { const itemUpdate = migrateOldItemData(item, worldTemplateVersion); if (!isObjectEmpty(itemUpdate)) { @@ -465,11 +464,11 @@ export const migrateOldCompendium = async function (pack, worldTemplateVersion) // Save the entry, if data was changed if ( foundry.utils.isObjectEmpty(updateData) ) continue; await ent.update(updateData); - console.info(`Migrated ${entity} entity ${ent.name} in Compendium ${pack.collection}`); + game.symbaroum.info(`Migrated ${entity} entity ${ent.name} in Compendium ${pack.collection}`); } catch(err) { err.message = `Failed system migration for entity ${ent.name} in pack ${pack.collection}: ${err.message}`; - console.error(err); + game.symbaroum.error(err); } } }; diff --git a/script/common/roll.js b/script/common/roll.js index 7ab543ec..964e21df 100644 --- a/script/common/roll.js +++ b/script/common/roll.js @@ -179,7 +179,7 @@ export async function getOwnerPlayer(actor){ return idValue },[]) let owningPlayers = game.users.filter(user => user.active && !user.isGM && ownerIds.includes(user.data._id)); - console.log(owningPlayers); + // game.symbaroum.log(owningPlayers); return(owningPlayers) } @@ -334,7 +334,7 @@ export async function createResistRollChatButton(functionStuff){ }; ChatMessage.create(chatData); //send data message to the player session - console.log("toto"); + const emitData = Object.assign({}, functionStuff); emitData.mainText= functionStuff.targetData.name + game.i18n.localize("CHAT.RESIST_TEXT_BUTTON") + getAttributeLabel(functionStuff.targetData.actor, functionStuff.targetData.resistAttributeName); emitData.actor = null; @@ -499,7 +499,7 @@ export async function damageRollWithDiceParams(functionStuff, critSuccess, attac else newRollDmgString += " - 0"; } // final damage - // console.log(newRollDmgString); + // game.symbaroum.log(newRollDmgString); let dmgRoll= new Roll(newRollDmgString).evaluate(); return{ From f0f8135b4a39e6ac2d4c76e8da224bf45862eacc Mon Sep 17 00:00:00 2001 From: bithir Date: Wed, 13 Oct 2021 13:44:49 +0100 Subject: [PATCH 2/3] Lost changes from RT8 --- script/common/dialog.js | 58 +++++++++++++++++++++------------------ template/chat/dialog.html | 14 ++++------ 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/script/common/dialog.js b/script/common/dialog.js index d42716ed..0616190c 100644 --- a/script/common/dialog.js +++ b/script/common/dialog.js @@ -11,7 +11,6 @@ export async function prepareRollAttribute(actor, attributeName, armor, weapon) weaponModifier.attribute = []; weaponModifier.attributeModifiers = []; weaponModifier.damageChoices = []; - weaponModifier.damageBonus = []; if(weapon !== null) { @@ -61,21 +60,21 @@ export async function prepareRollAttribute(actor, attributeName, armor, weapon) } attri_defaults.additionalModifier = damModifier; - for(let bonus of weaponModifier.damageBonus) { - damModifier += `${bonus.damageModifier}[${bonus.label}]`; - } for(let optionalBonus of weaponModifier.damageChoices) { - if(optionalBonus.type === "check") { + if(optionalBonus.type === "fixed") { + damModifier += `${optionalBonus.alternatives.damMod}[${optionalBonus.label}]` + } else if(optionalBonus.type === "check") { // Find if the box is checked - let ticked = html.find(`#${optionalBonus.label}`); + let ticked = html.find(`#${optionalBonus.id}`); + console.log("Hfm", ticked, optionalBonus); if( ticked.length > 0 && ticked[0].checked ) - damModifier += ticked[0].value; + damModifier += `${optionalBonus.alternatives.damMod}[${optionalBonus.label}]`; } else if( optionalBonus.type === "radio") { // Find the selected radio button - let radioSelection = html.find("input[name='"+optionalBonus.identifier+"']"); + let radioSelection = html.find(`input[name='${optionalBonus.id}']`); for( let f of radioSelection) { if( f.checked ) - damModifier += f.value; + damModifier += `${f.value}[${optionalBonus.label}]`; } } } @@ -101,7 +100,7 @@ export async function prepareRollAttribute(actor, attributeName, armor, weapon) } attri_defaults.impeding = html.find("#impeding")[0].checked ? "checked":""; } - // game.symbaroum.log("Damage bonus",damModifier); + console.log("Damage bonus",damModifier); await rollAttribute(actor, attributeName, getTarget(), targetAttributeName, favour, modifier, armor, weapon, advantage, damModifier); }, }, @@ -174,12 +173,11 @@ function calculateWeaponModifiers(actor, weapon, weaponModifier) let choice = {}; choice["label"] = robust[0].name; choice["type"] = "check"; + choice["id"] = robust[0].id; let damMod = `+1d${(dice+1)*2}`; let damlabel = `(${damMod})`; - damMod = `${damMod}[${robust[0].name}]`; choice["alternatives"] = { - "label":damlabel, - "damMod":damMod + "damMod":damMod, }; choice["restrition"] = "1st-attack"; // Only apply damage bonus to first attack weaponModifier.damageChoices.push(choice); @@ -192,24 +190,30 @@ function calculateWeaponModifiers(actor, weapon, weaponModifier) if( power.level > 0) { weaponModifier.attribute.push( { attribute:"strong", - label: ironFist[0].name + label: ironFist[0].name, + id: ironFist[0].id }); } if( power.level === 2) { - let bonus = {}; - bonus.label = ironFist[0].name; - bonus.damageModifier = "+1d4"; - // No choice - weaponModifier.damageBonus.push(bonus); + let choice = {}; + choice.label = ironFist[0].name; + choice["type"] = "fixed"; + choice["alternatives"] = { + "damMod":"+1d4" + }; + // No choice + weaponModifier.damageChoices.push(choice); } else if( power.level === 3) { let choice = {}; choice["type"] = "radio"; choice["label"] = ironFist[0].name; - choice["identifier"] = "weapMod_"+ironFist[0].name; - choice["defaultSelect"] = `+1d4[${ironFist[0].name}]`; + choice["id"] = ironFist[0].id; + choice["defaultSelect"] = `+1d4`; choice["alternatives"] = {}; - choice["alternatives"][`+1d4[${ironFist[0].name}]`] = `${ironFist[0].name} - ${power.lvlName} (1d4)`; - choice["alternatives"][`+1d8[${ironFist[0].name}]`] = `${ironFist[0].name} - ${power.lvlName} (1d8)`; + // Change this to fixed values + // Add in alternatives.damageModifier + choice["alternatives"][`+1d4`] = `${ironFist[0].name} - ${power.lvlName} (1d4)`; + choice["alternatives"][`+1d8`] = `${ironFist[0].name} - ${power.lvlName} (1d8)`; weaponModifier.damageChoices.push(choice); } } @@ -232,13 +236,12 @@ function calculateWeaponModifiers(actor, weapon, weaponModifier) if( weapon.isDistance && hunterInstinct.length > 0 && hunterInstinct[0].getLevel().level > 1) { let choice = {}; choice["label"] = hunterInstinct[0].name; + choice["id"] = hunterInstinct[0].id; choice["type"] = "check"; let damMod = `+1d4`; - let damlabel = `(${damMod})`; - damMod = `${damMod}[${hunterInstinct[0].name}]`; + let damlabel = `(${damMod})`; choice["alternatives"] = { - "label":damlabel, - "damMod":damMod + "damMod":damMod, }; weaponModifier.damageChoices.push(choice); } @@ -247,6 +250,7 @@ function calculateWeaponModifiers(actor, weapon, weaponModifier) if(weapon.qualities.precise) { let attributeModifier = { label: game.i18n.localize("QUALITY.PRECISE"), + id: weapon.id, modifier: "+1" } weaponModifier.attributeModifiers.push(attributeModifier); diff --git a/template/chat/dialog.html b/template/chat/dialog.html index 8e1c0eb0..ce5fbaa9 100644 --- a/template/chat/dialog.html +++ b/template/chat/dialog.html @@ -50,18 +50,16 @@
- {{#ifgt weaponModifier.damageBonus.length 0}} - {{#each weaponModifier.damageBonus as |bonus|}} -
- {{/each}} - {{/ifgt}} {{#ifgt weaponModifier.damageChoices.length 0}} {{#each weaponModifier.damageChoices as |choicebonus|}} + {{#ife choicebonus.type "fixed"}} +
+ {{/ife}} {{#ife choicebonus.type "radio"}} -
+
{{/ife}} {{#ife choicebonus.type "check"}} -
+
{{/ife}} {{/each}} {{/ifgt}} @@ -76,4 +74,4 @@ {{/if}} - + \ No newline at end of file From d124da8d07dec0c514753c647c304e9968d7438c Mon Sep 17 00:00:00 2001 From: pwatson100 Date: Wed, 13 Oct 2021 15:46:25 +0100 Subject: [PATCH 3/3] Updated release number and release notes. --- Release_Notes.txt | 5 ++++- system.json | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Release_Notes.txt b/Release_Notes.txt index 21bd3ecf..eb980342 100644 --- a/Release_Notes.txt +++ b/Release_Notes.txt @@ -200,4 +200,7 @@ Version 3.1.1 - Code simplification and debuging Version 3.1.2 -- updated readmen compendium as the user guide had vanished. \ No newline at end of file +- updated readmen compendium as the user guide had vanished. + +Version 3.1.3 +- Fixed a number of minor issues \ No newline at end of file diff --git a/system.json b/system.json index d83a6c78..874416a0 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "symbaroum", "title": "Symbaroum", "description": "Twilight falls. Davokar darkens.", - "version": "3.1.2", + "version": "3.1.3", "minimumCoreVersion": "0.8.5", "compatibleCoreVersion": "0.8.9", "authors": ["Paul Watson", "Bithir", "Khaali"], @@ -231,7 +231,7 @@ "initiative": "1d20[tiebreaker]/100000 + @initiative.value", "socket": true, "url": "https://github.com/pwatson100/symbaroum", - "manifest": "https://github.com/pwatson100/symbaroum/releases/download/3.1.2/system.json", - "download": "https://github.com/pwatson100/symbaroum/releases/download/3.1.2/master.zip", + "manifest": "https://github.com/pwatson100/symbaroum/releases/download/3.1.3/system.json", + "download": "https://github.com/pwatson100/symbaroum/releases/download/3.1.3/master.zip", "license": "LICENSE.txt" }