Working on 0.8.x

- Title's Advancements are now reflected on actor
- Migration update
This commit is contained in:
Vlyan
2021-05-22 17:20:17 +02:00
parent 4f9b72c63f
commit 53f04e6cef
33 changed files with 423 additions and 281 deletions

View File

@@ -7,7 +7,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
/**
* Sub Types of advancements
*/
static types = ["ring", "skill"]; // "peculiarity" and "technique" have theirs own xp count
static types = ["ring", "skill"]; // others have theirs own xp count
/** @override */
static get defaultOptions() {
@@ -73,47 +73,55 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
// Modify image to reflect choice
if (newChoice.ring) {
name = game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) + "+1";
img = `systems/l5r5e/assets/icons/rings/${newChoice.ring}.svg`;
} else if (newChoice.skill) {
name =
game.i18n.localize(`l5r5e.skills.${CONFIG.l5r5e.skills.get(newChoice.skill)}.${newChoice.skill}`) +
"+1";
img = `systems/l5r5e/assets/dices/default/skill_blank.svg`;
}
// Object embed in actor ?
if (this.actor) {
const actor = duplicate(this.actor.data.data);
const actor = this.document.actor;
if (actor) {
const actorData = foundry.utils.duplicate(actor.data.data);
let skillCatId = null;
// Old choices
if (oldChoice.ring) {
actor.rings[oldChoice.ring] = Math.max(1, actor.rings[oldChoice.ring] - 1);
actorData.rings[oldChoice.ring] = Math.max(1, actorData.rings[oldChoice.ring] - 1);
}
if (oldChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(oldChoice.skill);
actor.skills[skillCatId][oldChoice.skill] = Math.max(0, actor.skills[skillCatId][oldChoice.skill] - 1);
actorData.skills[skillCatId][oldChoice.skill] = Math.max(
0,
actorData.skills[skillCatId][oldChoice.skill] - 1
);
}
// new choices
if (newChoice.ring) {
actor.rings[newChoice.ring] = actor.rings[newChoice.ring] + 1;
xp_used = actor.rings[newChoice.ring] * CONFIG.l5r5e.xp.ringCostMultiplier;
actorData.rings[newChoice.ring] = actorData.rings[newChoice.ring] + 1;
xp_used = actorData.rings[newChoice.ring] * CONFIG.l5r5e.xp.ringCostMultiplier;
name =
game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) +
` +1 (${actor.rings[newChoice.ring] - 1} -> ${actor.rings[newChoice.ring]})`;
` +1 (${actorData.rings[newChoice.ring] - 1} -> ${actorData.rings[newChoice.ring]})`;
}
if (newChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill);
actor.skills[skillCatId][newChoice.skill] = actor.skills[skillCatId][newChoice.skill] + 1;
xp_used = actor.skills[skillCatId][newChoice.skill] * CONFIG.l5r5e.xp.skillCostMultiplier;
actorData.skills[skillCatId][newChoice.skill] = actorData.skills[skillCatId][newChoice.skill] + 1;
xp_used = actorData.skills[skillCatId][newChoice.skill] * CONFIG.l5r5e.xp.skillCostMultiplier;
name =
game.i18n.localize(`l5r5e.skills.${skillCatId}.${newChoice.skill}`) +
` +1 (${actor.skills[skillCatId][newChoice.skill] - 1} -> ${
actor.skills[skillCatId][newChoice.skill]
` +1 (${actorData.skills[skillCatId][newChoice.skill] - 1} -> ${
actorData.skills[skillCatId][newChoice.skill]
})`;
}
// Update Actor
await this.actor.update({
data: diffObject(this.actor.data.data, actor),
await actor.update({
data: foundry.utils.diffObject(actor.data.data, actorData),
});
}

View File

@@ -21,9 +21,6 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e {
async getData(options = {}) {
const sheetData = await super.getData(options);
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.ringsList = game.l5r5e.HelpersL5r5e.getRingsList();
// Linked Property
sheetData.data.linkedProperty = await this.getLinkedProperty(sheetData);

View File

@@ -256,6 +256,23 @@ export class ItemSheetL5r5e extends ItemSheet {
event.preventDefault();
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
this.document.deleteEmbedItem(itemId);
const item = this.document.getEmbedItem(itemId);
if (!item) {
return;
}
const callback = async () => {
this.document.deleteEmbedItem(itemId);
};
// Holing Ctrl = without confirm
if (event.ctrlKey) {
return callback();
}
game.l5r5e.HelpersL5r5e.confirmDeleteDialog(
game.i18n.format("l5r5e.global.delete_confirm", { name: item.name }),
callback
);
}
}

View File

@@ -21,14 +21,15 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
async getData(options = {}) {
const sheetData = await super.getData(options);
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.ringsList = game.l5r5e.HelpersL5r5e.getRingsList();
console.log(sheetData.data.data.items); // todo tmp
// Prepare OwnedItems
sheetData.data.embedItemsList = this._prepareEmbedItems(sheetData.data.data.items);
console.log(sheetData); // todo tmp
// Automatically compute the xp cost
sheetData.data.data.xp_used = sheetData.data.embedItemsList.reduce(
(acc, item) => acc + (+item.data.xp_used || 0),
0
);
return sheetData;
}
@@ -63,17 +64,19 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
// Check item type and subtype
let item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || (item.documentName !== "Item" && !["technique", "advancement"].includes(item.data.type))) {
if (!item || item.documentName !== "Item" || !["technique", "advancement"].includes(item.data.type)) {
return;
}
const data = item.data.toJSON();
const data = item.data.toObject(false);
console.log("------ data", data); // todo tmp
// Check xp for techs
if (item.data.type === "technique") {
data.data.xp_cost = data.data.xp_cost > 0 ? data.data.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
data.data.xp_used = data.data.xp_cost;
}
this.document.addEmbedItem(data);
console.log(this.document); // todo tmp
}
/**
@@ -93,16 +96,4 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
html.find(`.item-edit`).on("click", this._editSubItem.bind(this));
html.find(`.item-delete`).on("click", this._deleteSubItem.bind(this));
}
/**
* This method is called upon form submission after form data is validated
* @param {Event} event The initial triggering submission event
* @param {object} formData The object of validated form data with which to update the object
* @returns {Promise} A Promise which resolves once the update operation has completed
* @abstract
*/
// async _updateObject(event, formData) {
// console.log("------- _updateObject.", formData); // todo TMP
// return super._updateObject(event, formData);
// }
}