chore: refractor
This commit is contained in:
58
ReplicatedStorage/Shared/ModLoader.lua
Normal file
58
ReplicatedStorage/Shared/ModLoader.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
--!native
|
||||
--!optimize 2
|
||||
|
||||
local ML = {}
|
||||
|
||||
type modContext = {
|
||||
name: string,
|
||||
description: string,
|
||||
ns: string,
|
||||
author: {string},
|
||||
init: typeof(function()end)
|
||||
}
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local ModsFolder = ReplicatedStorage:WaitForChild("Mods")
|
||||
|
||||
function ML.loadModsS()
|
||||
print("[SSModLoader] Loading Mods")
|
||||
|
||||
for _, m in pairs(ModsFolder:GetChildren()) do
|
||||
local success, reason = pcall(function()
|
||||
-- ignore type err
|
||||
local mod: modContext = require(m)
|
||||
mod.init()
|
||||
print(`[SSModLoader] Loaded {mod.name} ({mod.ns}) by {table.concat(mod.author,", ")}`)
|
||||
end)
|
||||
if not success then
|
||||
warn(`[CSModLoader] Error loading {m.Name}: {reason}`)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ML.loadModsC(onProgress: ((number, number, Instance, boolean) -> ())?)
|
||||
print("[CSModLoader] Loading Mods")
|
||||
|
||||
local mods = ModsFolder:GetChildren()
|
||||
local total = #mods
|
||||
|
||||
for i, m in ipairs(mods) do
|
||||
local success, reason = pcall(function()
|
||||
-- ignore type err
|
||||
local mod: modContext = require(m)
|
||||
mod.init()
|
||||
print(`[CSModLoader] Loaded {mod.name} ({mod.ns}) by {table.concat(mod.author,", ")}`)
|
||||
end)
|
||||
if not success then
|
||||
warn(`[CSModLoader] Error loading {m.Name}: {reason}`)
|
||||
end
|
||||
if onProgress then
|
||||
pcall(function()
|
||||
onProgress(i, total, m, success)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return ML
|
||||
Reference in New Issue
Block a user