DataModels + Appv2 migration : OK

This commit is contained in:
2026-02-28 21:00:06 +01:00
parent 8017bb207d
commit 1ffb8b08fc
119 changed files with 2268 additions and 384 deletions

View File

@@ -1,3 +1,7 @@
export { default as BoLBaseItemSheet } from "./base-item-sheet.mjs"
export { default as BoLItemSheet } from "./item-sheet.mjs"
export { default as BoLFeatureSheet } from "./feature-sheet.mjs"
export { default as BoLBaseActorSheet } from "./base-actor-sheet.mjs"
export { default as BoLActorSheet } from "./actor-sheet.mjs"
export { default as BoLHordeSheet } from "./horde-sheet.mjs"
export { default as BoLVehicleSheet } from "./vehicle-sheet.mjs"

View File

@@ -0,0 +1,144 @@
import BoLBaseActorSheet from "./base-actor-sheet.mjs"
import { BoLUtility } from "../../system/bol-utility.js"
/**
* Actor Sheet for BoL characters and encounters using AppV2
*/
export default class BoLActorSheet extends BoLBaseActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
...super.DEFAULT_OPTIONS,
classes: [...super.DEFAULT_OPTIONS.classes],
actions: {
...super.DEFAULT_OPTIONS.actions,
},
}
/** @override */
static PARTS = {
sheet: {
template: "systems/bol/templates/actor/actor-sheet.hbs",
},
}
/** @override */
tabGroups = { primary: "stats" }
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
const actor = this.document
context.data = actor.toObject()
context.details = actor.details
context.attributes = actor.attributes
context.aptitudes = actor.aptitudes
context.resources = actor.getResourcesFromType()
context.xp = actor.system.xp
context.equipment = actor.equipment
context.equipmentCreature = actor.equipmentCreature
context.weapons = actor.weapons
context.protections = actor.protections
context.spells = actor.spells
context.alchemy = actor.alchemy
context.containers = actor.containers
context.treasure = actor.treasure
context.boleffects = actor.boleffects
context.alchemyrecipe = actor.alchemyrecipe
context.horoscopes = actor.horoscopes
context.vehicles = actor.vehicles
context.fightoptions = actor.fightoptions
context.ammos = actor.ammos
context.misc = actor.misc
context.xplog = actor.xplog
context.combat = actor.buildCombat()
context.initiativeRank = actor.getInitiativeRank()
context.features = actor.buildFeatures()
context.options = this.options
context.editScore = this.options.editScore
context.useBougette = (actor.type === "character" && BoLUtility.getUseBougette()) || false
context.bougette = actor.getBougette()
context.charType = actor.getCharType()
context.villainy = actor.getVillainy()
context.isUndead = actor.isUndead()
context.biography = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
actor.system.details?.biography || "", { async: true }
)
context.notes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
actor.system.details?.notes || "", { async: true }
)
context.isSorcerer = actor.isSorcerer()
context.isAlchemist = actor.isAlchemist()
context.isAstrologer = actor.isAstrologer()
context.isMysteries = context.isSorcerer || context.isAlchemist || context.isAstrologer
context.isPriest = actor.isPriest()
context.horoscopeGroupList = game.settings.get("bol", "horoscope-group")
console.log("ACTORDATA (AppV2)", context)
return context
}
/** @override */
_activateListeners() {
super._activateListeners()
if (!this.isEditable) return
// Create generic item
this.element.querySelectorAll(".create-item").forEach((el) => {
el.addEventListener("click", () => {
this.actor.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("BOL.ui.newEquipment"), type: "item" }], { renderSheet: true })
})
})
// Create natural weapon
this.element.querySelectorAll(".create-natural-weapon").forEach((el) => {
el.addEventListener("click", () => {
const system = foundry.utils.duplicate(game.bol.config.defaultNaturalWeapon)
this.actor.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("BOL.ui.newNaturalWeapon"), type: "item", system }], { renderSheet: true })
})
})
// Create natural protection
this.element.querySelectorAll(".create-natural-protection").forEach((el) => {
el.addEventListener("click", () => {
const system = foundry.utils.duplicate(game.bol.config.defaultNaturalProtection)
this.actor.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("BOL.ui.newNaturalProtection"), type: "item", system }], { renderSheet: true })
})
})
// Item create via header dataset (type-based creation)
this.element.querySelectorAll(".item-create").forEach((el) => {
el.addEventListener("click", (ev) => {
ev.preventDefault()
const header = ev.currentTarget
const type = header.dataset.type
const data = foundry.utils.duplicate(header.dataset)
const name = `New ${type}`
delete data.type
this.actor.createEmbeddedDocuments("Item", [{ name, type, data }])
})
})
// Add XP Log entry
this.element.querySelectorAll(".xplog-add").forEach((el) => {
el.addEventListener("click", (ev) => {
ev.preventDefault()
this.actor.addXPLog("other", "Nouveau", 0, 0)
})
})
// Add item by category/subtype (equipment tab headers)
this.element.querySelectorAll(".item-add").forEach((el) => {
el.addEventListener("click", (ev) => {
ev.preventDefault()
const { itemType, category, subtype } = ev.currentTarget.dataset
const system = { category, subtype }
this.actor.createEmbeddedDocuments("Item", [{
name: game.i18n.localize("BOL.ui.newEquipment"),
type: itemType || "item",
system,
}], { renderSheet: true })
})
})
}
}

