Working on Compatibility for FVTT v10

This commit is contained in:
Vlyan
2022-07-21 16:08:47 +02:00
parent cf937c4979
commit eebd26d32a
108 changed files with 989 additions and 962 deletions

View File

@@ -28,7 +28,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
* @private
*/
_initialize() {
const data = this.object.data.data;
const data = this.object.system;
// update linked actor datas
if (data.commander_actor_id) {
@@ -79,10 +79,13 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
*/
activateEditor(name, options = {}, initialContent = "") {
// Symbols Compatibility with old compendium modules (PRE l5r v1.7.2)
if (["data.army_abilities", "data.supplies_logistics", "data.past_battles"].includes(name) && initialContent) {
if (
["system.army_abilities", "system.supplies_logistics", "system.past_battles"].includes(name) &&
initialContent
) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
return super.activateEditor(name, options, initialContent);
}
/**
@@ -100,7 +103,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
// Casualties/Panic +/-
html.find(".addsub-control").on("click", this._modifyCasualtiesOrPanic.bind(this));
if (this.actor.data.data.soft_locked) {
if (this.actor.system.soft_locked) {
return;
}
@@ -109,12 +112,19 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
}
/** @inheritdoc */
getData(options = {}) {
const sheetData = super.getData(options);
async getData(options = {}) {
const sheetData = await super.getData(options);
// Split Items by types
sheetData.data.splitItemsList = this._splitItems(sheetData);
// Editors enrichment
for (const name of ["army_abilities", "supplies_logistics", "past_battles"]) {
sheetData.data.enrichedHtml[name] = await TextEditor.enrichHTML(sheetData.data.system[name], {
async: true,
});
}
return sheetData;
}
@@ -143,15 +153,15 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
*/
async _onDrop(event) {
// *** Everything below here is only needed if the sheet is editable ***
if (!this.isEditable || this.actor.data.data.soft_locked) {
if (!this.isEditable || this.actor.system.soft_locked) {
return;
}
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || item.documentName !== "Item" || !["army_cohort", "army_fortification"].includes(item.data.type)) {
if (!item || item.documentName !== "Item" || !["army_cohort", "army_fortification"].includes(item.type)) {
// actor dual trigger...
if (item?.documentName !== "Actor") {
console.warn("L5R5E | Characters items are not allowed", item?.data?.type, item);
console.warn("L5R5E | Characters items are not allowed", item?.type, item);
}
return;
}
@@ -162,7 +172,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
return;
}
let itemData = item.data.toObject(true);
let itemData = item.toObject(true);
// Finally, create the embed
return this.actor.createEmbeddedDocuments("Item", [itemData]);
@@ -175,7 +185,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
*/
async _onDropActors(type, event) {
// *** Everything below here is only needed if the sheet is editable ***
if (!this.isEditable || this.actor.data.data.soft_locked) {
if (!this.isEditable || this.actor.system.soft_locked) {
return;
}
@@ -211,7 +221,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
*/
async _updateLinkedActorData(type, actor, isInit = false) {
if (!actor || actor.documentName !== "Actor" || !actor.isCharacter) {
console.warn("L5R5E | Wrong actor type", actor?.data?.type, actor);
console.warn("L5R5E | Wrong actor type", actor?.type, actor);
return;
}
@@ -219,26 +229,26 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
const actorData = {};
switch (type) {
case "commander":
actorData["data.commander"] = actor.data.name;
actorData["data.commander_actor_id"] = actor.data._id;
actorData["data.commander_standing.honor"] = actor.data.data.social.honor;
actorData["data.commander_standing.glory"] = actor.data.data.social.glory;
actorData["data.commander_standing.status"] = actor.data.data.social.status;
actorData["system.commander"] = actor.name;
actorData["system.commander_actor_id"] = actor._id;
actorData["system.commander_standing.honor"] = actor.system.social.honor;
actorData["system.commander_standing.glory"] = actor.system.social.glory;
actorData["system.commander_standing.status"] = actor.system.social.status;
// Replace the image by commander's image
if (
!isInit &&
this.actor.data.img !== actor.data.img &&
![`${actorPath}character.svg`, `${actorPath}npc.svg`].includes(actor.data.img)
this.actor.img !== actor.img &&
![`${actorPath}character.svg`, `${actorPath}npc.svg`].includes(actor.img)
) {
actorData["img"] = actor.data.img;
actorData["token.img"] = actor.data.token.img;
actorData["img"] = actor.img;
actorData["prototypeToken.texture.src"] = actor.prototypeToken.texture.src;
}
break;
case "warlord":
actorData["data.warlord"] = actor.data.name;
actorData["data.warlord_actor_id"] = actor.data._id;
actorData["system.warlord"] = actor.name;
actorData["system.warlord_actor_id"] = actor._id;
break;
default:
@@ -269,7 +279,7 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
console.warn("L5R5E | Unknown type", type);
return;
}
return this.actor.update({ data: actorData });
return this.actor.update({ system: actorData });
}
/**
@@ -290,13 +300,10 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
switch (type) {
case "casualties":
await this.actor.update({
data: {
system: {
battle_readiness: {
casualties_strength: {
value: Math.max(
0,
this.actor.data.data.battle_readiness.casualties_strength.value + mod
),
value: Math.max(0, this.actor.system.battle_readiness.casualties_strength.value + mod),
},
},
},
@@ -305,10 +312,10 @@ export class ArmySheetL5r5e extends BaseSheetL5r5e {
case "panic":
await this.actor.update({
data: {
system: {
battle_readiness: {
panic_discipline: {
value: Math.max(0, this.actor.data.data.battle_readiness.panic_discipline.value + mod),
value: Math.max(0, this.actor.system.battle_readiness.panic_discipline.value + mod),
},
},
},

View File

@@ -19,8 +19,8 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
}
/** @inheritdoc */
getData(options = {}) {
const sheetData = super.getData(options);
async getData(options = {}) {
const sheetData = await super.getData(options);
sheetData.data.stances = CONFIG.l5r5e.stances;
sheetData.data.techniquesList = game.l5r5e.HelpersL5r5e.getTechniquesList({ displayInTypes: true });
@@ -58,31 +58,31 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
sheetData.items.forEach((item) => {
switch (item.type) {
case "technique":
if (!out[item.data.technique_type]) {
if (!out[item.system.technique_type]) {
console.warn(
`L5R5E | Empty or unknown technique type[${item.data.technique_type}] forced to "kata" in item id[${item._id}], name[${item.name}]`
`L5R5E | Empty or unknown technique type[${item.system.technique_type}] forced to "kata" in item id[${item._id}], name[${item.name}]`
);
item.data.technique_type = "kata";
item.system.technique_type = "kata";
}
out[item.data.technique_type].push(item);
out[item.system.technique_type].push(item);
break;
case "title":
// Embed technique in titles
Array.from(item.data.items).forEach(([id, embedItem]) => {
if (embedItem.data.type === "technique") {
if (!out[embedItem.data.data.technique_type]) {
Array.from(item.system.items).forEach(([id, embedItem]) => {
if (embedItem.type === "technique") {
if (!out[embedItem.system.technique_type]) {
console.warn(
`L5R5E | Empty or unknown technique type[${embedItem.data.data.technique_type}] forced to "kata" in item id[${id}], name[${embedItem.data.name}], parent: id[${item._id}], name[${item.name}]`
`L5R5E | Empty or unknown technique type[${embedItem.system.technique_type}] forced to "kata" in item id[${id}], name[${embedItem.name}], parent: id[${item._id}], name[${item.name}]`
);
embedItem.data.data.technique_type = "kata";
embedItem.system.technique_type = "kata";
}
out[embedItem.data.data.technique_type].push(embedItem.data);
out[embedItem.system.technique_type].push(embedItem);
}
});
// If unlocked, add the "title_ability" as technique (or always displayed for npc)
if (item.data.xp_used >= item.data.xp_cost || this.document.type === "npc") {
if (item.system.xp_used >= item.system.xp_cost || this.document.type === "npc") {
out["title_ability"].push(item);
}
break;
@@ -91,17 +91,17 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
// Remove unused techs
Object.keys(out).forEach((tech) => {
if (out[tech].length < 1 && !sheetData.data.data.techniques[tech] && !schoolTechniques.includes(tech)) {
if (out[tech].length < 1 && !sheetData.data.system.techniques[tech] && !schoolTechniques.includes(tech)) {
delete out[tech];
}
});
// Manage school add button
sheetData.data.data.techniques["school_ability"] = out["school_ability"].length === 0;
sheetData.data.data.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
sheetData.data.system.techniques["school_ability"] = out["school_ability"].length === 0;
sheetData.data.system.techniques["mastery_ability"] = out["mastery_ability"].length === 0;
// Always display "school_ability", but display a empty "mastery_ability" field only if rank >= 5
if (sheetData.data.data.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
if (sheetData.data.system.identity?.school_rank < 5 && out["mastery_ability"].length === 0) {
delete out["mastery_ability"];
}
@@ -134,56 +134,59 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
*/
async _onDrop(event) {
// *** Everything below here is only needed if the sheet is editable ***
if (!this.isEditable || this.actor.data.data.soft_locked) {
if (!this.isEditable || this.actor.system.soft_locked) {
console.log("LR5E | Not editable");
return;
}
// Check item type and subtype
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || !["Item", "JournalEntry"].includes(item.documentName) || item.data.type === "property") {
if (!item || !["Item", "JournalEntry"].includes(item.documentName) || item.type === "property") {
console.log(`LR5E | Wrong subtype ${item?.type}`, item);
return;
}
// Specific curriculum journal drop
if (item.documentName === "JournalEntry") {
// npc does not have this
if (!this.actor.data.data.identity?.school_curriculum_journal) {
if (!this.actor.system.identity?.school_curriculum_journal) {
console.log("LR5E | NPC won't go to school :'(");
return;
}
this.actor.data.data.identity.school_curriculum_journal = {
id: item.data._id,
name: item.data.name,
this.actor.system.identity.school_curriculum_journal = {
id: item._id,
name: item.name,
pack: item.pack || null,
};
await this.actor.update({
data: {
system: {
identity: {
school_curriculum_journal: this.actor.data.data.identity.school_curriculum_journal,
school_curriculum_journal: this.actor.system.identity.school_curriculum_journal,
},
},
});
return;
}
// Dropped a item with same "id" as one owned
if (this.actor.data.items) {
// Dropped an item with same "id" as one owned
if (this.actor.items) {
// Exit if we already owned exactly this id (drag a personal item on our own sheet)
if (
this.actor.data.items.some((embedItem) => {
this.actor.items.some((embedItem) => {
// Search in children
if (embedItem.items instanceof Map && embedItem.items.has(item.data._id)) {
return true;
}
return embedItem.data._id === item.data._id;
return embedItem._id === item._id;
})
) {
return;
}
// Add quantity instead if they have (id is different so use type and name)
if (item.data.data.quantity) {
const tmpItem = this.actor.data.items.find(
(embedItem) => embedItem.name === item.data.name && embedItem.type === item.data.type
if (item.system.quantity) {
const tmpItem = this.actor.items.find(
(embedItem) => embedItem.name === item.name && embedItem.type === item.type
);
if (tmpItem && this._modifyQuantity(tmpItem.id, 1)) {
return;
@@ -197,13 +200,13 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
return;
}
let itemData = item.data.toObject(true);
let itemData = item.toObject(true);
// Item subtype specific
switch (itemData.type) {
case "army_cohort":
case "army_fortification":
console.warn("L5R5E | Army items are not allowed", item?.data?.type, item);
console.warn("L5R5E | Army items are not allowed", item?.type, item);
return;
case "advancement":
@@ -216,24 +219,22 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
await item.generateNewIdsForAllEmbedItems();
// Add embed advancements bonus
for (let [embedId, embedItem] of item.data.data.items) {
for (let [embedId, embedItem] of item.system.items) {
if (embedItem.data.type === "advancement") {
await this.actor.addBonus(embedItem);
}
}
// refresh data
itemData = item.data.toObject(true);
itemData = item.toObject(true);
break;
case "technique":
// School_ability and mastery_ability, allow only 1 per type
if (CONFIG.l5r5e.techniques.get(itemData.data.technique_type)?.type === "school") {
if (CONFIG.l5r5e.techniques.get(itemData.system.technique_type)?.type === "school") {
if (
Array.from(this.actor.items).some((e) => {
return (
e.type === "technique" && e.data.data.technique_type === itemData.data.technique_type
);
return e.type === "technique" && e.system.technique_type === itemData.system.technique_type;
})
) {
ui.notifications.info(game.i18n.localize("l5r5e.techniques.only_one"));
@@ -241,27 +242,27 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
}
// No cost for schools
itemData.data.xp_cost = 0;
itemData.data.xp_used = 0;
itemData.data.in_curriculum = true;
itemData.system.xp_cost = 0;
itemData.system.xp_used = 0;
itemData.system.in_curriculum = true;
} else {
// Check if technique is allowed for this character
if (!game.user.isGM && !this.actor.data.data.techniques[itemData.data.technique_type]) {
if (!game.user.isGM && !this.actor.system.techniques[itemData.system.technique_type]) {
ui.notifications.info(game.i18n.localize("l5r5e.techniques.not_allowed"));
return;
}
// Verify cost
itemData.data.xp_cost =
itemData.data.xp_cost > 0 ? itemData.data.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
itemData.data.xp_used = itemData.data.xp_cost;
itemData.system.xp_cost =
itemData.system.xp_cost > 0 ? itemData.system.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
itemData.system.xp_used = itemData.system.xp_cost;
}
break;
}
// Modify the bought at rank to the current actor rank
if (itemData.data.bought_at_rank !== undefined && this.actor.data.data.identity?.school_rank) {
itemData.data.bought_at_rank = this.actor.data.data.identity.school_rank;
if (itemData.system.bought_at_rank !== undefined && this.actor.system.identity?.school_rank) {
itemData.system.bought_at_rank = this.actor.system.identity.school_rank;
}
// Finally create the embed
@@ -332,10 +333,10 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
event.preventDefault();
event.stopPropagation();
this.actor.data.data.prepared = !this.actor.data.data.prepared;
this.actor.system.prepared = !this.actor.system.prepared;
this.actor.update({
data: {
prepared: this.actor.data.data.prepared,
system: {
prepared: this.actor.system.prepared,
},
});
this.render(false);
@@ -367,26 +368,26 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
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) {
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
if (["advancement", "technique"].includes(item.data.type)) {
item.data.data.rank = this.actor.data.data.identity.school_rank;
if (this.actor.system.identity?.school_rank) {
item.system.bought_at_rank = this.actor.system.identity.school_rank;
if (["advancement", "technique"].includes(item.type)) {
item.system.rank = this.actor.system.identity.school_rank;
}
}
switch (item.data.type) {
switch (item.type) {
case "item": // no break
case "armor": // no break
case "weapon":
item.data.data.equipped = isEquipped;
item.system.equipped = isEquipped;
break;
case "technique": {
// If technique, select the current sub-type
if (CONFIG.l5r5e.techniques.get(techniqueType)) {
item.data.name = game.i18n.localize(`l5r5e.techniques.${techniqueType}`);
item.data.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techniqueType}.svg`;
item.data.data.technique_type = techniqueType;
item.name = game.i18n.localize(`l5r5e.techniques.${techniqueType}`);
item.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${techniqueType}.svg`;
item.system.technique_type = techniqueType;
}
break;
}
@@ -496,8 +497,8 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
const item = this.actor.items.get(itemId);
if (item.type !== "item") {
item.update({
data: {
in_curriculum: !item.data.data.in_curriculum,
system: {
in_curriculum: !item.system.in_curriculum,
},
});
}
@@ -510,10 +511,10 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
_modifyQuantity(itemId, add) {
const tmpItem = this.actor.items.get(itemId);
if (tmpItem) {
tmpItem.data.data.quantity = Math.max(1, tmpItem.data.data.quantity + add);
tmpItem.system.quantity = Math.max(1, tmpItem.system.quantity + add);
tmpItem.update({
data: {
quantity: tmpItem.data.data.quantity,
system: {
quantity: tmpItem.system.quantity,
},
});
return true;
@@ -539,9 +540,9 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
switch (type) {
case "fatigue":
await this.actor.update({
data: {
system: {
fatigue: {
value: Math.max(0, this.actor.data.data.fatigue.value + mod),
value: Math.max(0, this.actor.system.fatigue.value + mod),
},
},
});
@@ -549,9 +550,9 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
case "strife":
await this.actor.update({
data: {
system: {
strife: {
value: Math.max(0, this.actor.data.data.strife.value + mod),
value: Math.max(0, this.actor.system.strife.value + mod),
},
},
});
@@ -579,20 +580,20 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
const itemId = $(event.currentTarget).data("item-id");
const tmpItem = this.actor.items.get(itemId);
if (!tmpItem || tmpItem.data.data[type] === undefined) {
if (!tmpItem || tmpItem.system[type] === undefined) {
return;
}
tmpItem.data.data[type] = !tmpItem.data.data[type];
tmpItem.system[type] = !tmpItem.system[type];
const data = {
equipped: tmpItem.data.data.equipped,
equipped: tmpItem.system.equipped,
};
// Only weapons
if (tmpItem.data.data.readied !== undefined) {
data.readied = tmpItem.data.data.readied;
if (tmpItem.system.readied !== undefined) {
data.readied = tmpItem.system.readied;
}
tmpItem.update({ data });
tmpItem.update({ system: data });
}
/**

View File

@@ -29,16 +29,16 @@ export class BaseSheetL5r5e extends ActorSheet {
if (this.isEditable && !this.actor.limited) {
// Lock/Unlock
buttons.unshift({
label: `l5r5e.global.${this.actor.data.data.soft_locked ? "" : "un"}locked`,
label: `l5r5e.global.${this.actor.system.soft_locked ? "" : "un"}locked`,
class: "l5r-softlock",
icon: this.actor.data.data.soft_locked ? "fas fa-lock" : "fas fa-unlock",
icon: this.actor.system.soft_locked ? "fas fa-lock" : "fas fa-unlock",
onclick: () =>
game.l5r5e.HelpersL5r5e.debounce(
"lock-" + this.object.id,
() => {
this.actor.update({
data: {
soft_locked: !this.actor.data.data.soft_locked,
system: {
soft_locked: !this.actor.system.soft_locked,
},
});
},
@@ -66,8 +66,8 @@ export class BaseSheetL5r5e extends ActorSheet {
}
/** @inheritdoc */
getData(options = {}) {
const sheetData = super.getData(options);
async getData(options = {}) {
const sheetData = await super.getData(options);
// System Header Buttons
sheetData.l5rHeaderButtons = this._getL5rHeaderButtons();
@@ -79,8 +79,14 @@ export class BaseSheetL5r5e extends ActorSheet {
return a.name.localeCompare(b.name);
});
// Editors enrichment
sheetData.data.enrichedHtml = {
description: await TextEditor.enrichHTML(sheetData.data.system.description, { async: true }),
notes: await TextEditor.enrichHTML(sheetData.data.system.notes, { async: true }),
};
// Shortcut for some tests
sheetData.data.editable_not_soft_locked = sheetData.editable && !sheetData.data.data.soft_locked;
sheetData.data.editable_not_soft_locked = sheetData.editable && !sheetData.data.system.soft_locked;
return sheetData;
}
@@ -105,10 +111,10 @@ export class BaseSheetL5r5e extends ActorSheet {
*/
activateEditor(name, options = {}, initialContent = "") {
// Symbols Compatibility with old compendium modules (PRE l5r v1.7.2)
if (["data.notes", "data.description"].includes(name) && initialContent) {
if (["system.notes", "system.description"].includes(name) && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
return super.activateEditor(name, options, initialContent);
}
/**

View File

@@ -69,7 +69,7 @@ export class CharacterGeneratorDialog extends FormApplication {
* Try to get values from actor to initialize the generator
*/
initializeFromActor() {
const actorDatas = this.actor.data.data;
const actorDatas = this.actor.system;
// Identity
this.object.clan = actorDatas.identity.clan || "random";
@@ -97,7 +97,7 @@ export class CharacterGeneratorDialog extends FormApplication {
label: game.i18n.localize("l5r5e.clans." + e),
}));
return {
...super.getData(options),
...(await super.getData(options)),
isNpc: this.actor.type === "npc",
clanList: [{ id: "random", label: game.i18n.localize("l5r5e.global.random") }, ...clans],
genderList: [

View File

@@ -291,7 +291,7 @@ export class CharacterGenerator {
narrative: true,
}
) {
const actorDatas = actor.data.data;
const actorDatas = actor.system;
const isNpc = actor.type === "npc";
// Need to set some required values
@@ -304,7 +304,7 @@ export class CharacterGenerator {
actorDatas.identity.female = this.isFemale;
// Name
let newName = actor.data.name;
let newName = actor.name;
if (generate.name) {
newName =
this.data.family +
@@ -325,9 +325,9 @@ export class CharacterGenerator {
`${folder}/npc.svg`,
`${folder}/traditional-japanese-man.svg`,
`${folder}/traditional-japanese-woman.svg`,
].includes(actor.data.img)
].includes(actor.img)
? `${folder}/traditional-japanese-${this.isFemale ? "woman" : "man"}.svg`
: actor.data.img;
: actor.img;
// Generate attributes & Social Standing
if (generate.attributes) {
@@ -453,7 +453,7 @@ export class CharacterGenerator {
*/
async _generatePeculiarities(actor, newItemsData) {
// Clear actor peculiarities
const deleteIds = actor.data.items.filter((e) => e.type === "peculiarity").map((e) => e.id);
const deleteIds = actor.items.filter((e) => e.type === "peculiarity").map((e) => e.id);
if (deleteIds.length > 0) {
await actor.deleteEmbeddedDocuments("Item", deleteIds);
}
@@ -476,7 +476,7 @@ export class CharacterGenerator {
*/
async _generateItems(actor, newItemsData) {
// Clear actor items
const deleteIds = actor.data.items.filter((e) => ["armor", "weapon", "item"].includes(e.type)).map((e) => e.id);
const deleteIds = actor.items.filter((e) => ["armor", "weapon", "item"].includes(e.type)).map((e) => e.id);
if (deleteIds.length > 0) {
await actor.deleteEmbeddedDocuments("Item", deleteIds);
}
@@ -521,7 +521,7 @@ export class CharacterGenerator {
*/
async _generateTechniques(actor, newItemsData) {
// Clear actor items
const deleteIds = actor.data.items.filter((e) => e.type === "technique").map((e) => e.id);
const deleteIds = actor.items.filter((e) => e.type === "technique").map((e) => e.id);
if (deleteIds.length > 0) {
await actor.deleteEmbeddedDocuments("Item", deleteIds);
}
@@ -598,7 +598,7 @@ export class CharacterGenerator {
const cfg = techCfg[pack];
// Minimum skill required (npc only for now)
if (!!cfg.skill && actor.data.data.skills[cfg.skill.grp_name] < cfg.skill.value_min) {
if (!!cfg.skill && actor.system.skills[cfg.skill.grp_name] < cfg.skill.value_min) {
continue;
}
@@ -613,9 +613,10 @@ export class CharacterGenerator {
let item;
do {
item = await CharacterGenerator._getItemFromPack(`l5r5e.core-techniques-${pack}`);
} while (item && item.data.data.rank > avgrv);
} while (item && item.system.rank > avgrv);
if (item) {
console.log(item); //todo tmp check this!
newItemsData.push(foundry.utils.duplicate(item.data));
}
} // fr qty

View File

@@ -41,14 +41,14 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
/**
* Commons datas
*/
getData(options = {}) {
const sheetData = super.getData(options);
async getData(options = {}) {
const sheetData = await super.getData(options);
// Min rank = 1
this.actor.data.data.identity.school_rank = Math.max(1, this.actor.data.data.identity.school_rank);
this.actor.system.identity.school_rank = Math.max(1, this.actor.system.identity.school_rank);
// Split Money
sheetData.data.data.money = this._zeniToMoney(this.actor.data.data.zeni);
sheetData.data.system.money = this._zeniToMoney(this.actor.system.zeni);
// Split school advancements by rank, and calculate xp spent and add it to total
this._prepareSchoolAdvancement(sheetData);
@@ -57,8 +57,8 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
this._prepareOthersAdvancement(sheetData);
// Total
sheetData.data.data.xp_saved = Math.floor(
parseInt(sheetData.data.data.xp_total) - parseInt(sheetData.data.data.xp_spent)
sheetData.data.system.xp_saved = Math.floor(
parseInt(sheetData.data.system.xp_total) - parseInt(sheetData.data.system.xp_spent)
);
return sheetData;
@@ -87,7 +87,7 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
"data.identity.family",
CONFIG.l5r5e.families.get(
Object.entries(game.i18n.translations.l5r5e.clans).find(
([k, v]) => v === this.actor.data.data.identity.clan
([k, v]) => v === this.actor.system.identity.clan
)?.[0]
)
);
@@ -118,7 +118,7 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
// TODO class "Active" Bug on load, dunno why :/
this._tabs
.find((e) => e._navSelector === ".advancements-tabs")
.activate("advancement_rank_" + (this.actor.data.data.identity.school_rank || 0));
.activate("advancement_rank_" + (this.actor.system.identity.school_rank || 0));
}
/**
@@ -126,14 +126,14 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
*/
_prepareSchoolAdvancement(sheetData) {
const adv = [];
sheetData.data.data.xp_spent = 0;
sheetData.data.system.xp_spent = 0;
sheetData.items
.filter((item) => ["peculiarity", "technique", "advancement"].includes(item.type))
.forEach((item) => {
const { xp_used_total, xp_used } = game.l5r5e.HelpersL5r5e.getItemsXpCost(item);
sheetData.data.data.xp_spent += xp_used_total;
sheetData.data.system.xp_spent += xp_used_total;
const rank = Math.max(0, item.data.bought_at_rank);
const rank = Math.max(0, item.system.bought_at_rank);
if (!adv[rank]) {
adv[rank] = {
rank: rank,
@@ -162,16 +162,16 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
);
// Sort by rank desc
sheetData.data.advancementsOthers.sort((a, b) => (b.data.rank || 0) - (a.data.rank || 0));
sheetData.data.advancementsOthers.sort((a, b) => (b.system.rank || 0) - (a.system.rank || 0));
// Total xp spent in curriculum & total
sheetData.data.advancementsOthersTotalXp = sheetData.data.advancementsOthers.reduce(
(acc, item) => acc + parseInt(item.data.xp_used_total || item.data.xp_used || 0),
(acc, item) => acc + parseInt(item.system.xp_used_total || item.system.xp_used || 0),
0
);
// Update the total spent
sheetData.data.data.xp_spent += sheetData.data.advancementsOthersTotalXp;
sheetData.data.system.xp_spent += sheetData.data.advancementsOthersTotalXp;
}
/**
@@ -182,39 +182,39 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
_updateObject(event, formData) {
// Clan tag trim if autocomplete in school name
if (
formData["autoCompleteListName"] === "data.identity.school" &&
formData["autoCompleteListName"] === "system.identity.school" &&
formData["autoCompleteListSelectedIndex"] >= 0 &&
!!formData["data.identity.clan"] &&
formData["data.identity.school"].indexOf(` [${formData["data.identity.clan"]}]`) !== -1
!!formData["system.identity.clan"] &&
formData["system.identity.school"].indexOf(` [${formData["system.identity.clan"]}]`) !== -1
) {
formData["data.identity.school"] = formData["data.identity.school"].replace(
` [${formData["data.identity.clan"]}]`,
formData["system.identity.school"] = formData["system.identity.school"].replace(
` [${formData["system.identity.clan"]}]`,
""
);
}
// Store money in Zeni
if (formData["data.money.koku"] || formData["data.money.bu"] || formData["data.money.zeni"]) {
formData["data.zeni"] = this._moneyToZeni(
formData["data.money.koku"] || 0,
formData["data.money.bu"] || 0,
formData["data.money.zeni"] || 0
if (formData["system.money.koku"] || formData["system.money.bu"] || formData["system.money.zeni"]) {
formData["system.zeni"] = this._moneyToZeni(
formData["system.money.koku"] || 0,
formData["system.money.bu"] || 0,
formData["system.money.zeni"] || 0
);
// Remove fake money object
delete formData["data.money.koku"];
delete formData["data.money.bu"];
delete formData["data.money.zeni"];
delete formData["system.money.koku"];
delete formData["system.money.bu"];
delete formData["system.money.zeni"];
}
// Save computed values
const currentData = this.object.data.data;
formData["data.focus"] = currentData.focus;
formData["data.vigilance"] = currentData.vigilance;
formData["data.endurance"] = currentData.endurance;
formData["data.composure"] = currentData.composure;
formData["data.fatigue.max"] = currentData.fatigue.max;
formData["data.strife.max"] = currentData.strife.max;
formData["data.void_points.max"] = currentData.void_points.max;
const currentData = this.object.system;
formData["system.focus"] = currentData.focus;
formData["system.vigilance"] = currentData.vigilance;
formData["system.endurance"] = currentData.endurance;
formData["system.composure"] = currentData.composure;
formData["system.fatigue.max"] = currentData.fatigue.max;
formData["system.strife.max"] = currentData.strife.max;
formData["system.void_points.max"] = currentData.void_points.max;
return super._updateObject(event, formData);
}
@@ -276,10 +276,10 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
mod = Math.floor(mod * CONFIG.l5r5e.money[type === "koku" ? 0 : 1]);
}
this.actor.data.data.zeni = +this.actor.data.data.zeni + mod;
this.actor.system.zeni = +this.actor.system.zeni + mod;
this.actor.update({
data: {
zeni: this.actor.data.data.zeni,
system: {
zeni: this.actor.system.zeni,
},
});
this.render(false);
@@ -294,11 +294,11 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
event.preventDefault();
event.stopPropagation();
this.actor.data.data.identity.school_rank = this.actor.data.data.identity.school_rank + 1;
this.actor.system.identity.school_rank = this.actor.system.identity.school_rank + 1;
await this.actor.update({
data: {
system: {
identity: {
school_rank: this.actor.data.data.identity.school_rank,
school_rank: this.actor.system.identity.school_rank,
},
},
});
@@ -314,7 +314,7 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
event.preventDefault();
event.stopPropagation();
const actorJournal = this.actor.data.data.identity.school_curriculum_journal;
const actorJournal = this.actor.system.identity.school_curriculum_journal;
if (!actorJournal.id) {
return;
}

View File

@@ -24,7 +24,7 @@ export class NpcSheetL5r5e extends BaseCharacterSheetL5r5e {
*/
_getL5rHeaderButtons() {
const buttons = super._getL5rHeaderButtons();
if (!this.isEditable || this.actor.limited || this.actor.data.data.soft_locked) {
if (!this.isEditable || this.actor.limited || this.actor.system.soft_locked) {
return buttons;
}
@@ -41,11 +41,11 @@ export class NpcSheetL5r5e extends BaseCharacterSheetL5r5e {
}
/** @inheritdoc */
getData(options = {}) {
const sheetData = super.getData();
async getData(options = {}) {
const sheetData = await super.getData();
// NPC Subtypes
sheetData.data.data.types = NpcSheetL5r5e.types.map((e) => ({
sheetData.data.types = NpcSheetL5r5e.types.map((e) => ({
id: e,
label: game.i18n.localize("l5r5e.character_types." + e),
}));

View File

@@ -145,7 +145,7 @@ export class TwentyQuestionsDialog extends FormApplication {
const skillsListStep7 = this._getSkillZero(skillsList, skillsPoints, "step7.skill");
const skillsListStep17 = this._getSkillZero(skillsList, skillsPoints, "step17.skill");
return {
...super.getData(options),
...(await super.getData(options)),
ringsList: game.l5r5e.HelpersL5r5e.getRingsList(),
skillsList,
skillsListStep7,
@@ -260,20 +260,20 @@ export class TwentyQuestionsDialog extends FormApplication {
// Get item
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (item.documentName !== "Item" || !item) {
console.warn(`L5R5E | Forbidden item for this drop zone ${type} : ${item.data.type}`);
console.warn(`L5R5E | Forbidden item for this drop zone ${type} : ${item.type}`);
return;
}
// Specific step18_heritage, all item/tech allowed
if (stepKey === "step18.heritage_item") {
type = item.data.type;
type = item.type;
}
if (
(type !== "item" && item.data.type !== type) ||
(type === "item" && !["item", "weapon", "armor"].includes(item.data.type))
(type !== "item" && item.type !== type) ||
(type === "item" && !["item", "weapon", "armor"].includes(item.type))
) {
console.warn(`L5R5E | Forbidden item for this drop zone ${type} : ${item.data.type}`);
console.warn(`L5R5E | Forbidden item for this drop zone ${type} : ${item.type}`);
return;
}
@@ -284,13 +284,13 @@ export class TwentyQuestionsDialog extends FormApplication {
case "technique":
// School Ability
if (stepKey === "step3.school_ability") {
if (item.data.data.technique_type !== "school_ability") {
if (item.system.technique_type !== "school_ability") {
console.warn(
`L5R5E | This technique is not a school ability : ${item.data.data.technique_type}`
`L5R5E | This technique is not a school ability : ${item.system.technique_type}`
);
return;
}
} else if (!this.object.data.step3.allowed_techniques?.[item.data.data.technique_type]) {
} else if (!this.object.data.step3.allowed_techniques?.[item.system.technique_type]) {
// Tech not allowed
ui.notifications.info(game.i18n.localize("l5r5e.techniques.not_allowed"));
return;
@@ -300,38 +300,38 @@ export class TwentyQuestionsDialog extends FormApplication {
case "peculiarity":
switch (stepKey) {
case "step9.distinction":
if (item.data.data.peculiarity_type !== "distinction") {
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
if (item.system.peculiarity_type !== "distinction") {
console.warn("L5R5E | Wrong type", item.system.peculiarity_type);
return;
}
break;
case "step10.adversity":
if (item.data.data.peculiarity_type !== "adversity") {
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
if (item.system.peculiarity_type !== "adversity") {
console.warn("L5R5E | Wrong type", item.system.peculiarity_type);
return;
}
break;
case "step11.passion":
if (item.data.data.peculiarity_type !== "passion") {
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
if (item.system.peculiarity_type !== "passion") {
console.warn("L5R5E | Wrong type", item.system.peculiarity_type);
return;
}
break;
case "step12.anxiety":
if (item.data.data.peculiarity_type !== "anxiety") {
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
if (item.system.peculiarity_type !== "anxiety") {
console.warn("L5R5E | Wrong type", item.system.peculiarity_type);
return;
}
break;
case "step13.advantage":
if (!["distinction", "passion"].includes(item.data.data.peculiarity_type)) {
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
if (!["distinction", "passion"].includes(item.system.peculiarity_type)) {
console.warn("L5R5E | Wrong type", item.system.peculiarity_type);
return;
}
break;
case "step13.disadvantage":
if (!["adversity", "anxiety"].includes(item.data.data.peculiarity_type)) {
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
if (!["adversity", "anxiety"].includes(item.system.peculiarity_type)) {
console.warn("L5R5E | Wrong type", item.system.peculiarity_type);
return;
}
break;
@@ -391,9 +391,9 @@ export class TwentyQuestionsDialog extends FormApplication {
this.summary = this.object.validateForm();
// Store this form datas in actor
this.actor.data.data.twenty_questions = this.object.data;
this.actor.system.twenty_questions = this.object.data;
await this.actor.update({
data: {
system: {
template: formData["template"],
twenty_questions: this.object.data,
},

View File

@@ -191,10 +191,10 @@ export class TwentyQuestions {
* Initialize data from a actor
*/
fromActor(actor) {
const actorDatas = actor.data.data;
const actorDatas = actor.system;
// already 20q struct ?
if (!foundry.utils.isObjectEmpty(actorDatas.twenty_questions)) {
if (!foundry.utils.isEmpty(actorDatas.twenty_questions)) {
this.data = {
...this.data,
...actorDatas.twenty_questions,
@@ -220,14 +220,14 @@ export class TwentyQuestions {
this.data.step6.social_ninjo = actorDatas.social.ninjo;
this.data.step8.tenet_paramount = actorDatas.social.bushido_tenets.paramount;
this.data.step8.tenet_less_significant = actorDatas.social.bushido_tenets.less_significant;
this.data.step19.firstname = actor.data.name.replace(/^(?:\w+\s+)?(.+)$/gi, "$1") || "";
this.data.step19.firstname = actor.name.replace(/^(?:\w+\s+)?(.+)$/gi, "$1") || "";
}
/**
* Fill a actor data from this object
*/
async toActor(actor, itemsCache) {
const actorDatas = actor.data.data;
const actorDatas = actor.system;
const formData = this.data;
this.data.generated = true;
@@ -304,7 +304,7 @@ export class TwentyQuestions {
});
// Clear and add items to actor
const deleteIds = actor.data.items.map((e) => e.id);
const deleteIds = actor.items.map((e) => e.id);
if (deleteIds.length > 0) {
await actor.deleteEmbeddedDocuments("Item", deleteIds);
}
@@ -330,7 +330,7 @@ export class TwentyQuestions {
// Update actor
await actor.update({
name: ((formData.template !== "pow" ? formData.step2.family + " " : "") + formData.step19.firstname).trim(),
data: actorDatas,
system: actorDatas,
});
}