Add party an army sheeets

This commit is contained in:
2026-03-25 18:02:39 +01:00
parent b46c6d804c
commit f1dda301d7
37 changed files with 2024 additions and 254 deletions

View File

@@ -1,6 +1,6 @@
import OathHammerActorSheet from "./base-actor-sheet.mjs"
const ALLOWED_ITEM_TYPES = new Set(["building", "equipment", "weapon", "armor", "regiment"])
const ALLOWED_ITEM_TYPES = new Set(["building", "equipment", "weapon", "armor"])
export default class OathHammerSettlementSheet extends OathHammerActorSheet {
/** @override */
@@ -17,8 +17,9 @@ export default class OathHammerSettlementSheet extends OathHammerActorSheet {
adjustCurrency: OathHammerSettlementSheet.#onAdjustCurrency,
adjustQty: OathHammerSettlementSheet.#onAdjustQty,
toggleConstructed: OathHammerSettlementSheet.#onToggleConstructed,
createRegiment: OathHammerSettlementSheet.#onCreateRegiment,
collectTaxes: OathHammerSettlementSheet.#onCollectTaxes,
openRegiment: OathHammerSettlementSheet.#onOpenRegiment,
removeRegiment: OathHammerSettlementSheet.#onRemoveRegiment,
},
}
@@ -102,7 +103,9 @@ export default class OathHammerSettlementSheet extends OathHammerActorSheet {
}
case "garrison":
context.tab = context.tabs.garrison
context.regiments = doc.itemTypes.regiment ?? []
context.regiments = (doc.system.garrisonRefs ?? [])
.map(id => game.actors?.get(id))
.filter(Boolean)
break
}
return context
@@ -112,6 +115,17 @@ export default class OathHammerSettlementSheet extends OathHammerActorSheet {
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)
// Regiment actors dropped onto garrison tab
if (data.type === "Actor") {
const actor = await fromUuid(data.uuid)
if (!actor || actor.type !== "regiment") return
const refs = foundry.utils.deepClone(this.document.system.garrisonRefs ?? [])
if (refs.includes(actor.id)) return // already linked
refs.push(actor.id)
return this.document.update({ "system.garrisonRefs": refs })
}
if (data.type !== "Item") return
const item = await fromUuid(data.uuid)
if (!item || !ALLOWED_ITEM_TYPES.has(item.type)) return
@@ -144,11 +158,15 @@ export default class OathHammerSettlementSheet extends OathHammerActorSheet {
await item.update({ "system.constructed": !item.system.constructed })
}
static async #onCreateRegiment() {
await this.document.createEmbeddedDocuments("Item", [{
name: game.i18n.localize("OATHHAMMER.NewItem.Regiment"),
type: "regiment",
}])
static async #onOpenRegiment(event, target) {
const actor = game.actors?.get(target.dataset.actorId)
if (actor) actor.sheet.render(true)
}
static async #onRemoveRegiment(event, target) {
const actorId = target.dataset.actorId
const refs = (this.document.system.garrisonRefs ?? []).filter(id => id !== actorId)
await this.document.update({ "system.garrisonRefs": refs })
}
static async #onCollectTaxes() {