View File

@@ -0,0 +1,307 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
import { BoLRoll } from "../../controllers/bol-rolls.js"
import { BoLUtility } from "../../system/bol-utility.js"
/**
* Base Actor Sheet for BoL system using AppV2
* @extends {ActorSheetV2}
*/
export default class BoLBaseActorSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ActorSheetV2) {
constructor(options = {}) {
super(options)
this.#dragDrop = this.#createDragDropHandlers()
}
#dragDrop
/** @override */
static DEFAULT_OPTIONS = {
classes: ["bol", "sheet", "actor"],
position: {
width: 836,
height: 807,
},
form: {
submitOnChange: true,
closeOnSubmit: false,
},
window: {
resizable: true,
},
tabs: [
{
navSelector: "nav[data-group=\"primary\"]",
contentSelector: "section.sheet-body",
initial: "stats",
},
],
dragDrop: [{ dragSelector: ".items-list .item", dropSelector: null }],
actions: {},
}
/** Tab groups state */
tabGroups = { primary: "stats" }
/** @override */
async _prepareContext() {
const actor = this.document
return {
actor,
system: actor.system,
config: game.bol.config,
isGM: game.user.isGM,
isEditable: this.isEditable,
owner: this.document.isOwner,
cssClass: this.options.classes.join(" "),
}
}
/** @override */
_onRender(context, options) {
super._onRender(context, options)
this.#dragDrop.forEach((d) => d.bind(this.element))
this._activateTabs()
this._activateListeners()
this._applyBackgroundImage()
this._activateImageEdit()
}
/**
* Apply background image to the actor form
* @private
*/
_applyBackgroundImage() {
const logoUrl = BoLUtility.getLogoActorSheet()
const form = this.element.querySelector(".bol-actor-form")
if (form) form.style.backgroundImage = `url(${logoUrl})`
}
/**
* Activate image editing via FilePicker
* @private
*/
_activateImageEdit() {
const img = this.element.querySelector('[data-edit="img"]')
if (img && this.isEditable) {
img.style.cursor = "pointer"
img.addEventListener("click", () => {
new FilePicker({
type: "image",
current: this.document.img,
callback: (path) => this.document.update({ img: path }),
}).browse()
})
}
}
/**
* Activate tab navigation
* @private
*/
_activateTabs() {
const nav = this.element.querySelector("nav[data-group]")
if (!nav) return
const group = nav.dataset.group
const activeTab = this.tabGroups[group] || "stats"
nav.querySelectorAll("[data-tab]").forEach((link) => {
const tab = link.dataset.tab
link.classList.toggle("active", tab === activeTab)
link.addEventListener("click", (event) => {
event.preventDefault()
this.tabGroups[group] = tab
this.render()
})
})
this.element.querySelectorAll(`[data-group="${group}"][data-tab]`).forEach((content) => {
content.classList.toggle("active", content.dataset.tab === activeTab)
})
}
/**
* Activate event listeners (replaces activateListeners with vanilla DOM)
* @private
*/
_activateListeners() {
if (!this.isEditable) return
// Item edit
this.element.querySelectorAll(".item-edit").forEach((el) => {
el.addEventListener("click", (ev) => {
const li = ev.currentTarget.closest(".item")
const item = this.actor.items.get(li?.dataset.itemId)
item?.sheet.render(true)
})
})
// Item delete
this.element.querySelectorAll(".item-delete").forEach((el) => {
el.addEventListener("click", (ev) => {
const li = ev.currentTarget.closest(".item")
const itemId = li?.dataset.itemId
Dialog.confirm({
title: game.i18n.localize("BOL.ui.deletetitle"),
content: game.i18n.localize("BOL.ui.confirmdelete"),
yes: () => {
this.actor.deleteEmbeddedDocuments("Item", [itemId])
li?.remove()
},
no: () => {},
defaultYes: false,
})
})
})
// Item equip/unequip
this.element.querySelectorAll(".item-equip").forEach((el) => {
el.addEventListener("click", (ev) => {
const li = ev.currentTarget.closest(".item")
const item = this.actor.items.get(li?.dataset.itemId)
if (item) this.actor.toggleEquipItem(item)
})
})
// Toggle fight option
this.element.querySelectorAll(".toggle-fight-option").forEach((el) => {
el.addEventListener("click", (ev) => {
const li = ev.currentTarget.closest(".item")
this.actor.toggleFightOption(li?.dataset.itemId)
})
})
// Inc/dec alchemy points
this.element.querySelectorAll(".inc-dec-btns-alchemy").forEach((el) => {
el.addEventListener("click", (ev) => {
const li = ev.currentTarget.closest(".item")
this.actor.spendAlchemyPoint(li?.dataset.itemId, 1)
})
})
// Inc/dec resource buttons
this.element.querySelectorAll(".inc-dec-btns-resource").forEach((el) => {
el.addEventListener("click", (ev) => {
const dataset = ev.currentTarget.dataset
this.actor.incDecResources(dataset.target, parseInt(dataset.incr))
})
})
// Generic inc/dec buttons for item fields
this.element.querySelectorAll(".inc-dec-btns").forEach((el) => {
el.addEventListener("click", (ev) => {
const li = ev.currentTarget.closest(".item")
if (!li) return
const item = this.actor.items.get(li.dataset.itemId)
if (!item) return
const dataset = ev.currentTarget.dataset
const operator = dataset.operator
const target = dataset.target
const incr = parseInt(dataset.incr)
const min = parseInt(dataset.min)
const max = parseInt(dataset.max) || 10000
// eslint-disable-next-line no-eval
let value = eval("item." + target) || 0
if (operator === "minus") value = value >= min + incr ? value - incr : min
if (operator === "plus") value = value <= max - incr ? value + incr : max
item.update({ [target]: value })
})
})
// Rollable elements
this.element.querySelectorAll(".rollable").forEach((el) => {
el.addEventListener("click", (ev) => this._onRoll(ev))
})
}
/**
* Handle clickable rolls (replaces _onRoll with vanilla DOM)
* @param {Event} event
* @private
*/
_onRoll(event) {
event.preventDefault()
const element = event.currentTarget
const dataset = element.dataset
const rollType = dataset.rollType
const li = element.closest(".item")
const itemId = li?.dataset.itemId
switch (rollType) {
case "attribute":
BoLRoll.attributeCheck(this.actor, dataset.key, event)
break
case "aptitude":
BoLRoll.aptitudeCheck(this.actor, dataset.key, event)
break
case "weapon":
BoLRoll.weaponCheck(this.actor, event)
break
case "spell":
BoLRoll.spellCheck(this.actor, event)
break
case "alchemy":
BoLRoll.alchemyCheck(this.actor, event)
break
case "protection":
this.actor.rollProtection(itemId)
break
case "damage":
this.actor.rollWeaponDamage(itemId)
break
case "aptitudexp":
this.actor.incAptitudeXP(dataset.key)
break
case "attributexp":
this.actor.incAttributeXP(dataset.key)
break
case "careerxp":
this.actor.incCareerXP(itemId)
break
case "horoscope-minor":
BoLRoll.horoscopeCheck(this.actor, event, "minor")
break
case "horoscope-major":
BoLRoll.horoscopeCheck(this.actor, event, "major")
break
case "horoscope-major-group":
BoLRoll.horoscopeCheck(this.actor, event, "majorgroup")
break
case "bougette":
this.actor.rollBougette()
break
default:
break
}
}
// #region Drag-and-Drop
#createDragDropHandlers() {
return (this.options.dragDrop || []).map((dragDrop) =>
new foundry.applications.ux.DragDrop.implementation({
...dragDrop,
permissions: {
dragstart: this._canDragStart.bind(this),
drop: this._canDragDrop.bind(this),
},
callbacks: {
dragstart: this._onDragStart.bind(this),
dragover: this._onDragOver.bind(this),
drop: this._onDrop.bind(this),
},
})
)
}
_canDragStart(selector) {
return this.isEditable
}
_canDragDrop(selector) {
return this.isEditable
}
// #endregion
}

