v12 fixes

- effect.icon to effect.img
- flags.core.sourceId to _stats.compendiumSource
- isLinkValid now use uuid
This commit is contained in:
Vlyan
2024-05-25 11:00:35 +02:00
parent 3b37859cb5
commit 47e040509f
5 changed files with 18 additions and 42 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -184,8 +184,8 @@ export class HelpersL5r5e {
// Final
if (document) {
// Flag the source GUID
if (document.uuid && !document.pack && !document.getFlag("core", "sourceId")) {
document.updateSource({ "flags.core.sourceId": document.uuid });
if (document.uuid && !document._stats?.compendiumSource) {
document.updateSource({ "_stats.compendiumSource": document.uuid });
}
// Care to infinite loop in properties
@@ -614,8 +614,8 @@ export class HelpersL5r5e {
// Create the link
let link = null;
if (document.flags.core?.sourceId) {
link = document.flags.core?.sourceId.replace(/(\w+)\.(.+)/, "@$1[$2]");
if (document._stats?.compendiumSource) {
link = document._stats.compendiumSource.replace(/(\w+)\.(.+)/, "@$1[$2]");
if (!HelpersL5r5e.isLinkValid(link)) {
link = null;
}
@@ -644,34 +644,10 @@ export class HelpersL5r5e {
* @param {string} link
* @return {boolean}
*/
static isLinkValid(link) {
static async isLinkValid(link) {
const [type, target] = link.replace(/@(\w+)\[([^\]]+)\].*/, "$1|$2").split("|");
// Get a matched World document
// "@Item[L5RCoreIte000042]{Amigasa}"
if (CONST.DOCUMENT_TYPES.includes(type)) {
const collection = game.collections.get(type);
const document = /^[a-zA-Z0-9]{16}$/.test(target) ? collection.get(target) : collection.getName(target);
return !!document;
}
// Get a matched Compendium entity
// "@Compendium[l5r5e.core-peculiarities-distinctions.L5RCoreDis000002]{Ambidextrie}"
if (type === "Compendium") {
// Get the linked Entity
const [scope, packName, id] = target.split(".");
const pack = game.packs.get(`${scope}.${packName}`);
if (!pack) {
return false;
}
// If the pack is indexed, check, if not assume it's ok
if (pack.index.size) {
const index = pack.index.find((i) => i._id === id || i.name === id);
return !!index;
}
}
return true;
const document = await fromUuid(`${type}.${target}`);
return !!document;
}
/**

View File

@@ -1,7 +1,7 @@
<ul class="effects">
{{#each actor.effects as |effect|}}
<li class="effect-container" title="{{name}}">
<div class="effect-icon" style="background-image: url({{effect.icon}})"></div>
<div class="effect-icon" style="background-image: url({{effect.img}})"></div>
<div class="effect-name"><label>{{name}}</label></div>
</li>
{{/each}}

View File

@@ -1,7 +1,7 @@
<ul class="effects">
{{#each actor.effects as |effect|}}
<li class="effect-container" title="{{name}}">
<div class="effect-icon" style="background-image: url({{effect.icon}})"></div>
<div class="effect-icon" style="background-image: url({{effect.img}})"></div>
<div class="effect-name"><label>{{name}}</label></div>
</li>
{{/each}}