From 3214c70276ce3d55ae080f120c177c1ab6b2158f Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Wed, 16 Oct 2024 22:13:56 +0200 Subject: [PATCH] Debug colors and now sockets really work, its downhill from here --- backend/io/campaign.js | 3 +- backend/models/Concept.js | 13 ---- backend/routes/campaign.js | 3 - backend/routes/concept.js | 68 ------------------- backend/server.js | 7 +- backend/services/api.js | 4 +- client/src/main.js | 2 - client/src/services/Api.js | 15 ++-- client/src/services/Campaign.js | 3 - client/src/services/ContextMenu.js | 1 - client/src/services/Windows.js | 2 - client/src/views/managers/GameManager.vue | 1 - client/src/views/partials/GameEntry.vue | 2 - client/src/views/partials/GameSystem.vue | 1 - client/src/views/partials/IconSelector.vue | 1 - client/src/views/partials/MapEntry.vue | 1 - client/src/views/partials/SystemSelector.vue | 1 - .../views/partials/parameters/ColorValue.vue | 1 - .../views/windows/dm/EnvironmentWindow.vue | 1 - client/src/views/windows/game/DiceWindow.vue | 1 - .../settings/AccountManagementWindow.vue | 1 - .../windows/settings/RegisterUserWindow.vue | 3 - plugins/dnd-5e/backend/main.js | 14 ++-- plugins/dnd-5e/client/data.js | 1 - plugins/dnd-5e/client/main.js | 3 +- plugins/dnd-5e/client/views/ItemSheet.vue | 4 +- 26 files changed, 22 insertions(+), 135 deletions(-) delete mode 100644 backend/models/Concept.js delete mode 100644 backend/routes/concept.js diff --git a/backend/io/campaign.js b/backend/io/campaign.js index 89396b65..94c55845 100644 --- a/backend/io/campaign.js +++ b/backend/io/campaign.js @@ -7,7 +7,6 @@ let sessions = {}; async function GetOfflinePlayers(campaign){ let players = await CampaignUser.find({campaign}).populate('user').exec(); let finalPlayers = []; - console.log(players) // TODO: Filter players.forEach(player => finalPlayers.push(FilterUser(player))); @@ -48,7 +47,7 @@ module.exports = io => { } - console.log(socket.user.username + " ha entrado!"); + // console.log(socket.user.username + " ha entrado!"); SetPlayerProperty(campaignId, socket.user._id, "online", true); // io.to(socket.campaign).emit('update-players', sessions[campaignId].players) socket.emit('init-info', {players: sessions[campaignId].players}) diff --git a/backend/models/Concept.js b/backend/models/Concept.js deleted file mode 100644 index 3043b316..00000000 --- a/backend/models/Concept.js +++ /dev/null @@ -1,13 +0,0 @@ -const mongoose = require("mongoose"); -const Schema = mongoose.Schema; - -const ConceptSchema = new Schema({ - name: {type: String, required: true, default: "New Concept"}, - type: { type: String, required: true, default: "Concept" }, - info: { type: Object }, // For preview only - data: { type: Object }, // Advanced item - book: {type: mongoose.Types.ObjectId, ref: "Book"}, - campaign: {type: mongoose.Types.ObjectId, ref: "Campaign"}, -}); - -module.exports = mongoose.model('Concept', ConceptSchema); \ No newline at end of file diff --git a/backend/routes/campaign.js b/backend/routes/campaign.js index 0e3895ea..a9001206 100644 --- a/backend/routes/campaign.js +++ b/backend/routes/campaign.js @@ -83,7 +83,6 @@ router.post('/join', (req, res) => { router.get('/list', (req, res) => { CampaignUser.find({user: req.user}).populate("campaign").lean().then((data) => { res.json(data); - console.log(data); return; }).catch((err) => res.json({status: "error", msg: "internal"})); }); @@ -91,8 +90,6 @@ router.get('/list', (req, res) => { router.get('/players', (req, res) => { Campaign.findById(req.query.campaign).lean().then((campaign) => { CampaignUser.find({campaign}).populate('user').then((data) => { - console.log("djskajdk") - console.log(data); res.json(data); return; }).catch((err) => res.json({status: "error", msg: "internal"})); diff --git a/backend/routes/concept.js b/backend/routes/concept.js deleted file mode 100644 index d8b5e279..00000000 --- a/backend/routes/concept.js +++ /dev/null @@ -1,68 +0,0 @@ -const express = require('express'); -const router = express.Router(); - -const Concept = require('../models/Concept'); -const { hasCampaign } = require('../services/middleware'); -const { getIo } = require('../io/socket'); - -const io = getIo(); - -router.get('/list', hasCampaign, (req, res) => { - const campaign = req.campaign; - Concept.find({campaign}).select('-data').lean().then(data => { - res.json({status: "ok", data}); - }); -}); - -router.post('/create', hasCampaign, (req, res) => { - const campaign = req.campaign; - let data = req.body.data; - - if(!(data.type && data.name)) { - res.json({status: "error", msg: "args"}); - return; - } - - let concept = new Concept({campaign, type: data.type, name: data.name}); - concept.save().then(concept => { - io.to(req.room).emit('update-concepts'); - res.json({status: "ok", concept}); - }) -}); - -router.delete('/delete', hasCampaign, (req, res) => { - const campaign = req.campaign; - let id = req.query.id; - if(!id) { - res.json({status: "error", msg: "args"}); - return; - } - - Concept.deleteOne({_id: id, campaign}).then(() => { - io.to(req.room).emit('update-concepts'); - res.json({status: "ok"}); - }); -}); - -router.get('/get', hasCampaign, (req, res) => { - const campaign = req.campaign; - let id = req.query.id; - - Concept.findOne({_id: id, campaign}).lean().then(concept => { - res.json({status: "ok", concept}); - }); -}); - -router.put('/update', hasCampaign, (req, res) => { - const campaign = req.campaign; - let id = req.query.id; - - Concept.findOneAndUpdate({_id: id, campaign}, req.body.concept).then(result => { - console.log(req.room) - if(req.query.fireUpdate) io.to(req.room).emit('update-concepts'); - io.to(req.room).emit('update-concept', id); - res.json({status: "ok"}); - }); -}); - -module.exports = router; \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index 1ec9150e..e8217847 100755 --- a/backend/server.js +++ b/backend/server.js @@ -78,7 +78,6 @@ app.use(checkAuth); // ROUTES WITH AUTH app.use('/campaign', require('./routes/campaign')); app.use('/maps', require('./routes/map')) -app.use('/concept', require('./routes/concept')) app.use('/admin', require('./routes/admin')) // GET localhost:8081/concept/list @@ -96,9 +95,9 @@ function print (path, layer) { } else if (layer.name === 'router' && layer.handle.stack) { layer.handle.stack.forEach(print.bind(null, path.concat(split(layer.regexp)))) } else if (layer.method) { - console.log('%s /%s', - layer.method.toUpperCase(), - path.concat(split(layer.regexp)).filter(Boolean).join('/')) + console.log('\x1b[33m%s\x1b[0m', + `${layer.method.toUpperCase()} /${ + path.concat(split(layer.regexp)).filter(Boolean).join('/')}`) } } diff --git a/backend/services/api.js b/backend/services/api.js index 8d27dad7..a8e087c5 100644 --- a/backend/services/api.js +++ b/backend/services/api.js @@ -250,7 +250,8 @@ class BackendSocket { } emit(campaign, msg, data = {}){ - getIo().to(campaign).emit(msg, data); + console.log('\x1b[35m%s\x1b[0m', "EMIT " + `${this.#_prefix}/${msg}` + " IN " + campaign); + getIo().in(campaign).emit(`${this.#_prefix}/${msg}`, data); } } @@ -272,6 +273,7 @@ function ParseSchema(schema){ else newSchema[key].type = typeTable[newSchema[key].type]; } + return newSchema; } diff --git a/client/src/main.js b/client/src/main.js index 09f89724..f31d5fd2 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -29,7 +29,6 @@ let locale = 'en-US'; let supportedLocales = ['en-US', 'es-ES', 'ca']; let navLocale = window.navigator.language; -console.log(navLocale); if(supportedLocales.includes(navLocale)) locale = navLocale; @@ -38,7 +37,6 @@ try { } catch(ex) { LogoutUser(); } -console.log(locale); const i18n = createI18n({ legacy: false, diff --git a/client/src/services/Api.js b/client/src/services/Api.js index e7d9119b..cda5cf39 100644 --- a/client/src/services/Api.js +++ b/client/src/services/Api.js @@ -72,7 +72,6 @@ class ClientApi { } clearWindow(id){ - console.log(id) _Windows.ClearWindow(id); } @@ -164,7 +163,7 @@ class ClientModule { this.#_plugin = plugin; this.#_id = id; this.#_router = new ClientRouter(`/plugins/${plugin.package}/_module/${id}`, {}); - this.#_socket = new ClientSocket(`${plugin.package}/${id}`) + this.#_socket = new ClientSocket(`plugins/${plugin.package}/${id}`) } setData(data){ @@ -174,7 +173,6 @@ class ClientModule { set onInit(init){ this.#_init = (campaign) => { this.#_campaign = campaign; this.#_router._setParam("campaign", campaign._id); - console.log(campaign); init(); }; } @@ -220,6 +218,7 @@ class ClientSocket { } on(msg, callback){ + // alert(`${this.#_prefix}/${msg}`) socket.on(`${this.#_prefix}/${msg}`, callback); } } @@ -229,7 +228,7 @@ function ParseQuery(queryData){ if(keys.length == 0) return ""; let res = "?"; for(let i = 0; i < keys.length; i++){ - res += keys[i] + "=" + queryData[keys]; + res += keys[i] + "=" + queryData[keys[i]]; if(i != keys.length - 1) res += "&"; } return res; @@ -266,28 +265,28 @@ class ClientRouter { get(route, query){ if(route.startsWith('/')) route = route.substring(1, route.length); let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; - console.log("GET " + f); + console.log("%cGET%c " + f, 'color: #00ff00', 'color: unset'); return Server().get(f); } post(route, query, data = {}){ if(route.startsWith('/')) route = route.substring(1, route.length); let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; - console.log("POST " + f); + console.log("%cPOST%c " + f, 'color: #0384fc', 'color: unset'); return Server().post(f, data); } put(route, query, data = {}){ if(route.startsWith('/')) route = route.substring(1, route.length); let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; - console.log("PUT " + f); + console.log("%cPUT%c " + f, 'color: #ff8000', 'color: unset'); return Server().put(f, data); } delete(route, query){ if(route.startsWith('/')) route = route.substring(1, route.length); let f = `${this.#_path}/${route}${ParseQuery({...this.#_defParams, ...query})}`; - console.log("DELETE " + f); + console.log("%cDELETE%c " + f, 'color: #fa254c', 'color: unset'); return Server().delete(f); } diff --git a/client/src/services/Campaign.js b/client/src/services/Campaign.js index 22ac19df..d57969dc 100644 --- a/client/src/services/Campaign.js +++ b/client/src/services/Campaign.js @@ -19,8 +19,6 @@ function ConnectToCampaign(campaign){ chat.value = []; socket.emit('enter', GetUser(), _currentCampaign._id); - console.log("Hola") - console.log(_currentCampaign) } function Disconnect(){ @@ -48,7 +46,6 @@ socket.on('update-players', data => { }) socket.on('init-info', data => { - console.log("Hola2") _UpdatePlayers(data.players); DisplayCampaign(); }) diff --git a/client/src/services/ContextMenu.js b/client/src/services/ContextMenu.js index 6639bdba..f1805498 100644 --- a/client/src/services/ContextMenu.js +++ b/client/src/services/ContextMenu.js @@ -26,7 +26,6 @@ function PopulateContext(val){ let children = []; let elementNum = 0; - console.log(val); val.forEach(element => { let contextMenuElement = document.createElement('div'); contextMenuElement.classList.add("context-menu-element"); diff --git a/client/src/services/Windows.js b/client/src/services/Windows.js index fab4c33b..472f3435 100644 --- a/client/src/services/Windows.js +++ b/client/src/services/Windows.js @@ -69,8 +69,6 @@ async function InjectWindow(window_type, plugin, window_component){ let systemWidows = {}; systemWidows[window_type] = (await import(`../../plugins/${plugin}/views/${window_component}.vue`)).default; windowMap = {...windowMap, ...systemWidows}; - - console.log("Window injected"); } // Presets diff --git a/client/src/views/managers/GameManager.vue b/client/src/views/managers/GameManager.vue index 00ebd937..9f0dbfc6 100644 --- a/client/src/views/managers/GameManager.vue +++ b/client/src/views/managers/GameManager.vue @@ -65,7 +65,6 @@ watch(in_game, () => { // Check if we are dm is_dm.value = GetClient().is_dm; - console.log("Can we get the module here?"); rightModuleButtons.value = GetCampaignModule().buttons.right; } }); diff --git a/client/src/views/partials/GameEntry.vue b/client/src/views/partials/GameEntry.vue index 97ce044f..9f446f38 100644 --- a/client/src/views/partials/GameEntry.vue +++ b/client/src/views/partials/GameEntry.vue @@ -12,8 +12,6 @@ const props = defineProps(['data']); let data = props.data; onMounted(() => { - console.log(data.height); - console.log(data.editable) if(data.editable) editable.value = true; }) diff --git a/client/src/views/partials/GameSystem.vue b/client/src/views/partials/GameSystem.vue index bae4efcd..59b77ad9 100644 --- a/client/src/views/partials/GameSystem.vue +++ b/client/src/views/partials/GameSystem.vue @@ -12,7 +12,6 @@ function Select(){ } onMounted(() => { - console.log(data); title.value = data.previewData.title; image.value.src = `plugins/${data.id}/${data.previewData.icon}`; }) diff --git a/client/src/views/partials/IconSelector.vue b/client/src/views/partials/IconSelector.vue index 40e10183..010fae19 100644 --- a/client/src/views/partials/IconSelector.vue +++ b/client/src/views/partials/IconSelector.vue @@ -14,7 +14,6 @@ function SelectIcon(){ CreateChildWindow(props.window, 'icon_selector', { id: 'icon-selector-' + uuid, done: (res) => { - console.log(res); icon.value = res.selected.path; done(res); ClearWindow('icon-selector-' + uuid); diff --git a/client/src/views/partials/MapEntry.vue b/client/src/views/partials/MapEntry.vue index 5018b114..1dd1a539 100644 --- a/client/src/views/partials/MapEntry.vue +++ b/client/src/views/partials/MapEntry.vue @@ -14,7 +14,6 @@ const props = defineProps(['data']); let data = props.data; function ShowMap(){ - console.log("ShowMap") SendMap(data._id); } diff --git a/client/src/views/partials/SystemSelector.vue b/client/src/views/partials/SystemSelector.vue index 90bba495..866ddbaa 100644 --- a/client/src/views/partials/SystemSelector.vue +++ b/client/src/views/partials/SystemSelector.vue @@ -13,7 +13,6 @@ let windowId = props.windowId; function DisplaySystemSelector(){ CreateChildWindow(windowId, 'system_selector', {'done': (data) => { - console.log("Hola") let module = GetModule(data.selected); selectedSystem.value = data.selected; selectedImage.value.src = `modules/${module.id}/icon.png`; diff --git a/client/src/views/partials/parameters/ColorValue.vue b/client/src/views/partials/parameters/ColorValue.vue index 8c9c144d..dfa98785 100644 --- a/client/src/views/partials/parameters/ColorValue.vue +++ b/client/src/views/partials/parameters/ColorValue.vue @@ -7,7 +7,6 @@ const colorPicker = ref(null); onMounted(() => { colorValue.value.addEventListener('click', () => { - console.log("Click"); colorPicker.value.click(); }) diff --git a/client/src/views/windows/dm/EnvironmentWindow.vue b/client/src/views/windows/dm/EnvironmentWindow.vue index 644275c8..ff306887 100644 --- a/client/src/views/windows/dm/EnvironmentWindow.vue +++ b/client/src/views/windows/dm/EnvironmentWindow.vue @@ -21,7 +21,6 @@ onMounted(() => { SetSize(id, {width: 200, height: 300}); ResetPosition(id, {x: data.x, y: data.y}); - console.log(env_background.value.GetColor()); watch(env_background.value.GetColor(), () => { ChangeBackgroundColor(env_background.value.GetColor().value); }); diff --git a/client/src/views/windows/game/DiceWindow.vue b/client/src/views/windows/game/DiceWindow.vue index 8c6cf49f..1aef7b71 100644 --- a/client/src/views/windows/game/DiceWindow.vue +++ b/client/src/views/windows/game/DiceWindow.vue @@ -52,7 +52,6 @@ function ThrowDice(expr){ audio.type = "audio/wav" audio.play(); - console.log(result) diceResult.value = result; SendMessage({ diff --git a/client/src/views/windows/settings/AccountManagementWindow.vue b/client/src/views/windows/settings/AccountManagementWindow.vue index 96ddb7ac..e4d712e0 100644 --- a/client/src/views/windows/settings/AccountManagementWindow.vue +++ b/client/src/views/windows/settings/AccountManagementWindow.vue @@ -35,7 +35,6 @@ function RefreshUsers(){ let users = response.data.users; elements.value = []; users.forEach(user => { - console.log(user); if(user.setupCode){ elements.value.push({ name: t('register-account.pending-account'), diff --git a/client/src/views/windows/settings/RegisterUserWindow.vue b/client/src/views/windows/settings/RegisterUserWindow.vue index 8e5c8a0e..858ed68f 100644 --- a/client/src/views/windows/settings/RegisterUserWindow.vue +++ b/client/src/views/windows/settings/RegisterUserWindow.vue @@ -40,13 +40,10 @@ onMounted(() => { function register(){ Server().post('/user/register').then((response) => { const data = response.data; - console.log(data); if(data.error){ - console.log(data); errorMessage.value = data.msg; } else { errorMessage.value = ""; - console.log("Logged successfully"); DisplayToast('green', 'Account created successfully', 3000); CallWindow(id, 'done'); } diff --git a/plugins/dnd-5e/backend/main.js b/plugins/dnd-5e/backend/main.js index 04e38535..dbe61bdd 100644 --- a/plugins/dnd-5e/backend/main.js +++ b/plugins/dnd-5e/backend/main.js @@ -3,8 +3,6 @@ let Api; function Main(api){ Api = api; - - console.log("Hello World from backend!"); // Create our module in the backend. We only need the package name, it must be equal to the one that // we made inside the client @@ -26,22 +24,20 @@ function Main(api){ type: "The test item" }) */ - - console.log("FUNCIONA!!!!"); res.json({ status: "ok" }) }) dndModule.router.get('/item/list', (req, res) => { - const campaign = req.campaign; + const campaign = req.query.campaign; itemModel.find({campaign}).select('-data').lean().then(data => { res.json({status: "ok", data}); }); }); dndModule.router.post('/item/create', (req, res) => { - const campaign = req.campaign; + const campaign = req.query.campaign; let data = req.body.data; if(!(data.type && data.name)) { @@ -56,7 +52,7 @@ function Main(api){ }); dndModule.router.get('/item/get', (req, res) => { - const campaign = req.campaign; + const campaign = req.query.campaign; let id = req.query.id; itemModel.findOne({_id: id, campaign}).lean().then(concept => { @@ -65,12 +61,12 @@ function Main(api){ }) dndModule.router.put('/item/update', (req, res) => { - const campaign = req.campaign; + const campaign = req.query.campaign; let id = req.query.id; itemModel.findOneAndUpdate({_id: id, campaign}, req.body.concept).then(result => { if(req.query.fireUpdate) dndModule.socket.emit(campaign, 'update-concepts'); - dndModule.socket.emit(campaign).emit('update-concept', id); + dndModule.socket.emit(campaign, 'update-concept', id); res.json({status: "ok"}); }); }) diff --git a/plugins/dnd-5e/client/data.js b/plugins/dnd-5e/client/data.js index 9ffcd2de..001090fd 100644 --- a/plugins/dnd-5e/client/data.js +++ b/plugins/dnd-5e/client/data.js @@ -21,7 +21,6 @@ function InitData(){ function FetchConcepts(){ dndModule.router.get('/item/list', {}).then(response => { data.value.concepts = response.data.data; - console.log(response.data); }).catch(err => console.log(err)); } diff --git a/plugins/dnd-5e/client/main.js b/plugins/dnd-5e/client/main.js index ce3be6da..f311c2be 100644 --- a/plugins/dnd-5e/client/main.js +++ b/plugins/dnd-5e/client/main.js @@ -58,7 +58,7 @@ function Main(Api){ }); - Api.socket.on('update-concepts', () => { + dndModule.socket.on('update-concepts', () => { FetchConcepts(); }); @@ -69,7 +69,6 @@ function Main(Api){ Api.registerModule(dndModule); - Global('dnd-5e').DndModule = dndModule; } diff --git a/plugins/dnd-5e/client/views/ItemSheet.vue b/plugins/dnd-5e/client/views/ItemSheet.vue index 9c3a03c4..683ac8e2 100644 --- a/plugins/dnd-5e/client/views/ItemSheet.vue +++ b/plugins/dnd-5e/client/views/ItemSheet.vue @@ -75,8 +75,8 @@ function Upload(){ oldInfo = structuredClone(concept.value.info); } - dndModule.router.put('/concept/update', params, {concept: concept.value}).then(response => { - console.log(response); + dndModule.router.put('/item/update', params, {concept: concept.value}).then(response => { + // console.log(response); }); }