Ok communications work, falta passar alguna forma de comunicar el Api object bé
Some checks failed
test / run-tests-client (push) Successful in 45s
test / run-tests-backend (push) Failing after 15s

This commit is contained in:
BinarySandia04 2024-10-16 11:48:50 +02:00
parent 65741da5cf
commit d4f1f631cd
8 changed files with 72 additions and 37 deletions

View File

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

View File

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

View File

@ -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(){

View File

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

View File

@ -1,6 +1,6 @@
<script setup>
import { onMounted, ref, watch } from 'vue';
import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
import { marked } from "marked";
const props = defineProps(['done', 'editable']);
import FixedBottomButtons from './FixedBottomButtons.vue';

View File

@ -15,10 +15,10 @@ function Main(api){
type: { type: "String", required: true, default: "Item" },
info: { type: "Object" }, // For preview only
data: { type: "Object" }, // Advanced item
book: { type: "ObjectId", ref: "Book"},
campaign: { type: "ObjectId", ref: "Campaign"},
book: { type: "ObjectId", ref: "Book"}
});
dndModule.router.get('/testing', (req, res) => {
/*
let item = itemModel.create({
@ -33,6 +33,13 @@ function Main(api){
})
})
dndModule.router.get('/item/list', (req, res) => {
const campaign = req.campaign;
itemModel.find({campaign}).select('-data').lean().then(data => {
res.json({status: "ok", data});
});
})
Api.socket.on("test", () => console.log("test"));
// Api.router.createModelRoutes(itemModel, 'item');
}

View File

@ -1,5 +1,3 @@
import { Api } from './main.js'
import Server from '@/services/Server'
import { reactive } from 'vue';
@ -7,17 +5,23 @@ import { GetCampaign } from "@/services/Dragonroll";
let data = reactive({});
function InitData(){
let Api;
let dndModule;
function InitData(api, module){
Api = api;
dndModule = module;
data.value = {
concepts: []
};
}
function FetchConcepts(){
console.log(Api.router)
Server().get('/concept/list?campaign=' + GetCampaign()._id).then(response => {
dndModule.router.get('/item/list', {}).then(response => {
data.value.concepts = response.data.data;
}).catch((err) => console.log(err));
console.log(response.data);
}).catch(err => console.log(err));
}
function FetchData(){

View File

@ -66,17 +66,13 @@ function Main(api){
// Api.windows.registerWindow('create_item_prompt', Api.createView('CreateItemPrompt'));
dndModule.onInit = () => {
InitData();
InitData(Api, dndModule);
FetchData();
}
Api.registerModule(dndModule);
}
export {
Main,
Api,
dndModule
Main
};