fix: Correct critical bugs and complete Creature/Group DataModel implementation

- Fix TypeError: controls.find is not a function in hooks.mjs
- Fix undefined 'npc' variable in applications.mjs
- Fix CONFIG.VERMINE.model undefined by checking game.system.template existence
- Fix TypeError: html.find(...).forEach is not a function in roll.mjs
- Fix Cannot set properties of undefined (setting 'initial') in actor.mjs
- Fix Cannot read properties of undefined (reading 'difficulty') in actor.mjs
- Fix ActiveEffect application phase 'initial' already completed by adding combatStatus to base template
- Fix Missing helper: 'select' in roll-dialog.hbs (removed invalid Handlebars select block)
- Add SIZE_LEVELS labels to creatureSizeLevels config
- Add SIZE_LEVELS translations to fr.json
- Add combatStatus to base actor template
- Convert all .html templates to .hbs for Foundry v14 compatibility
- Update item-sheet.mjs to use .hbs extension
- Update handlebars-manager.mjs to use .hbs for all partials

Complete Vermine2047 Creature and Group sheet implementation:
- Creature: Pattern, Size, Role, Pack with computed values
- Group: Totem, Reserve, Morale, Objectives, Members management
- All templates functional with proper styling

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-06-04 20:58:22 +02:00
parent f9f07cbc7e
commit 30d6f71fc7
43 changed files with 19225 additions and 609 deletions
+52 -9
View File
@@ -12,9 +12,9 @@ export class VermineCreatureSheet extends VermineActorSheet {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["vermine2047", "sheet", "actor", "creature"],
template: "systems/vermine2047/templates/actor/actor-sheet.hbs",
width: 300,
height: 300,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
width: 650,
height: 600,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }]
});
}
@@ -52,6 +52,12 @@ export class VermineCreatureSheet extends VermineActorSheet {
this._prepareItems(context);
}
// Prepare Creature data and items.
if (actorData.type == 'creature') {
this._prepareItems(context);
this._prepareCreatureData(context);
}
// Add roll data for TinyMCE editors.
context.rollData = context.actor.getRollData();
@@ -68,6 +74,18 @@ export class VermineCreatureSheet extends VermineActorSheet {
*
* @return {undefined}
*/
_prepareItems(context) {
context.gear = this.actor.itemTypes['item'];
context.traits = this.actor.itemTypes['trait'];
}
/**
* Prepare Character type specific data.
*
* @param {Object} actorData The actor to prepare.
*
* @return {undefined}
*/
_prepareCharacterData(context) {
// Handle ability scores.
for (let [k, v] of Object.entries(context.system.abilities)) {
@@ -76,15 +94,40 @@ export class VermineCreatureSheet extends VermineActorSheet {
}
/**
* Organize and classify Items for Character sheets.
*
* @param {Object} actorData The actor to prepare.
* Prepare Creature type specific data for the sheet.
*
* @param {Object} context The context data to prepare.
* @return {undefined}
*/
_prepareItems(context) {
context.gear = this.actor.itemTypes['item'];
context.traits = this.actor.itemTypes['trait'];
_prepareCreatureData(context) {
if (this.actor.type !== 'creature') return;
// Add computed values to context
context.computed = context.system.computed || {};
// Get labels for pattern, size, role
const patternLevel = context.system.pattern?.value || 1;
const sizeLevel = context.system.size?.value || 1;
const roleLevel = context.system.role?.value || 1;
const packLevel = context.system.pack?.value || 0;
// Add pattern label
const patternConfig = CONFIG.VERMINE.creaturePatternLevels[patternLevel];
if (patternConfig) {
context.patternLabel = game.i18n.localize(patternConfig.label);
}
// Add size label (using numeric for now)
context.sizeLabel = sizeLevel;
// Add role label
const roleConfig = CONFIG.VERMINE.creatureRoleLevels[roleLevel];
if (roleConfig) {
context.roleLabel = game.i18n.localize(roleConfig.label);
}
// Add pack label
context.packLabel = packLevel > 0 ? packLevel : game.i18n.localize('VERMINE.none');
}
/* -------------------------------------------- */
+167
View File
@@ -0,0 +1,167 @@
import { onManageActiveEffect, prepareActiveEffectCategories } from "../system/effects.mjs";
import { VermineActorSheet } from "./actor-sheet.mjs";
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class VermineCreatureSheet extends VermineActorSheet {
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["vermine2047", "sheet", "actor", "creature"],
template: "systems/vermine2047/templates/actor/actor-sheet.hbs",
width: 650,
height: 600,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }]
});
}
/** @override */
get template() {
return `systems/vermine2047/templates/actor/actor-${this.actor.type}-sheet.hbs`;
}
/* -------------------------------------------- */
/** @override */
getData() {
// Retrieve the data structure from the base sheet. You can inspect or log
// the context variable to see the structure, but some key properties for
// sheets are the actor object, the data object, whether or not it's
// editable, the items array, and the effects array.
const context = super.getData();
// Use a safe clone of the actor data for further operations.
const actorData = this.actor.toObject(false);
// Add the actor's data to context.data for easier access, as well as flags.
context.system = actorData.system;
context.flags = actorData.flags;
context.config = CONFIG.VERMINE;
// Prepare character data and items.
if (actorData.type == 'character') {
this._prepareItems(context);
this._prepareCharacterData(context);
}
// Prepare NPC data and items.
if (actorData.type == 'npc') {
this._prepareItems(context);
}
// Prepare Creature data and items.
if (actorData.type == 'creature') {
this._prepareItems(context);
this._prepareCreatureData(context);
}
// Add roll data for TinyMCE editors.
context.rollData = context.actor.getRollData();
// Prepare active effects
context.effects = prepareActiveEffectCategories(this.actor.effects);
return context;
/**
* Prepare Creature type specific data for the sheet.
*
* @param {Object} context The context data to prepare.
* @return {undefined}
*/
_prepareCreatureData(context) {
if (this.actor.type !== 'creature') return;
// Add computed values to context
context.computed = context.system.computed || {};
// Get labels for pattern, size, role
const patternLevel = context.system.pattern?.value || 1;
const sizeLevel = context.system.size?.value || 1;
const roleLevel = context.system.role?.value || 1;
const packLevel = context.system.pack?.value || 0;
// Add pattern label
const patternConfig = CONFIG.VERMINE.creaturePatternLevels[patternLevel];
if (patternConfig) {
context.patternLabel = game.i18n.localize(patternConfig.label);
}
// Add size label (using numeric for now)
context.sizeLabel = sizeLevel;
// Add role label
const roleConfig = CONFIG.VERMINE.creatureRoleLevels[roleLevel];
if (roleConfig) {
context.roleLabel = game.i18n.localize(roleConfig.label);
}
// Add pack label
context.packLabel = packLevel > 0 ? packLevel : game.i18n.localize('VERMINE.none');
}}
/**
* Organize and classify Items for Character sheets.
*
* @param {Object} actorData The actor to prepare.
*
* @return {undefined}
*/
_prepareCharacterData(context) {
// Handle ability scores.
for (let [k, v] of Object.entries(context.system.abilities)) {
v.label = game.i18n.localize(context.system.abilities[k].label) ?? k;
}
}
/**
* Organize and classify Items for Character sheets.
*
* @param {Object} actorData The actor to prepare.
*
* @return {undefined}
*/
_prepareItems(context) {
context.gear = this.actor.itemTypes['item'];
context.traits = this.actor.itemTypes['trait'];
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
html.find('.item-create').click(this._onItemCreate.bind(this));
}
async _onItemCreate(event) {
event.preventDefault();
const header = event.currentTarget;
// Get the type of item to create.
const type = header.dataset.type;
// Grab any data associated with this control.
const data = duplicate(header.dataset);
// Initialize a default name.
// const name = `New ${type.capitalize()}`;
const name = game.i18n.localize('ITEMS.new_' + type);
console.log('onItemCreate child', data.type, this.actor.type);
// Prepare the item object.
const itemData = {
name: name,
type: type,
system: data
};
// Remove the type from the dataset since it's in the itemData.type prop.
delete itemData.system["type"];
// Finally, create the item!
return await Item.create(itemData, { parent: this.actor });
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ export class VermineItemSheet extends ItemSheet {
/** @override */
get template() {
const path = "systems/vermine2047/templates/item";
return `${path}/item-${this.item.type}-sheet.html`;
return `${path}/item-${this.item.type}-sheet.hbs`;
}
/* -------------------------------------------- */
+103 -3
View File
@@ -13,9 +13,9 @@ export class VermineGroupSheet extends VermineActorSheet {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["vermine2047", "sheet", "actor", "group"],
template: "systems/vermine2047/templates/actor/actor-sheet.hbs",
width: 500,
height: 500,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
width: 700,
height: 600,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }]
});
}
@@ -55,6 +55,7 @@ export class VermineGroupSheet extends VermineActorSheet {
if (actorData.type == 'group') {
this._prepareItems(context);
this._prepareGroupData(context);
}
// Add roll data for TinyMCE editors.
@@ -80,6 +81,73 @@ export class VermineGroupSheet extends VermineActorSheet {
}
}
/**
* Prepare Group type specific data.
* Resolves member and encounter actor IDs to actual actor data.
*
* @param {Object} context The context data to prepare.
* @return {undefined}
*/
_prepareGroupData(context) {
if (this.actor.type !== 'group') return;
// Resolve member IDs to actor data
context.resolvedMembers = {};
if (context.system.members && context.system.members.length > 0) {
context.system.members.forEach(memberId => {
const actor = game.actors.get(memberId);
if (actor) {
context.resolvedMembers[memberId] = {
name: actor.name,
id: actor.id
};
}
});
}
// Resolve encounter IDs to actor data
context.resolvedEncounters = {};
if (context.system.encounters && context.system.encounters.length > 0) {
context.system.encounters.forEach(encounterId => {
const actor = game.actors.get(encounterId);
if (actor) {
context.resolvedEncounters[encounterId] = {
name: actor.name,
id: actor.id
};
}
});
}
// Set morale level based on dice value (rules: p. 68-69)
this._updateMoraleLevel(context);
}
/**
* Update morale level based on dice value.
* Rules: 7D+ = Haut, 6-3D = Normal, 2D- = Bas, 0D = Crise
*
* @param {Object} context The context data.
* @return {undefined}
*/
_updateMoraleLevel(context) {
const moraleValue = context.system.morale.value || 0;
// If level is already set, keep it
if (context.system.morale.level) return;
// Determine morale level based on dice value
if (moraleValue >= 7) {
context.system.morale.level = "high";
} else if (moraleValue >= 3) {
context.system.morale.level = "normal";
} else if (moraleValue >= 1) {
context.system.morale.level = "low";
} else {
context.system.morale.level = "crisis";
}
}
/**
* Organize and classify Items for Character sheets.
*
@@ -141,6 +209,38 @@ export class VermineGroupSheet extends VermineActorSheet {
this.render(true);
});
// Handle objective deletion
html.find('.objective-delete').click(ev => {
ev.preventDefault();
const btn = $(ev.currentTarget);
const type = btn.data("type"); // 'major' or 'minor'
const index = parseInt(btn.data("index"));
if (!isNaN(index)) {
const objectives = foundry.utils.duplicate(this.actor.system.objectives || { major: [], minor: [] });
objectives[type].splice(index, 1);
this.actor.update({ "system.objectives": objectives });
}
});
// Handle adding new objectives
html.find('.item-create[data-type="major_objective"], .item-create[data-type="minor_objective"]').click(ev => {
ev.preventDefault();
const btn = $(ev.currentTarget);
const type = btn.data("type") === "major_objective" ? "major" : "minor";
const objectives = foundry.utils.duplicate(this.actor.system.objectives || { major: [], minor: [] });
objectives[type].push("");
this.actor.update({ "system.objectives": objectives });
});
// Handle morale level change
html.find('select[name="system.morale.level"]').change(ev => {
const select = $(ev.currentTarget);
const level = select.val();
this.actor.update({ "system.morale.level": level });
});
}
+89 -30
View File
@@ -1,8 +1,9 @@
import { onManageActiveEffect, prepareActiveEffectCategories } from "../system/effects.mjs";
import { VermineActorSheet } from "./actor-sheet.mjs";
import { TotemPicker } from "../system/applications.mjs";
/**
* Extend the basic ActorSheet with some very simple modifications
* Extend the basic ActorSheet for NPC type
* @extends {VermineActorSheet}
*/
export class VermineNpcSheet extends VermineActorSheet {
@@ -12,9 +13,11 @@ export class VermineNpcSheet extends VermineActorSheet {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["vermine2047", "sheet", "actor", "npc"],
template: "systems/vermine2047/templates/actor/actor-sheet.hbs",
width: 400,
height: 400,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "features" }]
width: 600,
height: 700,
tabs: [
{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "characteristics" }
]
});
}
@@ -27,10 +30,7 @@ export class VermineNpcSheet extends VermineActorSheet {
/** @override */
getData() {
// Retrieve the data structure from the base sheet. You can inspect or log
// the context variable to see the structure, but some key properties for
// sheets are the actor object, the data object, whether or not it's
// editable, the items array, and the effects array.
// Retrieve the data structure from the base sheet.
const context = super.getData();
// Use a safe clone of the actor data for further operations.
@@ -41,19 +41,16 @@ export class VermineNpcSheet extends VermineActorSheet {
context.flags = actorData.flags;
context.config = CONFIG.VERMINE;
// Prepare character data and items.
if (actorData.type == 'character') {
this._prepareItems(context);
this._prepareCharacterData(context);
// Prepare items for all actor types
this._prepareItems(context);
// Prepare NPC-specific data
if (actorData.type === 'npc') {
this._prepareNpcData(context);
}
// Prepare NPC data and items.
if (actorData.type == 'npc') {
this._prepareItems(context);
}
// Add roll data for TinyMCE editors.
context.rollData = context.actor.getRollData();
// Add roll data for TinyMCE editors
context.rollData = this.actor.getRollData();
// Prepare active effects
context.effects = prepareActiveEffectCategories(this.actor.effects);
@@ -62,26 +59,75 @@ export class VermineNpcSheet extends VermineActorSheet {
}
/**
* Organize and classify Items for Character sheets.
*
* @param {Object} actorData The actor to prepare.
*
* @return {undefined}
* Prepare NPC specific data
*/
_prepareCharacterData(context) {
_prepareNpcData(context) {
// Calculate derived values from threat, experience, and role
const threat = CONFIG.VERMINE.npcThreatLevels[context.system.threat.value];
const experience = CONFIG.VERMINE.npcExperienceLevels[context.system.experience.value];
const role = CONFIG.VERMINE.npcRoleLevels[context.system.role.value];
// Add calculated values to context for easier access
context.threatData = threat;
context.experienceData = experience;
context.roleData = role;
// Set wound thresholds based on threat level
if (threat) {
context.system.minorWound.threshold = threat.minorWound || context.system.minorWound.threshold;
context.system.majorWound.threshold = threat.majorWound || context.system.majorWound.threshold;
context.system.deadlyWound.threshold = threat.deadlyWound || context.system.deadlyWound.threshold;
// Set max wounds
context.system.minorWound.max = threat.minorWound || context.system.minorWound.max;
context.system.majorWound.max = threat.majorWound || context.system.majorWound.max;
context.system.deadlyWound.max = threat.deadlyWound || context.system.deadlyWound.max;
}
// Set reserve max values based on role
if (role) {
context.system.attributes.effort.max = role.pools || context.system.attributes.effort.max;
context.system.attributes.self_control.max = role.reaction_bonus || context.system.attributes.self_control.max;
}
// Prepare abilities with labels
for (let [k, v] of Object.entries(context.system.abilities)) {
v.label = game.i18n.localize(CONFIG.VERMINE.abilities[k]) ?? k;
}
// Prepare skills with localized names
for (let [k, v] of Object.entries(context.system.skills)) {
const skillKey = `VERMINE.skill.${k}`;
v.name = game.i18n.localize(skillKey);
if (v.name === skillKey) {
// Fallback to key if no translation
v.name = k.charAt(0).toUpperCase() + k.slice(1);
}
}
// Prepare skill categories
for (let [k, v] of Object.entries(context.system.skill_categories)) {
if (k !== 'preferred') {
v.label = game.i18n.localize(v.label) ?? k;
}
}
}
/**
* Organize and classify Items for Character sheets.
* Organize and classify Items for NPC sheets.
*
* @param {Object} actorData The actor to prepare.
*
* @return {undefined}
* @param {Object} context - The context to prepare.
*/
_prepareItems(context) {
context.gear = this.actor.itemTypes['item'];
context.traits = this.actor.itemTypes['trait'];
context.weapons = this.actor.itemTypes['weapon'];
context.defenses = this.actor.itemTypes['defense'];
context.vehicles = this.actor.itemTypes['vehicle'];
context.abilities = this.actor.itemTypes['ability'];
context.specialties = this.actor.itemTypes['specialty'];
context.backgrounds = this.actor.itemTypes['background'];
context.traumas = this.actor.itemTypes['trauma'];
context.evolutions = this.actor.itemTypes['evolution'];
}
/* -------------------------------------------- */
@@ -90,6 +136,19 @@ export class VermineNpcSheet extends VermineActorSheet {
activateListeners(html) {
super.activateListeners(html);
// Choose Totem
html.find('.chooseTotem').click(this._onTotemButton.bind(this));
}
/**
* Handle totem pick
* @param {Event} event - The originating click event
* @private
*/
_onTotemButton(event) {
event.preventDefault();
const el = event.currentTarget;
const totemPicker = new TotemPicker(el, this.actor);
totemPicker.render(true);
}
}