some change on items

This commit is contained in:
Vlyan
2020-12-17 23:01:22 +01:00
parent 889a3d0656
commit efca6cd083
24 changed files with 328 additions and 94 deletions

View File

@@ -4,6 +4,11 @@ import { ItemSheetL5r5e } from "./item-sheet.js";
* @extends {ItemSheet}
*/
export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
/**
* Sub Types of advancements
*/
static types = ["ring", "skill", "advantage"]; // "technique" has it's own type
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
@@ -14,4 +19,13 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
getData() {
const sheetData = super.getData();
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.subTypesList = AdvancementSheetL5r5e.types;
return sheetData;
}
}

View File

@@ -19,6 +19,20 @@ export class ItemSheetL5r5e extends ItemSheet {
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.ringsList = CONFIG.L5r5e.stances.map((e) => {
return {
id: e,
label: game.i18n.localize(`l5r5e.rings.${e}`),
};
});
sheetData.data.techniquesList = CONFIG.L5r5e.techniques.map((e) => {
return {
id: e,
label: game.i18n.localize(`l5r5e.techniques.${e}`),
};
});
return sheetData;
}

View File

@@ -8,7 +8,7 @@ export class PeculiaritySheetL5r5e extends ItemSheetL5r5e {
/**
* Sub Types of Advantage/Disadvantage
*/
static SUB_TYPES = ["distinction", "passion", "adversity", "anxiety"];
static types = ["distinction", "passion", "adversity", "anxiety"];
/** @override */
static get defaultOptions() {
@@ -23,7 +23,10 @@ export class PeculiaritySheetL5r5e extends ItemSheetL5r5e {
getData() {
const sheetData = super.getData();
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.subTypesList = PeculiaritySheetL5r5e.types;
return sheetData;
}
}

View File

@@ -13,6 +13,7 @@ import { WeaponSheetL5r5e } from "./items/weapon-sheet.js";
import { TechniqueSheetL5r5e } from "./items/technique-sheet.js";
import { QualitySheetL5r5e } from "./items/quality-sheet.js";
import { AdvancementSheetL5r5e } from "./items/advancement-sheet.js";
import { PeculiaritySheetL5r5e } from "./items/peculiarity-sheet.js";
// Import Dice Types
@@ -70,6 +71,7 @@ Hooks.once("init", async function () {
Items.registerSheet("l5r5e", WeaponSheetL5r5e, { types: ["weapon"], makeDefault: true });
Items.registerSheet("l5r5e", TechniqueSheetL5r5e, { types: ["technique"], makeDefault: true });
Items.registerSheet("l5r5e", QualitySheetL5r5e, { types: ["quality"], makeDefault: true });
Items.registerSheet("l5r5e", PeculiaritySheetL5r5e, { types: ["peculiarity"], makeDefault: true });
Items.registerSheet("l5r5e", AdvancementSheetL5r5e, { types: ["advancement"], makeDefault: true });
// for debug

View File

@@ -38,6 +38,9 @@ export const PreloadTemplates = async function () {
"systems/l5r5e/templates/item/advancements.html",
"systems/l5r5e/templates/item/advancement-sheet.html",
"systems/l5r5e/templates/item/advancement-entry.html",
"systems/l5r5e/templates/item/peculiarities.html",
"systems/l5r5e/templates/item/peculiarity-sheet.html",
"systems/l5r5e/templates/item/peculiarity-entry.html",
];
return loadTemplates(templatePaths);

View File

@@ -31,7 +31,44 @@ export class ActorSheetL5r5e extends BaseSheetL5r5e {
await new TwentyQuestionsDialog({}, this.actor).render(true);
},
});
return buttons;
}
/**
* Commons datas
*/
getData() {
const sheetData = super.getData();
// Sort Items by rank 0->6 for advancements tab
sheetData.items.sort((a, b) => {
return (a.data.bought_at_rank || 0) - (b.data.bought_at_rank || 0);
});
// Xp spent only in current rank
sheetData.data.advancement.xp_spent_rank = this.getXpSpentInThisRank();
return sheetData;
}
/**
* Return the current total xp spent for this rank
*/
getXpSpentInThisRank() {
const currentRank = this.actor.data.data.identity.school_rank || 0;
const spent = this.actor.items.reduce((tot, item) => {
// TODO c'est bien par rang actuel +1 ?
if (currentRank + 1 === item.data.data.rank) {
let xp = item.data.data.xp_used || 0;
// if not in curriculum, xp spent /2 for this item
if (!item.data.data.in_curriculum && xp > 0) {
xp = Math.floor(xp / 2);
}
return tot + xp;
}
return tot;
}, 0);
return spent;
}
}