View File

@@ -25,6 +25,13 @@ export default class BoLBaseItemSheet extends HandlebarsApplicationMixin(foundry
window: {
resizable: true,
},
tabs: [
{
navSelector: 'nav[data-group="primary"]',
contentSelector: "section.sheet-body",
initial: "description",
},
],
actions: {
editImage: BoLBaseItemSheet.#onEditImage,
postItem: BoLBaseItemSheet.#onPostItem,
@@ -146,29 +153,34 @@ export default class BoLBaseItemSheet extends HandlebarsApplicationMixin(foundry
}
/**
* Activate tab navigation
* Activate tab navigation via CSS only (no re-render) to preserve unsaved form state.
* @private
*/
_activateTabs() {
const nav = this.element.querySelector('nav.tabs[data-group="primary"]')
const nav = this.element.querySelector('nav[data-group="primary"]')
if (!nav) return
const section = this.element.querySelector('section.sheet-body')
if (!section) return
const activeTab = this.tabGroups.primary || "description"
// Activate tab links
// Set initial active state
nav.querySelectorAll('[data-tab]').forEach(link => {
const tab = link.dataset.tab
link.classList.toggle('active', tab === activeTab)
link.addEventListener('click', (event) => {
event.preventDefault()
this.tabGroups.primary = tab
this.render()
})
link.classList.toggle('active', link.dataset.tab === activeTab)
})
section.querySelectorAll('[data-tab]').forEach(content => {
content.classList.toggle('active', content.dataset.tab === activeTab)
})
// Show/hide tab content
this.element.querySelectorAll('.tab[data-tab]').forEach(content => {
content.classList.toggle('active', content.dataset.tab === activeTab)
// Tab click — CSS-only switch, no render()
nav.querySelectorAll('[data-tab]').forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault()
const tab = link.dataset.tab
this.tabGroups.primary = tab
nav.querySelectorAll('[data-tab]').forEach(l => l.classList.toggle('active', l.dataset.tab === tab))
section.querySelectorAll('[data-tab]').forEach(c => c.classList.toggle('active', c.dataset.tab === tab))
})
})
}

