diff --git a/fxmanifest.lua b/fxmanifest.lua index 181457e..0485079 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -33,10 +33,14 @@ dependencies { '/onesync', } +ui_page 'web/build/index.html' + files { 'init.lua', 'imports/**/client.lua', 'imports/**/shared.lua', + 'web/build/index.html', + 'web/build/**/*' } shared_script 'resource/main.lua' diff --git a/web/.gitignore b/web/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/web/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/web/craco.config.js b/web/craco.config.js new file mode 100644 index 0000000..2a19cf4 --- /dev/null +++ b/web/craco.config.js @@ -0,0 +1,24 @@ +const path = require("path"); +module.exports = { + webpack: { + configure: (webpackConfig) => { + // Because CEF has issues with loading source maps properly atm, + // lets use the best we can get in line with `eval-source-map` + if (webpackConfig.mode === 'development' && process.env.IN_GAME_DEV) { + webpackConfig.devtool = 'eval-source-map' + webpackConfig.output.path = path.join(__dirname, 'build') + } + + return webpackConfig + } + }, + + devServer: (devServerConfig) => { + if (process.env.IN_GAME_DEV) { + // Used for in-game dev mode + devServerConfig.devMiddleware.writeToDisk = true + } + + return devServerConfig + } +} diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..a32c604 --- /dev/null +++ b/web/package.json @@ -0,0 +1,54 @@ +{ + "name": "web", + "version": "0.1.0", + "homepage": "web/build", + "private": true, + "dependencies": { + "@chakra-ui/react": "^1.8.6", + "@emotion/react": "11", + "@emotion/styled": "11", + "@testing-library/jest-dom": "^5.16.1", + "@testing-library/react": "^12.1.2", + "@testing-library/user-event": "^13.5.0", + "@types/jest": "^26.0.24", + "@types/node": "^16.11.18", + "@types/react": "^17.0.38", + "@types/react-dom": "^17.0.11", + "framer-motion": "6", + "react": "^17.0.2", + "react-dom": "^17.0.2", + "react-scripts": "5.0.0", + "typescript": "^4.5.5", + "web-vitals": "^2.1.3" + }, + "scripts": { + "start": "cross-env PUBLIC_URL=/ craco start", + "start:game": "cross-env IN_GAME_DEV=1 craco start", + "build": "rimraf build && craco build", + "test": "craco test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "devDependencies": { + "@craco/craco": "^6.4.3", + "cross-env": "^7.0.3", + "rimraf": "^3.0.2" + } +} diff --git a/web/public/index.html b/web/public/index.html new file mode 100644 index 0000000..7bc4a2d --- /dev/null +++ b/web/public/index.html @@ -0,0 +1,23 @@ + + +
+ + + +(events: DebugEvent
[], timer = 1000): void => {
+ if (process.env.NODE_ENV === "development" && isEnvBrowser()) {
+ for (const event of events) {
+ setTimeout(() => {
+ window.dispatchEvent(
+ new MessageEvent("message", {
+ data: {
+ action: event.action,
+ data: event.data,
+ },
+ })
+ );
+ }, timer);
+ }
+ }
+};
\ No newline at end of file
diff --git a/web/src/utils/fetchNui.ts b/web/src/utils/fetchNui.ts
new file mode 100644
index 0000000..6069465
--- /dev/null
+++ b/web/src/utils/fetchNui.ts
@@ -0,0 +1,28 @@
+/**
+ * Simple wrapper around fetch API tailored for CEF/NUI use. This abstraction
+ * can be extended to include AbortController if needed or if the response isn't
+ * JSON. Tailor it to your needs.
+ *
+ * @param eventName - The endpoint eventname to target
+ * @param data - Data you wish to send in the NUI Callback
+ *
+ * @return returnData - A promise for the data sent back by the NuiCallbacks CB argument
+ */
+
+export async function fetchNui