mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-30 02:31:41 -04:00
[#35] Use different ID attributes for sidebar documents depending on foundry version.
This commit is contained in:
parent
e966775723
commit
84562bd9c2
3 changed files with 15 additions and 12 deletions
|
@ -532,7 +532,7 @@ export class EntitySheetHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the document creation form
|
// Render the document creation form
|
||||||
const useEntity = foundry.utils.isNewerVersion("9", game.version ?? game.data.version);
|
const useEntity = game.worldbuilding.useEntity;
|
||||||
const template = `templates/sidebar/${useEntity ? "entity" : "document" }-create.html`;
|
const template = `templates/sidebar/${useEntity ? "entity" : "document" }-create.html`;
|
||||||
const html = await renderTemplate(template, {
|
const html = await renderTemplate(template, {
|
||||||
name: data.name || game.i18n.format("DOCUMENT.New", {type: label}),
|
name: data.name || game.i18n.format("DOCUMENT.New", {type: label}),
|
||||||
|
|
|
@ -32,7 +32,8 @@ Hooks.once("init", async function() {
|
||||||
|
|
||||||
game.worldbuilding = {
|
game.worldbuilding = {
|
||||||
SimpleActor,
|
SimpleActor,
|
||||||
createWorldbuildingMacro
|
createWorldbuildingMacro,
|
||||||
|
useEntity: foundry.utils.isNewerVersion("9", game.version ?? game.data.version)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define custom Document classes
|
// Define custom Document classes
|
||||||
|
@ -104,16 +105,17 @@ Hooks.on("hotbarDrop", (bar, data, slot) => createWorldbuildingMacro(data, slot)
|
||||||
* Adds the actor template context menu.
|
* Adds the actor template context menu.
|
||||||
*/
|
*/
|
||||||
Hooks.on("getActorDirectoryEntryContext", (html, options) => {
|
Hooks.on("getActorDirectoryEntryContext", (html, options) => {
|
||||||
|
const idAttr = game.worldbuilding.useEntity ? "entityId" : "documentId";
|
||||||
// Define an actor as a template.
|
// Define an actor as a template.
|
||||||
options.push({
|
options.push({
|
||||||
name: game.i18n.localize("SIMPLE.DefineTemplate"),
|
name: game.i18n.localize("SIMPLE.DefineTemplate"),
|
||||||
icon: '<i class="fas fa-stamp"></i>',
|
icon: '<i class="fas fa-stamp"></i>',
|
||||||
condition: li => {
|
condition: li => {
|
||||||
const actor = game.actors.get(li.data("documentId"));
|
const actor = game.actors.get(li.data(idAttr));
|
||||||
return !actor.getFlag("worldbuilding", "isTemplate");
|
return !actor.getFlag("worldbuilding", "isTemplate");
|
||||||
},
|
},
|
||||||
callback: li => {
|
callback: li => {
|
||||||
const actor = game.actors.get(li.data("documentId"));
|
const actor = game.actors.get(li.data(idAttr));
|
||||||
actor.setFlag("worldbuilding", "isTemplate", true);
|
actor.setFlag("worldbuilding", "isTemplate", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -123,11 +125,11 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
|
||||||
name: game.i18n.localize("SIMPLE.UnsetTemplate"),
|
name: game.i18n.localize("SIMPLE.UnsetTemplate"),
|
||||||
icon: '<i class="fas fa-times"></i>',
|
icon: '<i class="fas fa-times"></i>',
|
||||||
condition: li => {
|
condition: li => {
|
||||||
const actor = game.actors.get(li.data("documentId"));
|
const actor = game.actors.get(li.data(idAttr));
|
||||||
return actor.getFlag("worldbuilding", "isTemplate");
|
return actor.getFlag("worldbuilding", "isTemplate");
|
||||||
},
|
},
|
||||||
callback: li => {
|
callback: li => {
|
||||||
const actor = game.actors.get(li.data("documentId"));
|
const actor = game.actors.get(li.data(idAttr));
|
||||||
actor.setFlag("worldbuilding", "isTemplate", false);
|
actor.setFlag("worldbuilding", "isTemplate", false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -137,16 +139,17 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
|
||||||
* Adds the item template context menu.
|
* Adds the item template context menu.
|
||||||
*/
|
*/
|
||||||
Hooks.on("getItemDirectoryEntryContext", (html, options) => {
|
Hooks.on("getItemDirectoryEntryContext", (html, options) => {
|
||||||
|
const idAttr = game.worldbuilding.useEntity ? "entityId" : "documentId";
|
||||||
// Define an item as a template.
|
// Define an item as a template.
|
||||||
options.push({
|
options.push({
|
||||||
name: game.i18n.localize("SIMPLE.DefineTemplate"),
|
name: game.i18n.localize("SIMPLE.DefineTemplate"),
|
||||||
icon: '<i class="fas fa-stamp"></i>',
|
icon: '<i class="fas fa-stamp"></i>',
|
||||||
condition: li => {
|
condition: li => {
|
||||||
const item = game.items.get(li.data("documentId"));
|
const item = game.items.get(li.data(idAttr));
|
||||||
return !item.getFlag("worldbuilding", "isTemplate");
|
return !item.getFlag("worldbuilding", "isTemplate");
|
||||||
},
|
},
|
||||||
callback: li => {
|
callback: li => {
|
||||||
const item = game.items.get(li.data("documentId"));
|
const item = game.items.get(li.data(idAttr));
|
||||||
item.setFlag("worldbuilding", "isTemplate", true);
|
item.setFlag("worldbuilding", "isTemplate", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -156,11 +159,11 @@ Hooks.on("getItemDirectoryEntryContext", (html, options) => {
|
||||||
name: game.i18n.localize("SIMPLE.UnsetTemplate"),
|
name: game.i18n.localize("SIMPLE.UnsetTemplate"),
|
||||||
icon: '<i class="fas fa-times"></i>',
|
icon: '<i class="fas fa-times"></i>',
|
||||||
condition: li => {
|
condition: li => {
|
||||||
const item = game.items.get(li.data("documentId"));
|
const item = game.items.get(li.data(idAttr));
|
||||||
return item.getFlag("worldbuilding", "isTemplate");
|
return item.getFlag("worldbuilding", "isTemplate");
|
||||||
},
|
},
|
||||||
callback: li => {
|
callback: li => {
|
||||||
const item = game.items.get(li.data("documentId"));
|
const item = game.items.get(li.data(idAttr));
|
||||||
item.setFlag("worldbuilding", "isTemplate", false);
|
item.setFlag("worldbuilding", "isTemplate", false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "worldbuilding",
|
"name": "worldbuilding",
|
||||||
"title": "Simple World-Building",
|
"title": "Simple World-Building",
|
||||||
"description": "A minimalist game system which provides configurable Actor and Item templates to support free-form system agnostic game-play.",
|
"description": "A minimalist game system which provides configurable Actor and Item templates to support free-form system agnostic game-play.",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"minimumCoreVersion": "0.8.9",
|
"minimumCoreVersion": "0.8.9",
|
||||||
"compatibleCoreVersion": "9",
|
"compatibleCoreVersion": "9",
|
||||||
"author": "Atropos",
|
"author": "Atropos",
|
||||||
|
@ -22,6 +22,6 @@
|
||||||
"secondaryTokenAttribute": "power",
|
"secondaryTokenAttribute": "power",
|
||||||
"url": "https://gitlab.com/foundrynet/worldbuilding/",
|
"url": "https://gitlab.com/foundrynet/worldbuilding/",
|
||||||
"manifest": "https://gitlab.com/foundrynet/worldbuilding/raw/0.6.x/system.json",
|
"manifest": "https://gitlab.com/foundrynet/worldbuilding/raw/0.6.x/system.json",
|
||||||
"download": "https://gitlab.com/foundrynet/worldbuilding/-/archive/release-060/worldbuilding-release-060.zip",
|
"download": "https://gitlab.com/foundrynet/worldbuilding/-/archive/release-061/worldbuilding-release-061.zip",
|
||||||
"license": "LICENSE.txt"
|
"license": "LICENSE.txt"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue