add type
This commit is contained in:
parent
0935cbf272
commit
d0275487e0
19
impl.lua
19
impl.lua
|
@ -1,9 +1,15 @@
|
||||||
|
---@class Class
|
||||||
|
---@field destroyed boolean
|
||||||
|
---@field originalMethods table
|
||||||
|
---@field eventHandlers table
|
||||||
Class = {}
|
Class = {}
|
||||||
env = IsDuplicityVersion() and "sv" or "cl"
|
env = IsDuplicityVersion() and "sv" or "cl"
|
||||||
-- default (empty) constructor
|
-- default (empty) constructor
|
||||||
function Class:Init(...) end
|
function Class:Init(...) end
|
||||||
|
|
||||||
-- create a subclass
|
---comment
|
||||||
|
---@param obj any
|
||||||
|
---@return any
|
||||||
function Class:extend(obj)
|
function Class:extend(obj)
|
||||||
local obj = obj or {}
|
local obj = obj or {}
|
||||||
|
|
||||||
|
@ -81,9 +87,11 @@ end
|
||||||
function Class:set(prop, value)
|
function Class:set(prop, value)
|
||||||
if not value and type(prop) == "table" then
|
if not value and type(prop) == "table" then
|
||||||
for k, v in pairs(prop) do
|
for k, v in pairs(prop) do
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
rawset(self._, k, v)
|
rawset(self._, k, v)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
rawset(self._, prop, value)
|
rawset(self._, prop, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,11 +107,16 @@ function Class:new(...)
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: lowercase-global
|
||||||
function class(attr)
|
function class(attr)
|
||||||
attr = attr or {}
|
attr = attr or {}
|
||||||
return Class:extend(attr)
|
return Class:extend(attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class Impl:Class
|
||||||
|
---@field name string
|
||||||
|
---@field config table
|
||||||
|
---@field implType "impl"
|
||||||
Impl = class()
|
Impl = class()
|
||||||
|
|
||||||
function Impl:GetName()
|
function Impl:GetName()
|
||||||
|
@ -288,7 +301,11 @@ function Impl:GetConfig()
|
||||||
return self.config
|
return self.config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Create a new Implemented class
|
||||||
|
---@param name string
|
||||||
|
---@return Impl
|
||||||
function NewImpl(name)
|
function NewImpl(name)
|
||||||
|
---@type Impl
|
||||||
local impl = Impl:extend({
|
local impl = Impl:extend({
|
||||||
name = name,
|
name = name,
|
||||||
config = Config[name] or {},
|
config = Config[name] or {},
|
||||||
|
|
41
main.lua
41
main.lua
|
@ -13,6 +13,9 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class Main
|
||||||
|
---@field impls table<string, Impl>
|
||||||
|
---@field initializedImpls table<string, Impl>
|
||||||
Main = {}
|
Main = {}
|
||||||
ResourceName = GetCurrentResourceName()
|
ResourceName = GetCurrentResourceName()
|
||||||
local RegisteredEvents = {}
|
local RegisteredEvents = {}
|
||||||
|
@ -26,6 +29,9 @@ else
|
||||||
NuiReady = true
|
NuiReady = true
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Init main class
|
||||||
|
---@return Main
|
||||||
function Main:Init()
|
function Main:Init()
|
||||||
local o = {}
|
local o = {}
|
||||||
setmetatable(o, { __index = Main })
|
setmetatable(o, { __index = Main })
|
||||||
|
@ -42,25 +48,23 @@ function Main:Init()
|
||||||
o.playerServerId = GetPlayerServerId(o.playerId)
|
o.playerServerId = GetPlayerServerId(o.playerId)
|
||||||
o:Thread1()
|
o:Thread1()
|
||||||
else
|
else
|
||||||
if Config.ClientLazyLoad then
|
o.ClientImpls = {}
|
||||||
o.ClientImpls = {}
|
for k, v in pairs(Config.EnableModules) do
|
||||||
for k, v in pairs(Config.EnableModules) do
|
if v then
|
||||||
if v then
|
local path = "client/impl/" .. k .. ".impl.lua"
|
||||||
local path = "client/impl/" .. k .. ".impl.lua"
|
local source = LoadResourceFile(ResourceName, path)
|
||||||
local source = LoadResourceFile(ResourceName, path)
|
if source == nil then
|
||||||
if source == nil then
|
self:LogWarning("Failed to load %s", path)
|
||||||
self:LogWarning("Failed to load %s", path)
|
else
|
||||||
else
|
--[[ self:LogInfo("Loading %s", path)
|
||||||
--[[ self:LogInfo("Loading %s", path)
|
self:LogInfo("Loaded %s", source) ]]
|
||||||
self:LogInfo("Loaded %s", source) ]]
|
o.ClientImpls[k] = source
|
||||||
o.ClientImpls[k] = source
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
lib.callback.register(ResourceName .. ":getClientImpl", function(source, implName)
|
|
||||||
return o.ClientImpls[implName]
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
lib.callback.register(ResourceName .. ":getClientImpl", function(source, implName)
|
||||||
|
return o.ClientImpls[implName]
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
o:Exports()
|
o:Exports()
|
||||||
o:RegisterCommands()
|
o:RegisterCommands()
|
||||||
|
@ -75,6 +79,7 @@ end
|
||||||
|
|
||||||
if not IsDuplicityVersion() then
|
if not IsDuplicityVersion() then
|
||||||
function Main:Thread1()
|
function Main:Thread1()
|
||||||
|
self.playerServerId = GetPlayerServerId(self.playerId)
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
self.playerId = PlayerId()
|
self.playerId = PlayerId()
|
||||||
|
@ -127,7 +132,7 @@ function Main:RegisterCommands()
|
||||||
end
|
end
|
||||||
local source = LoadResourceFile(ResourceName, "server/impl/" .. implName .. ".impl.lua")
|
local source = LoadResourceFile(ResourceName, "server/impl/" .. implName .. ".impl.lua")
|
||||||
if source == nil then
|
if source == nil then
|
||||||
self:LogWarning("Failed to load %s", path)
|
self:LogWarning("Failed to load %s", ResourceName, "server/impl/" .. implName .. ".impl.lua")
|
||||||
else
|
else
|
||||||
self:LogInfo("Loading %s", implName)
|
self:LogInfo("Loading %s", implName)
|
||||||
load(source)()
|
load(source)()
|
||||||
|
@ -136,7 +141,7 @@ function Main:RegisterCommands()
|
||||||
if mode == "0" or mode == "1" then
|
if mode == "0" or mode == "1" then
|
||||||
local clSource = LoadResourceFile(ResourceName, "client/impl/" .. implName .. ".impl.lua")
|
local clSource = LoadResourceFile(ResourceName, "client/impl/" .. implName .. ".impl.lua")
|
||||||
if clSource == nil then
|
if clSource == nil then
|
||||||
self:LogWarning("Failed to load %s", path)
|
self:LogWarning("Failed to load %s", ResourceName, "client/impl/" .. implName .. ".impl.lua")
|
||||||
else
|
else
|
||||||
self:LogInfo("Loading %s", "client/impl/" .. implName .. ".impl.lua")
|
self:LogInfo("Loading %s", "client/impl/" .. implName .. ".impl.lua")
|
||||||
TriggerClientEvent(ResourceName .. ":restartClientImpl", -1, implName, clSource)
|
TriggerClientEvent(ResourceName .. ":restartClientImpl", -1, implName, clSource)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user