Get the weapons block implemented
This commit is contained in:
parent
a8619246fe
commit
f68e7161df
4 changed files with 149 additions and 27 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -205,7 +205,82 @@
|
|||
|
||||
|
||||
{{#> dotdungeon.panel class="weapons" title="dotdungeon.actor.pc.panel.weapons"}}
|
||||
Weapons
|
||||
<details class="main-hand" {{dotdungeon-expanded meta.expanded "weapons.main-hand"}}>
|
||||
<summary data-collapse-id="weapons.main-hand">
|
||||
Main-Hand
|
||||
</summary>
|
||||
<label>
|
||||
Name
|
||||
<input
|
||||
type="text"
|
||||
name=""
|
||||
>
|
||||
</label>
|
||||
<label>
|
||||
Damage
|
||||
<select name="system.weapon.mainHand.damage"></select>
|
||||
</label>
|
||||
<label>
|
||||
Ranged
|
||||
<input
|
||||
type="checkbox"
|
||||
name="system.weapon.mainHand.ranged"
|
||||
{{checked system.weapon.mainHand.ranged}}
|
||||
>
|
||||
</label>
|
||||
{{#if system.weapon.mainHand.ranged}}
|
||||
<label>
|
||||
Scope
|
||||
<input
|
||||
type="checkbox"
|
||||
name="system.weapon.mainHand.scope"
|
||||
{{checked system.weapon.mainHand.scope}}
|
||||
>
|
||||
</label>
|
||||
<label>
|
||||
Ammo
|
||||
<select name=""></select>
|
||||
</label>
|
||||
{{/if}}
|
||||
</details>
|
||||
<details {{dotdungeon-expanded meta.expanded "weapons.off-hand"}}>
|
||||
<summary data-collapse-id="weapons.off-hand">
|
||||
Off-Hand
|
||||
</summary>
|
||||
<label>
|
||||
Name
|
||||
<input
|
||||
type="text"
|
||||
name=""
|
||||
>
|
||||
</label>
|
||||
<label>
|
||||
Damage
|
||||
<select name="system.weapon.offHand.damage"></select>
|
||||
</label>
|
||||
<label>
|
||||
Ranged
|
||||
<input
|
||||
type="checkbox"
|
||||
name="system.weapon.offHand.ranged"
|
||||
{{checked system.weapon.offHand.ranged}}
|
||||
>
|
||||
</label>
|
||||
{{#if system.weapon.offHand.ranged}}
|
||||
<label>
|
||||
Scope
|
||||
<input
|
||||
type="checkbox"
|
||||
name="system.weapon.offHand.scope"
|
||||
{{checked system.weapon.offHand.scope}}
|
||||
>
|
||||
</label>
|
||||
<label>
|
||||
Ammo
|
||||
<select name=""></select>
|
||||
</label>
|
||||
{{/if}}
|
||||
</details>
|
||||
{{/ dotdungeon.panel}}
|
||||
|
||||
|
||||
|
|
@ -244,6 +319,10 @@
|
|||
<pre><code>{{dotdungeon-stringify settings}}</code></pre>
|
||||
</div>
|
||||
<hr>
|
||||
<div>
|
||||
Expanded: {{dotdungeon-stringify expanded}}
|
||||
</div>
|
||||
<hr>
|
||||
<div>
|
||||
System:
|
||||
<pre><code>{{dotdungeon-stringify system}}</code></pre>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue