z
This commit is contained in:
parent
77dc46460b
commit
796cd23e8d
|
@ -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
|
||||
|
|
@ -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
|
11
config.lua
11
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
|
||||
|
|
2
main.lua
2
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
|
||||
|
|
|
@ -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<ISettingContext>(DefaultUISetting);
|
||||
|
||||
function App() {
|
||||
const show = useSelector((state: RootState) => state.main.show);
|
||||
const [setting, setSetting] = useState<UISetting>({ locale: {} });
|
||||
const L = (key: string) => setting.locale[key] || key;
|
||||
useEffect(() => {
|
||||
if (!isEnvBrowser()) {
|
||||
setTimeout(() => {
|
||||
fetchNui('AppReady');
|
||||
setTimeout(async () => {
|
||||
const UISetting = await fetchNui<UISetting>('AppReady');
|
||||
setSetting(UISetting);
|
||||
}, 2000);
|
||||
}
|
||||
}, []);
|
||||
}, [setSetting]);
|
||||
return (
|
||||
show && (
|
||||
<SettingContext.Provider value={{ setting, setSetting, L }}>
|
||||
<NextUIProvider>
|
||||
<Box
|
||||
display='flex'
|
||||
|
@ -39,19 +45,20 @@ function App() {
|
|||
);
|
||||
})}
|
||||
</Box>
|
||||
<Box
|
||||
width={'100%'}
|
||||
height={'100%'}
|
||||
display='flex'
|
||||
justifyContent='center'
|
||||
alignItems='center'
|
||||
className='prose'
|
||||
pointerEvents='none'
|
||||
></Box>
|
||||
|
||||
{show && (
|
||||
<Box
|
||||
width={'100%'}
|
||||
height={'100%'}
|
||||
display='flex'
|
||||
justifyContent='center'
|
||||
alignItems='center'
|
||||
className='prose'
|
||||
pointerEvents='none'
|
||||
></Box>
|
||||
)}
|
||||
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
|
||||
</NextUIProvider>
|
||||
)
|
||||
</SettingContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ interface Props {
|
|||
function AppActionHook(props: Props) {
|
||||
const dispatch = useDispatch<AppDispatch>();
|
||||
const isDev = isEnvBrowser();
|
||||
console.log('AppActionHook', props.action);
|
||||
useNuiEvent(props.action, (data) => {
|
||||
//dynamicDispatch(action, data);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export * from './redux.type';
|
||||
export * from './setting.type';
|
||||
|
|
16
web/src/types/setting.type.ts
Normal file
16
web/src/types/setting.type.ts
Normal 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,
|
||||
};
|
Loading…
Reference in New Issue
Block a user