diff --git a/.gitignore b/.gitignore index fc8b3afdb9..7199f177af 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ package-lock.json scripts/buildresource/*.json src-webviews/src/plugins/imports.ts src-webviews/src/plugins/vue-plugin-imports.ts +!src-webviews/public/plugins/.gitkeep +src-webviews/public/plugins/** # Yarn stuff .yarn/ diff --git a/package.json b/package.json index 3c08d03c5a..f530f9267e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "check": "tsc -p ./src/tsconfig.json | npx loose-ts-check --ignored-error-codes ./.loose-ts-check/ignore-codes.json --loosely-type-checked-files ./.loose-ts-check/loosely-type-checked-files.json", "fix": "node ./scripts/doctor/index.js", "[-] Vue WebView Deployment": "", - "vue-dev": "node ./scripts/plugins/webview && npx vite ./src-webviews --clearScreen=false --debug=false --logLevel=silent", + "vue-dev": "node ./scripts/plugins/webview && node ./scripts/plugins/webview-images && npx vite ./src-webviews --clearScreen=false", "[-] Utility": "", "prepare": "husky install && husky-init", "lint": "prettier --end-of-line auto --config package.json --write ./src/**/*.ts", diff --git a/scripts/plugins/webview-images.js b/scripts/plugins/webview-images.js new file mode 100644 index 0000000000..3d035126e0 --- /dev/null +++ b/scripts/plugins/webview-images.js @@ -0,0 +1,52 @@ +import fs from 'fs-extra'; +import glob from 'glob'; +import path from 'path'; +import { getEnabledPlugins, sanitizePath } from './shared.js'; + +function getWebviewImages(pluginName) { + const pluginFolder = sanitizePath(path.join(process.cwd(), 'src/core/plugins', pluginName)); + if (!fs.existsSync(sanitizePath(path.join(pluginFolder, 'webview', 'images')))) { + return 0; + } + + let allFiles = []; + let amountCopied = 0; + + for (let ext of ['png', 'gif', 'jpg', 'jpeg', 'webm']) { + const files = glob.sync(sanitizePath(path.join(pluginFolder, `webview/images/**/*.${ext}`))); + allFiles = allFiles.concat(files); + } + + for (let i = 0; i < allFiles.length; i++) { + const imgPath = allFiles[i]; + const finalPath = sanitizePath(imgPath.replace(/.*\/webview\/images/gm, `src-webviews/public/plugins/${pluginName}`)) + if (fs.existsSync(imgPath)) { + const folderPath = sanitizePath(path.dirname(finalPath)); + if (!fs.existsSync(folderPath)) { + fs.mkdirSync(folderPath, { recursive: true }); + } + + fs.copyFileSync(imgPath, finalPath); + amountCopied += 1; + } + } + + return amountCopied; +} + +function run() { + const enabledPlugins = getEnabledPlugins(); + fs.emptyDirSync(sanitizePath('src-webviews/public/plugins/')); + fs.writeFileSync(sanitizePath('src-webviews/public/plugins/.gitkeep'), ''); + + let totalCopied = 0; + + for (const pluginName of enabledPlugins) { + const count = getWebviewImages(pluginName); + totalCopied += count; + } + + console.log(`WebView Images Moved -- ${totalCopied}`); +} + +run(); diff --git a/scripts/runtime/index.js b/scripts/runtime/index.js index 7cd2553e3a..3e9227c771 100644 --- a/scripts/runtime/index.js +++ b/scripts/runtime/index.js @@ -223,6 +223,7 @@ async function coreBuildProcess() { await runFile(node, './scripts/compiler/core'); await runFile(node, './scripts/plugins/core'); await runFile(node, './scripts/plugins/webview'); + await runFile(node, './scripts/plugins/webview-images'); console.log(`===> Finished Core Build (${Date.now() - start}ms)`); } diff --git a/src-webviews/src/defaultPage.ts b/src-webviews/src/defaultPage.ts index 03e9b44b40..f902729b6a 100644 --- a/src-webviews/src/defaultPage.ts +++ b/src-webviews/src/defaultPage.ts @@ -2,4 +2,4 @@ // This does not change anything in-game. // It's solely for development mode only. -export default [{ name: 'SimpleHud' }]; +export default [{ name: 'Factions' }]; diff --git a/src-webviews/src/utility/pathResolver.ts b/src-webviews/src/utility/pathResolver.ts index fe5436ee06..27dc1d138e 100644 --- a/src-webviews/src/utility/pathResolver.ts +++ b/src-webviews/src/utility/pathResolver.ts @@ -1,4 +1,8 @@ -export default function resolvePath(currentPath: string): string { +export default function resolvePath(currentPath: string, pluginName = ''): string { + if (currentPath.includes('images/') && pluginName) { + currentPath = currentPath.replace(/.*images\//gm, `./plugins/${pluginName}/`); + } + if (!('alt' in window)) { return currentPath; } diff --git a/src/core/plugins/core-factions/webview/Factions.vue b/src/core/plugins/core-factions/webview/Factions.vue index 1d6019eaad..6016e683e4 100644 --- a/src/core/plugins/core-factions/webview/Factions.vue +++ b/src/core/plugins/core-factions/webview/Factions.vue @@ -56,7 +56,7 @@ export default defineComponent({ }, data() { return { - pageIndex: 5, + pageIndex: 0, pages: [ { name: 'Members', page: 'Members' }, { name: 'Ranks', page: 'Ranks' }, diff --git a/src/core/plugins/core-factions/webview/pages/Bank.vue b/src/core/plugins/core-factions/webview/pages/Bank.vue index 713a4e4a99..8f2168d04f 100644 --- a/src/core/plugins/core-factions/webview/pages/Bank.vue +++ b/src/core/plugins/core-factions/webview/pages/Bank.vue @@ -123,7 +123,7 @@ export default defineComponent({ this.manageRanks = rank.rankPermissions.manageRanks; this.manageRankPermissions = rank.rankPermissions.manageRankPermissions; - } + }, }, watch: { amount() { diff --git a/src/core/plugins/example-webview/disable b/src/core/plugins/example-webview/disable deleted file mode 100644 index e69de29bb2..0000000000