Merge branch 'develop' into #49-draggable-items
This commit is contained in:
@@ -1,26 +1,21 @@
|
||||
import Logger from "../../utils/Logger";
|
||||
import { M5Character } from "../actors/M5Character";
|
||||
import { M5Item } from "../items/M5Item";
|
||||
import {
|
||||
M5ItemType,
|
||||
M5SkillLearned,
|
||||
M5SkillType,
|
||||
M5SkillUnlearned,
|
||||
} from "../M5Base";
|
||||
import { M5Roll } from "../rolls/M5Roll";
|
||||
import Logger from '../../utils/Logger';
|
||||
import { M5Character } from '../actors/M5Character';
|
||||
import { M5Item } from '../items/M5Item';
|
||||
import { M5ItemType, M5SkillLearned, M5SkillType, M5SkillUnlearned } from '../M5Base';
|
||||
import { M5Roll } from '../rolls/M5Roll';
|
||||
|
||||
export default class M5CharacterSheet extends ActorSheet {
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
template: "systems/midgard5/templates/sheets/character/main.hbs",
|
||||
template: 'systems/midgard5/templates/sheets/character/main.hbs',
|
||||
width: 1000,
|
||||
height: 800,
|
||||
classes: ["midgard5", "sheet", "character"],
|
||||
classes: ['midgard5', 'sheet', 'character'],
|
||||
tabs: [
|
||||
{
|
||||
navSelector: ".sheet-navigation",
|
||||
contentSelector: ".sheet-content",
|
||||
initial: "base_values",
|
||||
navSelector: '.sheet-navigation',
|
||||
contentSelector: '.sheet-content',
|
||||
initial: 'base_values',
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -31,13 +26,11 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
// }Options extends ActorSheet.Options = ActorSheet.Options, Data extends object = ActorSheet.Data<Options>
|
||||
|
||||
override getData(
|
||||
options?: Partial<ActorSheet.Options>,
|
||||
):
|
||||
| ActorSheet.Data<ActorSheet.Options>
|
||||
| Promise<ActorSheet.Data<ActorSheet.Options>> {
|
||||
options?: Partial<ActorSheet.Options>
|
||||
): ActorSheet.Data<ActorSheet.Options> | Promise<ActorSheet.Data<ActorSheet.Options>> {
|
||||
const actor = this.actor as M5Character;
|
||||
//console.log("Sheet getData", (actor as any).data)
|
||||
return Promise.resolve(super.getData(options)).then((context) => {
|
||||
return Promise.resolve(super.getData(options)).then(context => {
|
||||
actor.prepareDerivedData();
|
||||
|
||||
context.actor = (actor as any).toObject(false);
|
||||
@@ -50,16 +43,16 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
|
||||
override setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const fillerWidth = this.element.find(".attributes .filler:first").width();
|
||||
this.element.find(".attributes .attribute-filler-fixed").width(fillerWidth);
|
||||
const fillerWidth = this.element.find('.attributes .filler:first').width();
|
||||
this.element.find('.attributes .attribute-filler-fixed').width(fillerWidth);
|
||||
return position;
|
||||
}
|
||||
|
||||
override activateListeners(html: JQuery) {
|
||||
super.activateListeners(html);
|
||||
|
||||
html.find(".update-lp").on("click", async (event) => {
|
||||
const valueStr = event.target.dataset["value"];
|
||||
html.find('.update-lp').on('click', async event => {
|
||||
const valueStr = event.target.dataset['value'];
|
||||
const value = parseInt(valueStr);
|
||||
this.actor.update({
|
||||
data: {
|
||||
@@ -70,8 +63,8 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".update-ap").on("click", async (event) => {
|
||||
const valueStr = event.target.dataset["value"];
|
||||
html.find('.update-ap').on('click', async event => {
|
||||
const valueStr = event.target.dataset['value'];
|
||||
const value = parseInt(valueStr);
|
||||
this.actor.update({
|
||||
data: {
|
||||
@@ -82,31 +75,27 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".roll-attribute-button").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-attribute]") as HTMLElement;
|
||||
html.find('.roll-attribute-button').on('click', async event => {
|
||||
let target = event.target.closest('[data-attribute]') as HTMLElement;
|
||||
let attributeValue = target ? parseInt(target.dataset.value) : null;
|
||||
let attributeStr = target ? target.dataset.attribute : null;
|
||||
|
||||
const roll = M5Roll.fromAttributeValue(
|
||||
this.actor,
|
||||
attributeStr,
|
||||
attributeValue,
|
||||
);
|
||||
const roll = M5Roll.fromAttributeValue(this.actor, attributeStr, attributeValue);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".edit-item").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.edit-item').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
const item = context.items.get(itemId);
|
||||
console.log("edit-item", item);
|
||||
console.log('edit-item', item);
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
html.find(".quantity-increase").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.quantity-increase').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
@@ -122,8 +111,8 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
this.render();
|
||||
});
|
||||
|
||||
html.find(".quantity-decrease").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.quantity-decrease').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
@@ -138,8 +127,8 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
this.render();
|
||||
});
|
||||
|
||||
html.find(".roll-consumable-item").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.roll-consumable-item').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
@@ -156,8 +145,8 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
this.render();
|
||||
});
|
||||
|
||||
html.find(".item-delete").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.item-delete').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
@@ -166,8 +155,8 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
this.render(false);
|
||||
});
|
||||
|
||||
html.find(".roll-learned-button").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.roll-learned-button').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let skillId = target ? target.dataset.itemId : null;
|
||||
|
||||
const actor = this.actor as any;
|
||||
@@ -175,46 +164,40 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
await item.roll();
|
||||
});
|
||||
|
||||
html.find(".roll-general-button").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-skill]") as HTMLElement;
|
||||
html.find('.roll-general-button').on('click', async event => {
|
||||
let target = event.target.closest('[data-skill]') as HTMLElement;
|
||||
let skillName = target ? target.dataset.itemId : null;
|
||||
|
||||
const data = this.actor.system;
|
||||
const unlearnedSkill = data.skills.general[skillName] as M5SkillUnlearned;
|
||||
|
||||
const roll = M5Roll.fromUnlearnedSkill(
|
||||
this.actor,
|
||||
unlearnedSkill,
|
||||
skillName,
|
||||
);
|
||||
const roll = M5Roll.fromUnlearnedSkill(this.actor, unlearnedSkill, skillName);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".learn-button").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-skill]") as HTMLElement;
|
||||
html.find('.learn-button').on('click', async event => {
|
||||
let target = event.target.closest('[data-skill]') as HTMLElement;
|
||||
let skillName = target ? target.dataset.itemId : null;
|
||||
|
||||
const data = this.actor.system;
|
||||
const unlearnedSkill = data.skills.general[skillName] as M5SkillUnlearned;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character
|
||||
.createSkill((game as Game).i18n.localize("midgard5." + skillName))
|
||||
.then((skill) => {
|
||||
const item = skill as any;
|
||||
item.update({
|
||||
data: {
|
||||
fw: unlearnedSkill.initial,
|
||||
attribute: unlearnedSkill.attribute,
|
||||
skill: skillName,
|
||||
type: "general",
|
||||
},
|
||||
});
|
||||
character.createSkill((game as Game).i18n.localize('midgard5.' + skillName)).then(skill => {
|
||||
const item = skill as any;
|
||||
item.update({
|
||||
data: {
|
||||
fw: unlearnedSkill.initial,
|
||||
attribute: unlearnedSkill.attribute,
|
||||
skill: skillName,
|
||||
type: 'general',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".roll-weapon-button").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.roll-weapon-button').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
@@ -223,38 +206,38 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
this.render();
|
||||
});
|
||||
|
||||
html.find(".roll-brawl-button").on("click", async (event) => {
|
||||
html.find('.roll-brawl-button').on('click', async event => {
|
||||
const roll = M5Roll.brawl(this.actor);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".roll-perception-button").on("click", async (event) => {
|
||||
html.find('.roll-perception-button').on('click', async event => {
|
||||
const roll = M5Roll.perception(this.actor);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".roll-drinking-button").on("click", async (event) => {
|
||||
html.find('.roll-drinking-button').on('click', async event => {
|
||||
const roll = M5Roll.drinking(this.actor);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".roll-defense-button").on("click", async (event) => {
|
||||
html.find('.roll-defense-button').on('click', async event => {
|
||||
const roll = M5Roll.defense(this.actor);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".roll-resistanceMind-button").on("click", async (event) => {
|
||||
html.find('.roll-resistanceMind-button').on('click', async event => {
|
||||
const roll = M5Roll.resistanceMind(this.actor);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".roll-resistanceBody-button").on("click", async (event) => {
|
||||
html.find('.roll-resistanceBody-button').on('click', async event => {
|
||||
const roll = M5Roll.resistanceBody(this.actor);
|
||||
await roll.toMessage();
|
||||
});
|
||||
|
||||
html.find(".change-equipped").on("click", async (event) => {
|
||||
let target = event.target.closest("[data-item-id]") as HTMLElement;
|
||||
html.find('.change-equipped').on('click', async event => {
|
||||
let target = event.target.closest('[data-item-id]') as HTMLElement;
|
||||
let itemId = target ? target.dataset.itemId : null;
|
||||
|
||||
const context = this.actor as any;
|
||||
@@ -268,145 +251,107 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
this.render();
|
||||
});
|
||||
|
||||
html.find(".add-item").on("click", async (event) => {
|
||||
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,
|
||||
{ quantity: 1 },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.item'), M5ItemType.ITEM, { quantity: 1 });
|
||||
});
|
||||
|
||||
html.find(".add-weapon").on("click", async (event) => {
|
||||
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,
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.weapon'), M5ItemType.WEAPON);
|
||||
});
|
||||
|
||||
html.find(".add-defensiveWeapon").on("click", async (event) => {
|
||||
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,
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.defensiveWeapon'), M5ItemType.DEFENSIVE_WEAPON);
|
||||
});
|
||||
|
||||
html.find(".add-armor").on("click", async (event) => {
|
||||
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,
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.armor'), M5ItemType.ARMOR);
|
||||
});
|
||||
|
||||
html.find(".add-container").on("click", async (event) => {
|
||||
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,
|
||||
{ quantity: 1 },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.container'), M5ItemType.CONTAINER, { quantity: 1 });
|
||||
});
|
||||
|
||||
html.find(".add-innate-skill").on("click", async (event) => {
|
||||
html.find('.add-innate-skill').on('click', async event => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem(
|
||||
(game as Game).i18n.localize("midgard5.innate-ability"),
|
||||
M5ItemType.SKILL,
|
||||
{ type: M5SkillType.INNATE },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('midgard5.innate-ability'), M5ItemType.SKILL, {
|
||||
type: M5SkillType.INNATE,
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-general-skill").on("click", async (event) => {
|
||||
html.find('.add-general-skill').on('click', async event => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem(
|
||||
(game as Game).i18n.localize("TYPES.Item.skill"),
|
||||
M5ItemType.SKILL,
|
||||
{ type: M5SkillType.GENERAL },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.skill'), M5ItemType.SKILL, {
|
||||
type: M5SkillType.GENERAL,
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-combat-skill").on("click", async (event) => {
|
||||
html.find('.add-combat-skill').on('click', async event => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem(
|
||||
(game as Game).i18n.localize("midgard5.weapon-skill"),
|
||||
M5ItemType.SKILL,
|
||||
{ type: M5SkillType.COMBAT },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('midgard5.weapon-skill'), M5ItemType.SKILL, {
|
||||
type: M5SkillType.COMBAT,
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-language-skill").on("click", async (event) => {
|
||||
html.find('.add-language-skill').on('click', async event => {
|
||||
const data = this.actor.system;
|
||||
|
||||
const character = this.actor as M5Character;
|
||||
character.createItem(
|
||||
(game as Game).i18n.localize("midgard5.language"),
|
||||
M5ItemType.SKILL,
|
||||
{ type: M5SkillType.LANGUAGE },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('midgard5.language'), M5ItemType.SKILL, {
|
||||
type: M5SkillType.LANGUAGE,
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-spell").on("click", async (event) => {
|
||||
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,
|
||||
{ process: "none" },
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.spell'), M5ItemType.SPELL, { process: 'none' });
|
||||
});
|
||||
|
||||
html.find(".add-kampfkunst").on("click", async (event) => {
|
||||
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,
|
||||
{
|
||||
type: "angriff",
|
||||
variante: "anstuermen",
|
||||
},
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.kampfkunst'), M5ItemType.KAMPFKUNST, {
|
||||
type: 'angriff',
|
||||
variante: 'anstuermen',
|
||||
});
|
||||
});
|
||||
|
||||
html.find(".add-effect").on("click", async (event) => {
|
||||
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,
|
||||
);
|
||||
character.createItem((game as Game).i18n.localize('TYPES.Item.effect'), M5ItemType.EFFECT);
|
||||
});
|
||||
|
||||
html.find(".join-combat").on("click", async (event) => {
|
||||
if (!!game["combat"]) {
|
||||
let combatant = game["combat"].getCombatantByActor(this.actor._id);
|
||||
html.find('.join-combat').on('click', async event => {
|
||||
if (!!game['combat']) {
|
||||
let combatant = game['combat'].getCombatantByActor(this.actor._id);
|
||||
if (!combatant) {
|
||||
await game["combat"].createEmbeddedDocuments("Combatant", [
|
||||
{ actorId: this.actor._id },
|
||||
]);
|
||||
combatant = game["combat"].getCombatantByActor(this.actor._id);
|
||||
await game['combat'].createEmbeddedDocuments('Combatant', [{ actorId: this.actor._id }]);
|
||||
combatant = game['combat'].getCombatantByActor(this.actor._id);
|
||||
}
|
||||
|
||||
const initiatives = {
|
||||
@@ -414,20 +359,16 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
initiative: this.actor.system.calc.attributes.gw.value,
|
||||
};
|
||||
|
||||
await game["combat"].updateEmbeddedDocuments("Combatant", [
|
||||
initiatives,
|
||||
]);
|
||||
await game['combat'].updateEmbeddedDocuments('Combatant', [initiatives]);
|
||||
}
|
||||
});
|
||||
|
||||
html.find(".ranged-combat").on("click", async (event) => {
|
||||
if (!!game["combat"]) {
|
||||
let combatant = game["combat"].getCombatantByActor(this.actor._id);
|
||||
html.find('.ranged-combat').on('click', async event => {
|
||||
if (!!game['combat']) {
|
||||
let combatant = game['combat'].getCombatantByActor(this.actor._id);
|
||||
if (!combatant) {
|
||||
await game["combat"].createEmbeddedDocuments("Combatant", [
|
||||
{ actorId: this.actor._id },
|
||||
]);
|
||||
combatant = game["combat"].getCombatantByActor(this.actor._id);
|
||||
await game['combat'].createEmbeddedDocuments('Combatant', [{ actorId: this.actor._id }]);
|
||||
combatant = game['combat'].getCombatantByActor(this.actor._id);
|
||||
}
|
||||
|
||||
const initiatives = {
|
||||
@@ -435,20 +376,16 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
initiative: 0.01 * this.actor.system.calc.attributes.gw.value,
|
||||
};
|
||||
|
||||
await game["combat"].updateEmbeddedDocuments("Combatant", [
|
||||
initiatives,
|
||||
]);
|
||||
await game['combat'].updateEmbeddedDocuments('Combatant', [initiatives]);
|
||||
}
|
||||
});
|
||||
|
||||
html.find(".spell-combat").on("click", async (event) => {
|
||||
if (!!game["combat"]) {
|
||||
let combatant = game["combat"].getCombatantByActor(this.actor._id);
|
||||
html.find('.spell-combat').on('click', async event => {
|
||||
if (!!game['combat']) {
|
||||
let combatant = game['combat'].getCombatantByActor(this.actor._id);
|
||||
if (!combatant) {
|
||||
await game["combat"].createEmbeddedDocuments("Combatant", [
|
||||
{ actorId: this.actor._id },
|
||||
]);
|
||||
combatant = game["combat"].getCombatantByActor(this.actor._id);
|
||||
await game['combat'].createEmbeddedDocuments('Combatant', [{ actorId: this.actor._id }]);
|
||||
combatant = game['combat'].getCombatantByActor(this.actor._id);
|
||||
}
|
||||
|
||||
const initiatives = {
|
||||
@@ -456,15 +393,13 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
initiative: 0.001 * this.actor.system.calc.attributes.gw.value,
|
||||
};
|
||||
|
||||
await game["combat"].updateEmbeddedDocuments("Combatant", [
|
||||
initiatives,
|
||||
]);
|
||||
await game['combat'].updateEmbeddedDocuments('Combatant', [initiatives]);
|
||||
}
|
||||
});
|
||||
|
||||
// Drag & Drop
|
||||
const dragDrop = new DragDrop({
|
||||
dragSelector: ".items-list .item",
|
||||
dragSelector: '.items-list .item',
|
||||
dropSelector: null,
|
||||
permissions: {
|
||||
dragstart: this._canDragStart.bind(this),
|
||||
@@ -488,12 +423,12 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
|
||||
_onTransferItemDragStart(event) {
|
||||
const li = event.target;
|
||||
$(event.target).attr("data-item-actorid", this.actor.id);
|
||||
$(event.target).attr('data-item-actorid', this.actor.id);
|
||||
const item = this.actor.items.get(li.dataset.itemId);
|
||||
console.log(item);
|
||||
|
||||
const dragData = {
|
||||
type: "Transfer",
|
||||
type: 'Transfer',
|
||||
actorId: this.actor.id,
|
||||
data: item.toObject(false),
|
||||
tokenId: null,
|
||||
@@ -501,15 +436,15 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
|
||||
if (this.actor.isToken) dragData.tokenId = this.actor.token.id;
|
||||
|
||||
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(dragData));
|
||||
}
|
||||
|
||||
async _onTransferItemDrop(event) {
|
||||
// Try to extract the data
|
||||
let data = null;
|
||||
try {
|
||||
data = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||
if (data.type !== "Transfer") return false;
|
||||
data = JSON.parse(event.dataTransfer.getData('text/plain'));
|
||||
if (data.type !== 'Transfer') return false;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
@@ -521,21 +456,17 @@ export default class M5CharacterSheet extends ActorSheet {
|
||||
}
|
||||
|
||||
// limit transfer on personal weapons/armour/gear
|
||||
if (
|
||||
["item", "weapon", "defensiveWeapon", "armor", "container"].includes(
|
||||
data.data.type,
|
||||
)
|
||||
) {
|
||||
if (['item', 'weapon', 'defensiveWeapon', 'armor', 'container'].includes(data.data.type)) {
|
||||
try {
|
||||
this.actor.createEmbeddedDocuments("Item", [duplicate(data.data)]); // Create a new Item
|
||||
this.actor.createEmbeddedDocuments('Item', [duplicate(data.data)]); // Create a new Item
|
||||
const actor = (game as any).actors.get(data.actorId);
|
||||
await actor.items.get(data.data._id)?.delete(); // Delete originating item from other actor
|
||||
} catch (e) {
|
||||
console.error("Error transfering item between actors", e);
|
||||
console.error('Error transfering item between actors', e);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ui.notifications.warn("Nur Gegenstände können übertragen werden.");
|
||||
ui.notifications.warn('Nur Gegenstände können übertragen werden.');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user