mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 19:51:08 +01:00
Added Levelup data model and started at the render
This commit is contained in:
parent
ec303df84e
commit
3cc8800950
10 changed files with 618 additions and 409 deletions
|
|
@ -42,51 +42,17 @@ class DhLevelOption extends foundry.abstract.DataModel {
|
|||
checkboxQuantity: new fields.NumberField({ required: true, integer: true, initial: 1 }),
|
||||
minCost: new fields.NumberField({ required: true, integer: true, initial: 1 }),
|
||||
type: new fields.StringField({ required: true, choices: LevelOptionType }),
|
||||
choice: new fields.StringField(),
|
||||
value: new fields.NumberField({ integer: true }),
|
||||
amount: new fields.NumberField({ integer: true })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// class DhLevelOptionType extends foundry.abstract.DataModel {
|
||||
// static defineSchema(){
|
||||
// return new fields.SchemaField({
|
||||
// trait: new fields.SchemaField({
|
||||
// id: new fields.StringField({ required: true }),
|
||||
// label: new fields.StringField({ required: true }),
|
||||
// }),
|
||||
// attribute: new fields.SchemaField({
|
||||
// id: new fields.StringField({ required: true }),
|
||||
// label: new fields.StringField({ required: true }),
|
||||
// choice: new fields.StringField({ required: true, choices: attributeChoices })
|
||||
// }),
|
||||
// experience: new fields.SchemaField({
|
||||
// id: new fields.StringField({ required: true }),
|
||||
// label: new fields.StringField({ required: true }),
|
||||
// }),
|
||||
// domainCard: new fields.SchemaField({
|
||||
// id: new fields.StringField({ required: true }),
|
||||
// label: new fields.StringField({ required: true }),
|
||||
// }),
|
||||
// subclass: new fields.SchemaField({
|
||||
// id: new fields.StringField({ required: true }),
|
||||
// label: new fields.StringField({ required: true }),
|
||||
// }),
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
const LevelOptionType = {
|
||||
export const LevelOptionType = {
|
||||
trait: {
|
||||
id: 'trait',
|
||||
label: 'Character Trait'
|
||||
},
|
||||
// attribute: {
|
||||
// id: 'attribute',
|
||||
// label: 'Attribute',
|
||||
// choices: attributeChoices,
|
||||
// },
|
||||
hitPoint: {
|
||||
id: 'hitPoint',
|
||||
label: 'Hit Points'
|
||||
|
|
@ -121,25 +87,6 @@ const LevelOptionType = {
|
|||
}
|
||||
};
|
||||
|
||||
// const attributeChoices = {
|
||||
// hitPoint: {
|
||||
// id: 'hitPoint',
|
||||
// label: 'Hit Points',
|
||||
// },
|
||||
// stress: {
|
||||
// id: 'stress',
|
||||
// label: 'Stress',
|
||||
// },
|
||||
// evasion: {
|
||||
// id: 'evasion',
|
||||
// label: 'Evasion',
|
||||
// },
|
||||
// proficiency: {
|
||||
// id: 'proficiency',
|
||||
// label: 'Proficiency',
|
||||
// },
|
||||
// };
|
||||
|
||||
export const defaultLevelTiers = {
|
||||
tiers: {
|
||||
2: {
|
||||
|
|
|
|||
127
module/data/levelup.mjs
Normal file
127
module/data/levelup.mjs
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import { LevelOptionType } from './levelTier.mjs';
|
||||
|
||||
export class DhLevelup extends foundry.abstract.DataModel {
|
||||
static initializeData(levelTierData, levelChoices) {
|
||||
return {
|
||||
tiers: Object.keys(levelTierData.tiers).reduce((acc, key) => {
|
||||
acc[key] = DhLevelupTier.initializeData(levelTierData.tiers[key]);
|
||||
|
||||
return acc;
|
||||
}, {})
|
||||
};
|
||||
}
|
||||
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
tiers: new fields.TypedObjectField(new fields.EmbeddedDataField(DhLevelupTier))
|
||||
};
|
||||
}
|
||||
|
||||
get totalSelections() {
|
||||
return Object.values(this.tiers).reduce((acc, tier) => acc + tier.nrSelections, 0);
|
||||
}
|
||||
}
|
||||
|
||||
class DhLevelupTier extends foundry.abstract.DataModel {
|
||||
static initializeData(levelTier, levelChoices) {
|
||||
const levels = {};
|
||||
const levelEndCap = levelTier.levels.end + 1;
|
||||
for (var level = levelTier.levels.start; level < levelEndCap; level++) {
|
||||
levels[level] = DhLevelupLevel.initializeData(levelTier.availableOptions, levelTier.options);
|
||||
}
|
||||
|
||||
return {
|
||||
tier: levelTier.tier,
|
||||
name: levelTier.name,
|
||||
options: Object.keys(levelTier.options).reduce((acc, key) => {
|
||||
acc[key] = levelTier.options[key];
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
levels: levels,
|
||||
maxSelections: levelTier.availableOptions * (levelEndCap - levelTier.levels.start)
|
||||
};
|
||||
}
|
||||
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
tier: new fields.NumberField({ required: true, integer: true }),
|
||||
name: new fields.StringField({ required: true }),
|
||||
options: new fields.TypedObjectField(new fields.EmbeddedDataField(DhLevelupTierOption)),
|
||||
levels: new fields.TypedObjectField(new fields.EmbeddedDataField(DhLevelupLevel)),
|
||||
maxSelections: new fields.NumberField({ required: true, integer: true })
|
||||
};
|
||||
}
|
||||
|
||||
get nrSelections() {
|
||||
return Object.values(this.levels).reduce((acc, level) => acc + level.nrSelections, 0);
|
||||
}
|
||||
|
||||
/* Data to render all options in a Tier from */
|
||||
get tierCheckboxGroups() {
|
||||
return Object.keys(this.options).map(optionKey => {
|
||||
const option = this.options[optionKey];
|
||||
return {
|
||||
label: game.i18n.localize(option.label),
|
||||
checkboxes: [...Array(option.checkboxQuantity).keys()].map(checkboxNr => {
|
||||
const levelId = Object.keys(this.levels).find(levelKey => {
|
||||
Object.values(this.levels[levelKey].optionSelections).some(nr => nr === checkboxNr);
|
||||
});
|
||||
return {
|
||||
...option,
|
||||
tier: this.tier,
|
||||
level: levelId,
|
||||
selected: Boolean(levelId),
|
||||
optionkey: optionKey,
|
||||
checkboxNr: checkboxNr
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class DhLevelupTierOption extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
label: new fields.StringField({ required: true }),
|
||||
checkboxQuantity: new fields.NumberField({ required: true, integer: true }),
|
||||
minCost: new fields.NumberField({ required: true, integer: true }),
|
||||
type: new fields.StringField({ required: true, choices: LevelOptionType }),
|
||||
value: new fields.NumberField({ integer: true }),
|
||||
amount: new fields.NumberField({ integer: true })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class DhLevelupLevel extends foundry.abstract.DataModel {
|
||||
static initializeData(maxSelections, levelOptions, levelChoices) {
|
||||
return {
|
||||
maxSelections: maxSelections,
|
||||
optionSelections: {} // collate levelOption and levelChoices,
|
||||
};
|
||||
}
|
||||
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
maxSelections: new fields.NumberField({ required: true, integer: true }),
|
||||
optionSelections: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
checkboxNr: new fields.NumberField({ required: true, integer: true })
|
||||
})
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
get nrSelections() {
|
||||
return this.optionSelections.length;
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +104,8 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
|
||||
get canLevelUp() {
|
||||
// return Object.values(this.levels.data).some(x => !x.completed);
|
||||
return this.levelData.currentLevel !== this.levelData.changedLevel;
|
||||
// return this.levelData.currentLevel !== this.levelData.changedLevel;
|
||||
return true;
|
||||
}
|
||||
|
||||
get tier() {
|
||||
|
|
@ -334,20 +335,20 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
|
|||
for (var attributeKey in this.traits) {
|
||||
const attribute = this.traits[attributeKey];
|
||||
|
||||
attribute.levelMark = attribute.levelMarks.find(x => this.isSameTier(x)) ?? null;
|
||||
// attribute.levelMark = attribute.levelMarks.find(x => this.isSameTier(x)) ?? null;
|
||||
|
||||
const actualValue = attribute.data.base + attribute.levelMarks.length + attribute.data.bonus;
|
||||
attribute.data.actualValue = actualValue;
|
||||
attribute.data.value = attribute.data.overrideValue
|
||||
? attribute.data.overrideValue
|
||||
: attribute.data.actualValue;
|
||||
// const actualValue = attribute.data.base + attribute.levelMarks.length + attribute.data.bonus;
|
||||
// attribute.data.actualValue = actualValue;
|
||||
// attribute.data.value = attribute.data.overrideValue
|
||||
// ? attribute.data.overrideValue
|
||||
// : attribute.data.actualValue;
|
||||
}
|
||||
|
||||
this.evasion = this.class?.system?.evasion ?? 0;
|
||||
// this.armor.value = this.activeArmor?.baseScore ?? 0;
|
||||
this.damageThresholds = this.computeDamageThresholds();
|
||||
// this.damageThresholds = this.computeDamageThresholds();
|
||||
|
||||
this.applyLevels();
|
||||
// this.applyLevels();
|
||||
this.applyEffects();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue