From ada2dc40c5bcb7f774a684c3ad0cb96eb395bd72 Mon Sep 17 00:00:00 2001 From: Joscha Maier Date: Wed, 2 Oct 2024 00:14:03 +0200 Subject: [PATCH] feat: continuing to add data models --- modules/dataModel/baseActorModel.mjs | 25 ++++ modules/dataModel/dataModel.js | 149 --------------------- modules/dataModel/dataModel.mjs | 69 ++++++++++ modules/dataModel/itemModel.mjs | 45 +++++++ modules/dataModel/playerCharacterModel.mjs | 51 +++++++ 5 files changed, 190 insertions(+), 149 deletions(-) create mode 100644 modules/dataModel/baseActorModel.mjs delete mode 100644 modules/dataModel/dataModel.js create mode 100644 modules/dataModel/dataModel.mjs create mode 100644 modules/dataModel/itemModel.mjs create mode 100644 modules/dataModel/playerCharacterModel.mjs diff --git a/modules/dataModel/baseActorModel.mjs b/modules/dataModel/baseActorModel.mjs new file mode 100644 index 0000000..d22b38f --- /dev/null +++ b/modules/dataModel/baseActorModel.mjs @@ -0,0 +1,25 @@ +import Stat from "./dataModel.mjs" + +/* -------------------------------------------- */ +/* Actor base Model */ +/* -------------------------------------------- */ +const fields = foundry.data.fields; +class ActorGeneral extends foundry.abstract.TypeDataModel +{ + static defineSchema(){ + return { + age: new fields.StringField({required: false}), + pronouns: new fields.StringField({required: false}), + fear: new fields.StringField({required: false}), + grade: new fields.StringField({required: false}), + stats: new fields.SchemaField({ + fight: new fields.EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), + brains: new fields.EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), + charm: new fields.EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), + flight: new fields.EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), + brawn: new fields.EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), + grit: new fields.EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), + }), + } + } +} \ No newline at end of file diff --git a/modules/dataModel/dataModel.js b/modules/dataModel/dataModel.js deleted file mode 100644 index 354ba20..0000000 --- a/modules/dataModel/dataModel.js +++ /dev/null @@ -1,149 +0,0 @@ -const fields = foundry.data.fields; - -/* -------------------------------------------- */ -/* Base Models */ -/* -------------------------------------------- */ - -class Stat extends foundry.abstract.DataModel -{ - static defineSchema() { - return { - id: new StringField({ required: true, initial: "statID"}), - name: new StringField({ required: true, intial: "Stat"}), - die: new NumberField({ required: true, integer: true, min: 0, max: 20, initial: 4}), - modifiers: new ArrayField({ required: true, type: Modifier, default: []}), - }; - } - -} - -class Modifier extends foundry.abstract.DataModel -{ - static defineSchema() { - return { - statID: new StringField({ required: true, initial: "statID"}), - name: new StringField({ required: true, initial: "Modifier"}), - value: new NumberField({ required: true, integer: true, initial: 0}), - }; - } - - Modifier(statID,name,value) { - this.statID = statID; - this.name = name; - this.value = value; - }; -} - -/* -------------------------------------------- */ -/* Effect Models */ -/* -------------------------------------------- */ - -class Effect extends foundry.abstract.DataModel -{ - static defineSchema() { - return { - description: new StringField({ required: true, initial: "A EffectDescription" }), - modifier: new EmbeddedDataField(Modifier, { required: true, nullable: true, default: null}), - }; - } -} - -class Flaw extends foundry.abstract.DataModel -{ - static defineSchema() { - return { - name: new StringField({ required: true, initial: "Flaw"}), - description: new StringField({ required: true, initial: "A FlawDescription" }) - }; - } -} - -class Strength extends Effect -{ - static defineSchema() { - return { - ...super.defineSchema(), - name: new StringField({ required: true, initial: "Strength"}) - }; - } -} - -/* -------------------------------------------- */ -/* Item Models */ -/* -------------------------------------------- */ -/* How this will work is when we first load a sheet we load all the items we have and take their effects and apply them to our stats. */ - -class Item extends foundry.abstract.TypeDataModel -{ - static defineSchema() { - return { - name: new StringField({ required: true, initial: "Item"}), - description: new StringField({ required: true, initial: "An ItemDescription" }), - effects: new ArrayField({ required: true, type: Effect, default: []}), - }; - } - - Item(name,description,effects) { - this.name = name; - this.description = description; - this.effects = effects; - } -} - -class Wand extends foundry.abstract.DataModel -{ - static defineSchema() { - return { - name: new StringField({ required: true, initial: "Wand"}), - wood: new EmbeddedDataField(Item, { required: true, nullable: true, default: null}), //These are just items! - core: new EmbeddedDataField(Item, { required: true, nullable: true, default: null}), - }; - } -} - -class Broom extends foundry.abstact.DataModel -{ - static defineSchema(){ - return { - name: new StringField({required: true, initial: "Broom"}), - look: new StringField({requird: true, intial: "A broom"}), - mechanicalBenefit: new EmbeddedDataField(effect, {required: false}) - } - } -} - - -/* -------------------------------------------- */ -/* Actor Models */ -/* -------------------------------------------- */ - -class ActorGeneral extends foundry.abstract.TypeDataModel -{ - static defineSchema(){ - return { - name: new StringField({required: true, initial: "Actor"}), - age: new StringField({required: false}), - pronouns: new StringField({required: false}), - fear: new StringField({required: false}), - grade: new StringField({required: false}), - stats: new SchemaField({ - fight: new EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), - brains: new EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), - charm: new EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), - flight: new EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), - brawn: new EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), - grit: new EmbeddedDataField(Stat, {required: true, nullable: false, default: new Stat()}), - }), - } - } -} - -class PlayerCharacter extends ActorGeneral -{ - static defineSchema(){ - return { - ...super.defineSchema(), - - } - } -} \ No newline at end of file diff --git a/modules/dataModel/dataModel.mjs b/modules/dataModel/dataModel.mjs new file mode 100644 index 0000000..10a29c3 --- /dev/null +++ b/modules/dataModel/dataModel.mjs @@ -0,0 +1,69 @@ +/* -------------------------------------------- */ +/* Base Models */ +/* -------------------------------------------- */ +const fields = foundry.data.fields; +class Stat extends foundry.abstract.DataModel +{ + static defineSchema() { + return { + id: new fields.StringField({ required: true, initial: "statID"}), + name: new fields.StringField({ required: true, intial: "Stat"}), + die: new fields.NumberField({ required: true, nullable: false, initial: "d4"}), + modifiers: new fields.ArrayField({ required: true, type: Modifier, default: []}), + modifier: new fields.NumberField({required: true, integer: true, initial: 0}) + }; + } +} + +class Modifier extends foundry.abstract.DataModel +{ + static defineSchema() { + return { + statID: new fields.StringField({ required: true, initial: "statID"}), + name: new fields.StringField({ required: true, initial: "Modifier"}), + value: new fields.NumberField({ required: true, integer: true, initial: 0}), + }; + } + + Modifier(statID,name,value) { + this.statID = statID; + this.name = name; + this.value = value; + }; +} + +/* -------------------------------------------- */ +/* Effect Models */ +/* -------------------------------------------- */ +class Effect extends foundry.abstract.DataModel +{ + static defineSchema() { + return { + description: new fields.StringField({ required: true, initial: "A EffectDescription" }), + modifier: new fields.EmbeddedDataField(Modifier, { required: true, nullable: true, default: null}), + }; + } +} + +class Flaw extends foundry.abstract.DataModel +{ + static defineSchema() { + return { + name: new fields.StringField({ required: true, initial: "Flaw"}), + description: new fields.StringField({ required: true, initial: "A FlawDescription" }) + }; + } +} + +class Strength extends Effect +{ + static defineSchema() { + return { + ...super.defineSchema(), + name: new fields.StringField({ required: true, initial: "Strength"}) + }; + } +} + + + diff --git a/modules/dataModel/itemModel.mjs b/modules/dataModel/itemModel.mjs new file mode 100644 index 0000000..cee95ed --- /dev/null +++ b/modules/dataModel/itemModel.mjs @@ -0,0 +1,45 @@ +import Effect from "./dataModel.mjs"; + +/* -------------------------------------------- */ +/* Item Models */ +/* -------------------------------------------- */ +/* How this will work is when we first load a sheet we load all the items we have and take their effects and apply them to our stats. */ +const fields = foundry.data.fields; +class KidsOnBroomsItem extends foundry.abstract.TypeDataModel +{ + static defineSchema() { + return { + description: new fields.StringField({ required: true, initial: "An KidsOnBroomsItemDescription" }), + effects: new fields.ArrayField({ required: true, type: Effect, default: []}), + quantity: new fields.NumberField({required: true, nullable: false, integer: true, initial: 1, min: 0}), + price: new fields.NumberField({required: true, nullable: false, integer: true, initial: 0, min: 0}), + }; + } + + KidsOnBroomsItem(name,description,effects) { + this.name = name; + this.description = description; + this.effects = effects; + } +} + +class Wand extends KidsOnBroomsItem +{ + static defineSchema() { + return { + wood: new fields.EmbeddedDataField(KidsOnBroomsItem, { required: true, nullable: true, default: null}), //These are just KidsOnBroomsItems! + core: new fields.EmbeddedDataField(KidsOnBroomsItem, { required: true, nullable: true, default: null}), + }; + } +} + +class Broom extends KidsOnBroomsItem +{ + static defineSchema(){ + return { + look: new fields.StringField({requird: true, intial: "A broom"}), + mechanicalBenefit: new fields.EmbeddedDataField(Effect, {required: false}) + } + } +} + diff --git a/modules/dataModel/playerCharacterModel.mjs b/modules/dataModel/playerCharacterModel.mjs new file mode 100644 index 0000000..db05521 --- /dev/null +++ b/modules/dataModel/playerCharacterModel.mjs @@ -0,0 +1,51 @@ +import ActorGeneral from "./baseActorModel.mjs"; +import {KidsOnBroomsItem, Wand, Broom} from "./itemModel.mjs" + +/* -------------------------------------------- */ +/* PC Model */ +/* -------------------------------------------- */ +const fields = foundry.data.fields; +class PlayerCharacter extends ActorGeneral +{ + static defineSchema(){ + return { + ...super.defineSchema(), + description: new fields.StringField({required: false, intial: "Enter your characters description here."}), + broom: new fields.EmbeddedDataField(Broom, {nullable: true}), + wand: new fields.EmbeddedDataField(Wand, {nullable: true}), + animalFamiliar: new fields.StringField({required: false, initial: "Describe your companion!"}), + schoolbag: new fields.ArrayField({type: KidsOnBroomsItem, default: []}), + strengths: new fields.ArrayField({type: Strength, default: []}), + adversityTokens: new fields.NumberField({required: true, nullable: false, integer: true, initial: 3, min: 0}) + } + } + + prepareBaseData() { + let effectsToApply = this.gatherEffects(); + + effectsToApply.forEach(element => { + switch (element.statID) { + case value: + + break; + + default: + break; + } + }) + } + + gatherEffects() { + let effectsToApply = new []; + + this.schoolbag.array.forEach(element => { + if(element.effects != []) { + element.effects.forEach(effect => { + effectsToApply.push(effect); + }) + } + }); + + return effectsToApply; + } +} \ No newline at end of file