From d4f1f631cd7fe62c4f4e96e96af746d15d00f733 Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Wed, 16 Oct 2024 11:48:50 +0200 Subject: [PATCH] =?UTF-8?q?Ok=20communications=20work,=20falta=20passar=20?= =?UTF-8?q?alguna=20forma=20de=20comunicar=20el=20Api=20object=20b=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/api.js | 13 +++--- client/src/services/Api.js | 42 +++++++++++++++----- client/src/services/Game.js | 3 +- client/src/views/HomeView.vue | 2 +- client/src/views/partials/MarkdownEditor.vue | 2 +- plugins/dnd-5e/backend/main.js | 23 +++++++---- plugins/dnd-5e/client/data.js | 16 +++++--- plugins/dnd-5e/client/main.js | 8 +--- 8 files changed, 72 insertions(+), 37 deletions(-) diff --git a/backend/services/api.js b/backend/services/api.js index 79777d2a..e0cefd38 100644 --- a/backend/services/api.js +++ b/backend/services/api.js @@ -22,8 +22,8 @@ class BackendApi { this.#_plugin = plugin; this.#_expressRouter = router; this.#_internalSocket = internalSocket; - this.#_socket = new BackendSocket(`plugin/${plugin.package}`, internalSocket); - this.#_router = new BackendRouter(`plugin/${plugin.package}`, this.#_expressRouter); + this.#_socket = new BackendSocket(`plugins/${plugin.package}`, internalSocket); + this.#_router = new BackendRouter(`${plugin.package}`, this.#_expressRouter); } /** @@ -136,8 +136,8 @@ class BackendModule { this.#_plugin = plugin; this.#_id = id; this.#_internalSocket = internalSocket; - this.#_router = new BackendRouter(`module/${plugin.package}/${id}`, expressRouter) - this.#_socket = new BackendSocket(`module/${plugin.package}/${id}`, this.#_internalSocket); + this.#_router = new BackendRouter(`${plugin.package}/_module/${id}`, expressRouter) + this.#_socket = new BackendSocket(`plugins/${plugin.package}/${id}`, this.#_internalSocket); } get router(){ @@ -149,8 +149,11 @@ class BackendModule { } // Creates a model for the Module + // it also includes the campaign id for later on createModel(name, schema){ - return new BackendModel(name, `${this.#_plugin.package}/${this.#_id}`, schema); + return new BackendModel(name, `${this.#_plugin.package}/${this.#_id}`, {...{ + campaign: { type: "ObjectId", ref: "Campaign"} + }, ...schema}); } } diff --git a/client/src/services/Api.js b/client/src/services/Api.js index 480064b4..e7d9119b 100644 --- a/client/src/services/Api.js +++ b/client/src/services/Api.js @@ -25,10 +25,10 @@ class ClientApi { */ constructor(plugin){ this.#_plugin = plugin - this.#_router = new ClientRouter(`/plugin/${plugin.package}`) - this.#_baseRouter = new ClientRouter("") + this.#_router = new ClientRouter(`/plugins/${plugin.package}`, {}) + this.#_baseRouter = new ClientRouter("", {}) this.#_windows = new ClientWindows(plugin.package) - this.#_socket = new ClientSocket(plugin.package) + this.#_socket = new ClientSocket(`plugins/${plugin.package}`) } /** @@ -158,10 +158,12 @@ class ClientModule { #_socket; #_exit; + #_campaign; + constructor(plugin, id){ this.#_plugin = plugin; this.#_id = id; - this.#_router = new ClientRouter(`/module/${plugin.package}/${id}`); + this.#_router = new ClientRouter(`/plugins/${plugin.package}/_module/${id}`, {}); this.#_socket = new ClientSocket(`${plugin.package}/${id}`) } @@ -169,7 +171,13 @@ class ClientModule { this.#_previewData = data; } - set onInit(init){ this.#_init = init; } + set onInit(init){ this.#_init = (campaign) => { + this.#_campaign = campaign; + this.#_router._setParam("campaign", campaign._id); + console.log(campaign); + init(); + }; + } set onExit(exit){ this.#_exit = exit; } @@ -256,19 +264,35 @@ class ClientRouter { } get(route, query){ - return Server().get(`${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`); + if(route.startsWith('/')) route = route.substring(1, route.length); + let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; + console.log("GET " + f); + return Server().get(f); } post(route, query, data = {}){ - return Server().post(`${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`, data); + if(route.startsWith('/')) route = route.substring(1, route.length); + let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; + console.log("POST " + f); + return Server().post(f, data); } put(route, query, data = {}){ - return Server().put(`${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`, data); + if(route.startsWith('/')) route = route.substring(1, route.length); + let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; + console.log("PUT " + f); + return Server().put(f, data); } delete(route, query){ - return Server().delete(`${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`); + if(route.startsWith('/')) route = route.substring(1, route.length); + let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; + console.log("DELETE " + f); + return Server().delete(f); + } + + _setParam(key, value){ + this.#_defParams[key] = value; } } diff --git a/client/src/services/Game.js b/client/src/services/Game.js index e54c4f9b..052eaf80 100644 --- a/client/src/services/Game.js +++ b/client/src/services/Game.js @@ -1,12 +1,13 @@ import { ref } from "vue"; import { GetCampaignModule } from "./Campaign"; +import { GetCampaign } from "./Dragonroll"; const inGameRef = ref(false); let InGameRef = () => inGameRef; function LaunchGame(){ inGameRef.value = true; - GetCampaignModule().init(); + GetCampaignModule().init(GetCampaign()); } function ExitGame(){ diff --git a/client/src/views/HomeView.vue b/client/src/views/HomeView.vue index 8578fe57..1703add6 100644 --- a/client/src/views/HomeView.vue +++ b/client/src/views/HomeView.vue @@ -30,7 +30,7 @@ SetEmitter(emitter); async function DisplayFirstWindow(){ if(GetUser()){ - Server().get('/plugins/module/dnd-5e/dnd-5e/testing').then(res => {}) + Server().get('/plugins/dnd-5e/_module/dnd-5e/testing').then(res => {}) CreateWindow('main_menu'); return; } diff --git a/client/src/views/partials/MarkdownEditor.vue b/client/src/views/partials/MarkdownEditor.vue index 0f306a34..9a88fa3a 100644 --- a/client/src/views/partials/MarkdownEditor.vue +++ b/client/src/views/partials/MarkdownEditor.vue @@ -1,6 +1,6 @@