feat: continuing to add data models
This commit is contained in:
parent
ebed4c3622
commit
ada2dc40c5
25
modules/dataModel/baseActorModel.mjs
Normal file
25
modules/dataModel/baseActorModel.mjs
Normal file
@ -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()}),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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(),
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
69
modules/dataModel/dataModel.mjs
Normal file
69
modules/dataModel/dataModel.mjs
Normal file
@ -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"})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
45
modules/dataModel/itemModel.mjs
Normal file
45
modules/dataModel/itemModel.mjs
Normal file
@ -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})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
51
modules/dataModel/playerCharacterModel.mjs
Normal file
51
modules/dataModel/playerCharacterModel.mjs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user