Levelup Remake (#100)

* Set up DhLevelTier datamodel

* Added Levelup data model and started at the render

* Fixed data handling in the LevelUp view

* Added back the save function

* Finalised levelup selections and propagating to PC

* Added level advancement selection data

* Added DomainCard selection

* Css merge commit

* Added PC level/delevel benefits of leveling up

* Fixed sticky previous selections on continous leveling

* Fixed up Summary. Fixed multiclass/subclass blocking on selection

* Removed unused level.hbs

* Fixed attribute base for PC

* Improved naming of attribute properties

* Renamed/structured resources/evasion/proficiency

* Improved trait marking

* Rework to level up once at a time

* Added markers

* Removed tabs when in Summary

* Fixed multilevel buttons

* Improved multiclass/subclass recognition

* Fixed tagify error on selection

* Review fixes
This commit is contained in:
WBHarry 2025-06-07 01:50:50 +02:00 committed by GitHub
parent 47a6abddfb
commit a92221778e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 3279 additions and 1283 deletions

View file

@ -362,7 +362,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
name: x.actor.name,
img: x.actor.img,
difficulty: x.actor.system.difficulty,
evasion: x.actor.system.evasion
evasion: x.actor.system.evasion.value
}));
const cls = getDocumentClass('ChatMessage');

View file

@ -1,10 +1,10 @@
import { capitalize } from '../../helpers/utils.mjs';
import DhpDeathMove from '../deathMove.mjs';
import DhpDowntime from '../downtime.mjs';
import DhpLevelup from '../levelup.mjs';
import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs';
import DaggerheartSheet from './daggerheart-sheet.mjs';
import { abilities } from '../../config/actorConfig.mjs';
import DhlevelUp from '../levelup.mjs';
const { ActorSheetV2 } = foundry.applications.sheets;
const { TextEditor } = foundry.applications.ux;
@ -167,13 +167,23 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
$(htmlElement).find('.attribute-value').on('change', this.attributeChange.bind(this));
$(htmlElement).find('.tab-selector').on('click', this.tabSwitch.bind(this));
$(htmlElement).find('.level-title.levelup').on('click', this.openLevelUp.bind(this));
$(htmlElement).find('.feature-input').on('change', this.onFeatureInputBlur.bind(this));
$(htmlElement).find('.experience-description').on('change', this.experienceDescriptionChange.bind(this));
$(htmlElement).find('.experience-value').on('change', this.experienceValueChange.bind(this));
$(htmlElement).find('[data-item]').on('change', this.itemUpdate.bind(this));
htmlElement
.querySelectorAll('.attribute-value')
.forEach(element => element.addEventListener('change', this.attributeChange.bind(this)));
htmlElement
.querySelectorAll('.tab-selector')
.forEach(element => element.addEventListener('click', this.tabSwitch.bind(this)));
htmlElement.querySelector('.level-title.levelup')?.addEventListener('click', this.openLevelUp.bind(this));
htmlElement
.querySelectorAll('.feature-input')
.forEach(element => element.addEventListener('change', this.onFeatureInputBlur.bind(this)));
htmlElement
.querySelectorAll('.experience-description')
.forEach(element => element.addEventListener('change', this.experienceDescriptionChange.bind(this)));
htmlElement
.querySelectorAll('.experience-value')
.forEach(element => element.addEventListener('change', this.experienceValueChange.bind(this)));
htmlElement.querySelector('.level-value').addEventListener('change', this.onLevelChange.bind(this));
}
async _prepareContext(_options) {
@ -188,7 +198,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
context.storyEditor = this.storyEditor;
context.multiclassFeatureSetSelected = this.multiclassFeatureSetSelected;
const selectedAttributes = Object.values(this.document.system.attributes).map(x => x.data.base);
const selectedAttributes = Object.values(this.document.system.traits).map(x => x.base);
context.abilityScoreArray = JSON.parse(
await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.General.AbilityArray)
).reduce((acc, x) => {
@ -215,9 +225,9 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
}
: {};
context.attributes = Object.keys(this.document.system.attributes).reduce((acc, key) => {
context.attributes = Object.keys(this.document.system.traits).reduce((acc, key) => {
acc[key] = {
...this.document.system.attributes[key],
...this.document.system.traits[key],
name: game.i18n.localize(SYSTEM.ACTOR.abilities[key].name),
verbs: SYSTEM.ACTOR.abilities[key].verbs.map(x => game.i18n.localize(x))
};
@ -479,7 +489,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
}
async attributeChange(event) {
const path = `system.attributes.${event.currentTarget.dataset.attribute}.data.base`;
const path = `system.traits.${event.currentTarget.dataset.attribute}.base`;
await this.document.update({ [path]: event.currentTarget.value });
}
@ -531,21 +541,21 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
}
static async toggleAttributeMark(_, button) {
const attribute = this.document.system.attributes[button.dataset.attribute];
const attribute = this.document.system.traits[button.dataset.attribute];
const newMark = this.document.system.availableAttributeMarks
.filter(x => x > Math.max.apply(null, this.document.system.attributes[button.dataset.attribute].levelMarks))
.filter(x => x > Math.max.apply(null, this.document.system.traits[button.dataset.attribute].levelMarks))
.sort((a, b) => (a > b ? 1 : -1))[0];
if (attribute.levelMark || !newMark) return;
const path = `system.attributes.${button.dataset.attribute}.levelMarks`;
const path = `system.traits.${button.dataset.attribute}.levelMarks`;
await this.document.update({ [path]: [...attribute.levelMarks, newMark] });
}
static async toggleHP(_, button) {
const healthValue = Number.parseInt(button.dataset.value);
const newValue = this.document.system.resources.health.value >= healthValue ? healthValue - 1 : healthValue;
await this.document.update({ 'system.resources.health.value': newValue });
const newValue = this.document.system.resources.hitPoints.value >= healthValue ? healthValue - 1 : healthValue;
await this.document.update({ 'system.resources.hitPoints.value': newValue });
}
static async toggleStress(_, button) {
@ -576,7 +586,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
type: weapon.system.damage.type,
bonusDamage: this.document.system.bonuses.damage
};
const modifier = this.document.system.attributes[weapon.system.trait].data.value;
const modifier = this.document.system.traits[weapon.system.trait].value;
const { roll, hope, fear, advantage, disadvantage, modifiers, bonusDamageString } =
await this.document.dualityRoll(
@ -592,7 +602,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
name: x.actor.name,
img: x.actor.img,
difficulty: x.actor.system.difficulty,
evasion: x.actor.system.evasion
evasion: x.actor.system.evasion.value
}));
const systemData = {
@ -633,7 +643,12 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
}
openLevelUp() {
new DhpLevelup(this.document).render(true);
if (!this.document.system.class || !this.document.system.subclass) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.Sheets.PC.Errors.missingClassOrSubclass'));
return;
}
new DhlevelUp(this.document).render(true);
}
static domainCardsTab(toVault) {
@ -781,7 +796,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
}
static async makeDeathMove() {
if (this.document.system.resources.health.value === this.document.system.resources.health.max) {
if (this.document.system.resources.hitPoints.value === this.document.system.resources.hitPoints.max) {
await new DhpDeathMove(this.document).render(true);
await this.minimize();
}
@ -866,6 +881,11 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
await item.update({ [name]: event.currentTarget.value });
}
async onLevelChange(event) {
await this.document.updateLevel(Number(event.currentTarget.value));
this.render();
}
static async deleteItem(_, button) {
const item = await fromUuid($(button).closest('[data-item-id]')[0].dataset.itemId);
await item.delete();