From 3750969be4dceceb3a7334642c3137a62cff8597 Mon Sep 17 00:00:00 2001 From: Lajos Meszaros Date: Wed, 2 Feb 2022 09:56:16 +0100 Subject: [PATCH] Found a solution to the routing issue --- rootpath.js | 11 +++++++++++ src/assets/ambiences.js | 6 +++--- src/assets/items.js | 8 ++++---- src/assets/textures.js | 4 ++-- src/constants.js | 11 ----------- src/electron/index.js | 3 --- src/electron/src/app.jsx | 4 ++++ 7 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 rootpath.js diff --git a/rootpath.js b/rootpath.js new file mode 100644 index 00000000..35af59d0 --- /dev/null +++ b/rootpath.js @@ -0,0 +1,11 @@ +let folder = __dirname; + +const getRootPath = () => { + return folder; +}; + +const setRootPath = (newFolder) => { + folder = newFolder; +}; + +module.exports = { getRootPath, setRootPath }; diff --git a/src/assets/ambiences.js b/src/assets/ambiences.js index 30cda50f..7ad78a8e 100644 --- a/src/assets/ambiences.js +++ b/src/assets/ambiences.js @@ -1,5 +1,5 @@ const { compose, clone, filter, propEq, reduce, uniq } = require("ramda"); -const { getAssetsFolder } = require("../constants"); +const { getRootPath } = require("../../rootpath"); const ambiences = { none: { @@ -28,13 +28,13 @@ const exportAmbiences = (outputDir) => { reduce((files, ambience) => { const filename = `${outputDir}/sfx/ambiance/${ambience.name}.amb`; - files[filename] = `${getAssetsFolder()}/sfx/ambiance/${ + files[filename] = `${getRootPath()}/assets/sfx/ambiance/${ ambience.name }.amb`; const tracks = ambience.tracks || []; tracks.forEach((track) => { - files[`${outputDir}/${track}`] = `${getAssetsFolder()}/${track}`; + files[`${outputDir}/${track}`] = `${getRootPath()}/assets/${track}`; }); return files; diff --git a/src/assets/items.js b/src/assets/items.js index fceeef57..140aa4fb 100644 --- a/src/assets/items.js +++ b/src/assets/items.js @@ -20,11 +20,11 @@ const { isEmpty, reject, pluck, - isNil, uniq, } = require("ramda"); const { padCharsStart, isFunction, isObject } = require("ramda-adjunct"); -const { PLAYER_HEIGHT_ADJUSTMENT, getAssetsFolder } = require("../constants"); +const { getRootPath } = require("../../rootpath"); +const { PLAYER_HEIGHT_ADJUSTMENT } = require("../constants"); const items = { marker: { @@ -316,11 +316,11 @@ const exportDependencies = (outputDir) => { const { dir: dir2, name: name2, ext: ext2 } = path.parse(source); files[ `${outputDir}/${dir1}/${name1}${ext1}` - ] = `${getAssetsFolder()}/${dir2}/${name2}${ext2}`; + ] = `${getRootPath()}/assets/${dir2}/${name2}${ext2}`; } else { const { dir, name, ext } = path.parse(filename); const target = `${outputDir}/${dir}/${name}${ext}`; - files[target] = `${getAssetsFolder()}/${dir}/${name}${ext}`; + files[target] = `${getRootPath()}/assets/${dir}/${name}${ext}`; } return files; diff --git a/src/assets/textures.js b/src/assets/textures.js index b243bc5e..753ddae8 100644 --- a/src/assets/textures.js +++ b/src/assets/textures.js @@ -10,7 +10,7 @@ const { reduce, uniq, } = require("ramda"); -const { getAssetsFolder } = require("../constants"); +const { getRootPath } = require("../../rootpath"); const textures = { none: null, @@ -137,7 +137,7 @@ const exportTextures = (outputDir) => { return compose( reduce((files, texture) => { const filename = `${outputDir}/graph/obj3d/textures/${texture.src}`; - files[filename] = `${getAssetsFolder()}/graph/obj3d/textures/${ + files[filename] = `${getRootPath()}/assets/graph/obj3d/textures/${ texture.src }`; return files; diff --git a/src/constants.js b/src/constants.js index 3a9ae56a..d93f9801 100644 --- a/src/constants.js +++ b/src/constants.js @@ -70,14 +70,6 @@ const PLAYER_HEIGHT_ADJUSTMENT = -140; const ISLAND_JOINT_LENGTH = 5; const ISLAND_JOINT_WIDTH = 3; -let assetsFolder = path.resolve("./assets"); - -const getAssetsFolder = () => assetsFolder; - -const setAssetsFolder = (folder) => { - assetsFolder = folder; -}; - module.exports = { POLY_NO_SHADOW, POLY_DOUBLESIDED, @@ -138,7 +130,4 @@ module.exports = { ISLAND_JOINT_LENGTH, ISLAND_JOINT_WIDTH, - - getAssetsFolder, - setAssetsFolder, }; diff --git a/src/electron/index.js b/src/electron/index.js index bcd4b4b4..e91fc581 100644 --- a/src/electron/index.js +++ b/src/electron/index.js @@ -1,6 +1,5 @@ const { app, BrowserWindow, dialog, ipcMain } = require("electron"); const path = require("path"); -const { setAssetsFolder, getAssetsFolder } = require("../constants"); let win; @@ -22,8 +21,6 @@ const createWindow = () => { }; app.whenReady().then(() => { - setAssetsFolder(path.resolve(app.getAppPath(), "../../assets")); - createWindow(); app.on("activate", () => { diff --git a/src/electron/src/app.jsx b/src/electron/src/app.jsx index 8a9c77ca..05063cf1 100644 --- a/src/electron/src/app.jsx +++ b/src/electron/src/app.jsx @@ -1,7 +1,11 @@ +import path from "path"; import React from "react"; import ReactDOM from "react-dom"; +import { setRootPath } from "../../../rootpath.js"; import App from "./components/App.jsx"; +setRootPath(path.resolve(__dirname, "../../../")); + window.addEventListener("DOMContentLoaded", () => { ReactDOM.render(, document.getElementById("app")); });