Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Add Image Path Resolving to Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Aug 3, 2022
1 parent d6a9bd1 commit d17d175
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 52 additions & 0 deletions scripts/plugins/webview-images.js
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions scripts/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`);
}

Expand Down
2 changes: 1 addition & 1 deletion src-webviews/src/defaultPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }];
6 changes: 5 additions & 1 deletion src-webviews/src/utility/pathResolver.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/core-factions/webview/Factions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineComponent({
},
data() {
return {
pageIndex: 5,
pageIndex: 0,
pages: [
{ name: 'Members', page: 'Members' },
{ name: 'Ranks', page: 'Ranks' },
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/core-factions/webview/pages/Bank.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default defineComponent({
this.manageRanks = rank.rankPermissions.manageRanks;
this.manageRankPermissions = rank.rankPermissions.manageRankPermissions;
}
},
},
watch: {
amount() {
Expand Down
Empty file.

0 comments on commit d17d175

Please sign in to comment.