This commit is contained in:
Lorraxs 2023-12-13 00:21:40 +07:00
parent eaba4d56f2
commit 2a5bea33b4
4 changed files with 70 additions and 19 deletions

View File

@ -1,10 +1,16 @@
Config = {} Config = {}
Config.EnableModules = { Config.EnableModules = {
["Newbie"] = false, ["Newbie"] = {
["Test"] = true, enabled = true,
["Test2"] = true, client = true, -- enable client side
priority = 1, -- 1 : init on start | 2 : init on player loaded
},
["Test"] = {
enabled = true,
priority = 2, -- 1 : init on start | 2 : init on player loaded
},
} }
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 = "esx" -- "qb" | "ProjectStarboy"

View File

@ -174,7 +174,7 @@ function Main:CheckValidImpl(name, impl)
end end
function Main:RegisterImpl(name, impl) function Main:RegisterImpl(name, impl)
if not Config.EnableModules[name] then if Config.EnableModules[name] == nil or not Config.EnableModules[name].enabled then
self:LogWarning("Impl %s not enabled", name) self:LogWarning("Impl %s not enabled", name)
return return
end end
@ -207,7 +207,7 @@ end
function Main:InitImpl() function Main:InitImpl()
if not IsDuplicityVersion() then if not IsDuplicityVersion() then
for k, v in pairs(Config.EnableModules) do for k, v in pairs(Config.EnableModules) do
if v then if v.enabled and v.priority == 1 and v.client then
self:LogInfo("Loading %s", k) self:LogInfo("Loading %s", k)
local source = lib.callback.await(ResourceName..":getClientImpl", false, k) local source = lib.callback.await(ResourceName..":getClientImpl", false, k)
if source ~= nil then if source ~= nil then
@ -216,16 +216,51 @@ function Main:InitImpl()
end end
end end
end end
for name, impl in pairs(self.impls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 1 then
self.initializedImpls[name] = impl(self)
end
end
self:LogInfo("All priority 1 initialized")
for name, impl in pairs(self.initializedImpls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 1 then
impl:OnReady()
end
end
else
for name, impl in pairs(self.impls) do
self.initializedImpls[name] = impl(self)
end
for name, impl in pairs(self.initializedImpls) do
impl:OnReady()
end
end end
for name, impl in pairs(self.impls) do end
self.initializedImpls[name] = impl(self)
end function Main:InitImplAfterPlayerLoaded()
self:LogInfo("All impls initialized") if not IsDuplicityVersion() then
self.ready = true for k, v in pairs(Config.EnableModules) do
for name, impl in pairs(self.initializedImpls) do if v.enabled and v.priority == 2 and v.client then
impl:OnReady() self:LogInfo("Loading %s", k)
end local source = lib.callback.await(ResourceName..":getClientImpl", false, k)
if not IsDuplicityVersion() then if source ~= nil then
self:LogInfo("Loaded %s", k)
load(source)()
end
end
end
for name, impl in pairs(self.impls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 2 then
self.initializedImpls[name] = impl(self)
end
end
self:LogInfo("All priority 2 initialized")
for name, impl in pairs(self.initializedImpls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 2 then
impl:OnReady()
end
end
SendNUIMessage({ SendNUIMessage({
action = "updateServerState", action = "updateServerState",
data = { data = {
@ -233,7 +268,7 @@ function Main:InitImpl()
} }
}) })
end end
self.ready = true
end end
function Main:GetImpl(name) function Main:GetImpl(name)
@ -301,6 +336,7 @@ Citizen.CreateThread(function()
main:LogInfo("Waiting for Framework") main:LogInfo("Waiting for Framework")
Wait(100) Wait(100)
end end
main:InitImpl()
if not IsDuplicityVersion() then if not IsDuplicityVersion() then
if Config.Framework == 'esx' then if Config.Framework == 'esx' then
while not Framework.IsPlayerLoaded() do while not Framework.IsPlayerLoaded() do
@ -317,5 +353,5 @@ Citizen.CreateThread(function()
Wait(100) Wait(100)
end end
end end
main:InitImpl() main:InitImplAfterPlayerLoaded()
end) end)

File diff suppressed because one or more lines are too long

View File

@ -1,13 +1,22 @@
import React from 'react'; import React, { useEffect } from 'react';
import { Provider, useSelector } from 'react-redux'; import { Provider, useSelector } from 'react-redux';
import { AppActions, RootState, store } from './store'; import { AppActions, RootState, store } from './store';
import { ToastContainer } from 'react-toastify'; import { ToastContainer } from 'react-toastify';
import { Box } from 'lr-components'; import { Box } from 'lr-components';
import { NextUIProvider } from '@nextui-org/react'; import { NextUIProvider } from '@nextui-org/react';
import AppActionHook from './components/AppActionHook'; import AppActionHook from './components/AppActionHook';
import { isEnvBrowser } from './utils/misc';
import { fetchNui } from './utils/fetchNui';
function App() { function App() {
const show = useSelector((state: RootState) => state.state.show); const show = useSelector((state: RootState) => state.state.show);
useEffect(() => {
if (!isEnvBrowser()) {
setTimeout(() => {
fetchNui('AppReady');
}, 2000);
}
}, []);
return ( return (
show && ( show && (
<NextUIProvider> <NextUIProvider>