Module plugin rework part 1

Ignore locales
This commit is contained in:
BinarySandia04 2024-09-27 00:54:26 +02:00
parent 225926bec2
commit 82902d13f3
25 changed files with 499 additions and 24903 deletions

5
.gitignore vendored
View File

@ -2,10 +2,13 @@
server/node_modules/
client/node_modules/
node_modules/
server/dist/
client/dist/
client/plugins/
backend/plugins/
client/public/data/
server/uploads/
client/src/locales/
# local env files
.env.local

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,10 @@ import useEmitter from '@/services/Emitter';
const emitter = useEmitter();
import { DisplayToast, SetEmitter } from './services/Dragonroll'
import { ImportModule, GetModulesToLoad } from './services/Modules'
import { CreateWindow } from './services/Windows';
import { FetchVanillaResources } from './services/Resources';
import { FetchResources } from './services/Resources';
import { ImportModule } from './services/Modules';
import { FetchPlugins } from './services/Plugins';
LoadUser();
@ -30,18 +31,12 @@ async function start(){
}
}
const modules = GetModulesToLoad();
let moduleLoads = [];
await FetchResources();
await FetchPlugins();
modules.forEach(moduleName => {
moduleLoads.push(ImportModule(moduleName));
});
await ImportModule('dnd-5e')
await Promise.all(moduleLoads);
await FetchVanillaResources();
DisplayToast('aqua', 'All modules loaded successfully');
DisplayToast('aqua', 'All plugins loaded successfully');
}

View File

@ -1,91 +0,0 @@
{
"general": {
"create": "Create",
"join": "Join",
"view": "View",
"players": "Players",
"description": "Description",
"details": "Details",
"name": "Name",
"email": "Email",
"username": "Username",
"password": "Password",
"password-confirm": "Confirm your password",
"register": "Register",
"quantity": "Quantity",
"weight": "Weight",
"price": "Price"
},
"placeholders": {
"name": "John Doe",
"email": "john@doe.com",
"username": "Enter your username...",
"password": "Enter your password...",
"password-confirm": "Enter again your password..."
},
"register-admin": {
"title": "Register Admin Account",
"welcome-message": "<h1>Welcome!</h1><b>You have successfull setup Dragonroll!</b><p>Please create the admin account</p><p>Once the admin account has been created, you will be able to create user accounts that will be able to access Dragonroll</p><hr>"
},
"main-menu": {
"title": "Dragonroll",
"main-menu": "Main Menu",
"campaigns": "Campaigns",
"cosmic-compendium": "The Cosmic Compendium",
"book-anvil": "Book Anvil",
"edit-profile": "Edit Profile",
"settings": "Settings",
"log-out": "Log Out"
},
"settings": {
"title": "Dragonroll settings",
"tabs": {
"account-settings": "Account Settings",
"site-administration": "Site Administration"
},
"account": {
"account-settings": "Account Settings",
"language": "Language:"
},
"site-administration": {
}
},
"campaigns": {
"title": "Campaigns",
"your-campaigns": "Your Campaigns",
"other-campaigns": "Other Campaigns",
"create": {
"title": "Create Campaign",
"enter": "Enter campaign name..."
},
"join": {
"title": "Join Campaign",
"enter": "Enter campaign code...",
"success": "Successfully joined the campaign!",
"already": "You are already in that campaign!",
"error": "Error joining this campaign, check if the code is correct"
},
"preview": {
"title": "Campaign preview",
"copy-code": "Copy invite code",
"copy-explain": "Click this button to copy the invite code of your campaign to the clipboard",
"copy-success": "Copied invite code successfully!",
"launch-game": "Launch game",
"exit-game": "Exit game"
}
},
"systems": {
"title": "Select a game system",
"not-selected": "No game system selected"
},
"database": {
"title": "Database",
"tabs": {
"items": "Items",
"spells": "Spells",
"features": "Features"
}
}
}