View File

@@ -8,6 +8,7 @@ export class BaseSheetL5r5e extends ActorSheet {
getData() {
const sheetData = super.getData();
sheetData.data.dtypes = ["String", "Number", "Boolean"];
sheetData.data.stances = CONFIG.L5r5e.stances;
return sheetData;
@@ -48,41 +49,35 @@ export class BaseSheetL5r5e extends ActorSheet {
return;
}
// *** Items / Inventory ***
html.find(".item-edit").on("click", (ev) => {
this._editSubItem(ev, "item");
});
html.find(".item-delete").on("click", (ev) => {
this._deleteSubItem(ev, "item");
// *** Items : edit, delete ***
["item", "peculiarity", "technique", "advancement"].forEach((type) => {
html.find(`.${type}-edit`).on("click", (ev) => {
this._editSubItem(ev, type);
});
html.find(`.${type}-delete`).on("click", (ev) => {
this._deleteSubItem(ev, type);
});
if (type !== "item") {
html.find(`.${type}-curriculum`).on("click", (ev) => {
this._switchSubItemCurriculum(ev, type);
});
}
});
// *** Techniques ***
// *** Items : add ***
html.find(".technique-add").on("click", (ev) => {
this._addSubItem({
name: game.i18n.localize("l5r5e.techniques.title_new"),
type: "technique",
});
});
html.find(".technique-edit").on("click", (ev) => {
this._editSubItem(ev, "technique");
});
html.find(".technique-delete").on("click", (ev) => {
this._deleteSubItem(ev, "technique");
});
// *** Advancement ***
html.find(".advancement-add").on("click", (ev) => {
this._addSubItem({
name: game.i18n.localize("l5r5e.xp.advancements"),
name: game.i18n.localize("l5r5e.advancements.title_new"),
type: "advancement",
});
});
html.find(".advancement-edit").on("click", (ev) => {
this._editSubItem(ev, "advancement");
});
html.find(".advancement-delete").on("click", (ev) => {
this._deleteSubItem(ev, "advancement");
});
}
/**
@@ -115,4 +110,19 @@ export class BaseSheetL5r5e extends ActorSheet {
const li = $(ev.currentTarget).parents("." + type);
return this.actor.deleteOwnedItem(li.data(type + "Id"));
}
/**
* Switch "in_curriculum"
* @private
*/
_switchSubItemCurriculum(ev, type) {
const li = $(ev.currentTarget).parents("." + type);
const itemId = li.data(type + "Id");
const item = this.actor.getOwnedItem(itemId);
return item.update({
data: {
in_curriculum: !item.data.data.in_curriculum,
},
});
}
}

View File

@@ -128,21 +128,21 @@ export class TwentyQuestionsDialog extends FormApplication {
let data;
try {
data = JSON.parse(event.dataTransfer.getData("text/plain"));
if (data.type !== "Item") return;
const item = game.items.get(data.id);
if (item.data.type !== type) {
if (data.type !== "Item") {
return;
}
const item = game.items.get(data.id);
if (item || item.data.type !== type) {
return;
}
// TODO
console.log("** OK ", item);
// sub_type === 'peculiarity'
} catch (err) {
return false;
console.warn(err);
}
// TODO
return false;
}