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
|
|
|
@ -1,4 +1,10 @@
|
||||||
Config = {}
|
Config = {}
|
||||||
|
|
||||||
|
Config.UISetting = {
|
||||||
|
locale = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
--Dont touch this
|
||||||
Config.EnableModules = {
|
Config.EnableModules = {
|
||||||
["Newbie"] = {
|
["Newbie"] = {
|
||||||
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
|
||||||
|
|
2
main.lua
2
main.lua
|
@ -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
|
||||||
|
|
|
@ -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,6 +45,7 @@ function App() {
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
|
{show && (
|
||||||
<Box
|
<Box
|
||||||
width={'100%'}
|
width={'100%'}
|
||||||
height={'100%'}
|
height={'100%'}
|
||||||
|
@ -48,10 +55,10 @@ function App() {
|
||||||
className='prose'
|
className='prose'
|
||||||
pointerEvents='none'
|
pointerEvents='none'
|
||||||
></Box>
|
></Box>
|
||||||
|
)}
|
||||||
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
|
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
|
||||||
</NextUIProvider>
|
</NextUIProvider>
|
||||||
)
|
</SettingContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
export * from './redux.type';
|
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