diff --git a/client/src/services/PluginGlobals.js b/client/src/services/PluginGlobals.js new file mode 100644 index 00000000..ae4a074c --- /dev/null +++ b/client/src/services/PluginGlobals.js @@ -0,0 +1,13 @@ +// We store it in window because i don't know somewhere else to +// store global variables + +const Global = (plugin) => { + if(window['__DRAGONROLL'] === undefined) window['__DRAGONROLL'] = {}; + if(window['__DRAGONROLL'][plugin] === undefined) window['__DRAGONROLL'][plugin] = {}; + + return window.__DRAGONROLL[plugin]; +} + +export { + Global +} \ No newline at end of file diff --git a/plugins/dnd-5e/client/data.js b/plugins/dnd-5e/client/data.js index efc2822a..560c8d8d 100644 --- a/plugins/dnd-5e/client/data.js +++ b/plugins/dnd-5e/client/data.js @@ -1,16 +1,17 @@ import Server from '@/services/Server' import { reactive } from 'vue'; +import { Global } from '@/services/PluginGlobals'; import { GetCampaign } from "@/services/Dragonroll"; let data = reactive({}); -let Api; -let dndModule; +let Api = Global('dnd-5e')['api']; +let dndModule = Global('dnd-5e')['dndModule']; -function InitData(api, module){ - Api = api; - dndModule = module; +function InitData(){ + Api = Global('dnd-5e')['api']; + dndModule = Global('dnd-5e')['dndModule']; data.value = { concepts: [] diff --git a/plugins/dnd-5e/client/main.js b/plugins/dnd-5e/client/main.js index 918c6f6c..0bfb1434 100644 --- a/plugins/dnd-5e/client/main.js +++ b/plugins/dnd-5e/client/main.js @@ -1,12 +1,10 @@ import { FetchConcepts, FetchData, InitData } from "./data"; +import { Global } from '@/services/PluginGlobals'; -// Entrypoint -let Api; -let dndModule; - -function Main(api){ - Api = api +var dndModule; +function Main(Api){ + Global('dnd-5e')['api'] = Api; console.log("Module registered!"); dndModule = Api.createModule('dnd-5e'); @@ -66,11 +64,14 @@ function Main(api){ // Api.windows.registerWindow('create_item_prompt', Api.createView('CreateItemPrompt')); dndModule.onInit = () => { - InitData(Api, dndModule); + InitData(); FetchData(); } Api.registerModule(dndModule); + + + Global('dnd-5e')['dndModule'] = dndModule; } export {