Get the weapons block implemented

This commit is contained in:
Oliver-Akins 2023-12-24 22:53:08 -07:00
parent a8619246fe
commit f68e7161df
4 changed files with 149 additions and 27 deletions

View file

@ -12,6 +12,7 @@ export async function registerHandlebarsHelpers() {
"dotdungeon-toFriendlyDuration": toFriendlyDuration,
"dotdungeon-objectValue": objectValue,
"dotdungeon-stringify": v => JSON.stringify(v, null, ` `),
"dotdungeon-expanded": detailsExpanded,
});
};
@ -73,4 +74,16 @@ function toFriendlyDuration(duration) {
friendly += `${duration}s`;
};
return friendly;
};
/**
* If the argument is truthy, it returns HTML data to indicate the collapse is
* open
*
* @param {Set<string>} expanded A set indicating what collapseIds are expanded
* @param {string} collapseId The collapseId to check for
* @returns {"open"|null} The HTML insertion indicating the details is expanded
*/
function detailsExpanded(expanded, collapseId) {
return expanded.has(collapseId) ? "open" : null;
};

View file

@ -18,6 +18,22 @@ function trainingLevelField() {
});
};
function weaponDamageTypeField() {
return new foundry.data.fields.StringField({
initial: ``,
blank: true,
options: [ ``, `slashing`, `piercing`, `smashing`, `gun`, `neon`, `shadow`, `solar` ],
});
};
function ammoTypeField() {
return new foundry.data.fields.StringField({
initial: ``,
blank: true,
options: [ ``, `quivers`, `mags`, `cells` ],
});
};
export class PlayerData extends foundry.abstract.DataModel {
static defineSchema() {
const fields = foundry.data.fields;
@ -78,12 +94,24 @@ export class PlayerData extends foundry.abstract.DataModel {
r4: new fields.StringField({ blank: true, trim: true }),
}),
weapon: new fields.SchemaField({
name: new fields.StringField(),
damage: new fields.StringField(),
mainHand: new fields.SchemaField({
name: new fields.StringField({ blank: true, trim: true }),
damage: weaponDamageTypeField(),
ranged: new fields.BooleanField({ initial: false }),
scope: new fields.BooleanField({ initial: false }),
ammo: ammoTypeField(),
}),
offHand: new fields.SchemaField({
name: new fields.StringField({ blank: true, trim: true }),
damage: weaponDamageTypeField(),
ranged: new fields.BooleanField({ initial: false }),
scope: new fields.BooleanField({ initial: false }),
ammo: ammoTypeField(),
}),
ammo: new fields.SchemaField({
quivers: new fields.NumberField({ min: 0, max: 5, integer: true }),
mags: new fields.NumberField({ min: 0, max: 5, integer: true }),
cells: new fields.NumberField({ min: 0, max: 5, integer: true }),
quivers: new fields.NumberField({ min: 0, max: 10, integer: true }),
mags: new fields.NumberField({ min: 0, max: 10, integer: true }),
cells: new fields.NumberField({ min: 0, max: 10, integer: true }),
}),
}),
supplies: new fields.NumberField({

View file

@ -19,29 +19,27 @@ export class PlayerSheet extends GenericSheet {
if (!this.isEditable) return;
console.debug(`.dungeon | Adding event listeners for Actor: ${this.id}`);
// html.find(`input.sync__input`).on("blur", ($e) => {
// console.debug(`.dungeon | input.sync__input blur event`);
// let value = parseInt($e.target.value);
// if (!value) {
// ui.notifications.error(
// `dotdungeon.notification.error.invalid-integer`,
// { localize: true }
// );
// return;
// };
// let delta = value - this.#syncValue();
// this.actor.system.syncDelta += delta;
// for (const actor of game.actors) {
// if (actor._sheet)
// }
// game.socket.emit(`system.dotdungeon`, {
// type: "reload",
// })
// });
/*
Toggles the expanded state for the detail elements in the sheet.
*/
html.find(`summary`).on(`click`, ($e) => {
console.debug(`.dungeon | summary[data-collapse-id="${$e.target.dataset.collapseId}"] click event`);
/*
This seeming inversion of logic is due to the fact that this handler
gets called before the element is updated to include/reflect the
change, so if the parentNode doesn't actually have it, then we're
opening it and vice-versa.
*/
if (!$e.target.parentNode.open) {
this._expanded.add($e.target.dataset.collapseId);
} else {
this._expanded.delete($e.target.dataset.collapseId);
};
});
};
_expanded = new Set();
#syncValue() {
let delta = 0;
for (const actor of game.actors) {
@ -62,6 +60,10 @@ export class PlayerSheet extends GenericSheet {
canChangeGroup: ctx.settings.playersCanChangeGroup || ctx.isGM,
};
ctx.meta = {
expanded: this._expanded,
};
console.groupCollapsed(`PlayerSheet.getData`);
console.log(`ctx`, ctx);
console.log(`actor`, actor);