mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Resource setup finished
This commit is contained in:
parent
0c742eb91b
commit
d9d7b23838
13 changed files with 104 additions and 44 deletions
12
lang/en.json
12
lang/en.json
|
|
@ -1054,6 +1054,10 @@
|
|||
"shortrest": "Short Rest",
|
||||
"longrest": "Long Rest"
|
||||
},
|
||||
"Resource": {
|
||||
"single": "Resource",
|
||||
"plural": "Resources"
|
||||
},
|
||||
"Tabs": {
|
||||
"details": "Details",
|
||||
"attack": "Attack",
|
||||
|
|
@ -1139,6 +1143,14 @@
|
|||
"value": "Value"
|
||||
},
|
||||
"ITEMS": {
|
||||
"FIELDS": {
|
||||
"resource": {
|
||||
"value": { "label": "Value" },
|
||||
"max": { "label": "Max" },
|
||||
"icon": { "label": "Icon" },
|
||||
"recovery": { "label": "Recovery" }
|
||||
}
|
||||
},
|
||||
"Armor": {
|
||||
"baseScore": "Base Score",
|
||||
"baseThresholds": {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,17 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
}
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
htmlElement.querySelectorAll('.inventory-item-resource').forEach(element => {
|
||||
element.addEventListener('change', this.updateItemResource.bind(this));
|
||||
});
|
||||
htmlElement.querySelectorAll('.inventory-item-quantity').forEach(element => {
|
||||
element.addEventListener('change', this.updateItemQuantity.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
async _onRender(context, options) {
|
||||
await super._onRender(context, options);
|
||||
|
|
@ -475,6 +486,28 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Listener Actions */
|
||||
/* -------------------------------------------- */
|
||||
async updateItemResource(event) {
|
||||
const item = this.getItem(event.currentTarget);
|
||||
if (!item) return;
|
||||
|
||||
const value = item.system.resource.max
|
||||
? Math.min(Number(event.currentTarget.value), item.system.resource.max)
|
||||
: event.currentTarget.value;
|
||||
await item.update({ 'system.resource.value': value });
|
||||
this.render();
|
||||
}
|
||||
|
||||
async updateItemQuantity(event) {
|
||||
const item = this.getItem(event.currentTarget);
|
||||
if (!item) return;
|
||||
|
||||
await item.update({ 'system.quantity': event.currentTarget.value });
|
||||
this.render();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Application Clicks Actions */
|
||||
/* -------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export default class FeatureSheet extends DHBaseItemSheet {
|
|||
header: { template: 'systems/daggerheart/templates/sheets/items/feature/header.hbs' },
|
||||
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
||||
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
|
||||
settings: { template: 'systems/daggerheart/templates/sheets/items/feature/settings.hbs' },
|
||||
actions: {
|
||||
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
|
||||
scrollable: ['.actions']
|
||||
|
|
@ -34,7 +35,7 @@ export default class FeatureSheet extends DHBaseItemSheet {
|
|||
/**@override */
|
||||
static TABS = {
|
||||
primary: {
|
||||
tabs: [{ id: 'description' }, { id: 'actions' }, { id: 'effects' }],
|
||||
tabs: [{ id: 'description' }, { id: 'settings' }, { id: 'actions' }, { id: 'effects' }],
|
||||
initial: 'description',
|
||||
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,15 @@
|
|||
const fields = foundry.data.fields;
|
||||
|
||||
export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ITEMS'];
|
||||
|
||||
/** @returns {ItemDataModelMetadata}*/
|
||||
static get metadata() {
|
||||
return {
|
||||
label: 'Base Item',
|
||||
type: 'base',
|
||||
hasDescription: false,
|
||||
hasResource: false,
|
||||
isQuantifiable: false,
|
||||
isInventoryItem: false
|
||||
};
|
||||
|
|
@ -29,20 +32,22 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
|
||||
/** @inheritDoc */
|
||||
static defineSchema() {
|
||||
const schema = {
|
||||
uses: new fields.SchemaField({
|
||||
value: new fields.NumberField({ nullable: true, initial: null }),
|
||||
const schema = {};
|
||||
|
||||
if (this.metadata.hasDescription) schema.description = new fields.HTMLField({ required: true, nullable: true });
|
||||
|
||||
if (this.metadata.hasResource) {
|
||||
schema.resource = new fields.SchemaField({
|
||||
value: new fields.NumberField({ integer: true, min: 0, nullable: true, initial: null }),
|
||||
max: new fields.NumberField({ nullable: true, initial: null }),
|
||||
icon: new fields.StringField({ initial: 'fa-solid fa-hashtag' }),
|
||||
icon: new fields.StringField(),
|
||||
recovery: new fields.StringField({
|
||||
choices: CONFIG.DH.GENERAL.refreshTypes,
|
||||
initial: null,
|
||||
nullable: true
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
if (this.metadata.hasDescription) schema.description = new fields.HTMLField({ required: true, nullable: true });
|
||||
});
|
||||
}
|
||||
|
||||
if (this.metadata.isQuantifiable)
|
||||
schema.quantity = new fields.NumberField({ integer: true, initial: 1, min: 0, required: true });
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ export default class DHDomainCard extends BaseDataItem {
|
|||
return foundry.utils.mergeObject(super.metadata, {
|
||||
label: 'TYPES.Item.domainCard',
|
||||
type: 'domainCard',
|
||||
hasDescription: true
|
||||
hasDescription: true,
|
||||
hasResource: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ export default class DHFeature extends BaseDataItem {
|
|||
return foundry.utils.mergeObject(super.metadata, {
|
||||
label: 'TYPES.Item.feature',
|
||||
type: 'feature',
|
||||
hasDescription: true
|
||||
hasDescription: true,
|
||||
hasResource: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
export default class RegisterHandlebarsHelpers {
|
||||
static registerHelpers() {
|
||||
Handlebars.registerHelper({
|
||||
emptyObject: this.emptyObject,
|
||||
add: this.add,
|
||||
includes: this.includes,
|
||||
times: this.times,
|
||||
|
|
@ -11,10 +10,6 @@ export default class RegisterHandlebarsHelpers {
|
|||
});
|
||||
}
|
||||
|
||||
static emptyObject(a) {
|
||||
return !a || typeof a !== 'object' || Object.keys(a).length === 0;
|
||||
}
|
||||
|
||||
static add(a, b) {
|
||||
const aNum = Number.parseInt(a);
|
||||
const bNum = Number.parseInt(b);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export const preloadHandlebarsTemplates = async function () {
|
|||
'systems/daggerheart/templates/sheets/global/partials/action-item.hbs',
|
||||
'systems/daggerheart/templates/sheets/global/partials/domain-card-item.hbs',
|
||||
'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs',
|
||||
'systems/daggerheart/templates/sheets/global/partials/resource-section.hbs',
|
||||
'systems/daggerheart/templates/components/card-preview.hbs',
|
||||
'systems/daggerheart/templates/levelup/parts/selectable-card-preview.hbs',
|
||||
'systems/daggerheart/templates/sheets/global/partials/feature-section-item.hbs',
|
||||
|
|
|
|||
|
|
@ -67,28 +67,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
.item-tokens {
|
||||
.item-resource {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: end;
|
||||
gap: 4px;
|
||||
|
||||
.item-token {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
i {
|
||||
flex: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
i {
|
||||
flex: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
|
||||
&::-webkit-outer-spin-button {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
input {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-type="{{type}}">
|
||||
<img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" data-action="useItem" {{#if (not noTooltip)}}data-tooltip="{{concat "#item#" item.uuid}}"{{/if}} />
|
||||
<div class="item-label-wrapper">
|
||||
<div class="item-label {{#if (emptyObject item.system.tokens)}}fullWidth{{/if}}">
|
||||
<div class="item-label {{#unless (and (not isSidebar) (or item.system.resource.max item.system.quantity))}}fullWidth{{/unless}}">
|
||||
{{#if isCompanion}}
|
||||
<a class="item-name" data-action="attackRoll">{{item.name}}</a>
|
||||
{{else}}
|
||||
|
|
@ -123,16 +123,17 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#unless (emptyObject item.system.tokens)}}
|
||||
<div class="item-tokens">
|
||||
{{#each item.system.tokens as | token |}}
|
||||
<div class="item-token">
|
||||
<i class="fa-solid fa-hashtag"></i>
|
||||
<input type="number" value="{{token.value}}" step="1" min="0" max="10" />
|
||||
</div>
|
||||
{{/each}}
|
||||
{{#if (and (not isSidebar) item.system.resource.max)}}
|
||||
<div class="item-resource">
|
||||
<i class="{{#if item.system.resource.icon}}{{item.system.resource.icon}}{{else}}fa-solid fa-hashtag{{/if}}"></i>
|
||||
<input type="number" class="inventory-item-resource" value="{{item.system.resource.value}}" step="1" />
|
||||
</div>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
{{#if (and (not isSidebar) item.system.quantity)}}
|
||||
<div class="item-resource">
|
||||
<input type="number" class="inventory-item-quantity" value="{{item.system.quantity}}" step="1" />
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#unless hideControls}}
|
||||
{{#if isActor}}
|
||||
|
|
|
|||
10
templates/sheets/global/partials/resource-section.hbs
Normal file
10
templates/sheets/global/partials/resource-section.hbs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<fieldset>
|
||||
<legend>{{localize "DAGGERHEART.GENERAL.Resource.single"}}</legend>
|
||||
|
||||
<div class="two-columns even">
|
||||
{{formGroup systemFields.resource.fields.value value=source.system.resource.value localize=true}}
|
||||
{{formGroup systemFields.resource.fields.max value=source.system.resource.max localize=true}}
|
||||
{{formGroup systemFields.resource.fields.icon value=source.system.resource.icon localize=true placeholder="fa-solid fa-hashtag"}}
|
||||
{{formGroup systemFields.resource.fields.recovery value=source.system.resource.recovery localize=true}}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
|
@ -17,4 +17,6 @@
|
|||
<span>{{localize "DAGGERHEART.ITEMS.DomainCard.recallCost"}}</span>
|
||||
{{formField systemFields.recallCost value=source.system.recallCost data-dtype="Number"}}
|
||||
</fieldset>
|
||||
|
||||
{{> "systems/daggerheart/templates/sheets/global/partials/resource-section.hbs" }}
|
||||
</section>
|
||||
7
templates/sheets/items/feature/settings.hbs
Normal file
7
templates/sheets/items/feature/settings.hbs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<section
|
||||
class='tab {{tabs.settings.cssClass}} {{tabs.settings.id}}'
|
||||
data-tab='{{tabs.settings.id}}'
|
||||
data-group='{{tabs.settings.group}}'
|
||||
>
|
||||
{{> "systems/daggerheart/templates/sheets/global/partials/resource-section.hbs" }}
|
||||
</section>
|
||||
Loading…
Add table
Add a link
Reference in a new issue