tellement de trucs

This commit is contained in:
rwanoux
2024-05-13 18:27:54 +02:00
parent 9cee590267
commit 83c3f1df0b
83 changed files with 1457 additions and 702 deletions
+31 -1
View File
@@ -1,4 +1,5 @@
import { onManageActiveEffect, prepareActiveEffectCategories } from "../system/effects.mjs";
import { preloadHandlebarsTemplates } from "../system/handlebars-manager.mjs";
/**
* Extend the basic ActorSheet with some very simple modifications
@@ -53,7 +54,7 @@ export class VermineActorSheet extends ActorSheet {
/** @override */
activateListeners(html) {
super.activateListeners(html);
html.find('.min-max-edit').click(this._onMinMaxEdit.bind(this))
// Render the item sheet for viewing/editing prior to the editable check.
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
@@ -105,6 +106,35 @@ export class VermineActorSheet extends ActorSheet {
this.actor.update(update)
}
async _onMinMaxEdit(event) {
event.preventDefault();
let propPath = event.currentTarget.dataset.prop;
let propName = propPath.split('.').slice(-1).pop()
let data = {
actorName: this.actor.name,
propName: propName
}
let html = await renderTemplate('systems/vermine2047/templates/dialogs/min-max-edit.hbs', data);
let ui = new Dialog({
title: "edit : " + propName,
content: html,
buttons: {
roll: {
label: "ok",
callback: (html) => { }
},
cancel: {
label: game.i18n.localize('Close'),
callback: () => { }
}
}
}
);
ui.render(true)
}
async _onItemCreate(event) {
event.preventDefault();
const header = event.currentTarget;
+35 -10
View File
@@ -1,6 +1,6 @@
import { onManageActiveEffect, prepareActiveEffectCategories } from "../system/effects.mjs";
import { VermineActorSheet } from "./actor-sheet.mjs";
import { RollDialog } from "../system/dialogs.mjs";
import RollDialog from "../system/dialogs/rollDialog.mjs";
import { TotemPicker } from "../system/applications.mjs";
/**
@@ -14,7 +14,8 @@ export class VermineCharacterSheet extends VermineActorSheet {
return mergeObject(super.defaultOptions, {
classes: ["vermine2047", "sheet", "character", "actor"],
template: "systems/vermine2047/templates/actor/actor-sheet.hbs",
width: "fit-content",
height: "fit-content",
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
});
}
@@ -73,6 +74,14 @@ export class VermineCharacterSheet extends VermineActorSheet {
for (let [k, v] of Object.entries(context.system.abilities)) {
v.label = game.i18n.localize(context.system.abilities[k].label) ?? k;
}
for (let [k, v] of Object.entries(context.system.skills)) {
if (v.value >= 2) {
let spe = this.actor.items.filter(it => it.type == "specialty").filter(spec => spec.system.skill == k);
v.specialties = spe
}
}
}
/**
@@ -103,10 +112,23 @@ export class VermineCharacterSheet extends VermineActorSheet {
// Choose Totem
html.find('.chooseTotem').click(this._onTotemButton.bind(this));
html.find('.ability .rollable').click(this._onRoll.bind(this));
html.find('[data-totem-name]').click(this._onClickTotemDice.bind(this))
html.find('[data-totem-name]').click(this._onClickTotemDice.bind(this));
if (!this.actor.flags.world?.editMode) {
this.disableInputs(html)
}
}
disableInputs(html) {
for (let input of html.find('input')) {
if (input.name != "flags.world.editMode") {
input.setAttribute('disabled', true)
}
}
for (let select of html.find('select')) {
select.setAttribute('disabled', true)
}
}
async _onClickTotemDice(ev) {
let el = ev.currentTarget;
let totem = el.dataset.totemName;
@@ -116,14 +138,17 @@ export class VermineCharacterSheet extends VermineActorSheet {
if (value === oldValue) { value-- };
let updates = {};
updates[`system.adaptation.totems.${totem}.value`] = value;
let totems = this.actor.system.adaptation.totems;
let sumTotems = Object.keys(totems).reduce(function (previous, key) {
return previous + totems[key].value;
}, 0);
if (sumTotems >5) {
ui.notifications.warn('vous ne pouvez pas avoir plus de 5 dés totems')
//verifier le max des dés totems
let sum = value;
switch (totem) {
case "human":
sum += this.actor.system.adaptation.totems.adapted.value;
break;
case "adapted":
sum += this.actor.system.adaptation.totems.human.value;
break;
}
console.log(sumTotems, updates)
if (sum > 5) { return ui.notifications.warn("pas plus de 5 dés totems") }
await this.actor.update(updates);
}
/**
+14 -2
View File
@@ -9,7 +9,7 @@ export class VermineItemSheet extends ItemSheet {
return mergeObject(super.defaultOptions, {
classes: ["vermine2047", "sheet", "item"],
width: 520,
height: 480,
height: "auto",
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }]
});
}
@@ -34,7 +34,7 @@ export class VermineItemSheet extends ItemSheet {
// Use a safe clone of the item data for further operations.
const itemData = context.item;
// Retrieve the roll data for TinyMCE editors.
context.rollData = {};
let actor = this.object?.parent ?? null;
@@ -58,7 +58,19 @@ export class VermineItemSheet extends ItemSheet {
// Everything below here is only needed if the sheet is editable
if (!this.isEditable) return;
//click on wound radio
html.find('.damages-row [type="radio"]').click(ev => {
this._onClickDamage(ev)
})
// Roll handlers, click handlers, etc. would go here.
}
async _onClickDamage(ev) {
if (!ev.currentTarget.checked) { return }
let prop = ev.currentTarget.name;
let update = {};
update[prop] = ev.currentTarget.value - 1
this.item.update(update)
}
}
-265
View File
@@ -35,268 +35,3 @@ export class CombatResultDialog extends Dialog {
}
/**
* Represents a dialog for rolling dice.
*/
export class RollDialog extends Dialog {
/**
* Creates a new RollDialog instance.
* @param {Object} data - The data for the dialog.
* @param {HTMLElement} html - The HTML content of the dialog.
* @param {Object} options - The options for the dialog.
* @param {Function} close - The callback function for closing the dialog.
*/
constructor(data, html, options, close = undefined) {
let conf = {
title: "jet de dés",
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer !",
callback: () => {
this.roll()
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
},
close: close,
}
return super({ ...conf, ...data }, options);
};
/**
* Creates a new RollDialog instance.
* @param {Object} data - The data for the dialog.
* @param {HTMLElement} html - The HTML content of the dialog.
* @param {Object} options - The options for the dialog.
* @param {Function} close - The callback function for closing the dialog.
*/
static async create(data = {
label: null,
rolltype: null,
NoD: 1,
Reroll: false,
actorId: game.user.character.id
}) {
// Retrieve the actor data based on the actorId
data.actor = await game.actors.get(data.actorId);
data.config = CONFIG.VERMINE;
// Define options for the dialog
let options = { classes: ["nocDialog"], width: 420, height: 'fit-content', 'z-index': 99999 };
// Render the HTML template for the dialog
let html = await renderTemplate('systems/vermine2047/templates/roll-dialog.hbs', data);
// Return a new RollDialog instance with the provided data, HTML, and options
return new RollDialog(data, html, options);
}
/**
* Retrieves the default options for the RollDialog.
*/
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
focus: true,
classes: ["dialog vermine-roll"],
});
}
/**
* Retrieves the data for the dialog.
* @returns {Object} The context data for the dialog.
*/
getData() {
// Get the context data from the superclass
let context = super.getData();
context.data = this.data;
context.config = CONFIG.VERMINE;
return context;
}
/**
* Activates event listeners for the dialog.
* @param {HTMLElement} html - The HTML element of the dialog.
*/
async activateListeners(html) {
// Activate event listeners from the superclass
super.activateListeners(html);
// Retrieve roll data and set up event listeners
await this.getRollData();
let rollInputs = html.find('[data-roll');
for (let inp of rollInputs) {
// Add event listener for roll input changes
inp.addEventListener('change', await this.getRollData.bind(this))
};
let selectAbil = html.find('#ability')[0];
// Set the maximum value for self control based on ability value
html.find("#self_control")[0].max = selectAbil.value;
selectAbil.addEventListener('change', this._onChangeAbility.bind(this));
let selfControl = html.find('#self_control')[0]
// Add event listener for self control changes
selfControl.addEventListener('change', this._onChangeSelfControl.bind(this));
};
/**
* Retrieves the roll data for the dialog.
* @param {Event} ev - The event triggering the roll data retrieval.
*/
async getRollData(ev) {
console.log(this)
// Calculate and store the roll data
this.rollData = {
actor: this.data.actor,
NoD: this.getDicePool(),
Reroll: this.getReroll(),
difficulty: this.getDifficulty(),
rollLabel: this.data.labelKey,
totems: this.getTotems(),
self_control: this.getSelfControl(),
max_effort: this.getMaxEffort()
}
};
/**
* Handles the change in self control value.
* @param {Event} ev - The event triggering the change in self control value.
*/
_onChangeSelfControl(ev) {
let html = this.element[0];
// Update the displayed self control value based on the event
html.querySelector('#self_control_value').innerText = ev.currentTarget.value;
};
/**
* Retrieves the self control value from the HTML element.
* @returns {number} The self control value.
*/
getSelfControl() {
let html = this.element[0];
// Parse and return the self control value from the HTML element
let selfControl = parseInt(html.querySelector('#self_control').value)
return selfControl
}
/**
* Retrieves the maximum effort value from the HTML element.
* @returns {number} The maximum effort value.
*/
getMaxEffort() {
let html = this.element[0];
// Retrieve and return the maximum effort value from the HTML element
return parseInt(html.querySelector('#ability').value);
}
/**
* Retrieves the selected totems from the HTML element.
* @returns {Object} An object containing the selected totems.
*/
getTotems() {
let html = this.element[0];
// Check and store the status of human and adapted totems
let totems = {
human: html.querySelector('#human-totem')?.checked,
adapted: html.querySelector('#adapted-totem')?.checked,
}
return totems
}
/**
* Handles the change in ability value.
* @param {Event} ev - The event triggering the change in ability value.
*/
_onChangeAbility(ev) {
let html = this.element[0];
// Retrieve the selected ability score and update related elements
let score = html.querySelector('#ability').options[html.querySelector('#ability').selectedIndex].value;
// Check if the score is a number, otherwise set it to 0
if (!typeof score == "number") {
score = 0
}
html.querySelector('#abilityScore').value = score;
html.querySelector('#self_control').max = score;
}
/**
* Retrieves the total dice pool based on various factors.
* @returns {number} The total dice pool value.
*/
getDicePool() {
// Retrieve the HTML element
let html = this.element[0];
// Get the ability value or set to 0 if not found
let abilValue = html.querySelector('#ability').options[html.querySelector('#ability').selectedIndex].value || 0;
// Get the skill value or set to 0 if not found
let skillValue = html.querySelector('#skill').options[html.querySelector('#skill').selectedIndex].dataset.pool || 0;
// Get the self control value
let selfControl = html.querySelector('#self_control').value;
// Calculate bonuses based on certain conditions
let bonuses =
(html.querySelector('#usingSpecialization').checked ? 1 : 0) +
(html.querySelector('#helped').checked ? 1 : 0) +
(html.querySelector('#usingTools').checked ? 1 : 0);
// Calculate the total dice pool
let total = parseInt(abilValue) + parseInt(selfControl) + parseInt(skillValue) + bonuses;
return total || 0;
}
/**
* Retrieves the reroll value based on selected skill.
* @returns {number} The reroll value.
*/
getReroll() {
// Retrieve the HTML element
let html = this.element[0];
// Get the selected skill index
let selected = html.querySelector('#skill').selectedIndex;
// Get the reroll value from the selected skill or set to 0 if not found
let reroll = html.querySelector('#skill').options[selected].dataset.reroll || 0;
return parseInt(reroll) || 0;
}
/**
* Retrieves the difficulty value based on selected option.
* @returns {number} The difficulty value.
*/
getDifficulty() {
// Retrieve the HTML element
let html = this.element[0];
// Get the selected index for difficulty
let selected = html.querySelector('#difficulty').selectedIndex;
// Get the difficulty value from the selected option or set to 0 if not found
let diff = html.querySelector('#difficulty').options[selected].value || 0;
return parseInt(diff) || 0;
}
/**
* Performs a dice roll based on the roll data and handles self control checks.
* @returns {Promise} A promise that resolves with the result of the dice roll.
*/
async roll() {
// Check if self control is required for the roll
if (this.rollData.self_control > 0) {
// Check if the actor has enough self control
if (this.rollData.actor.system.attributes.self_control.value < this.rollData.self_control) {
// Display a warning message if self control is insufficient
ui.notifications.warn('vous navez pas assez de sang-froid');
// Re-render the dialog
this.render(true);
return false; // Exit the function if self control is insufficient
}
}
// Deduct self control points if necessary
if (this.rollData.self_control > 0) {
// Update the actor's self control value
await this.rollData.actor.update({ "system.attributes.self_control.value": this.rollData.actor.system.attributes.self_control.value - this.rollData.self_control });
}
// Perform the dice roll using VermineUtils
return VermineUtils.roll({ ...this.rollData });
}
}
+316
View File
@@ -0,0 +1,316 @@
import { VermineUtils } from "../roll.mjs";
/**
* Represents a dialog for rolling dice.
*/
export default class RollDialog extends Dialog {
/**
* Creates a new RollDialog instance.
* @param {Object} data - The data for the dialog.
* @param {HTMLElement} html - The HTML content of the dialog.
* @param {Object} options - The options for the dialog.
* @param {Function} close - The callback function for closing the dialog.
*/
constructor(data, html, options, close = undefined) {
let conf = {
title: "jet de dés",
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
label: "Lancer !",
callback: () => {
this.roll()
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler",
callback: () => { this.close() }
}
},
close: close,
}
return super({ ...conf, ...data }, options);
};
/**
* Creates a new RollDialog instance.
* @param {Object} data - The data for the dialog.
* @param {HTMLElement} html - The HTML content of the dialog.
* @param {Object} options - The options for the dialog.
* @param {Function} close - The callback function for closing the dialog.
*/
static async create(data = {
label: null,
rolltype: null,
NoD: 1,
Reroll: false,
actorId: game.user.character.id
}) {
// Retrieve the actor data based on the actorId
data.actor = await game.actors.get(data.actorId);
data.availableSpecialties = data.actor.items.filter(it => it.type == "specialty");
data.availableItems = data.actor.items.filter(it => it.type == "item");
data.config = CONFIG.VERMINE;
// Define options for the dialog
let options = { classes: ["vermineDialog"], width: "fit-content", height: 'fit-content', 'z-index': 99999 };
// Render the HTML template for the dialog
let html = await renderTemplate('systems/vermine2047/templates/dialogs/roll-dialog.hbs', data);
// Return a new RollDialog instance with the provided data, HTML, and options
return new RollDialog(data, html, options);
}
/**
* Retrieves the default options for the RollDialog.
*/
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
focus: true,
classes: ["dialog vermine-roll"],
});
}
/**
* Retrieves the data for the dialog.
* @returns {Object} The context data for the dialog.
*/
getData() {
// Get the context data from the superclass
let context = super.getData();
context.data = this.data;
context.config = CONFIG.VERMINE;
// Return the context data
return context;
}
prepareItems() {
return this.data.actor.items.filter(it => it.type == "item")
}
prepareSpecialties() {
return this.data.actor.items.filter(it => it.type == "specialty")
}
/**
* Activates event listeners for the dialog.
* @param {HTMLElement} html - The HTML element of the dialog.
*/
async activateListeners(html) {
// Activate event listeners from the superclass
super.activateListeners(html);
// Retrieve roll data and set up event listeners
await this.getRollData();
let rollInputs = html.find('[data-roll');
for (let inp of rollInputs) {
// Add event listener for roll input changes
inp.addEventListener('change', await this.getRollData.bind(this))
};
this.displaySpecialties();
let selectAbil = html.find('#ability')[0];
// Set the maximum value for self control based on ability value
html.find("#self_control")[0].max = selectAbil.value;
selectAbil.addEventListener('change', this._onChangeAbility.bind(this));
let selfControl = html.find('#self_control')[0]
// Add event listener for self control changes
selfControl.addEventListener('change', this._onChangeSelfControl.bind(this));
};
/**
* Retrieves the roll data for the dialog.
* @param {Event} ev - The event triggering the roll data retrieval.
*/
async getRollData(ev) {
console.log(this)
// Calculate and store the roll data
this.rollData = {
actor: this.data.actor,
NoD: this.getDicePool(),
Reroll: this.getReroll(),
difficulty: this.getDifficulty(),
handicap: this.getHandicap(),
rollType: this.getRollType(),
rollLabel: this.getLabel(),
totems: this.getTotems(),
self_control: this.getSelfControl(),
max_effort: this.getMaxEffort()
}
this.displaySpecialties();
};
/**
* Handles the change in self control value.
* @param {Event} ev - The event triggering the change in self control value.
*/
_onChangeSelfControl(ev) {
let html = this.element[0];
// Update the displayed self control value based on the event
html.querySelector('#self_control_value').innerText = ev.currentTarget.value;
};
getHandicap() {
let html = this.element[0];
// Parse and return the self control value from the HTML element
let handicap = parseInt(html.querySelector('#handicap').value)
return handicap
}
getRollType() {
let html = this.element[0];
// Update the displayed self control value based on the event
if (html.querySelector('select#skill').value) {
return "skill"
} return "ability"
}
getLabel() {
let html = this.element[0];
if (this.getRollType() == "skill") {
return html.querySelector('select#skill').options[html.querySelector('select#skill').selectedIndex].dataset.label
}
return html.querySelector('select#ability').options[html.querySelector('select#ability').selectedIndex].dataset.label
}
displaySpecialties() {
console.log(this)
let specialties = this.element[0].querySelectorAll('[data-spec-skill]');
for (let specEl of specialties) {
if (specEl.dataset.specSkill != this.getLabel()) {
specEl.style.display = "none";
specEl.querySelector('input').checked = null;
} else { specEl.style.display = "inline" }
}
}
/**
* Retrieves the self control value from the HTML element.
* @returns {number} The self control value.
*/
getSelfControl() {
let html = this.element[0];
// Parse and return the self control value from the HTML element
let selfControl = parseInt(html.querySelector('#self_control').value)
return selfControl
}
/**
* Retrieves the maximum effort value from the HTML element.
* @returns {number} The maximum effort value.
*/
getMaxEffort() {
let html = this.element[0];
// Retrieve and return the maximum effort value from the HTML element
return parseInt(html.querySelector('#ability').value);
}
/**
* Retrieves the selected totems from the HTML element.
* @returns {Object} An object containing the selected totems.
*/
getTotems() {
let html = this.element[0];
// Check and store the status of human and adapted totems
let totems = {
human: html.querySelector('#human-totem')?.checked,
adapted: html.querySelector('#adapted-totem')?.checked,
}
return totems
}
/**
* Handles the change in ability value.
* @param {Event} ev - The event triggering the change in ability value.
*/
_onChangeAbility(ev) {
let html = this.element[0];
// Retrieve the selected ability score and update related elements
let score = html.querySelector('#ability').options[html.querySelector('#ability').selectedIndex].value;
// Check if the score is a number, otherwise set it to 0
if (!typeof score == "number") {
score = 0
}
html.querySelector('#abilityScore').value = score;
html.querySelector('#self_control').max = score;
}
/**
* Retrieves the total dice pool based on various factors.
* @returns {number} The total dice pool value.
*/
getDicePool() {
// Retrieve the HTML element
let html = this.element[0];
// Get the ability value or set to 0 if not found
let abilValue = html.querySelector('#ability').options[html.querySelector('#ability').selectedIndex].value || 0;
// Get the skill value or set to 0 if not found
let skillValue = html.querySelector('#skill').options[html.querySelector('#skill').selectedIndex].dataset.pool || 0;
// Get the self control value
let selfControl = html.querySelector('#self_control').value;
// Calculate bonuses based on certain conditions
console.log(html.querySelector('#usingTools').checked)
let bonuses =
(html.querySelector('#usingSpecialization')?.checked ? 1 : 0) +
(html.querySelector('#helped').checked ? 1 : 0) +
(html.querySelector('#usingTools').checked ? 1 : 0);
// Calculate the total dice pool
let total = parseInt(abilValue) + parseInt(selfControl) + parseInt(skillValue) + bonuses;
return total || 0;
}
/**
* Retrieves the reroll value based on selected skill.
* @returns {number} The reroll value.
*/
getReroll() {
// Retrieve the HTML element
let html = this.element[0];
// Get the selected skill index
let selected = html.querySelector('#skill').selectedIndex;
// Get the reroll value from the selected skill or set to 0 if not found
let reroll = html.querySelector('#skill').options[selected].dataset.reroll || 0;
return parseInt(reroll) || 0;
}
/**
* Retrieves the difficulty value based on selected option.
* @returns {number} The difficulty value.
*/
getDifficulty() {
// Retrieve the HTML element
let html = this.element[0];
// Get the selected index for difficulty
let selected = html.querySelector('#difficulty').selectedIndex;
// Get the difficulty value from the selected option or set to 0 if not found
let diff = html.querySelector('#difficulty').options[selected].value || 0;
return parseInt(diff) || 0;
}
/**
* Performs a dice roll based on the roll data and handles self control checks.
* @returns {Promise} A promise that resolves with the result of the dice roll.
*/
async roll() {
// Check if self control is required for the roll
if (this.rollData.self_control > 0) {
// Check if the actor has enough self control
if (this.rollData.actor.system.attributes.self_control.value < this.rollData.self_control) {
// Display a warning message if self control is insufficient
ui.notifications.warn('vous navez pas assez de sang-froid');
// Re-render the dialog
this.render(true);
return false; // Exit the function if self control is insufficient
}
}
// Deduct self control points if necessary
if (this.rollData.self_control > 0) {
// Update the actor's self control value
await this.rollData.actor.update({ "system.attributes.self_control.value": this.rollData.actor.system.attributes.self_control.value - this.rollData.self_control });
}
// Perform the dice roll using VermineUtils
return VermineUtils.roll({ ...this.rollData });
}
}
+17 -11
View File
@@ -10,32 +10,31 @@ export async function initUserDice(dice3d, user) {
name: 'regular_' + user.name,
description: "regular dice for " + user.name,
category: "vermine 2047",
foreground: '#9F8003',
foreground: oppositeColor(baseColor),
background: baseColor,
outline: 'black',
texture: 'none',
material: 'plastic',
visibility: 'visible'
});
visibility: 'visible',
}, "preferred");
dice3d.addColorset({
name: 'human_' + user.name,
description: "human totem dice for " + user.name,
category: "vermine 2047",
foreground: '#9F8003',
foreground: oppositeColor(lightenColor(baseColor, 60)),
background: lightenColor(baseColor, 60),
outline: 'black',
material: 'plastic',
visibility: 'visible'
visibility: 'visible',
});
dice3d.addColorset({
name: 'adapted_' + user.name,
description: "adapted totem dice for " + user.name,
category: "vermine 2047",
foreground: '#9F8003',
foreground: oppositeColor(darkenColor(baseColor, 60)),
background: darkenColor(baseColor, 60),
outline: 'black',
material: 'plastic',
visibility: 'visible'
visibility: 'visible',
});
await user.setFlag("world", "diceInit", true);
@@ -57,4 +56,11 @@ export function lightenColor(color, percent) {
const G = ((num >> 8) & 0x00FF) - amt;
const B = (num & 0x0000FF) - amt;
return '#' + (0x1000000 + (R < 0 ? 0 : R > 255 ? 255 : R) * 0x10000 + (G < 0 ? 0 : G > 255 ? 255 : G) * 0x100 + (B < 0 ? 0 : B > 255 ? 255 : B)).toString(16).slice(1);
}
export function oppositeColor(color) {
const num = parseInt(color.replace('#', ''), 16);
const R = 255 - (num >> 16);
const G = 255 - ((num >> 8) & 0x00FF);
const B = 255 - (num & 0x0000FF);
return '#' + (0x1000000 + R * 0x10000 + G * 0x100 + B).toString(16).slice(1);
}
+41 -15
View File
@@ -35,8 +35,12 @@ export const preloadHandlebarsTemplates = async function () {
// creature partials
"systems/vermine2047/templates/actor/creature/creature-combat.hbs",
// additional templates
"systems/vermine2047/templates/roll-dialog.hbs",
// dialog templates
"systems/vermine2047/templates/dialogs/roll-dialog.hbs",
//items damages
"systems/vermine2047/templates/item/partials/damages.html",
]);
};
@@ -98,7 +102,12 @@ export const registerHandlebarsHelpers = function () {
return text;
});
//return damge data
Handlebars.registerHelper('getDamagesData', function (damageObject, prop) {
let propObject = damageObject[prop]
let propValue = propObject[damageObject.value - 1]
return propValue
});
// return threat level information
Handlebars.registerHelper('threatLevel', function (property, level, options) {
if (level < 1 || level > 4)
@@ -218,17 +227,8 @@ export const registerHandlebarsHelpers = function () {
});
Handlebars.registerHelper('range', function () {
var args = Array.prototype.slice.call(arguments),
rangeArgs = args.slice(0, -1),
options = args[args.length - 1];
return range.apply(null, rangeArgs)
.map(function (num) { return options.fn(num); })
.join('');
});
// return age type information
// booleans if if equal if greater etc...
Handlebars.registerHelper('ife', function (arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
});
@@ -252,11 +252,34 @@ export const registerHandlebarsHelpers = function () {
return (arg1.includes(arg2)) ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('repeat', function (times, start, block) {
//math operations
Handlebars.registerHelper('math_add', function (a, b, options) {
return (parseInt(a) + parseInt(b))
});
Handlebars.registerHelper('math_subs', function (a, b, options) {
return (parseInt(a) - parseInt(b))
});
Handlebars.registerHelper('math_mult', function (a, b, options) {
return (parseInt(a) * parseInt(b))
});
Handlebars.registerHelper('math_div', function (a, b, options) {
return (parseInt(a) / parseInt(b))
});
// loop with named index
Handlebars.registerHelper('repeat', function (times, start, indexLabel, block) {
var accum = '';
if (!indexLabel) { indexLabel = "index" }
if (!start) { start = 0; }
for (var i = start; i < times + start; ++i) {
block.data.index = i;
block.data[indexLabel] = i;
block.data.first = i === start;
block.data.last = i === (times + start - 1);
accum += block.fn(this);
@@ -264,4 +287,7 @@ export const registerHandlebarsHelpers = function () {
return accum;
});
Handlebars.registerHelper("setVar", function (varName, varValue, options) {
options.data.root[varName] = varValue;
});
}
+17 -22
View File
@@ -1,4 +1,4 @@
import { RollDialog } from "./dialogs.mjs";
import RollDialog from "./dialogs/rollDialog.mjs";
import { initUserDice } from "./dice3d.mjs";
import { VermineUtils } from "./roll.mjs";
import { registerTours } from "./tour.mjs";
@@ -11,6 +11,11 @@ export const registerHooks = function () {
Hooks.once('diceSoNiceReady', async (dice3d) => {
dice3d.addSystem({ id: "Vermine2047", name: "Vermine 2047" }, "preferred");
game.users.forEach(user => {
initUserDice(dice3d, user)
});
dice3d.addDicePreset({
type: "d10",
labels: [
@@ -26,17 +31,17 @@ export const registerHooks = function () {
"systems/vermine2047/assets/images/die/d10-0.webp",
],
system: "Vermine2047"
});
system: "Vermine2047",
game.users.forEach(user => {
initUserDice(dice3d, user)
});
},);
});
Hooks.on('renderChatMessage', async (message, html, data) => {
let rerollTitle = html[0].querySelector(".reroll-fromroll h4");
if (rerollTitle) {
rerollTitle.addEventListener("click", () => { html[0].querySelector(".reroll").classList.toggle('visible') })
}
if (message.user._id != game.user._id || !game.user.isGM) {
html[0].querySelectorAll("input").forEach(inp => inp.disabled = true);
html[0].querySelectorAll("div.reroll-from-effort").forEach(el => el.style.display = "none")
@@ -101,6 +106,7 @@ export const registerHooks = function () {
if (actor.img == "icons/svg/mystery-man.svg") {
actor.updateSource({ "img": `systems/vermine2047/assets/icons/actors/${actor.type}.webp` });
}
});
Hooks.on("preCreateItem", function (item) {
@@ -136,18 +142,7 @@ export const registerHooks = function () {
}*/
}
});
/* Hooks.on("chatCommandsReady", function (chatCommands) {
chatCommands.registerCommand(chatCommands.createCommandFromData({
commandKey: "/dr",
invokeOnCommand: (chatlog, messageText, chatdata) => {
Roll.get().parse(messageText);
},
shouldDisplayToChat: false,
iconClass: "fa-dice-d6",
description: "Roll Vermine 2047 check"
}));
});*/
}
Hooks.on("createActor", function (actor, options, id) {
actor.setFlag("world", "editMode", true)
})
}
+3 -6
View File
@@ -13,9 +13,7 @@ export class VermineUtils {
if (totems.human) {
NoD--;
modFormula = "(1D10cs>=" + difficulty + `[human_${game.user.name}]*2)`;
await actor.update({
"system.adaptation.totems.human.value": actor.system.adaptation.totems.human.value - 1
})
}
// Vérification des totems adaptés
if (totems.adapted) {
@@ -26,9 +24,7 @@ export class VermineUtils {
} else {
modFormula = "(1D10cs>=" + difficulty + `[adapted_${game.user.name}]*2)`;
}
await actor.update({
"system.adaptation.totems.adapted.value": actor.system.adaptation.totems.adapted.value - 1
})
};
// Construction de la formule de base
@@ -45,6 +41,7 @@ export class VermineUtils {
let roll = new Roll(formula, actor.getRollData());
//effectuer le lancé
await roll.evaluate();
roll.dice.forEach(die => die.options.appearance = { system: "vermine2047" })
//afficher le lancer 3d
await VermineUtils.showDiceSoNice(roll);
// afficher le résultat dans le chat
-1
View File
@@ -18,7 +18,6 @@ import { VermineCombat, VermineCombatTracker } from "./system/fight.mjs";
// Import helper/utility classes and constants.
import { preloadHandlebarsTemplates, registerHandlebarsHelpers } from "./system/handlebars-manager.mjs";
import { VERMINE } from "./system/config.mjs";
import { initUserDice } from "./system/dice3d.mjs";
/* -------------------------------------------- */
/* Init Hook */