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:
2024-01-20 12:37:05 +01:00
parent c13fef5103
commit 9d72b31d5f
7 changed files with 137 additions and 16 deletions
+101 -6
View File
@@ -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({