Prepare sous-classes Item

This commit is contained in:
Vincent Vandemeulebrouck 2022-12-23 00:22:13 +01:00
parent 81e3ceb4dc
commit f397c82c6d
2 changed files with 49 additions and 32 deletions

View File

@ -3,6 +3,7 @@ import { Grammar } from "./grammar.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDHerbes } from "./rdd-herbes.js"; import { RdDHerbes } from "./rdd-herbes.js";
import { RdDUtility } from "./rdd-utility.js"; import { RdDUtility } from "./rdd-utility.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
const typesObjetsInventaire = [ const typesObjetsInventaire = [
"arme", "arme",
@ -69,7 +70,7 @@ export const defaultItemImg = {
export class RdDItem extends Item { export class RdDItem extends Item {
static getDefaultImg(itemType) { static getDefaultImg(itemType) {
return defaultItemImg[itemType]; return game.system.rdd.itemClasses[itemType]?.defaultIcon ?? defaultItemImg[itemType];
} }
static isItemInventaire(newLocal) { static isItemInventaire(newLocal) {
@ -92,6 +93,42 @@ export class RdDItem extends Item {
return true; return true;
} }
static async getCorrespondingItem(itemRef) {
if (itemRef.pack) {
return await SystemCompendiums.loadDocument(itemRef)
}
return game.items.get(itemRef.id ?? itemRef._id);
}
static getItemTypesInventaire() {
return typesObjetsInventaire
}
static getTypesOeuvres() {
return typesObjetsOeuvres
}
constructor(docData, context = {}) {
if (!context.rdd?.ready) {
mergeObject(context, { rdd: { ready: true } });
const ItemConstructor = game.system.rdd.itemClasses[docData.type];
if (ItemConstructor) {
if (!docData.img) {
docData.img = ItemConstructor.defaultIcon;
}
return new ItemConstructor(docData, context);
}
}
if (!docData.img) {
docData.img = RdDItem.getDefaultImg(docData.type);
}
super(docData, context);
}
static get defaultIcon() {
return undefined;
}
getUniteQuantite() { getUniteQuantite() {
switch (this.type) { switch (this.type) {
case "monnaie": return "(Pièces)" case "monnaie": return "(Pièces)"
@ -107,27 +144,12 @@ export class RdDItem extends Item {
return ''; return '';
} }
constructor(itemData, context) { isCompetencePersonnage() { return this.type == 'competence' }
if (!itemData.img) { isCompetenceCreature() { return this.type == 'competencecreature' }
itemData.img = RdDItem.getDefaultImg(itemData.type); isConteneur() { return this.type == 'conteneur'; }
} isMonnaie() { return this.type == 'monnaie'; }
super(itemData, context); isNourritureBoisson() { return this.type == 'nourritureboisson'; }
} isService() { return this.type == 'service'; }
static getItemTypesInventaire() {
return typesObjetsInventaire
}
static getTypesOeuvres() {
return typesObjetsOeuvres
}
isCompetencePersonnage() {
return this.type == 'competence'
}
isCompetenceCreature() {
return this.type == 'competencecreature'
}
isCompetence() { isCompetence() {
return typesObjetsCompetence.includes(this.type) return typesObjetsCompetence.includes(this.type)
} }
@ -146,12 +168,7 @@ export class RdDItem extends Item {
isConnaissance() { isConnaissance() {
return typesObjetsConnaissance.includes(this.type) return typesObjetsConnaissance.includes(this.type)
} }
isConteneur() {
return this.type == 'conteneur';
}
isMonnaie() {
return this.type == 'monnaie';
}
getItemGroup() { getItemGroup() {
if (this.isInventaire()) return "equipement"; if (this.isInventaire()) return "equipement";
@ -175,10 +192,6 @@ export class RdDItem extends Item {
return !this.isConteneur() || (this.system.contenu?.length ?? 0) == 0; return !this.isConteneur() || (this.system.contenu?.length ?? 0) == 0;
} }
isNourritureBoisson() {
return this.type == 'nourritureboisson';
}
isComestible() { isComestible() {
switch (this.type) { switch (this.type) {
case 'nourritureboisson': return 'pret'; case 'nourritureboisson': return 'pret';

View File

@ -51,6 +51,10 @@ export class SystemReveDeDragon {
constructor() { constructor() {
this.RdDUtility = RdDUtility; this.RdDUtility = RdDUtility;
this.RdDHotbar = RdDHotbar; this.RdDHotbar = RdDHotbar;
this.itemClasses = {
}
this.actorClasses = {
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */