Skip to content

Commit

Permalink
Merge pull request #3 from Kekilla0/9.235
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Kekilla0 authored Dec 11, 2021
2 parents 6b48411 + 42a41da commit fad5175
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"kekilla#7036"
],
"version" : "",
"minimumCoreVersion" : "0.8.0",
"compatibleCoreVersion" : "0.8.9",
"minimumCoreVersion" : "9.235",
"compatibleCoreVersion" : "9.235",
"esmodules" : [
"scripts/hooks.js"
],
Expand All @@ -23,7 +23,7 @@
"name" : "macros",
"label" : "World Scripter Macros",
"path" : "packs/wsMacros.db",
"entity" : "Macro",
"type" : "Macro",
"module" : "world-scripter"
}
],
Expand Down
15 changes: 11 additions & 4 deletions scripts/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import { settings } from './settings.js';
import { scripter } from './scripter.js';

logger.info("Initializing Module");

//CONFIG.debug.hooks = true;

Hooks.on('init', settings.register);
Hooks.on('ready', scripter.execute_pack);
Hooks.on('getMacroDirectoryEntryContext', scripter.add_context);
Hooks.on('getMacroDirectoryEntryContext', (html, options) =>scripter.add_context("MacroDirectory", options));
Hooks.on('getHotbarEntryContext', (html, options) => scripter.add_context("HotBar", options));


/*
Fixes :
TODO Fixes :
Macro Execution => Async
setting module builder => add
settingsData => change how settings work
change update scheme to mirror item/note macro
Ideas :
Add context menu to macro bar
TODO Ideas :
Update Notes :
Added context menu to macro hot bar
Updated compatibility for 9.X
*/
17 changes: 11 additions & 6 deletions scripts/scripter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ export class scripter{
}
}

static add_context(html, contextOptions){
static add_context(origin, contextOptions){
logger.info("Adding Context Menu Items");

const callback = origin == "HotBar"
? (li) => scripter.add_To_Compendium(li?.data("macroId"))
: (li) => scripter.add_To_Compendium(li?.data("documentId"));

contextOptions.push({
name : `${settings.i18n("context.PreTitle")} ${settings.TITLE} ${settings.i18n("context.PostTitle")}`,
icon : '<i class="fas fa-download"></i>',
condition : () => game.user.isGM,
callback : li => scripter.add_To_Compendium(li?.data("entityId")),
callback,
});
}

Expand All @@ -46,14 +51,14 @@ export class scripter{
if(!pack) return logger.error(`${settings.TITLE} ${settings.i18n("error.scriptMissing")}`);

let status = pack.locked;
if(!status) pack.configure({ locked : !status });
if(status) pack.configure({ locked : false });

let index = await pack.getIndex();
if(index.find(ele => ele.name === macro.name))
await pack.updateEntity({_id : index.find(ele => ele.name === macro.name)._id, command : macro.data.command });
await (await pack.getDocument(index.find(ele => ele.name === macro.name)._id)).update({ command : macro.data.command }, { pack : pack.collection });
else
await pack.createEntity(macro.data);
await pack.documentClass.create(macro.data, { pack : pack.collection });

if(!status) pack.configure({ locked : status });
if(status) pack.configure({ locked : true });
}
}

0 comments on commit fad5175

Please sign in to comment.