Add Items on Character Sheet
Changes: + add button to add all different kind of items directly onto the character sheet + fix #1 by correctly updating the item
This commit is contained in:
parent
c13fef5103
commit
9d72b31d5f
|
|
@ -49,6 +49,18 @@ export interface M5RollResult extends M5RollTemplate {
|
|||
css: string;
|
||||
}
|
||||
|
||||
export enum M5ItemType {
|
||||
SKILL = "skill",
|
||||
ITEM = "item",
|
||||
WEAPON = "weapon",
|
||||
DEFENSIVE_WEAPON = "defensiveWeapon",
|
||||
ARMOR = "armor",
|
||||
CONTAINER = "container",
|
||||
SPELL = "spell",
|
||||
KAMPFKUNST = "kampfkunst",
|
||||
EFFECT = "effect",
|
||||
}
|
||||
|
||||
export enum M5EwResult {
|
||||
TBD = "",
|
||||
FUMBLE = "roll-ew-result-fumble",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { M5Item } from "../items/M5Item";
|
||||
import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ModOperation, M5ModResult, M5RollData, M5Skill, M5SkillCalculated, M5SkillLearned } from "../M5Base";
|
||||
import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ItemType, M5ModOperation, M5ModResult, M5RollData, M5Skill, M5SkillCalculated, M5SkillLearned } from "../M5Base";
|
||||
import M5ModAggregate from "./M5ModAggregate";
|
||||
export class M5Character extends Actor {
|
||||
// constructor(
|
||||
|
|
@ -522,6 +522,18 @@ export class M5Character extends Actor {
|
|||
});
|
||||
}
|
||||
|
||||
createItem(itemName: string, itemType: M5ItemType): Promise<M5Item> {
|
||||
const itemData = {
|
||||
name: itemName,
|
||||
type: itemType,
|
||||
};
|
||||
|
||||
return (this as any).createEmbeddedDocuments("Item", [itemData]).then((docs) => {
|
||||
const item = docs[0];
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
getItem(itemId: string): any {
|
||||
if (!(this as any).items) return null;
|
||||
return (this as any).getEmbeddedDocument("Item", itemId);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import Logger from "../../utils/Logger";
|
||||
import { M5Character } from "../actors/M5Character";
|
||||
import { M5Item } from "../items/M5Item";
|
||||
import { M5SkillLearned, M5SkillUnlearned } from "../M5Base";
|
||||
import { M5ItemType, M5SkillLearned, M5SkillUnlearned } from "../M5Base";
|
||||
import { M5Roll } from "../rolls/M5Roll";
|
||||
|
||||
export default class M5CharacterSheet extends ActorSheet {
|
||||
|
|
@ -111,7 +111,11 @@ export default class M5CharacterSheet extends ActorSheet {
|
|||
if (!item.system.quantity) {
|
||||
item.system.quantity = 0;
|
||||
}
|
||||
item.system.quantity += 1;
|
||||
item.update({
|
||||
data: {
|
||||
quantity: item.system.quantity + 1,
|
||||
},
|
||||
});
|
||||
this.render();
|
||||
});
|
||||
|
||||
|
|
@ -127,7 +131,11 @@ export default class M5CharacterSheet extends ActorSheet {
|
|||
const context = this.actor as any;
|
||||
const item = context.items.get(itemId);
|
||||
if (item.system.quantity > 0) {
|
||||
item.system.quantity -= 1;
|
||||
item.update({
|
||||
data: {
|
||||
quantity: item.system.quantity - 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
this.render();
|
||||
});
|
||||
|
|
@ -144,7 +152,11 @@ export default class M5CharacterSheet extends ActorSheet {
|
|||
const context = this.actor as any;
|
||||
const item = context.items.get(itemId);
|
||||
if (item.system.quantity > 0) {
|
||||
item.system.quantity -= 1;
|
||||
item.update({
|
||||
data: {
|
||||
quantity: item.system.quantity - 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await item.roll();
|
||||
|
|
@ -260,13 +272,96 @@ export default class M5CharacterSheet extends ActorSheet {
|
|||
const item = context.items.get(itemId);
|
||||
if (item.system.equipped === true) {
|
||||
item.system.equipped = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
item.system.equipped = true;
|
||||
}
|
||||
this.render();
|
||||
});
|
||||
|
||||
html.find(".add-item").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.item"), M5ItemType.ITEM).then((i) => {
|
||||
const item = i as any;
|
||||
item.update({
|
||||
data: {
|
||||
quantity: 1,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-weapon").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.weapon"), M5ItemType.WEAPON);
|
||||
});
|
||||
|
||||
html.find(".add-defensiveWeapon").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.defensiveWeapon"), M5ItemType.DEFENSIVE_WEAPON);
|
||||
});
|
||||
|
||||
html.find(".add-armor").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.armor"), M5ItemType.ARMOR);
|
||||
});
|
||||
|
||||
html.find(".add-container").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.container"), M5ItemType.CONTAINER).then((i) => {
|
||||
const item = i as any;
|
||||
item.update({
|
||||
data: {
|
||||
quantity: 1,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-spell").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.spell"), M5ItemType.SPELL).then((i) => {
|
||||
const item = i as any;
|
||||
item.update({
|
||||
data: {
|
||||
process: "none",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-kampfkunst").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.kampfkunst"), M5ItemType.KAMPFKUNST).then((i) => {
|
||||
const item = i as any;
|
||||
item.update({
|
||||
data: {
|
||||
type: "angriff",
|
||||
variante: "anstuermen",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-effect").on("click", async (event) => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem((game as Game).i18n.localize("TYPES.Item.effect"), M5ItemType.EFFECT);
|
||||
});
|
||||
|
||||
// Drag & Drop
|
||||
const dragDrop = new DragDrop({
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
<th class="title">{{localize "midgard5.kampfkunst-variante-short"}}</th>
|
||||
<th class="title">{{localize "midgard5.ew"}}</th>
|
||||
<th class="title"><img src="/icons/svg/d20.svg" class="table-icon"></th>
|
||||
<th class="title"></th>
|
||||
<th class="title add-kampfkunst"><i class="fa-regular fa-plus"></i></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th class="title">{{localize "TYPES.Item.effect"}}</th>
|
||||
<th class="title"></th>
|
||||
<th class="title add-effect"><i class="fa-regular fa-plus"></i></th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@
|
|||
<th class="title center">{{localize "midgard5.item-quantity"}}</th>
|
||||
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
||||
<th class="title"><img src="/systems/midgard5/assets/icons/icon/battle-gear.svg" class="table-icon"></th>
|
||||
<th class="title"><img src="/icons/svg/d20.svg" class="table-icon"></th>
|
||||
<th class="title"> </th>
|
||||
<th class="title"><img src="/icons/svg/d20.svg" class="table-icon"></th></th>
|
||||
<th class="title add-item"><i class="fa-regular fa-plus"></i></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
@ -90,7 +90,8 @@
|
|||
<th class="title">{{localize "TYPES.Item.weapon"}}</th>
|
||||
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
||||
<th class="title"><img src="/systems/midgard5/assets/icons/icon/battle-gear.svg" class="table-icon"></th>
|
||||
<th class="title"> </th>
|
||||
<th class="title add-weapon"><i class="fa-regular fa-plus"></i></th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
@ -124,7 +125,7 @@
|
|||
<th class="title">{{localize "TYPES.Item.defensiveWeapon"}}</th>
|
||||
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
||||
<th class="title"><img src="/systems/midgard5/assets/icons/icon/battle-gear.svg" class="table-icon"></th>
|
||||
<th class="title"> </th>
|
||||
<th class="title add-defensiveWeapon"><i class="fa-regular fa-plus"></i></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
@ -158,7 +159,7 @@
|
|||
<th class="title">{{localize "TYPES.Item.armor"}}</th>
|
||||
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
||||
<th class="title"><img src="/systems/midgard5/assets/icons/icon/battle-gear.svg" class="table-icon"></th>
|
||||
<th class="title"> </th>
|
||||
<th class="title add-armor"><i class="fa-regular fa-plus"></i></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
@ -196,7 +197,7 @@
|
|||
<th class="title center">{{localize "midgard5.item-value"}}</th>
|
||||
<th class="title center"><img src="/systems/midgard5/assets/icons/icon/battle-gear.svg" class="table-icon"></th>
|
||||
<th class="title"><img src="/icons/svg/d20.svg" class="table-icon"></th>
|
||||
<th class="title"> </th>
|
||||
<th class="title add-container"><i class="fa-regular fa-plus"></i></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<th class="title">{{localize "TYPES.Item.spell"}}</th>
|
||||
<th class="title">{{localize "midgard5.ew"}}</th>
|
||||
<th class="title"></th>
|
||||
<th class="title"></th>
|
||||
<th class="title add-spell"><i class="fa-regular fa-plus"></i></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
|
|||
Loading…
Reference in New Issue