More docs and better module data params
Some checks failed
test / run-tests-client (push) Successful in 52s
test / run-tests-backend (push) Failing after 18s

This commit is contained in:
BinarySandia04 2024-10-15 11:01:51 +02:00
parent 708c0aa354
commit 2753bb4331
8 changed files with 183 additions and 52 deletions

View File

@ -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

View File

@ -19,6 +19,8 @@ let GetModules = () => modules;
// let GetModulesToLoad = () => modulesToLoad;
function GetModule(id){
console.log(modules);
console.log(modules[id])
return modules[id];
}

View File

@ -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}`;
})
</script>

View File

@ -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, `<p>${t('campaigns.preview.copy-explain')}</p>`, {max_width: 300})
});

View File

@ -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
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

View File

@ -1 +1,43 @@
# 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

View File

@ -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();
});

View File

@ -2,19 +2,26 @@ import { FetchData, InitData } from "./data";
// Entrypoint
let Api;
let dndModule;
function Main(api){
Api = api
console.log("Hello World!");
let dndModule = Api.createModule('dnd-5e');
console.log("Module registered!");
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 };
export {
Main,
Api,
dndModule
};