View File

@ -1,4 +1,5 @@
{
"plugins": {},
"general": {
"create": "Create",
"join": "Join",

View File

@ -0,0 +1,93 @@
{
"plugins": {
"dnd-5e": {
"test": "Test"
}
},
"general": {
"create": "Create",
"join": "Join",
"view": "View",
"players": "Players",
"description": "Description",
"details": "Details",
"name": "Name",
"email": "Email",
"username": "Username",
"password": "Password",
"password-confirm": "Confirm your password",
"register": "Register",
"quantity": "Quantity",
"weight": "Weight",
"price": "Price"
},
"placeholders": {
"name": "John Doe",
"email": "john@doe.com",
"username": "Enter your username...",
"password": "Enter your password...",
"password-confirm": "Enter again your password..."
},
"register-admin": {
"title": "Register Admin Account",
"welcome-message": "<h1>Welcome!</h1><b>You have successfull setup Dragonroll!</b><p>Please create the admin account</p><p>Once the admin account has been created, you will be able to create user accounts that will be able to access Dragonroll</p><hr>"
},
"main-menu": {
"title": "Dragonroll",
"main-menu": "Main Menu",
"campaigns": "Campaigns",
"cosmic-compendium": "The Cosmic Compendium",
"book-anvil": "Book Anvil",
"edit-profile": "Edit Profile",
"settings": "Settings",
"log-out": "Log Out"
},
"settings": {
"title": "Dragonroll settings",
"tabs": {
"account-settings": "Account Settings",
"site-administration": "Site Administration"
},
"account": {
"account-settings": "Account Settings",
"language": "Language:"
},
"site-administration": {}
},
"campaigns": {
"title": "Campaigns",
"your-campaigns": "Your Campaigns",
"other-campaigns": "Other Campaigns",
"create": {
"title": "Create Campaign",
"enter": "Enter campaign name..."
},
"join": {
"title": "Join Campaign",
"enter": "Enter campaign code...",
"success": "Successfully joined the campaign!",
"already": "You are already in that campaign!",
"error": "Error joining this campaign, check if the code is correct"
},
"preview": {
"title": "Campaign preview",
"copy-code": "Copy invite code",
"copy-explain": "Click this button to copy the invite code of your campaign to the clipboard",
"copy-success": "Copied invite code successfully!",
"launch-game": "Launch game",
"exit-game": "Exit game"
}
},
"systems": {
"title": "Select a game system",
"not-selected": "No game system selected"
},
"database": {
"title": "Database",
"tabs": {
"items": "Items",
"spells": "Spells",
"features": "Features"
}
}
}

View File

@ -1,4 +1,5 @@
{
"plugins": {},
"general": {
"create": "Crear",
"join": "Entrar",

View File

@ -45,12 +45,13 @@ const i18n = createI18n({
locale,
fallbackLocale: 'en-US',
messages: {
'en-US': (await import(`./locale/en-US.json`)).default,
'es-ES': (await import(`./locale/es-ES.json`)).default,
'ca': (await import(`./locale/ca.json`)).default,
'en-US': (await import(`./locales/en-US.json`)).default,
'es-ES': (await import(`./locales/es-ES.json`)).default,
'ca': (await import(`./locales/ca.json`)).default,
}
});
app.use(router)
app.use(i18n);

View File

@ -31,6 +31,7 @@ function Disconnect(){
function DisplayCampaign(data = _currentCampaign){
ClearAll();
console.log(data)
CreateWindow('campaign_preview', {campaign: data});
}

View File

@ -0,0 +1,37 @@
import { GetPluginPaths } from "./Resources"
import * as Dragonroll from "@/services/Dragonroll"
import * as Chat from "@/services/Chat"
import * as ContextMenu from "@/services/ContextMenu"
import * as Map from "@/services/Map"
import * as Modules from "@/services/Modules"
import * as Sound from "@/services/Sound"
import * as Tooltip from "@/services/Tooltip"
import * as Windows from "@/services/Windows"
async function FetchPlugins(){
let pluginNames = GetPluginPaths();
for(let i = 0; i < pluginNames.length; i++){
let pluginName = pluginNames[i];
let pluginData = (await import(/* @vite-ignore */ `../../plugins/${pluginName}/plugin.json`)).default
console.log(`Loading plugin %c${pluginData.name}`, "color: #00ffff");
import(/* @vite-ignore */ `../../plugins/${pluginName}/${pluginData.entrypoint}`).then(module => {
module.Main({
Dragonroll,
Chat,
ContextMenu,
Map,
Modules,
Sound,
Tooltip,
Windows
});
})
}
}
export {
FetchPlugins
}

View File

@ -1,20 +1,28 @@
let icons = [];
let plugins = [];
async function GetJson(url){
let obj = await (await fetch(url)).json();
return obj;
}
async function FetchVanillaResources(){
icons = (await GetJson('/data/icons.json')).files;
async function FetchResources(){
let data = await GetJson('/data/data.json');
icons = data.icons.files;
plugins = data.plugins;
}
function GetIcons(){
return icons;
}
function GetPluginPaths(){
return plugins;
}
export {
FetchVanillaResources,
FetchResources,
GetIcons,
GetPluginPaths,
};

View File

@ -24,7 +24,6 @@ import MapWindow from '../windows/dm/MapWindow.vue'
import CombatWindow from '../windows/game/CombatWindow.vue'
import EntityWindow from '../windows/dm/EntityWindow.vue'
import CharactersWindow from '../windows/game/CharactersWindow.vue'
import CharacterSheet from '../windows/game/dnd-5e/CharacterSheet.vue'
import WelcomeWindow from '../windows/WelcomeWindow.vue'
import CompendiumWindow from '../windows/CompendiumWindow.vue'
import BookAnvilWindow from '../windows/BookAnvilWindow.vue'
@ -66,9 +65,9 @@ let WindowMap = {
async function InjectSystemWindows(system){
// Hack
let systemWidows = {
character_sheet: (await import(`../windows/game/${system}/CharacterSheet.vue`)).default,
item_sheet: (await import(`../windows/game/${system}/ItemSheet.vue`)).default,
create_item_prompt: (await import(`../windows/game/${system}/CreateItemPrompt.vue`)).default,
character_sheet: (await import(`../../../plugins/${system}/views/CharacterSheet.vue`)).default,
item_sheet: (await import(`../../../plugins/${system}/views/ItemSheet.vue`)).default,
create_item_prompt: (await import(`../../../plugins/${system}/views/CreateItemPrompt.vue`)).default,
};
WindowMap = {...WindowMap, ...systemWidows};

View File

@ -2,7 +2,6 @@
import { onMounted, onUpdated, provide, ref, watch } from 'vue';
import { SetupHandle, SetSize, SetPosition, ResetPosition } from '@/services/Windows';
import { CreateChildWindow } from '../../services/Windows';
import { GetModules } from '../../services/Modules';
const selectedSystem = ref("");
const selectedImage = ref(null);

View File

@ -1,4 +1,5 @@
import { fileURLToPath, URL } from 'node:url'
import path from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
@ -11,7 +12,7 @@ export default defineConfig({
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'vue': 'vue/dist/vue.esm-bundler.js'
'@plugins': fileURLToPath(new URL('./plguins', import.meta.url)),
}
},
proxy: {
@ -21,5 +22,8 @@ export default defineConfig({
secure: false,
ws: true,
}
},
build: {
target: 'esnext'
}
})

89
locales/ca.json Normal file
View File

@ -0,0 +1,89 @@
{
"plugins": {},
"general": {
"create": "Create",
"join": "Join",
"view": "View",
"players": "Jugadores",
"description": "Description",
"details": "Details",
"name": "Name",
"email": "Email",
"username": "Username",
"password": "Password",
"password-confirm": "Confirm your password",
"register": "Register",
"quantity": "Quantity",
"weight": "Weight",
"price": "Price"
},
"placeholders": {
"name": "John Doe",
"email": "john@doe.com",
"username": "Enter your username...",
"password": "Enter your password...",
"password-confirm": "Enter again your password..."
},
"register-admin": {
"title": "Register Admin Account",
"welcome-message": "<h1>Welcome!</h1><b>You have successfull setup Dragonroll!</b><p>Please create the admin account</p><p>Once the admin account has been created, you will be able to create user accounts that will be able to access Dragonroll</p><hr>"
},
"main-menu": {
"title": "Dragonroll",
"main-menu": "Main Menu",
"campaigns": "Campaigns",
"cosmic-compendium": "The Cosmic Compendium",
"book-anvil": "Book Anvil",
"edit-profile": "Edit Profile",
"settings": "Settings",
"log-out": "Log Out"
},
"settings": {
"title": "Dragonroll settings",
"tabs": {
"account-settings": "Account Settings",
"site-administration": "Site Administration"
},
"account": {
"account-settings": "Account Settings",
"language": "Language:"
},
"site-administration": {}
},
"campaigns": {
"title": "Campaigns",
"your-campaigns": "Your Campaigns",
"other-campaigns": "Other Campaigns",
"create": {
"title": "Create Campaign",
"enter": "Enter campaign name..."
},
"join": {
"title": "Join Campaign",
"enter": "Enter campaign code...",
"success": "Successfully joined the campaign!",
"already": "You are already in that campaign!",
"error": "Error joining this campaign, check if the code is correct"
},
"preview": {
"title": "Campaign preview",
"copy-code": "Copy invite code",
"copy-explain": "Click this button to copy the invite code of your campaign to the clipboard",
"copy-success": "Copied invite code successfully!",
"launch-game": "Launch game",
"exit-game": "Exit game"
}
},
"systems": {
"title": "Select a game system",
"not-selected": "No game system selected"
},
"database": {
"title": "Database",
"tabs": {
"items": "Items",
"spells": "Spells",
"features": "Features"
}
}
}

89
locales/en-US.json Normal file
View File

@ -0,0 +1,89 @@
{
"plugins": {},
"general": {
"create": "Create",
"join": "Join",
"view": "View",
"players": "Players",
"description": "Description",
"details": "Details",
"name": "Name",
"email": "Email",
"username": "Username",
"password": "Password",
"password-confirm": "Confirm your password",
"register": "Register",
"quantity": "Quantity",
"weight": "Weight",
"price": "Price"
},
"placeholders": {
"name": "John Doe",
"email": "john@doe.com",
"username": "Enter your username...",
"password": "Enter your password...",
"password-confirm": "Enter again your password..."
},
"register-admin": {
"title": "Register Admin Account",
"welcome-message": "<h1>Welcome!</h1><b>You have successfull setup Dragonroll!</b><p>Please create the admin account</p><p>Once the admin account has been created, you will be able to create user accounts that will be able to access Dragonroll</p><hr>"
},
"main-menu": {
"title": "Dragonroll",
"main-menu": "Main Menu",
"campaigns": "Campaigns",
"cosmic-compendium": "The Cosmic Compendium",
"book-anvil": "Book Anvil",
"edit-profile": "Edit Profile",
"settings": "Settings",
"log-out": "Log Out"
},
"settings": {
"title": "Dragonroll settings",
"tabs": {
"account-settings": "Account Settings",
"site-administration": "Site Administration"
},
"account": {
"account-settings": "Account Settings",
"language": "Language:"
},
"site-administration": {}
},
"campaigns": {
"title": "Campaigns",
"your-campaigns": "Your Campaigns",
"other-campaigns": "Other Campaigns",
"create": {
"title": "Create Campaign",
"enter": "Enter campaign name..."
},
"join": {
"title": "Join Campaign",
"enter": "Enter campaign code...",
"success": "Successfully joined the campaign!",
"already": "You are already in that campaign!",
"error": "Error joining this campaign, check if the code is correct"
},
"preview": {
"title": "Campaign preview",
"copy-code": "Copy invite code",
"copy-explain": "Click this button to copy the invite code of your campaign to the clipboard",
"copy-success": "Copied invite code successfully!",
"launch-game": "Launch game",
"exit-game": "Exit game"
}
},
"systems": {
"title": "Select a game system",
"not-selected": "No game system selected"
},
"database": {
"title": "Database",
"tabs": {
"items": "Items",
"spells": "Spells",
"features": "Features"
}
}
}

89
locales/es-ES.json Normal file
View File

@ -0,0 +1,89 @@
{
"plugins": {},
"general": {
"create": "Crear",
"join": "Entrar",
"view": "Abrir",
"players": "Jugadores",
"description": "Descripción",
"details": "Detalles",
"name": "Nombre",
"email": "Correo",
"username": "Nombre de usuario",
"password": "Contraseña",
"password-confirm": "Confirma tu contraseña",
"register": "Registrar-se",
"quantity": "Quantity",
"weight": "Weight",
"price": "Price"
},
"placeholders": {
"name": "John Doe",
"email": "john@doe.com",
"username": "Introduce tu nombre de usuario...",
"password": "Introduce tu contraseña...",
"password-confirm": "Vuelve a introducir tu contraseña..."
},
"register-admin": {
"title": "Registrar cuenta de administrador",
"welcome-message": "<h1>Bienvenido!</h1><b>Has configurado correctamente Dragonroll!</b><p>Porfavor, crea la cuenta de administrador</p><p>Una vez creada, esta cuenta te permitirá configurar el servidor y crear cuentas que puedan acceder a este</p><hr>"
},
"main-menu": {
"title": "Dragonroll",
"main-menu": "Menú Principal",
"campaigns": "Campañas",
"cosmic-compendium": "La librería cósmica",
"book-anvil": "Forjador de libros",
"edit-profile": "Editar perfil",
"settings": "Ajustes",
"log-out": "Cerrar sesión"
},
"settings": {
"title": "Ajustes de Dragonroll",
"tabs": {
"account-settings": "Ajustes de cuenta",
"site-administration": "Administración"
},
"account": {
"account-settings": "Ajustes de la cuenta",
"language": "Idioma:"
},
"site-administration": {}
},
"campaigns": {
"title": "Campañas",
"your-campaigns": "Tus campañas",
"other-campaigns": "Otras campañas",
"create": {
"title": "Crear campaña",
"enter": "Introduce el nombre de la campaña..."
},
"join": {
"title": "Entrar en la campaña",
"enter": "Introduce el código de la campaña...",
"success": "Has entrado en la campaña correctamente!",
"already": "Ya estás dentro de esta campaña!",
"error": "Ha habido un error al entrar en esta campaña, acaso el código existe?"
},
"preview": {
"title": "Previsualización de la campaña",
"copy-code": "Copiar codigo",
"copy-explain": "Haz clic en este botón para copiar el código de invitación a tu cortapapeles",
"copy-success": "Se ha copiado el código correctamente!",
"launch-game": "Abrir juego",
"exit-game": "Cerrar juego"
}
},
"systems": {
"title": "Selecciona un sistema de juego",
"not-selected": "Ningún sistema de juego seleccionado"
},
"database": {
"title": "Base de datos",
"tabs": {
"items": "Items",
"spells": "Hechizos",
"features": "Características"
}
}
}

View File

@ -0,0 +1,6 @@
function Main(Api){
console.log("Hello World!");
console.log(Api);
}
export { Main };

View File

@ -0,0 +1,4 @@
{
"name": "Dnd 5e System",
"entrypoint": "main.js"
}

View File

@ -3,7 +3,7 @@ import WindowHandle from '@/views/partials/WindowHandle.vue';
import { onMounted, ref } from 'vue';
import { SetupHandle, SetSize, ResetPosition } from '@/services/Windows';
import { ClearWindow, CreateWindow } from '../../../../services/Windows';
import { ClearWindow, CreateWindow } from '@/services/Windows';
const props = defineProps(['data']);
const data = props.data;

View File

@ -0,0 +1,3 @@
{
"test": "Test"
}

View File

@ -1,6 +1,13 @@
/*
DRAGONROLL PREBUILD SCRIPT
*/
const fs = require('fs');
const path = require('path');
const plugins = fs.readdirSync('./plugins')
// #region icons
const folderPaths = [
'./client/public/icons/weapons',
'./client/public/icons/equipment',
@ -16,7 +23,9 @@ const folderPaths = [
];
const outputPath = 'client/public/data/icons.json'
const outputPath = 'client/public/data/data.json'
fs.mkdirSync('client/public/data', { recursive: true });
let result = [];
let iconCount = 0;
@ -34,17 +43,16 @@ for(let i = 0; i < folderPaths.length; i++){
}
};
fs.writeFileSync(outputPath, JSON.stringify({files: result}, null, "\t"));
let icons = {files: result};
console.log('File list generated successfully!');
console.log("Generated " + iconCount + " icons");
// Locale generation
const locales = [
'./client/src/locale/en-US.json',
'./client/src/locale/es-ES.json',
'./client/src/locale/ca.json',
];
// #endregion
// #region locales
const locales = fs.readdirSync("./locales");
console.log(locales);
function deepMerge(obj1, obj2) {
for (let key in obj2) {
@ -59,10 +67,38 @@ function deepMerge(obj1, obj2) {
return obj1;
}
let originalJson = JSON.parse(fs.readFileSync(locales[0]));
for(let i = 1; i < locales.length; i++){
let data = JSON.parse(fs.readFileSync(locales[i]));
fs.writeFileSync(locales[i], JSON.stringify(deepMerge(structuredClone(originalJson), data), null, 2));
let originalJson = JSON.parse(fs.readFileSync("./locales/en-US.json"));
for(let i = 0; i < locales.length; i++){
let data = JSON.parse(fs.readFileSync("./locales/" + locales[i]));
fs.writeFileSync("./locales/" + locales[i], JSON.stringify(deepMerge(structuredClone(originalJson), data), null, 2));
};
for(let i = 0; i < locales.length; i++){
let originalLocale = JSON.parse(fs.readFileSync('./locales/' + locales[i]));
for(let j = 0; j < plugins.length; j++){
if(fs.existsSync(`./plugins/${plugins[j]}/locales/${locales[i]}`)){
let pluginLocale = JSON.parse(fs.readFileSync(`./plugins/${plugins[j]}/locales/${locales[i]}`));
let mergeJson = {plugins: {}};
mergeJson.plugins[plugins[j]] = pluginLocale;
originalLocale = deepMerge(originalLocale, mergeJson);
}
}
fs.writeFileSync("./client/src/locales/" + locales[i], JSON.stringify(originalLocale, null, 2));
}
console.log("Updated Locales")
// #endregion
// #region plugins
for(let j = 0; j < plugins.length; j++){
if(fs.existsSync(`./plugins/${plugins[j]}/client/`)){
fs.cpSync(`./plugins/${plugins[j]}/client/`, `./client/plugins/${plugins[j]}`, {recursive: true});
}
}
fs.writeFileSync(outputPath, JSON.stringify({
icons,
plugins
}, null, "\t"));
// #endregion

View File

@ -9,6 +9,7 @@ terminate(){
}
script_full_path=$(dirname "$0")
node prebuild.js
cd client
./start-dev.sh &
cd ..