This commit is contained in:
Lorraxs 2024-01-02 10:50:35 +07:00
parent 77dc46460b
commit 796cd23e8d
9 changed files with 50 additions and 69 deletions

View File

@ -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

View File

@ -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

View File

@ -1,9 +1,15 @@
Config = {} Config = {}
Config.UISetting = {
locale = {}
}
--Dont touch this
Config.EnableModules = { Config.EnableModules = {
["Newbie"] = { ["Newbie"] = {
enabled = true, enabled = true,
client = true, -- enable client side 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"] = { ["Test"] = {
enabled = true, enabled = true,
@ -13,4 +19,5 @@ Config.EnableModules = {
Config.Debug = true Config.Debug = true
Config.Nui = false Config.Nui = false
Config.Dev = false Config.Dev = false
Config.Framework = "esx" -- "qb" | "ProjectStarboy" Config.Framework = "custom" -- "qb" | "esx" | "custom"
Config.ClientLazyLoad = false

View File

@ -20,7 +20,7 @@ if IsDuplicityVersion() then
end end
else else
RegisterNUICallback('AppReady', function(data, cb) RegisterNUICallback('AppReady', function(data, cb)
cb({}) cb(Config.UISetting or {})
NuiReady = true NuiReady = true
end) end)
end end

View File

View File

@ -1,4 +1,4 @@
import React, { useEffect } from 'react'; import React, { createContext, useEffect, useState } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { AppActions, RootState } from './store'; import { AppActions, RootState } from './store';
import { ToastContainer } from 'react-toastify'; import { ToastContainer } from 'react-toastify';
@ -7,18 +7,24 @@ import { NextUIProvider } from '@nextui-org/react';
import AppActionHook from './components/AppActionHook'; import AppActionHook from './components/AppActionHook';
import { isEnvBrowser } from './utils/misc'; import { isEnvBrowser } from './utils/misc';
import { fetchNui } from './utils/fetchNui'; import { fetchNui } from './utils/fetchNui';
import { DefaultUISetting, ISettingContext, UISetting } from './types';
const SettingContext = createContext<ISettingContext>(DefaultUISetting);
function App() { function App() {
const show = useSelector((state: RootState) => state.main.show); const show = useSelector((state: RootState) => state.main.show);
const [setting, setSetting] = useState<UISetting>({ locale: {} });
const L = (key: string) => setting.locale[key] || key;
useEffect(() => { useEffect(() => {
if (!isEnvBrowser()) { if (!isEnvBrowser()) {
setTimeout(() => { setTimeout(async () => {
fetchNui('AppReady'); const UISetting = await fetchNui<UISetting>('AppReady');
setSetting(UISetting);
}, 2000); }, 2000);
} }
}, []); }, [setSetting]);
return ( return (
show && ( <SettingContext.Provider value={{ setting, setSetting, L }}>
<NextUIProvider> <NextUIProvider>
<Box <Box
display='flex' display='flex'
@ -39,19 +45,20 @@ function App() {
); );
})} })}
</Box> </Box>
<Box {show && (
width={'100%'} <Box
height={'100%'} width={'100%'}
display='flex' height={'100%'}
justifyContent='center' display='flex'
alignItems='center' justifyContent='center'
className='prose' alignItems='center'
pointerEvents='none' className='prose'
></Box> pointerEvents='none'
></Box>
)}
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} /> <ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
</NextUIProvider> </NextUIProvider>
) </SettingContext.Provider>
); );
} }

View File

@ -11,7 +11,6 @@ interface Props {
function AppActionHook(props: Props) { function AppActionHook(props: Props) {
const dispatch = useDispatch<AppDispatch>(); const dispatch = useDispatch<AppDispatch>();
const isDev = isEnvBrowser(); const isDev = isEnvBrowser();
console.log('AppActionHook', props.action);
useNuiEvent(props.action, (data) => { useNuiEvent(props.action, (data) => {
//dynamicDispatch(action, data); //dynamicDispatch(action, data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@ -1 +1,2 @@
export * from './redux.type'; export * from './redux.type';
export * from './setting.type';

View File

@ -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,
};