From 796cd23e8ddeb110d40e6f4415bd2efcbe02023a Mon Sep 17 00:00:00 2001 From: Lorraxs Date: Tue, 2 Jan 2024 10:50:35 +0700 Subject: [PATCH] z --- client/impl/newbie.impl.lua | 10 ------- client/impl/test2.impl.lua | 39 ---------------------------- config.lua | 11 ++++++-- main.lua | 2 +- server/server.lua | 0 web/src/App.tsx | 39 ++++++++++++++++------------ web/src/components/AppActionHook.tsx | 1 - web/src/types/index.ts | 1 + web/src/types/setting.type.ts | 16 ++++++++++++ 9 files changed, 50 insertions(+), 69 deletions(-) delete mode 100644 client/impl/newbie.impl.lua delete mode 100644 client/impl/test2.impl.lua delete mode 100644 server/server.lua create mode 100644 web/src/types/setting.type.ts diff --git a/client/impl/newbie.impl.lua b/client/impl/newbie.impl.lua deleted file mode 100644 index b1692a9..0000000 --- a/client/impl/newbie.impl.lua +++ /dev/null @@ -1,10 +0,0 @@ -local Impl = NewImpl("Newbie") - -function Impl:Init() - main:LogInfo("%s initialized", self:GetName()) -end - -function Impl:OnReady() - main:LogInfo("%s ready", self:GetName()) -end - diff --git a/client/impl/test2.impl.lua b/client/impl/test2.impl.lua deleted file mode 100644 index 68be622..0000000 --- a/client/impl/test2.impl.lua +++ /dev/null @@ -1,39 +0,0 @@ -local Impl = NewImpl("Test2") - -function Impl:OnReady() - self:MainThread() - self:TestHook() - self:TestReplaceMethod() -end - -function Impl:MainThread() - local testImpl = main:GetImpl("Test") - Citizen.CreateThread(function() - while true do - Wait(1000) - local result = testImpl:Add(1, 2) - main:LogInfo("TestImpl result %s", result) - end - end) -end - -function Impl:TestHook() - local testImpl = main:GetImpl("Test") - testImpl:HookMethod("Add", function(self, amount, amount2) - return amount+1, amount2 - end) -end - -function Impl:TestReplaceMethod() - Citizen.CreateThread(function() - Wait(5000) - local testImpl = main:GetImpl("Test") - local oldMethod = testImpl:GetMethod("Add") - testImpl:ReplaceMethod("Add", function(self, amount, amount2) - self.testVar = self.testVar * amount * amount2 - return self.testVar - end) - Wait(5000) - testImpl:ReplaceMethod("Add", oldMethod) - end) -end \ No newline at end of file diff --git a/config.lua b/config.lua index f2c0a29..f890043 100644 --- a/config.lua +++ b/config.lua @@ -1,9 +1,15 @@ Config = {} + +Config.UISetting = { + locale = {} +} + +--Dont touch this Config.EnableModules = { ["Newbie"] = { enabled = true, client = true, -- enable client side - priority = 1, -- 1 : init on start | 2 : init on player loaded + priority = 1, -- 1 : init on start | 2 : init on player loaded }, ["Test"] = { enabled = true, @@ -13,4 +19,5 @@ Config.EnableModules = { Config.Debug = true Config.Nui = false Config.Dev = false -Config.Framework = "esx" -- "qb" | "ProjectStarboy" +Config.Framework = "custom" -- "qb" | "esx" | "custom" +Config.ClientLazyLoad = false diff --git a/main.lua b/main.lua index 5756e4f..96dadbc 100644 --- a/main.lua +++ b/main.lua @@ -20,7 +20,7 @@ if IsDuplicityVersion() then end else RegisterNUICallback('AppReady', function(data, cb) - cb({}) + cb(Config.UISetting or {}) NuiReady = true end) end diff --git a/server/server.lua b/server/server.lua deleted file mode 100644 index e69de29..0000000 diff --git a/web/src/App.tsx b/web/src/App.tsx index 100e2ab..e0fba7a 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { createContext, useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import { AppActions, RootState } from './store'; import { ToastContainer } from 'react-toastify'; @@ -7,18 +7,24 @@ import { NextUIProvider } from '@nextui-org/react'; import AppActionHook from './components/AppActionHook'; import { isEnvBrowser } from './utils/misc'; import { fetchNui } from './utils/fetchNui'; +import { DefaultUISetting, ISettingContext, UISetting } from './types'; + +const SettingContext = createContext(DefaultUISetting); function App() { const show = useSelector((state: RootState) => state.main.show); + const [setting, setSetting] = useState({ locale: {} }); + const L = (key: string) => setting.locale[key] || key; useEffect(() => { if (!isEnvBrowser()) { - setTimeout(() => { - fetchNui('AppReady'); + setTimeout(async () => { + const UISetting = await fetchNui('AppReady'); + setSetting(UISetting); }, 2000); } - }, []); + }, [setSetting]); return ( - show && ( + - - + {show && ( + + )} - ) + ); } diff --git a/web/src/components/AppActionHook.tsx b/web/src/components/AppActionHook.tsx index 6030275..d3848f6 100644 --- a/web/src/components/AppActionHook.tsx +++ b/web/src/components/AppActionHook.tsx @@ -11,7 +11,6 @@ interface Props { function AppActionHook(props: Props) { const dispatch = useDispatch(); const isDev = isEnvBrowser(); - console.log('AppActionHook', props.action); useNuiEvent(props.action, (data) => { //dynamicDispatch(action, data); // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/web/src/types/index.ts b/web/src/types/index.ts index 7aeb546..c577e46 100644 --- a/web/src/types/index.ts +++ b/web/src/types/index.ts @@ -1 +1,2 @@ export * from './redux.type'; +export * from './setting.type'; diff --git a/web/src/types/setting.type.ts b/web/src/types/setting.type.ts new file mode 100644 index 0000000..887bd2f --- /dev/null +++ b/web/src/types/setting.type.ts @@ -0,0 +1,16 @@ +export interface ISettingContext { + setting: UISetting; + setSetting: (setting: UISetting) => void; + L: (key: string) => string; +} + +export interface UISetting { + locale: { [key: string]: string }; +} +export const DefaultUISetting: ISettingContext = { + setting: { + locale: {}, + }, + setSetting: () => {}, + L: (key: string) => key, +};