Working on 0.8.x - Character sheets related

This commit is contained in:
Vlyan
2021-04-24 17:16:52 +02:00
parent 80907c8a01
commit b6f3d42fa2
61 changed files with 1569 additions and 470 deletions

View File

@@ -64,7 +64,7 @@ export class BaseSheetL5r5e extends ActorSheet {
Object.keys(out).forEach((tech) => {
if (
out[tech].length < 1 &&
!sheetData.data.techniques[tech] &&
!sheetData.data.data.techniques[tech] &&
!CONFIG.l5r5e.techniques_school.includes(tech)
) {
delete out[tech];
@@ -72,11 +72,11 @@ export class BaseSheetL5r5e extends ActorSheet {
});
// Manage school add button
sheetData.data.techniques["school_ability"] = out["school_ability"].length === 0;
sheetData.data.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
sheetData.data.data.techniques["school_ability"] = out["school_ability"].length === 0;
sheetData.data.data.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
// Always display "school_ability", but display "mastery_ability" only if rank >= 5
if (sheetData.data.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
if (sheetData.data.data.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
delete out["mastery_ability"];
}
return out;
@@ -155,7 +155,7 @@ export class BaseSheetL5r5e extends ActorSheet {
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (
!item ||
item.entity !== "Item" ||
item.documentName !== "Item" ||
!["item", "armor", "weapon", "technique", "peculiarity", "advancement"].includes(item.data.type)
) {
return;
@@ -221,7 +221,7 @@ export class BaseSheetL5r5e extends ActorSheet {
if (allowed === false) {
return;
}
return this._onDropItem(event, item);
return this._onDropItemCreate(item.toJSON());
}
/**
@@ -321,12 +321,14 @@ export class BaseSheetL5r5e extends ActorSheet {
peculiarity: "l5r5e.peculiarities.title_new",
advancement: "l5r5e.advancements.title_new",
};
const created = await this.actor.createEmbeddedEntity("OwnedItem", {
name: game.i18n.localize(titles[type]),
type: type,
img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`,
});
const item = this.actor.getOwnedItem(created._id);
const created = await this.actor.createEmbeddedDocuments("Item", [
{
name: game.i18n.localize(titles[type]),
type: type,
img: `${CONFIG.l5r5e.paths.assets}icons/items/${type}.svg`,
},
]);
const item = this.actor.items.get(created[0].id);
// assign current school rank to the new adv/tech
if (this.actor.data.data.identity?.school_rank && ["advancement", "technique"].includes(item.data.type)) {
@@ -347,7 +349,7 @@ export class BaseSheetL5r5e extends ActorSheet {
const techType = $(event.currentTarget).data("tech-type");
if ([...CONFIG.l5r5e.techniques, ...CONFIG.l5r5e.techniques_school].includes(techType)) {
item.data.data.technique_type = techType;
item.data.img = `${CONFIG.l5r5e.paths.assets}/icons/techs/${techType}.svg`;
item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techType}.svg`;
}
break;
}
@@ -366,7 +368,7 @@ export class BaseSheetL5r5e extends ActorSheet {
event.stopPropagation();
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
const item = this.actor.items.get(itemId);
item.sheet.render(true);
}
@@ -382,7 +384,7 @@ export class BaseSheetL5r5e extends ActorSheet {
const itemId = $(event.currentTarget).data("item-id");
// Remove 1 qty if possible
const tmpItem = this.actor.getOwnedItem(itemId);
const tmpItem = this.actor.items.get(itemId);
if (tmpItem && tmpItem.data.data.quantity > 1 && this._modifyQuantity(tmpItem._id, -1)) {
return;
}
@@ -411,8 +413,7 @@ export class BaseSheetL5r5e extends ActorSheet {
data: diffObject(this.actor.data.data, actor),
});
}
return this.actor.deleteOwnedItem(itemId);
return this.actor.deleteEmbeddedDocuments("Item", [itemId]);
};
// Holing Ctrl = without confirm
@@ -433,7 +434,7 @@ export class BaseSheetL5r5e extends ActorSheet {
*/
_switchSubItemCurriculum(event) {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
const item = this.actor.items.get(itemId);
if (item.type !== "item") {
item.update({
data: {
@@ -448,7 +449,7 @@ export class BaseSheetL5r5e extends ActorSheet {
* @private
*/
_modifyQuantity(itemId, add) {
const tmpItem = this.actor.getOwnedItem(itemId);
const tmpItem = this.actor.items.get(itemId);
if (tmpItem) {
tmpItem.data.data.quantity = Math.max(1, tmpItem.data.data.quantity + add);
tmpItem.update({
@@ -476,7 +477,7 @@ export class BaseSheetL5r5e extends ActorSheet {
}
const itemId = $(event.currentTarget).data("item-id");
const tmpItem = this.actor.getOwnedItem(itemId);
const tmpItem = this.actor.items.get(itemId);
if (!tmpItem || tmpItem.data.data[type] === undefined) {
return;
}
@@ -498,7 +499,7 @@ export class BaseSheetL5r5e extends ActorSheet {
* @private
*/
_getWeaponSkillId(weaponId) {
const item = this.actor.getOwnedItem(weaponId);
const item = this.actor.items.get(weaponId);
if (!!item && item.type === "weapon") {
return item.data.data.skill;
}

View File

@@ -47,11 +47,13 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
this.actor.data.data.identity.school_rank = Math.max(1, this.actor.data.data.identity.school_rank);
// Split Money
sheetData.data.money = this._zeniToMoney(this.actor.data.data.zeni);
sheetData.data.data.money = this._zeniToMoney(this.actor.data.data.zeni);
// split advancements list by rank, and calculate xp spent
this._prepareAdvancement(sheetData);
sheetData.data.xp_saved = Math.floor(parseInt(sheetData.data.xp_total) - parseInt(sheetData.data.xp_spent));
sheetData.data.data.xp_saved = Math.floor(
parseInt(sheetData.data.data.xp_total) - parseInt(sheetData.data.data.xp_spent)
);
return sheetData;
}
@@ -100,14 +102,14 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
*/
_prepareAdvancement(sheetData) {
const adv = [];
sheetData.data.xp_spent = 0;
sheetData.data.data.xp_spent = 0;
sheetData.items.forEach((item) => {
if (!["peculiarity", "technique", "advancement"].includes(item.type)) {
return;
}
let xp = parseInt(item.data.xp_used) || 0;
sheetData.data.xp_spent = parseInt(sheetData.data.xp_spent) + xp;
sheetData.data.data.xp_spent = parseInt(sheetData.data.data.xp_spent) + xp;
// if not in curriculum, xp spent /2 for this item
if (!item.data.in_curriculum && xp > 0) {
@@ -126,7 +128,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
adv[rank].list.push(item);
adv[rank].spent = adv[rank].spent + xp;
});
sheetData.advancementsListByRank = adv;
sheetData.data.advancementsListByRank = adv;
}
/**

View File

@@ -19,7 +19,7 @@ export class NpcSheetL5r5e extends BaseSheetL5r5e {
getData() {
const sheetData = super.getData();
sheetData.data.types = NpcSheetL5r5e.types.map((e) => ({
sheetData.data.data.types = NpcSheetL5r5e.types.map((e) => ({
id: e,
label: game.i18n.localize("l5r5e.character_types." + e),
}));

View File

@@ -51,7 +51,7 @@ export class TwentyQuestionsDialog extends FormApplication {
* Define a unique and dynamic element ID for the rendered ActorSheet application
*/
get id() {
return `l5r5e-twenty-questions-dialog-${this.actor._id}`;
return `l5r5e-twenty-questions-dialog-${this.actor.id}`;
}
/**
@@ -69,7 +69,7 @@ export class TwentyQuestionsDialog extends FormApplication {
if (!this.actor) {
return;
}
this._initialize(game.actors.get(this.actor._id));
this._initialize(game.actors.get(this.actor.id));
await this._constructCache();
this.render(false);
}
@@ -234,7 +234,7 @@ export class TwentyQuestionsDialog extends FormApplication {
try {
// Get item
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (item.entity !== "Item" || !item) {
if (item.documentName !== "Item" || !item) {
console.warn("forbidden item for this drop zone", type, item.data.type);
return;
}

View File

@@ -82,6 +82,8 @@ export class TwentyQuestions {
shuji: false,
maho: false,
ninjutsu: false,
link: false,
specificity: false,
},
techniques: [],
school_ability: [],
@@ -285,8 +287,8 @@ export class TwentyQuestions {
});
// Clear and add items to actor
const deleteIds = actor.data.items.map((e) => e._id);
await actor.deleteEmbeddedEntity("OwnedItem", deleteIds);
const deleteIds = actor.data.items.map((e) => e.id);
await actor.deleteEmbeddedDocuments("Item", deleteIds);
// Add items in 20Q to actor
for (const types of Object.values(itemsCache)) {
@@ -298,7 +300,7 @@ export class TwentyQuestions {
if (itemData.data?.xp_spent) {
itemData.data.xp_spent = 0;
}
await actor.createEmbeddedEntity("OwnedItem", itemData);
await actor.createEmbeddedDocuments("Item", [itemData]);
}
}