View File

@@ -8,8 +8,7 @@ export default class BoLFeatureSheet extends BoLBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
...super.DEFAULT_OPTIONS,
classes: [...super.DEFAULT_OPTIONS.classes, "item-type-feature"],
classes: ["bol", "sheet", "item", "item-type-feature"],
}
/** @override */

View File

@@ -0,0 +1,65 @@
import BoLBaseActorSheet from "./base-actor-sheet.mjs"
/**
* Actor Sheet for BoL hordes using AppV2
*/
export default class BoLHordeSheet extends BoLBaseActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
...super.DEFAULT_OPTIONS,
classes: [...super.DEFAULT_OPTIONS.classes],
actions: {
...super.DEFAULT_OPTIONS.actions,
},
}
/** @override */
static PARTS = {
sheet: {
template: "systems/bol/templates/actor/horde-sheet.hbs",
},
}
/** @override */
tabGroups = { primary: "stats" }
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
const actor = this.document
context.options = this.options
context.editScore = this.options.editScore
context.description = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
actor.system.description || "", { async: true }
)
console.log("HORDE (AppV2)", context)
return context
}
/** @override */
_activateListeners() {
super._activateListeners()
if (!this.isEditable) return
// Item create via header dataset
this.element.querySelectorAll(".item-create").forEach((el) => {
el.addEventListener("click", (ev) => {
ev.preventDefault()
const header = ev.currentTarget
const type = header.dataset.type
const data = foundry.utils.duplicate(header.dataset)
delete data.type
this.actor.createEmbeddedDocuments("Item", [{ name: `New ${type}`, type, data }])
})
})
// Create generic item
this.element.querySelectorAll(".create_item").forEach((el) => {
el.addEventListener("click", () => {
this.actor.createEmbeddedDocuments("Item", [{ name: "Nouvel Equipement", type: "item" }], { renderSheet: true })
})
})
}
}

