Fix as per CSV sheet tracking + creature explanation

This commit is contained in:
2026-05-17 17:43:33 +02:00
parent a572c66678
commit 374854cc8b
99 changed files with 2716 additions and 464 deletions
+2
View File
@@ -3,6 +3,7 @@ export { default as MGNEItemSheet } from "./sheets/base-item-sheet.mjs"
export { default as MGNECharacterSheet } from "./sheets/character-sheet.mjs"
export { default as MGNECreatureSheet } from "./sheets/creature-sheet.mjs"
export { default as MGNECompanionSheet } from "./sheets/companion-sheet.mjs"
export { default as MGNEPartySheet } from "./sheets/party-sheet.mjs"
export { default as MGNEWeaponSheet } from "./sheets/weapon-sheet.mjs"
export { default as MGNEArmorSheet } from "./sheets/armor-sheet.mjs"
export { default as MGNEShieldSheet } from "./sheets/shield-sheet.mjs"
@@ -10,3 +11,4 @@ export { default as MGNEEquipmentSheet } from "./sheets/equipment-sheet.mjs"
export { default as MGNEResonanceCoreSheet } from "./sheets/resonance-core-sheet.mjs"
export { default as MGNEArtifactSheet } from "./sheets/artifact-sheet.mjs"
export { default as MGNEFeatureSheet } from "./sheets/feature-sheet.mjs"
export { default as MGNECreatureTraitSheet } from "./sheets/creature-trait-sheet.mjs"
@@ -64,6 +64,8 @@ export default class MGNEActorSheet extends HandlebarsApplicationMixin(foundry.a
switch (rollType) {
case "ability":
return this.document.rollAbility(target.dataset.abilityId)
case "armor":
return this.document.rollArmorSave()
case "defense":
return this.document.rollDefense()
case "weapon":
@@ -78,6 +80,8 @@ export default class MGNEActorSheet extends HandlebarsApplicationMixin(foundry.a
return this.document.rollResonation(itemId)
case "morale":
return this.document.rollMorale()
case "durability":
return this.document.rollDurability(itemId)
case "usage":
return this.document.rollUsage(itemId)
default:
+11 -7
View File
@@ -2,6 +2,10 @@ import MGNEActorSheet from "./base-actor-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"
import { buildCharacterSelectOptions } from "./select-options.mjs"
export function stripHtml(html) {
return (html ?? "").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim()
}
export default class MGNECharacterSheet extends MGNEActorSheet {
static DEFAULT_OPTIONS = {
classes: ["character"],
@@ -79,16 +83,16 @@ export default class MGNECharacterSheet extends MGNEActorSheet {
break
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon
context.armors = doc.itemTypes.armor
context.shields = doc.itemTypes.shield
context.equipmentItems = doc.itemTypes.equipment
context.cores = doc.itemTypes["resonance-core"]
context.artifacts = doc.itemTypes.artifact
context.weapons = doc.itemTypes.weapon.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
context.armors = doc.itemTypes.armor.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
context.shields = doc.itemTypes.shield.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
context.equipmentItems = doc.itemTypes.equipment.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
context.cores = doc.itemTypes["resonance-core"].map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
context.artifacts = doc.itemTypes.artifact.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
break
case "features":
context.tab = context.tabs.features
context.features = doc.itemTypes.feature
context.features = doc.itemTypes.feature.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
break
case "notes":
context.tab = context.tabs.notes
@@ -1,5 +1,4 @@
import MGNEActorSheet from "./base-actor-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"
export default class MGNECompanionSheet extends MGNEActorSheet {
static DEFAULT_OPTIONS = {
@@ -13,14 +12,4 @@ export default class MGNECompanionSheet extends MGNEActorSheet {
static PARTS = {
main: { template: "systems/fvtt-machine-gods-noxian-expanse/templates/companion-main.hbs" },
}
async _prepareContext() {
const context = await super._prepareContext()
context.abilityList = SYSTEM.abilityOrder.map(id => ({
id,
...SYSTEM.abilities[id],
value: context.source.system.abilities?.[id]?.value ?? 0,
}))
return context
}
}
+65 -6
View File
@@ -1,12 +1,17 @@
import MGNEActorSheet from "./base-actor-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"
import { stripHtml } from "./character-sheet.mjs"
export default class MGNECreatureSheet extends MGNEActorSheet {
static DEFAULT_OPTIONS = {
classes: ["creature"],
position: {
width: 760,
height: 640,
height: 680,
},
actions: {
rollActionTable: MGNECreatureSheet.prototype._rollActionTable,
clearActionTable: MGNECreatureSheet.prototype._clearActionTable,
openActionTable: MGNECreatureSheet.prototype._openActionTable,
},
}
@@ -14,13 +19,67 @@ export default class MGNECreatureSheet extends MGNEActorSheet {
main: { template: "systems/fvtt-machine-gods-noxian-expanse/templates/creature-main.hbs" },
}
_processSubmitData(event, form, submitData) {
// Foundry sends null for unchecked checkboxes in a SetField array — strip them
if (Array.isArray(submitData.system?.creatureType)) {
submitData.system.creatureType = submitData.system.creatureType.filter(v => v != null && v !== "")
}
return super._processSubmitData(event, form, submitData)
}
async _prepareContext() {
const context = await super._prepareContext()
context.abilityList = SYSTEM.abilityOrder.map(id => ({
id,
...SYSTEM.abilities[id],
value: context.source.system.abilities?.[id]?.value ?? 0,
context.traits = (this.document.itemTypes["creature-trait"] ?? [])
.map(i => ({ ...i, tooltip: stripHtml(i.system.description) }))
// Resolve linked action table
const uuid = this.document.system.actionTableUuid
if (uuid) {
const table = await fromUuid(uuid).catch(() => null)
context.actionTable = table ? { name: table.name, uuid } : null
} else {
context.actionTable = null
}
// Build creature type checkboxes
const typeSet = this.document.system.creatureType ?? new Set()
context.creatureTypes = ["human", "construct", "animal"].map(key => ({
key,
label: game.i18n.localize(`MGNE.Creature.Types.${key.charAt(0).toUpperCase() + key.slice(1)}`),
checked: typeSet.has(key),
}))
return context
}
async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)
if (data?.type === "RollTable") {
const table = await fromUuid(data.uuid)
if (table) {
await this.document.update({ "system.actionTableUuid": data.uuid })
return
}
}
return super._onDrop(event)
}
async _rollActionTable() {
const uuid = this.document.system.actionTableUuid
if (!uuid) return ui.notifications.warn(game.i18n.localize("MGNE.Creature.NoTableLinked"))
const table = await fromUuid(uuid).catch(() => null)
if (!table) return ui.notifications.warn(game.i18n.localize("MGNE.Creature.TableNotFound"))
await table.draw()
}
async _clearActionTable() {
await this.document.update({ "system.actionTableUuid": "" })
}
async _openActionTable() {
const uuid = this.document.system.actionTableUuid
if (!uuid) return
const table = await fromUuid(uuid).catch(() => null)
if (table) table.sheet.render(true)
}
}
@@ -0,0 +1,7 @@
import MGNEItemSheet from "./base-item-sheet.mjs"
export default class MGNECreatureTraitSheet extends MGNEItemSheet {
static PARTS = {
main: { template: "systems/fvtt-machine-gods-noxian-expanse/templates/creature-trait.hbs" },
}
}
+162
View File
@@ -0,0 +1,162 @@
import MGNEActorSheet from "./base-actor-sheet.mjs"
const SYSTEM_ID = "fvtt-machine-gods-noxian-expanse"
const PARTY_LOOT_TYPES = new Set(["weapon", "armor", "shield", "equipment", "resonance-core", "artifact"])
export default class MGNEPartySheet extends MGNEActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["party"],
position: { width: 820, height: 640 },
actions: {
openMember: MGNEPartySheet.#onOpenMember,
removeMember: MGNEPartySheet.#onRemoveMember,
moveMemberUp: MGNEPartySheet.#onMoveMemberUp,
moveMemberDown: MGNEPartySheet.#onMoveMemberDown,
adjustCredits: MGNEPartySheet.#onAdjustCredits,
},
}
/** @override */
static PARTS = {
main: { template: `systems/${SYSTEM_ID}/templates/party-main.hbs` },
tabs: { template: `systems/${SYSTEM_ID}/templates/party-tabs.hbs` },
members: { template: `systems/${SYSTEM_ID}/templates/party-members.hbs` },
loot: { template: `systems/${SYSTEM_ID}/templates/party-loot.hbs` },
notes: { template: `systems/${SYSTEM_ID}/templates/party-notes.hbs` },
}
tabGroups = { sheet: "members" }
#getTabs() {
const tabs = {
members: { id: "members", group: "sheet", label: game.i18n.localize("MGNE.Tabs.members") },
loot: { id: "loot", group: "sheet", label: game.i18n.localize("MGNE.Tabs.loot") },
notes: { id: "notes", group: "sheet", label: game.i18n.localize("MGNE.Tabs.notes") },
}
for (const tab of Object.values(tabs)) {
tab.active = this.tabGroups[tab.group] === tab.id
tab.cssClass = tab.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "members": {
context.tab = context.tabs.members
// Build member list using actorId for moves; store refIdx (position in
// memberRefs) so move actions always operate on the correct slot even
// when some refs point to deleted actors.
const refs = doc.system.memberRefs ?? []
const members = []
for (let refIdx = 0; refIdx < refs.length; refIdx++) {
const actor = game.actors?.get(refs[refIdx].id)
if (!actor) continue
members.push({
id: actor.id,
refIdx,
name: actor.name,
img: actor.img,
type: actor.type,
typeLabel: game.i18n.localize(`TYPES.Actor.${actor.type}`),
hp: actor.system.hp
? `${actor.system.hp.value ?? "—"}/${actor.system.hp.max ?? "—"}`
: "—",
})
}
// isFirst/isLast based on visible list, but swap uses refIdx
for (let vi = 0; vi < members.length; vi++) {
members[vi].isFirst = vi === 0
members[vi].isLast = vi === members.length - 1
}
context.members = members
break
}
case "loot": {
context.tab = context.tabs.loot
context.lootItems = doc.items.contents
.filter(i => PARTY_LOOT_TYPES.has(i.type))
.map(i => ({
id: i.id,
img: i.img,
name: i.name,
typeLabel: game.i18n.localize(`TYPES.Item.${i.type}`),
}))
break
}
case "notes":
context.tab = context.tabs.notes
break
}
return context
}
/** @override */
async _onDrop(event) {
if (!this.isEditable) return
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)
if (data.type === "Actor") {
const actor = await fromUuid(data.uuid)
if (!actor || !["character", "companion"].includes(actor.type)) return
const refs = foundry.utils.deepClone(this.document.system.memberRefs ?? [])
if (refs.some(r => r.id === actor.id)) return
refs.push({ id: actor.id })
return this.document.update({ "system.memberRefs": refs })
}
if (data.type === "Item") {
const item = await fromUuid(data.uuid)
if (!item || !PARTY_LOOT_TYPES.has(item.type)) return
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
}
}
// ── Actions ─────────────────────────────────────────────────────────────────
static async #onOpenMember(_event, target) {
const actor = game.actors?.get(target.dataset.actorId)
if (actor) actor.sheet.render(true)
}
static async #onRemoveMember(_event, target) {
const id = target.dataset.actorId
const refs = (this.document.system.memberRefs ?? []).filter(r => r.id !== id)
await this.document.update({ "system.memberRefs": refs })
}
static async #onMoveMemberUp(_event, target) {
const refIdx = parseInt(target.dataset.refIdx, 10)
if (refIdx <= 0) return
const refs = foundry.utils.deepClone(this.document.system.memberRefs ?? []);
[refs[refIdx - 1], refs[refIdx]] = [refs[refIdx], refs[refIdx - 1]]
await this.document.update({ "system.memberRefs": refs })
}
static async #onMoveMemberDown(_event, target) {
const refIdx = parseInt(target.dataset.refIdx, 10)
const refs = foundry.utils.deepClone(this.document.system.memberRefs ?? [])
if (refIdx >= refs.length - 1) return;
[refs[refIdx], refs[refIdx + 1]] = [refs[refIdx + 1], refs[refIdx]]
await this.document.update({ "system.memberRefs": refs })
}
static async #onAdjustCredits(_event, target) {
const delta = parseInt(target.dataset.delta, 10)
const current = this.document.system.credits ?? 0
await this.document.update({ "system.credits": Math.max(0, current + delta) })
}
}
@@ -31,12 +31,13 @@ export function buildSharedSelectOptions() {
armorPenalties: numericOptions(0, 6),
shieldPenalties: numericOptions(0, 4),
weaponCategories: objectOptions(SYSTEM.weaponCategories),
weaponProperties: Object.entries(SYSTEM.weaponProperties).map(([key, p]) => ({ value: key, label: p.label, hint: p.hint })),
weightCategories: objectOptions(SYSTEM.weightCategories),
usageDice: objectOptions(SYSTEM.usageDieChoices),
armorDice: objectOptions(SYSTEM.armorDieChoices),
omenDice: objectOptions(SYSTEM.omenDieChoices),
resonanceList: objectOptions(SYSTEM.resonanceList),
equipmentSubtypes: objectOptions(SYSTEM.equipmentSubtypes),
artifactIds: objectOptions(SYSTEM.artifactChoices),
featureIds: objectOptions(SYSTEM.featureChoices),
}
}