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 { RdDHerbes } from "./rdd-herbes.js";
import { RdDUtility } from "./rdd-utility.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
const typesObjetsInventaire = [
"arme",
@ -69,7 +70,7 @@ export const defaultItemImg = {
export class RdDItem extends Item {
static getDefaultImg(itemType) {
return defaultItemImg[itemType];
return game.system.rdd.itemClasses[itemType]?.defaultIcon ?? defaultItemImg[itemType];
}
static isItemInventaire(newLocal) {
@ -92,6 +93,42 @@ export class RdDItem extends Item {
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() {
switch (this.type) {
case "monnaie": return "(Pièces)"
@ -107,27 +144,12 @@ export class RdDItem extends Item {
return '';
}
constructor(itemData, context) {
if (!itemData.img) {
itemData.img = RdDItem.getDefaultImg(itemData.type);
}
super(itemData, context);
}
static getItemTypesInventaire() {
return typesObjetsInventaire
}
static getTypesOeuvres() {
return typesObjetsOeuvres
}
isCompetencePersonnage() {
return this.type == 'competence'
}
isCompetenceCreature() {
return this.type == 'competencecreature'
}
isCompetencePersonnage() { return this.type == 'competence' }
isCompetenceCreature() { return this.type == 'competencecreature' }
isConteneur() { return this.type == 'conteneur'; }
isMonnaie() { return this.type == 'monnaie'; }
isNourritureBoisson() { return this.type == 'nourritureboisson'; }
isService() { return this.type == 'service'; }
isCompetence() {
return typesObjetsCompetence.includes(this.type)
}
@ -146,12 +168,7 @@ export class RdDItem extends Item {
isConnaissance() {
return typesObjetsConnaissance.includes(this.type)
}
isConteneur() {
return this.type == 'conteneur';
}
isMonnaie() {
return this.type == 'monnaie';
}
getItemGroup() {
if (this.isInventaire()) return "equipement";
@ -175,10 +192,6 @@ export class RdDItem extends Item {
return !this.isConteneur() || (this.system.contenu?.length ?? 0) == 0;
}
isNourritureBoisson() {
return this.type == 'nourritureboisson';
}
isComestible() {
switch (this.type) {
case 'nourritureboisson': return 'pret';

View File

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