diff --git a/client/src/services/Api.js b/client/src/services/Api.js index 5b662db0..64751779 100644 --- a/client/src/services/Api.js +++ b/client/src/services/Api.js @@ -16,6 +16,7 @@ import { socket } from '@/services/Socket'; class ClientApi { #_plugin #_router + #_baseRouter #_windows #_socket @@ -25,6 +26,7 @@ class ClientApi { constructor(plugin){ this.#_plugin = plugin this.#_router = new ClientRouter(`/plugin/${plugin.package}`) + this.#_baseRouter = new ClientRouter("") this.#_windows = new ClientWindows(plugin.package) this.#_socket = new ClientSocket(plugin.package) } @@ -82,6 +84,10 @@ class ClientApi { return this.#_router; } + get baseRouter(){ + return this.#_baseRouter; + } + /** * Returns the windows object * @type {ClientWindows} @@ -152,6 +158,7 @@ class ClientModule { #_color; #_icon; #_buttons; + #_previewData; #_init; #_exit; @@ -163,39 +170,13 @@ class ClientModule { this.#_router = new ClientRouter(`/module/${plugin.package}/${id}`); } - /** - * The title of the module - * @type {string} - */ - set title(title) { this.#_title = title; } + setData(data){ + this.#_previewData = data; + } - /** - * The description of the module - * @type {string} - */ - set description(description){ this.#_description = description; } + set onInit(init){ this.#_init = init; } - /** - * The version of the module - * @type {string} - */ - set version(version){ this.#_version = version; } - - /** - * The accent color of the module. This will be displayed for example - * in the background title inside the campaign preview - * @type {string} - */ - set color(color){ this.#_color = color; } - - /** - * Sets the icon for the module. It must be placed inside the public folder of the plugin - */ - set icon(icon){ this.#_icon = icon; } - - set init(init){ this.#_init = init; } - - set exit(exit){ this.#_exit = exit; } + set onExit(exit){ this.#_exit = exit; } setButtons(buttons){ this.#_buttons = buttons; @@ -212,11 +193,7 @@ class ClientModule { get info(){ return { id: this.#_id, - title: this.#_title, - description: this.#_description, - version: this.#_version, - color: this.#_color, - icon: this.#_icon, + previewData: this.#_previewData, init: this.#_init, exit: () => {}, buttons: this.#_buttons diff --git a/client/src/services/Modules.js b/client/src/services/Modules.js index 7c689e7b..a3b5b158 100644 --- a/client/src/services/Modules.js +++ b/client/src/services/Modules.js @@ -19,6 +19,8 @@ let GetModules = () => modules; // let GetModulesToLoad = () => modulesToLoad; function GetModule(id){ + console.log(modules); + console.log(modules[id]) return modules[id]; } diff --git a/client/src/views/partials/GameSystem.vue b/client/src/views/partials/GameSystem.vue index b39d3a6b..bae4efcd 100644 --- a/client/src/views/partials/GameSystem.vue +++ b/client/src/views/partials/GameSystem.vue @@ -13,8 +13,8 @@ function Select(){ onMounted(() => { console.log(data); - title.value = data.title; - image.value.src = `plugins/${data.id}/${data.icon}`; + title.value = data.previewData.title; + image.value.src = `plugins/${data.id}/${data.previewData.icon}`; }) diff --git a/client/src/views/windows/campaigns/CampaignPreviewWindow.vue b/client/src/views/windows/campaigns/CampaignPreviewWindow.vue index c34d8b13..63ca28b9 100644 --- a/client/src/views/windows/campaigns/CampaignPreviewWindow.vue +++ b/client/src/views/windows/campaigns/CampaignPreviewWindow.vue @@ -75,7 +75,7 @@ onMounted(() => { AddSound(container.value) - campaign_title.value.style.backgroundColor = GetModule(data.campaign.system).color ? GetModule(data.campaign.system).color : "#1f1f1f"; + campaign_title.value.style.backgroundColor = GetModule(data.campaign.system).previewData.color ? GetModule(data.campaign.system).color : "#1f1f1f"; AddTooltip(copy_code_button.value, `
${t('campaigns.preview.copy-explain')}
`, {max_width: 300}) }); diff --git a/documentation/docs/client/api.md b/documentation/docs/client/api.md index 1ff7e817..e1726125 100644 --- a/documentation/docs/client/api.md +++ b/documentation/docs/client/api.md @@ -150,6 +150,102 @@ let databaseWindow = Api.registerWindow('database', Api.createView('Database')); ### router +Gets the router object associated with the API. It has no prefix and can make all kinds of calls to the Dragonroll backend + +#### Returns + +| Type | Description | +| ---- | ----------- | +| [ClientRouter](#clientrouter) | The client router | + +### baseRouter + +Gets the royter object associated with the API. It has no prefix and can make all kinds of calls to the Dragonroll backend. + +| Type | Description | +| ---- | ----------- | +| [ClientRouter](#clientrouter) | The client router from root | + ### socket -## ClientModule \ No newline at end of file +Gets the socket object associated with the Plugin. + +#### Returns + +| Type | Description | +| ---- | ----------- | +| [ClientSocket](#clientsocket) | The client socket | + +## ClientModule + +### setData + +Sets the information data displayed in Dragonroll of the current module + +#### Parameters + +This method accepts an Object type with the following properties: + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``title`` | String | yes | The display name of the module | +| ``description`` | String | yes | The description of the module | +| ``version`` | String | yes | The version of the module | +| ``color`` | String | yes | The display color for the module | +| ``authors`` | [Author] | no | The authors of the module | +| ``icon`` | String | yes | The icon to be displayed with the module. Relative to the `public` folder | + + +#### Example + +```js +dndModule.setData({ + title: "Dungeons & Dragons 5e", + description: "Dungeons & Dragons Fifth edition game system support", + version: "0.1", + color: "#e92026", + authors: [{ + name: "Aran Roig", + webpage: "aranroig.com" + }], + icon: "icon.png" +}); +``` + +### onInit + +### onExit + +### setButtons + +### router + +## ClientRouter + +### get + +### post + +### put + +### delete + +### baseGet + +### basePost + +### basePut + +### baseDelete + +## ClientSocket + +### on + +## ClientView + +### path + +## WindowType + +## WindowData \ No newline at end of file diff --git a/documentation/docs/server/api.md b/documentation/docs/server/api.md index bbb80218..28ac49d5 100644 --- a/documentation/docs/server/api.md +++ b/documentation/docs/server/api.md @@ -1 +1,43 @@ -# ServerApi \ No newline at end of file +# ServerApi + +## BakcendApi + +The BackendApi object is used for interacting with everything related to the Dragonroll backend. It is passed to the `Main` function at the entrypoint defined in the [plugin.json](/plugin/plugin.json) file + +### router + +### createModel + +### createModule + +## BackendRouter + +### get + +### post + +### put + +### delete + +### createModelRoutes + +## BackendModule + +### router + +### createModel + +## BackendModel + +### find + +### findOne + +### findById + +### create + +### updateOne + +### updateMany \ No newline at end of file diff --git a/plugins/dnd-5e/client/data.js b/plugins/dnd-5e/client/data.js index 5d863867..047e51d9 100644 --- a/plugins/dnd-5e/client/data.js +++ b/plugins/dnd-5e/client/data.js @@ -14,6 +14,7 @@ function InitData(){ } function FetchConcepts(){ + Server().get('/concept/list?campaign=' + GetCampaign()._id).then(response => { data.value.concepts = response.data.data; }).catch((err) => console.log(err)); @@ -22,7 +23,7 @@ function FetchConcepts(){ function FetchData(){ FetchConcepts(); } - +/* Api.socket.on('update-concepts', () => { FetchConcepts(); }); diff --git a/plugins/dnd-5e/client/main.js b/plugins/dnd-5e/client/main.js index 121ce8a2..711a71ff 100644 --- a/plugins/dnd-5e/client/main.js +++ b/plugins/dnd-5e/client/main.js @@ -2,19 +2,26 @@ import { FetchData, InitData } from "./data"; // Entrypoint let Api; +let dndModule; function Main(api){ Api = api - console.log("Hello World!"); + + console.log("Module registered!"); + dndModule = Api.createModule('dnd-5e'); - let dndModule = Api.createModule('dnd-5e'); - - dndModule.title = "Dungeons & Dragons 5e"; - dndModule.description = "Dungeons & Dragons Fifth edition game system support"; - dndModule.version = "0.1"; - dndModule.color = "#e92026"; - dndModule.icon = "icon.png"; + dndModule.setData({ + title: "Dungeons & Dragons 5e", + description: "Dungeons & Dragons Fifth edition game system support", + version: "0.1", + color: "#e92026", + authors: [{ + name: "Aran Roig", + webpage: "aranroig.com" + }], + icon: "icon.png" + }); let databaseWindow = Api.registerWindow('database', Api.createView('Database')); let actorsWindow = Api.registerWindow('actors', Api.createView('Actors')); @@ -58,12 +65,18 @@ function Main(api){ // Api.windows.registerWindow('item_sheet', Api.createView('ItemSheet')); // Api.windows.registerWindow('create_item_prompt', Api.createView('CreateItemPrompt')); - dndModule.init = () => { + dndModule.onInit = () => { InitData(); FetchData(); } Api.registerModule(dndModule); + + } -export { Main, Api }; \ No newline at end of file +export { + Main, + Api, + dndModule +}; \ No newline at end of file