View File

@@ -8,8 +8,7 @@ export default class BoLItemSheet extends BoLBaseItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
...super.DEFAULT_OPTIONS,
classes: [...super.DEFAULT_OPTIONS.classes, "item-type-item"],
classes: ["bol", "sheet", "item", "item-type-item"],
}
/** @override */

View File

@@ -0,0 +1,66 @@
import BoLBaseActorSheet from "./base-actor-sheet.mjs"
/**
* Actor Sheet for BoL vehicles using AppV2
*/
export default class BoLVehicleSheet extends BoLBaseActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
...super.DEFAULT_OPTIONS,
classes: [...super.DEFAULT_OPTIONS.classes],
actions: {
...super.DEFAULT_OPTIONS.actions,
},
}
/** @override */
static PARTS = {
sheet: {
template: "systems/bol/templates/actor/vehicle-sheet.hbs",
},
}
/** @override */
tabGroups = { primary: "stats" }
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
const actor = this.document
context.weapons = actor.vehicleWeapons
context.options = this.options
context.editScore = this.options.editScore
context.description = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
actor.system.description || "", { async: true }
)
console.log("VEHICLE (AppV2)", context)
return context
}
/** @override */
_activateListeners() {
super._activateListeners()
if (!this.isEditable) return
// Item create via header dataset
this.element.querySelectorAll(".item-create").forEach((el) => {
el.addEventListener("click", (ev) => {
ev.preventDefault()
const header = ev.currentTarget
const type = header.dataset.type
const data = foundry.utils.duplicate(header.dataset)
delete data.type
this.actor.createEmbeddedDocuments("Item", [{ name: `New ${type}`, type, data }])
})
})
// Create generic item
this.element.querySelectorAll(".create_item").forEach((el) => {
el.addEventListener("click", () => {
this.actor.createEmbeddedDocuments("Item", [{ name: "Nouvel Equipement", type: "item" }], { renderSheet: true })
})
})
}
}

View File

