30d6f71fc7
- 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>
276 lines
8.4 KiB
JavaScript
276 lines
8.4 KiB
JavaScript
import { onManageActiveEffect, prepareActiveEffectCategories } from "../system/effects.mjs";
|
|
import { VermineActorSheet } from "./actor-sheet.mjs";
|
|
import { TotemPicker, ActorPicker } from "../system/applications.mjs";
|
|
|
|
/**
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
* @extends {VermineActorSheet}
|
|
*/
|
|
export class VermineGroupSheet extends VermineActorSheet {
|
|
|
|
/** @override */
|
|
static get defaultOptions() {
|
|
return foundry.utils.mergeObject(super.defaultOptions, {
|
|
classes: ["vermine2047", "sheet", "actor", "group"],
|
|
template: "systems/vermine2047/templates/actor/actor-sheet.hbs",
|
|
width: 700,
|
|
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);
|
|
}
|
|
|
|
if (actorData.type == 'group') {
|
|
this._prepareItems(context);
|
|
this._prepareGroupData(context);
|
|
}
|
|
|
|
// Add roll data for TinyMCE editors.
|
|
context.rollData = this.actor.getRollData();
|
|
|
|
// Prepare active effects
|
|
context.effects = prepareActiveEffectCategories(this.actor.effects);
|
|
|
|
return context;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @param {Object} actorData The actor to prepare.
|
|
*
|
|
* @return {undefined}
|
|
*/
|
|
_prepareItems(context) {
|
|
context.specialties = this.actor.itemTypes['specialty'];
|
|
context.backgrounds = this.actor.itemTypes['background'];
|
|
context.evolutions = this.actor.itemTypes['evolution'];
|
|
context.traumas = this.actor.itemTypes['trauma'];
|
|
|
|
context.gear = this.actor.itemTypes['item'];
|
|
context.weapons = this.actor.itemTypes['weapon'];
|
|
context.defenses = this.actor.itemTypes['defense'];
|
|
context.vehicles = this.actor.itemTypes['vehicle'];
|
|
|
|
context.totem_abilities = this.actor.itemTypes['ability'].filter(i => i.system.type === 'totem');
|
|
context.abilities = this.actor.itemTypes['ability'].filter(i => i.system.type !== 'totem');
|
|
|
|
context.members = this.actor.system.members;
|
|
context.encounters = this.actor.system.encounters;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
activateListeners(html) {
|
|
super.activateListeners(html);
|
|
|
|
// Choose Totem
|
|
html.find('.chooseTotem').click(this._onTotemButton.bind(this));
|
|
|
|
// Choose Members / Encounters
|
|
html.find('.chooseActor').click(this._onRoadButton.bind(this));
|
|
html.find('.member-delete').click(ev => {
|
|
const li = $(ev.currentTarget).parents("li.actor");
|
|
const actorId = li.data("actor-id");
|
|
const actorIdIndex = this.actor.system.members.indexOf(actorId);
|
|
if (actorIdIndex !== -1) {
|
|
this.actor.system.members.splice(actorIdIndex, 1);
|
|
}
|
|
this.actor.update({ "system.members": this.actor.system.members });
|
|
this.render(true);
|
|
});
|
|
|
|
html.find('.encounter-delete').click(ev => {
|
|
const li = $(ev.currentTarget).parents("li.actor");
|
|
const actorId = li.data("actor-id");
|
|
const actorIdIndex = this.actor.system.encounters.indexOf(actorId);
|
|
if (actorIdIndex !== -1) {
|
|
this.actor.system.encounters.splice(actorIdIndex, 1);
|
|
}
|
|
this.actor.update({ "system.encounters": this.actor.system.encounters });
|
|
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 });
|
|
});
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Handle totem pick
|
|
* @param {Event} event The originating click event
|
|
* @private
|
|
*/
|
|
_onTotemButton(event) {
|
|
event.preventDefault();
|
|
const el = event.currentTarget;
|
|
// const dataset = el.dataset;
|
|
|
|
const totemPicker = new TotemPicker(el, this.actor);
|
|
totemPicker.render(true);
|
|
}
|
|
|
|
/**
|
|
* Handle actor pick
|
|
* @param {Event} event The originating click event
|
|
* @private
|
|
*/
|
|
_onRoadButton(event) {
|
|
event.preventDefault();
|
|
const el = event.currentTarget;
|
|
// const dataset = el.dataset;
|
|
|
|
const actorPicker = new ActorPicker(el, this.actor);
|
|
actorPicker.render(true);
|
|
}
|
|
|
|
}
|