From 0d0b322766a4eead3be3acea51757f110020e2a5 Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Wed, 16 Oct 2024 13:12:29 +0200 Subject: [PATCH] Ok so globals now are a thing --- client/src/services/PluginGlobals.js | 13 +++++++++++++ plugins/dnd-5e/client/data.js | 11 ++++++----- plugins/dnd-5e/client/main.js | 15 ++++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 client/src/services/PluginGlobals.js 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 {