Add Consumable Items (#62)
Changes: + add Quantity value for items + add plus and minus buttons for list + add roll button if item contains formulas + decrease quantity by 1 if rolled
This commit is contained in:
parent
c313d3448c
commit
bfa51605bc
|
|
@ -171,7 +171,15 @@ export class M5Character extends Actor {
|
||||||
if (item.system.magic) {
|
if (item.system.magic) {
|
||||||
label += "*";
|
label += "*";
|
||||||
}
|
}
|
||||||
|
let rollable = false;
|
||||||
|
|
||||||
|
// console.log(item.system.rolls.formulas.map((p) => p.enabled));
|
||||||
|
for (let key in item.system.rolls.formulas) {
|
||||||
|
rollable = item.system.rolls.formulas[key].enabled;
|
||||||
|
if (rollable) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
ret.gear.items[item.id] = {
|
ret.gear.items[item.id] = {
|
||||||
label: label,
|
label: label,
|
||||||
magic: item.system.magic,
|
magic: item.system.magic,
|
||||||
|
|
@ -179,6 +187,8 @@ export class M5Character extends Actor {
|
||||||
equipped: item.system?.equipped,
|
equipped: item.system?.equipped,
|
||||||
value: item.system.value || 0,
|
value: item.system.value || 0,
|
||||||
currency: item.system.currency || "",
|
currency: item.system.currency || "",
|
||||||
|
quantity: item.system.quantity || 0,
|
||||||
|
rollExist: rollable,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,60 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||||
item.sheet.render(true);
|
item.sheet.render(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
html.find(".quantity-increase").on("click", async (event) => {
|
||||||
|
let row = event.target.parentElement;
|
||||||
|
let itemId = row.dataset["item"];
|
||||||
|
while (!itemId) {
|
||||||
|
row = row.parentElement;
|
||||||
|
if (!row) return;
|
||||||
|
itemId = row.dataset["item"];
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = this.actor as any;
|
||||||
|
const item = context.items.get(itemId);
|
||||||
|
if (!item.system.quantity) {
|
||||||
|
item.system.quantity = 0;
|
||||||
|
}
|
||||||
|
item.system.quantity += 1;
|
||||||
|
this.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
html.find(".quantity-decrease").on("click", async (event) => {
|
||||||
|
let row = event.target.parentElement;
|
||||||
|
let itemId = row.dataset["item"];
|
||||||
|
while (!itemId) {
|
||||||
|
row = row.parentElement;
|
||||||
|
if (!row) return;
|
||||||
|
itemId = row.dataset["item"];
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = this.actor as any;
|
||||||
|
const item = context.items.get(itemId);
|
||||||
|
if (item.system.quantity > 0) {
|
||||||
|
item.system.quantity -= 1;
|
||||||
|
}
|
||||||
|
this.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
html.find(".roll-consumable-item").on("click", async (event) => {
|
||||||
|
let row = event.target.parentElement;
|
||||||
|
let itemId = row.dataset["item"];
|
||||||
|
while (!itemId) {
|
||||||
|
row = row.parentElement;
|
||||||
|
if (!row) return;
|
||||||
|
itemId = row.dataset["item"];
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = this.actor as any;
|
||||||
|
const item = context.items.get(itemId);
|
||||||
|
if (item.system.quantity > 0) {
|
||||||
|
item.system.quantity -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
await item.roll();
|
||||||
|
this.render();
|
||||||
|
});
|
||||||
|
|
||||||
html.find(".item-delete").on("click", async (event) => {
|
html.find(".item-delete").on("click", async (event) => {
|
||||||
let row = event.target.parentElement;
|
let row = event.target.parentElement;
|
||||||
let itemId = row.dataset["item"];
|
let itemId = row.dataset["item"];
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,10 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="title">{{localize "TYPES.Item.item"}}</th>
|
<th class="title">{{localize "TYPES.Item.item"}}</th>
|
||||||
|
<th class="title center">{{localize "midgard5.item-quantity"}}</th>
|
||||||
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
||||||
<th class="title"></th>
|
<th class="title"></th>
|
||||||
|
<th class="title"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
@ -137,11 +139,17 @@
|
||||||
<span class="spell-process">{{localize "midgard5.equipped"}}</span>
|
<span class="spell-process">{{localize "midgard5.equipped"}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<i class="fa fa-minus-circle quantity-decrease" style="cursor: pointer"></i>
|
||||||
|
<span>{{item.quantity}}</span>
|
||||||
|
<i class="fa fa-plus-circle quantity-increase" style="cursor: pointer"></i>
|
||||||
|
</td>
|
||||||
<td style="text-align: start">
|
<td style="text-align: start">
|
||||||
{{#unless (or (eq item.value 0) (eq item.currency ""))}}
|
{{#unless (or (eq item.value 0) (eq item.currency ""))}}
|
||||||
<span class="spell-process">{{item.value}} {{localize (m5concat "midgard5.currency-" item.currency)}}</span>
|
<span class="spell-process">{{item.value}} {{localize (m5concat "midgard5.currency-" item.currency)}}</span>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</td>
|
</td>
|
||||||
|
<td class="fixed-value">{{#if item.rollExist}}<button class="roll-button roll-consumable-item"></button>{{/if}}</td>
|
||||||
<td class="fixed-value"><a class="item-delete" title="Delete Item"><i class="fas fa-trash"></i></a></td>
|
<td class="fixed-value"><a class="item-delete" title="Delete Item"><i class="fas fa-trash"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="flexrow">
|
||||||
|
<span>{{localize "midgard5.item-quantity"}}</span>
|
||||||
|
<input id="data.quantity" type="number" name="data.quantity" value="{{data.quantity}}">
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div class="flexrow">
|
<div class="flexrow">
|
||||||
|
|
@ -36,6 +44,8 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{{> "systems/midgard5/templates/sheets/item/rolls.hbs"}}
|
||||||
|
|
||||||
{{> "systems/midgard5/templates/sheets/partial/mod.hbs" mods=data.mods calc=data.calc}}
|
{{> "systems/midgard5/templates/sheets/partial/mod.hbs" mods=data.mods calc=data.calc}}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue