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

@@ -41,9 +41,9 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
return;
}
// const currentType = this.object.data.data.advancement_type;
const currentRing = this.object.data.data.ring;
const currentSkill = this.object.data.data.skill;
// const currentType = this.object.system.advancement_type;
const currentRing = this.object.system.ring;
const currentSkill = this.object.system.skill;
html.find("#advancement_type").on("change", (event) => {
$(event.target).prop("disabled", true);
@@ -78,9 +78,9 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
* @private
*/
async _updateChoice(oldChoice, newChoice) {
let xp_used = this.object.data.data.xp_used;
let name = this.object.data.name;
let img = this.object.data.img;
let xp_used = this.object.system.xp_used;
let name = this.object.name;
let img = this.object.img;
// Modify image to reflect choice
if (newChoice.ring) {
@@ -96,7 +96,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
// Object embed in actor ?
const actor = this.document.actor;
if (actor) {
const actorData = foundry.utils.duplicate(actor.data.data);
const actorData = foundry.utils.duplicate(actor.system);
let skillCatId = null;
// Old choices
@@ -132,7 +132,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
// Update Actor
await actor.update({
data: foundry.utils.diffObject(actor.data.data, actorData),
system: foundry.utils.diffObject(actor.system, actorData),
});
}
@@ -140,7 +140,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
await this.object.update({
name: name,
img: img,
data: {
system: {
xp_used: xp_used,
},
});

View File

@@ -27,7 +27,7 @@ export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
* @private
*/
_initialize() {
const data = this.object.data.data;
const data = this.object.system;
// update linked actor datas
if (data.leader_actor_id) {
@@ -40,6 +40,20 @@ export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
}
}
/**
* @return {Object|Promise}
*/
async getData(options = {}) {
const sheetData = await super.getData(options);
// Editors enrichment
sheetData.data.enrichedHtml.abilities = await TextEditor.enrichHTML(sheetData.data.system.abilities, {
async: true,
});
return sheetData;
}
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
@@ -49,10 +63,10 @@ export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
*/
activateEditor(name, options = {}, initialContent = "") {
// Symbols Compatibility with old compendium modules (PRE l5r v1.7.2)
if (name === "data.abilities" && initialContent) {
if (name === "system.abilities" && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
return super.activateEditor(name, options, initialContent);
}
/**
@@ -100,15 +114,15 @@ export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
*/
async _updateLinkedActorData(actor) {
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;
}
return this.object.update({
img: actor.data.img,
data: {
leader: actor.data.name,
leader_actor_id: actor.data._id,
img: actor.img,
system: {
leader: actor.name,
leader_actor_id: actor._id,
},
});
}
@@ -120,7 +134,7 @@ export class ArmyCohortSheetL5r5e extends ItemSheetL5r5e {
*/
async _removeLinkedActor() {
return this.object.update({
data: {
system: {
leader_actor_id: null,
},
});

View File

@@ -62,10 +62,10 @@ export class BaseItemSheetL5r5e extends ItemSheet {
*/
activateEditor(name, options = {}, initialContent = "") {
// Symbols Compatibility with old compendium modules (PRE l5r v1.7.2)
if (name === "data.description" && initialContent) {
if (name === "system.description" && initialContent) {
initialContent = game.l5r5e.HelpersL5r5e.convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
return super.activateEditor(name, options, initialContent);
}
/**

View File

@@ -33,15 +33,15 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e {
* @return {Promise<null|{name, id}>}
*/
async getLinkedProperty(sheetData) {
if (sheetData.data.data.linked_property_id) {
if (sheetData.data.system.linked_property_id) {
const linkedProperty = await game.l5r5e.HelpersL5r5e.getObjectGameOrPack({
id: sheetData.data.data.linked_property_id,
id: sheetData.data.system.linked_property_id,
type: "Item",
});
if (linkedProperty) {
return {
id: linkedProperty.data._id,
name: linkedProperty.data.name,
id: linkedProperty._id,
name: linkedProperty.name,
};
}
}
@@ -77,15 +77,15 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e {
// Only property allowed here
let item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || item.documentName !== "Item" || item.data.type !== "property") {
if (!item || item.documentName !== "Item" || item.type !== "property") {
return;
}
// Set the new property, and update
this.document.data.data.linked_property_id = item.id;
this.document.system.linked_property_id = item.id;
this.document.update({
data: {
linked_property_id: this.document.data.data.linked_property_id,
system: {
linked_property_id: this.document.system.linked_property_id,
},
});
}
@@ -102,18 +102,18 @@ export class ItemPatternSheetL5r5e extends ItemSheetL5r5e {
let name;
const linkedProperty = await game.l5r5e.HelpersL5r5e.getObjectGameOrPack({
id: this.document.data.data.linked_property_id,
id: this.document.system.linked_property_id,
type: "Item",
});
if (linkedProperty) {
name = linkedProperty.data.name;
name = linkedProperty.name;
}
const callback = async () => {
this.document.data.data.linked_property_id = null;
this.document.system.linked_property_id = null;
this.document.update({
data: {
linked_property_id: this.document.data.data.linked_property_id,
system: {
linked_property_id: this.document.system.linked_property_id,
},
});
};

View File

@@ -27,6 +27,11 @@ export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
// Prepare Properties (id/name => object)
await this._prepareProperties(sheetData);
// Editors enrichment
sheetData.data.enrichedHtml = {
description: await TextEditor.enrichHTML(sheetData.data.system.description, { async: true }),
};
return sheetData;
}
@@ -37,9 +42,9 @@ export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
async _prepareProperties(sheetData) {
sheetData.data.propertiesList = [];
if (Array.isArray(sheetData.data.data.properties)) {
if (Array.isArray(sheetData.data.system.properties)) {
const props = [];
for (const property of sheetData.data.data.properties) {
for (const property of sheetData.data.system.properties) {
const gameProp = await game.l5r5e.HelpersL5r5e.getObjectGameOrPack({ id: property.id, type: "Item" });
if (gameProp) {
sheetData.data.propertiesList.push(gameProp);
@@ -56,7 +61,7 @@ export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
});
}
}
sheetData.data.data.properties = props;
sheetData.data.system.properties = props;
}
}
@@ -114,15 +119,15 @@ export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
}
// Specific ItemPattern's drop, get the associated props instead
if (item.data.type === "item_pattern" && item.data.data.linked_property_id) {
if (item.type === "item_pattern" && item.system.linked_property_id) {
item = await game.l5r5e.HelpersL5r5e.getObjectGameOrPack({
id: item.data.data.linked_property_id,
id: item.system.linked_property_id,
type: "Item",
});
}
// Final object has to be a property
if (item.data.type !== "property") {
if (item.type !== "property") {
return;
}
@@ -136,27 +141,27 @@ export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
* @private
*/
_addProperty(item) {
if (!Array.isArray(this.document.data.data.properties)) {
this.document.data.data.properties = [];
if (!Array.isArray(this.document.system.properties)) {
this.document.system.properties = [];
}
if (this.document.data.data.properties.findIndex((p) => p.id === item.id) !== -1) {
if (this.document.system.properties.findIndex((p) => p.id === item.id) !== -1) {
return;
}
this.document.data.data.properties.push({ id: item.id, name: item.name });
this.document.system.properties.push({ id: item.id, name: item.name });
// This props remove others ?
if (Array.isArray(item.data.data.properties) && item.data.data.properties.length > 0) {
const idsToRemove = item.data.data.properties.map((e) => e.id);
this.document.data.data.properties = this.document.data.data.properties.filter(
if (Array.isArray(item.system.properties) && item.system.properties.length > 0) {
const idsToRemove = item.system.properties.map((e) => e.id);
this.document.system.properties = this.document.system.properties.filter(
(p) => !idsToRemove.includes(p.id)
);
}
this.document.update({
data: {
properties: this.document.data.data.properties,
system: {
properties: this.document.system.properties,
},
});
}
@@ -171,21 +176,21 @@ export class ItemSheetL5r5e extends BaseItemSheetL5r5e {
event.preventDefault();
event.stopPropagation();
if (!Array.isArray(this.document.data.data.properties)) {
if (!Array.isArray(this.document.system.properties)) {
return;
}
const id = $(event.currentTarget).parents(".property").data("propertyId");
const tmpProps = this.document.data.data.properties.find((p) => p.id === id);
const tmpProps = this.document.system.properties.find((p) => p.id === id);
if (!tmpProps) {
return;
}
const callback = async () => {
this.document.data.data.properties = this.document.data.data.properties.filter((p) => p.id !== id);
this.document.system.properties = this.document.system.properties.filter((p) => p.id !== id);
this.document.update({
data: {
properties: this.document.data.data.properties,
system: {
properties: this.document.system.properties,
},
});
};

View File

@@ -27,9 +27,9 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
sheetData.data.techniquesList = game.l5r5e.HelpersL5r5e.getTechniquesList({ types });
// Sanitize Difficulty and Skill list
sheetData.data.data.difficulty = TechniqueSheetL5r5e.formatDifficulty(sheetData.data.data.difficulty);
sheetData.data.data.skill = TechniqueSheetL5r5e.translateSkillsList(
TechniqueSheetL5r5e.formatSkillList(sheetData.data.data.skill.split(",")),
sheetData.data.system.difficulty = TechniqueSheetL5r5e.formatDifficulty(sheetData.data.system.difficulty);
sheetData.data.system.skill = TechniqueSheetL5r5e.translateSkillsList(
TechniqueSheetL5r5e.formatSkillList(sheetData.data.system.skill.split(",")),
false
).join(", ");
@@ -46,16 +46,16 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
async _updateObject(event, formData) {
// Change the image according to the type if this is already the case
if (
formData["data.technique_type"] &&
formData.img === `${CONFIG.l5r5e.paths.assets}icons/techs/${this.object.data.data.technique_type}.svg`
formData["system.technique_type"] &&
formData.img === `${CONFIG.l5r5e.paths.assets}icons/techs/${this.object.system.technique_type}.svg`
) {
formData.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${formData["data.technique_type"]}.svg`;
formData.img = `${CONFIG.l5r5e.paths.assets}icons/techs/${formData["system.technique_type"]}.svg`;
}
// Sanitize Difficulty and Skill list
formData["data.difficulty"] = TechniqueSheetL5r5e.formatDifficulty(formData["data.difficulty"]);
formData["data.skill"] = TechniqueSheetL5r5e.formatSkillList(
TechniqueSheetL5r5e.translateSkillsList(formData["data.skill"].split(","), true)
formData["system.difficulty"] = TechniqueSheetL5r5e.formatDifficulty(formData["system.difficulty"]);
formData["system.skill"] = TechniqueSheetL5r5e.formatSkillList(
TechniqueSheetL5r5e.translateSkillsList(formData["system.skill"].split(","), true)
).join(",");
return super._updateObject(event, formData);
@@ -77,7 +77,7 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
// Autocomplete
game.l5r5e.HelpersL5r5e.autocomplete(
html,
"data.difficulty",
"system.difficulty",
[
"@T:intrigueRank",
"@T:focus",
@@ -93,7 +93,7 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
);
game.l5r5e.HelpersL5r5e.autocomplete(
html,
"data.skill",
"system.skill",
Object.values(TechniqueSheetL5r5e.getSkillsTranslationMap(false)),
","
);

View File

@@ -22,12 +22,12 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
const sheetData = await super.getData(options);
// Prepare OwnedItems
sheetData.data.embedItemsList = this._prepareEmbedItems(sheetData.data.data.items);
sheetData.data.embedItemsList = this._prepareEmbedItems(sheetData.data.system.items);
// Automatically compute the total xp cost (full price) and XP in title (cursus, some halved prices)
const { xp_used_total, xp_used } = game.l5r5e.HelpersL5r5e.getItemsXpCost(sheetData.data.embedItemsList);
sheetData.data.data.xp_used_total = xp_used_total;
sheetData.data.data.xp_used = xp_used;
sheetData.data.system.xp_used_total = xp_used_total;
sheetData.data.system.xp_used = xp_used;
return sheetData;
}
@@ -41,11 +41,11 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
_prepareEmbedItems(itemsMap) {
let itemsList = itemsMap;
if (itemsMap instanceof Map) {
itemsList = Array.from(itemsMap).map(([id, item]) => item.data);
itemsList = Array.from(itemsMap).map(([id, item]) => item);
}
// Sort by rank desc
itemsList.sort((a, b) => (b.data.rank || 0) - (a.data.rank || 0));
itemsList.sort((a, b) => (b.system.rank || 0) - (a.system.rank || 0));
return itemsList;
}
@@ -63,16 +63,16 @@ 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.type)) {
return;
}
const data = item.data.toObject(false);
const data = item.toObject(false);
// 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;
if (item.type === "technique") {
data.system.xp_cost = data.system.xp_cost > 0 ? data.system.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
data.system.xp_used = data.system.xp_cost;
}
this.document.addEmbedItem(data);
@@ -146,7 +146,7 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
}
// Switch the state and update
item.data.data.in_curriculum = !item.data.data.in_curriculum;
item.system.in_curriculum = !item.system.in_curriculum;
return this.document.updateEmbedItem(item);
}
}