Fix weapon sheet
This commit is contained in:
@@ -22,6 +22,8 @@ export default class OathHammerArmorSheet extends OathHammerItemSheet {
|
||||
/** @override */
|
||||
async _prepareContext() {
|
||||
const context = await super._prepareContext()
|
||||
const enrich = (v) => foundry.applications.ux.TextEditor.implementation.enrichHTML(v ?? "", { async: true })
|
||||
context.enrichedMagicEffect = await enrich(this.document.system.magicEffect)
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { HandlebarsApplicationMixin } = foundry.applications.api
|
||||
import { ARMOR_TYPE_CHOICES, WEAPON_PROFICIENCY_GROUPS } from "../../config/system.mjs"
|
||||
|
||||
export default class OathHammerItemSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ItemSheetV2) {
|
||||
static SHEET_MODES = { EDIT: 0, PLAY: 1 }
|
||||
@@ -68,6 +69,9 @@ export default class OathHammerItemSheet extends HandlebarsApplicationMixin(foun
|
||||
context.apChoices = Object.fromEntries(
|
||||
Array.from({ length: 7 }, (_, i) => [i, String(i)])
|
||||
)
|
||||
// Class proficiency choices (for class-sheet checkboxes)
|
||||
context.armorTypeChoices = ARMOR_TYPE_CHOICES
|
||||
context.weaponGroupChoices = WEAPON_PROFICIENCY_GROUPS
|
||||
return context
|
||||
}
|
||||
|
||||
|
||||
@@ -27,4 +27,16 @@ export default class OathHammerClassSheet extends OathHammerItemSheet {
|
||||
)
|
||||
return context
|
||||
}
|
||||
|
||||
/** @override — collect checkbox sets explicitly so unchecking all works */
|
||||
_prepareSubmitData(event, form, formData) {
|
||||
const data = super._prepareSubmitData(event, form, formData)
|
||||
data["system.armorProficiency"] = Array.from(
|
||||
form.querySelectorAll('input[name="system.armorProficiency"]:checked')
|
||||
).map(el => el.value)
|
||||
data["system.weaponProficiency"] = Array.from(
|
||||
form.querySelectorAll('input[name="system.weaponProficiency"]:checked')
|
||||
).map(el => el.value)
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ export default class OathHammerMagicItemSheet extends OathHammerItemSheet {
|
||||
/** @override */
|
||||
async _prepareContext() {
|
||||
const context = await super._prepareContext()
|
||||
const enrich = (v) => foundry.applications.ux.TextEditor.implementation.enrichHTML(v ?? "", { async: true })
|
||||
context.enrichedEffect = await enrich(this.document.system.effect)
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ export default class OathHammerWeaponSheet extends OathHammerItemSheet {
|
||||
/** @override */
|
||||
async _prepareContext() {
|
||||
const context = await super._prepareContext()
|
||||
const enrich = (v) => foundry.applications.ux.TextEditor.implementation.enrichHTML(v ?? "", { async: true })
|
||||
context.enrichedMagicEffect = await enrich(this.document.system.magicEffect)
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ARMOR_TYPE_CHOICES, WEAPON_PROFICIENCY_GROUPS } from "../config/system.mjs"
|
||||
|
||||
export default class OathHammerClass extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields
|
||||
@@ -8,14 +10,27 @@ export default class OathHammerClass extends foundry.abstract.TypeDataModel {
|
||||
// Class features, starting abilities, advancement options (rich text)
|
||||
schema.features = new fields.HTMLField({ required: true, textSearch: true })
|
||||
|
||||
// Armor proficiencies (e.g. "Light, Medium, Heavy")
|
||||
schema.armorProficiency = new fields.StringField({ required: true, nullable: false, initial: "" })
|
||||
// Armor proficiencies — set of keys from ARMOR_TYPE_CHOICES (light, medium, heavy)
|
||||
schema.armorProficiency = new fields.SetField(
|
||||
new fields.StringField({ choices: ARMOR_TYPE_CHOICES }),
|
||||
{ required: true, initial: [] }
|
||||
)
|
||||
|
||||
// Weapon proficiencies (e.g. "Common, Dueling, Heavy, Throwing")
|
||||
schema.weaponProficiency = new fields.StringField({ required: true, nullable: false, initial: "" })
|
||||
// Weapon proficiencies — set of keys from WEAPON_PROFICIENCY_GROUPS
|
||||
schema.weaponProficiency = new fields.SetField(
|
||||
new fields.StringField({ choices: WEAPON_PROFICIENCY_GROUPS }),
|
||||
{ required: true, initial: [] }
|
||||
)
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
// Migrate old free-text string values to empty sets
|
||||
static migrateData(source) {
|
||||
if (typeof source.armorProficiency === "string") source.armorProficiency = []
|
||||
if (typeof source.weaponProficiency === "string") source.weaponProficiency = []
|
||||
return super.migrateData(source)
|
||||
}
|
||||
|
||||
static LOCALIZATION_PREFIXES = ["OATHHAMMER.Class"]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
export default class OathHammerUtils {
|
||||
static registerHandlebarsHelpers() {
|
||||
Handlebars.registerHelper("ifThen", (condition, trueVal, falseVal) => condition ? trueVal : falseVal)
|
||||
Handlebars.registerHelper("includes", (collection, value) => {
|
||||
if (!collection) return false
|
||||
if (collection instanceof Set) return collection.has(value)
|
||||
if (Array.isArray(collection)) return collection.includes(value)
|
||||
return false
|
||||
})
|
||||
Handlebars.registerHelper("capitalize", (str) => {
|
||||
if (typeof str !== "string") return str
|
||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||
|
||||
Reference in New Issue
Block a user