Finishing v0.0.3

Layout fixes
Added support for rolling skill on spells
Fixed migration
Cleaned up the code
Fixed Hjältarnas Tid skill error, updated layout, fixed buttons not working
Fixed right click menu for weapons
Added roll dialog and exceptional rolls
Updated skills styling
Co-Authored-By: erebus <erebus@rikspolisen.se>
Co-Committed-By: erebus <erebus@rikspolisen.se>
This commit was merged in pull request #2.
This commit is contained in:
2020-12-01 16:30:39 +00:00
parent 6f030bd6b5
commit 2e389704ea
23 changed files with 702 additions and 89 deletions

View File

@@ -84,7 +84,7 @@ export default class KHDiceRoller {
});
}
async rollSkillInChat(skillName, skillValue, showValue, speaker) {
async rollSkillInChat(skillName, skillValue, showValue, speaker, openclosed) {
const roll = new Roll(`1d100`);
let res = roll.roll();
@@ -95,16 +95,43 @@ export default class KHDiceRoller {
computedName += " (" + skillValue + ")"
}
if(openclosed === undefined) {
openclosed = 0
}
let rollData = {
name: computedName,
res: res
};
if(skillValue > 0) {
if(res.total <= skillValue) {
let oneRes = Math.floor((res.total / 1) % 10);
let tenRes = Math.floor((res.total / 10) % 10);
if(openclosed < 0) {
rollData.closed = Math.abs(openclosed)
}
if(openclosed > 0) {
rollData.opened = Math.abs(openclosed)
}
if(openclosed < 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes) {
// roll is closed
rollData.failure = true
} else if(openclosed > 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes){
// roll is opened
rollData.success = true
} else {
rollData.failure = true
if (res.total <= skillValue) {
rollData.success = true
} else {
rollData.failure = true
}
}
if(oneRes === tenRes) {
rollData.excetional = true
}
}
@@ -121,4 +148,101 @@ export default class KHDiceRoller {
},
});
}
async rollSkillDialogInChat(skillName, skillValue, showValue, speaker, startopen) {
const id = randomID();
if(startopen === undefined) {
startopen = 0
}
const content = await renderTemplate("systems/kopparhavet/templates/roll-dialog.html", {
id,
startopen,
skillName,
skillValue,
});
await new Dialog({
title: game.i18n.localize("ROLL.TITLE"),
content,
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("BUTTON.ROLL"),
callback: async () => {
const container = document.getElementById(id);
let openclosed = container.querySelector('[name="openclosed"]').value
const roll = new Roll(`1d100`);
let res = roll.roll();
let computedName = skillName
if(showValue) {
computedName += " (" + skillValue + ")"
}
let rollData = {
name: computedName,
res: res
};
// Evaluate result only if we have a positive skillvalue
if(skillValue > 0) {
let oneRes = Math.floor((res.total / 1) % 10);
let tenRes = Math.floor((res.total / 10) % 10);
if(openclosed < 0) {
rollData.closed = Math.abs(openclosed)
}
if(openclosed > 0) {
rollData.opened = Math.abs(openclosed)
}
if(openclosed < 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes) {
// roll is closed
rollData.failure = true
} else if(openclosed > 0 && oneRes !== 0 && Math.abs(openclosed) >= oneRes){
// roll is opened
rollData.success = true
} else {
if (res.total <= skillValue) {
rollData.success = true
} else {
rollData.failure = true
}
}
if(oneRes === tenRes) {
rollData.excetional = true
}
}
const html = await renderTemplate("systems/kopparhavet/templates/dice/roll.html", rollData);
await roll.toMessage({
create: true,
content: html,
user: game.user._id,
speaker: {
actor: speaker._id,
token: speaker.token,
alias: speaker.name,
},
});
},
},
two: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("BUTTON.CANCEL"),
},
},
},
{
classes: ["dialog", "kopparhavet"],
}).render(true);
}
}

View File

@@ -0,0 +1,21 @@
/**
* Perform a system migration for the entire World, applying migrations for Actors, Items, and Compendium packs
* @return {Promise} A Promise which resolves once the migration is completed
*/
export const migrateWorld = async function () {
ui.notifications.info(
`Applying System Migration for version ${game.system.data.version}. Please be patient and do not close your game or shut down your server.`,
{permanent: true}
);
// Migrate to v0.0.3 from v0.0.2 and v0.0.1
game.items.forEach((item) => {
if(item.data.type === "spell") {
item.update({"data.roll.label": "SPELL.ROLLTITLE"});
}
});
// Set the migration as complete
game.settings.set("kopparhavet", "worldSchemaVersion", game.system.data.version);
ui.notifications.info(`System Migration to version ${game.system.data.version} completed!`, { permanent: true });
};