63 lines
2.6 KiB
JavaScript
63 lines
2.6 KiB
JavaScript
import { HeritiersUtility } from "./heritiers-utility.js";
|
|
|
|
export const defaultItemImg = {
|
|
competence: "systems/fvtt-les-heritiers/assets/icons/skill.webp",
|
|
avantage: "systems/fvtt-les-heritiers/assets/icons/advantage.webp",
|
|
desavantage: "systems/fvtt-les-heritiers/assets/icons/disadvantage.webp",
|
|
contact: "systems/fvtt-les-heritiers/assets/icons/contact.webp",
|
|
pouvoir: "systems/fvtt-les-heritiers/assets/icons/power.webp",
|
|
accessoire: "systems/fvtt-les-heritiers/assets/icons/accessoire.webp",
|
|
arme: "systems/fvtt-les-heritiers/assets/icons/melee.webp",
|
|
monnaie: "systems/fvtt-les-heritiers/assets/icons/monnaie.webp",
|
|
protection: "systems/fvtt-les-heritiers/assets/icons/protection.webp",
|
|
atoutfeerique: "systems/fvtt-les-heritiers/assets/icons/fairy_atout.webp",
|
|
capacitenaturelle: "systems/fvtt-les-heritiers/assets/icons/natural_capacity.webp",
|
|
arme: "systems/fvtt-les-heritiers/assets/icons/weapon.webp",
|
|
accessoire: "systems/fvtt-les-heritiers/assets/icons/item.webp",
|
|
protection: "systems/fvtt-les-heritiers/assets/icons/armor.webp",
|
|
fee: "systems/fvtt-les-heritiers/assets/icons/faery_type.webp",
|
|
profil: "systems/fvtt-les-heritiers/assets/icons/profil.webp",
|
|
equipement: "systems/fvtt-les-heritiers/assets/icons/equipement.webp",
|
|
sort: "systems/fvtt-les-heritiers/assets/icons/sort.webp",
|
|
}
|
|
|
|
/**
|
|
* Extend the basic ItemSheet with some very simple modifications
|
|
* @extends {ItemSheet}
|
|
*/
|
|
export class HeritiersItem extends Item {
|
|
|
|
constructor(data, context) {
|
|
if (!data.img) {
|
|
data.img = defaultItemImg[data.type];
|
|
}
|
|
// Coerce legacy string numeric fields before DataModel validation
|
|
if (data.system) {
|
|
for (const key of ["quantite", "rarete", "prix", "degats", "precision",
|
|
"magasin", "charge", "zone", "points", "malusagilite", "lieu"]) {
|
|
if (typeof data.system[key] === "string") {
|
|
const v = parseInt(data.system[key])
|
|
data.system[key] = Number.isNaN(v) ? 0 : v
|
|
}
|
|
}
|
|
}
|
|
super(data, context);
|
|
}
|
|
|
|
// Coerce legacy string values for NumberFields in system data (migration from pre-DataModel era)
|
|
static migrateData(data) {
|
|
if (data.system) {
|
|
const numericFields = ["quantite", "rarete", "prix", "degats", "precision",
|
|
"magasin", "charge", "zone", "points", "malusagilite", "lieu"]
|
|
for (const key of numericFields) {
|
|
if (typeof data.system[key] === "string") {
|
|
const v = parseInt(data.system[key])
|
|
data.system[key] = Number.isNaN(v) ? 0 : v
|
|
}
|
|
}
|
|
}
|
|
return super.migrateData(data)
|
|
}
|
|
|
|
}
|