@@ -1,9 +1,7 @@
/* -------------------------------------------- */
// Import Modules
import { BoLActor } from "./actor/actor.js"
import { BoLActorSheet } from "./actor/actor-sheet.js"
import { BoLVehicleSheet } from "./actor/vehicle-sheet.js"
import { BoLHordeSheet } from "./actor/horde-sheet.js"
// AppV1 actor sheets kept for reference only (AppV2 used via sheets.* below)
import { BoLItem } from "./item/item.js"
// Note: Old BoLItemSheet (AppV1) is now replaced by AppV2 sheets
import { System, BOL } from "./system/config.js"
@@ -72,9 +70,9 @@ Hooks.once('init', async function () {
// Register sheet application classes
foundry.documents.collections.Actors.unregisterSheet("core", foundry.appv1.sheets.ActorSheet);
foundry.documents.collections.Actors.registerSheet("bol", BoLActorSheet, { types: ["character", "encounter"], makeDefault: true })
foundry.documents.collections.Actors.registerSheet("bol", BoLVehicleSheet, { types: ["vehicle"], makeDefault: true })
foundry.documents.collections.Actors.registerSheet("bol", BoLHordeSheet, { types: ["horde"], makeDefault: true })
foundry.documents.collections.Actors.registerSheet("bol", sheets.BoLActorSheet, { types: ["character", "encounter"], makeDefault: true })
foundry.documents.collections.Actors.registerSheet("bol", sheets.BoLVehicleSheet, { types: ["vehicle"], makeDefault: true })
foundry.documents.collections.Actors.registerSheet("bol", sheets.BoLHordeSheet, { types: ["horde"], makeDefault: true })
// Register AppV2 Item Sheets
foundry.documents.collections.Items.unregisterSheet("core", foundry.appv1.sheets.ItemSheet);

View File

@@ -5,14 +5,47 @@ export default class BoLFeatureDataModel extends foundry.abstract.TypeDataModel
static defineSchema() {
const fields = foundry.data.fields;
const requiredInteger = { required: true, nullable: false, integer: true };
const nullableNumber = { required: false, nullable: true, initial: null };
return {
// Base fields
category: new fields.StringField({ initial: "" }),
subtype: new fields.StringField({ initial: "default" }),
description: new fields.HTMLField({ initial: "" }),
properties: new fields.SchemaField({}),
properties: new fields.SchemaField({
// Career
sorcerer: new fields.BooleanField({ initial: false }),
alchemist: new fields.BooleanField({ initial: false }),
priest: new fields.BooleanField({ initial: false }),
astrologer: new fields.BooleanField({ initial: false }),
// Boon
isbonusdice: new fields.BooleanField({ initial: false }),
// Flaw
ismalusdice: new fields.BooleanField({ initial: false }),
// Fight option
fightoptiontype: new fields.StringField({ initial: "" }),
activated: new fields.BooleanField({ initial: false }),
isspecial: new fields.BooleanField({ initial: false }),
// Effect (boleffect)
identifier: new fields.StringField({ initial: "" }),
modifier: new fields.StringField({ initial: "" }),
// Horoscope
horoscopeanswer: new fields.StringField({ initial: "" }),
rank: new fields.NumberField({ ...nullableNumber }),
// XP log
xptype: new fields.StringField({ initial: "" }),
xpdate: new fields.StringField({ initial: "" }),
xpname: new fields.StringField({ initial: "" }),
xpcost: new fields.NumberField({ ...nullableNumber }),
xpvalue: new fields.NumberField({ ...nullableNumber }),
}),
// Feature-specific fields
rank: new fields.NumberField({ ...requiredInteger, initial: 0 })
};

View File

@@ -5,6 +5,7 @@ export default class BoLItemDataModel extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
const requiredInteger = { required: true, nullable: false, integer: true };
const nullableNumber = { required: false, nullable: true, initial: null };
return {
// Base fields
@@ -12,6 +13,7 @@ export default class BoLItemDataModel extends foundry.abstract.TypeDataModel {
subtype: new fields.StringField({ initial: "default" }),
description: new fields.HTMLField({ initial: "" }),
properties: new fields.SchemaField({
// Base flags
ranged: new fields.BooleanField({ initial: false }),
melee: new fields.BooleanField({ initial: false }),
spell: new fields.BooleanField({ initial: false }),
@@ -27,7 +29,76 @@ export default class BoLItemDataModel extends foundry.abstract.TypeDataModel {
reloadable: new fields.BooleanField({ initial: false }),
bow: new fields.BooleanField({ initial: false }),
crossbow: new fields.BooleanField({ initial: false }),
throwing: new fields.BooleanField({ initial: false })
throwing: new fields.BooleanField({ initial: false }),
// Equipment
stackable: new fields.BooleanField({ initial: false }),
stacksize: new fields.NumberField({ ...nullableNumber }),
slot: new fields.StringField({ initial: "-" }),
// Weapon flags
natural: new fields.BooleanField({ initial: false }),
concealable: new fields.BooleanField({ initial: false }),
ignoreshield: new fields.BooleanField({ initial: false }),
attackBonusDice: new fields.BooleanField({ initial: false }),
attackMalusDice: new fields.BooleanField({ initial: false }),
onlymodifier: new fields.BooleanField({ initial: false }),
bashing: new fields.BooleanField({ initial: false }),
throwable: new fields.BooleanField({ initial: false }),
damageReroll1: new fields.BooleanField({ initial: false }),
// Weapon stats
attackAttribute: new fields.StringField({ initial: "vigor" }),
attackAptitude: new fields.StringField({ initial: "melee" }),
attackModifiers: new fields.NumberField({ ...nullableNumber }),
weaponSize: new fields.StringField({ initial: "unarmed" }),
damage: new fields.StringField({ initial: "0" }),
damageAttribute: new fields.StringField({ initial: "" }),
damageModifiers: new fields.NumberField({ ...nullableNumber }),
damageMultiplier: new fields.StringField({ initial: "1" }),
range: new fields.NumberField({ ...nullableNumber }),
reload: new fields.NumberField({ ...nullableNumber }),
// Protection
armorQuality: new fields.StringField({ initial: "" }),
soak: new fields.SchemaField({
formula: new fields.StringField({ initial: "" }),
value: new fields.NumberField({ initial: 0, nullable: true }),
modifier: new fields.NumberField({ initial: 0, nullable: true }),
}),
blocking: new fields.SchemaField({
malus: new fields.NumberField({ initial: 0, nullable: true }),
blocking1: new fields.BooleanField({ initial: false }),
blockingAll: new fields.BooleanField({ initial: false }),
}),
modifiers: new fields.SchemaField({
init: new fields.NumberField({ initial: 0, nullable: true }),
agility: new fields.NumberField({ initial: 0, nullable: true }),
powercost: new fields.NumberField({ initial: 0, nullable: true }),
social: new fields.BooleanField({ initial: false }),
}),
// Spell
circle: new fields.NumberField({ initial: 0, nullable: true }),
difficulty: new fields.StringField({ initial: "" }),
ppcost: new fields.NumberField({ initial: 0, nullable: true }),
duration: new fields.StringField({ initial: "" }),
nbmandatoryconditions: new fields.NumberField({ initial: 0, nullable: true }),
mandatoryconditions: new fields.ArrayField(new fields.StringField()),
optionnalconditions: new fields.ArrayField(new fields.StringField()),
// Alchemy
alchemytype: new fields.StringField({ initial: "" }),
pccost: new fields.NumberField({ initial: 0, nullable: true }),
pccurrent: new fields.NumberField({ initial: 0, nullable: true }),
// Vehicle weapon
isfiredamage: new fields.BooleanField({ initial: false }),
ishulldamage: new fields.BooleanField({ initial: false }),
iscrewdamage: new fields.BooleanField({ initial: false }),
isboarding: new fields.BooleanField({ initial: false }),
isspur: new fields.BooleanField({ initial: false }),
isbreakrow: new fields.BooleanField({ initial: false }),
}),
// Equipment fields

View File

@@ -237,6 +237,11 @@ export class BoLUtility {
if (chatData.img.includes("/blank.png")) {
chatData.img = null;
}
// For old-format weapon items lacking stat fields, apply defaults so the chat card can display them
if (chatData.system?.properties?.weapon && !chatData.system.properties.damage) {
const defaults = game.bol.config.defaultNaturalWeapon?.properties ?? {};
chatData.system.properties = Object.assign(foundry.utils.duplicate(defaults), chatData.system.properties);
}
// JSON object for easy creation
chatData.jsondata = JSON.stringify(
{