Залив
This commit is contained in:
104
lua/autorun/mw_assets/attachments.lua
Normal file
104
lua/autorun/mw_assets/attachments.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
MW_ATTS = {}
|
||||
|
||||
function GetAttachmentBaseClass(base)
|
||||
MW_ATTS[base] = MW_ATTS[base] || {}
|
||||
|
||||
return MW_ATTS[base]
|
||||
end
|
||||
|
||||
function LoadAttachment(path, fileName)
|
||||
ATTACHMENT = {}
|
||||
|
||||
if (mw_utils.CompileFile(path..fileName)) then
|
||||
local name = string.Replace(fileName, ".lua", "")
|
||||
ATTACHMENT.ClassName = name
|
||||
ATTACHMENT.Folder = path
|
||||
table.Merge(GetAttachmentBaseClass(name), table.Copy(ATTACHMENT))
|
||||
end
|
||||
end
|
||||
|
||||
local oldModel = Model
|
||||
function Model(dir) --sorry
|
||||
if (GetConVar("mgbase_precacheatts"):GetInt() > 0) then
|
||||
util.PrecacheModel(dir)
|
||||
end
|
||||
return dir
|
||||
end
|
||||
|
||||
local function loadAttachments(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
LoadAttachment(dir, v)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadAttachments(dir..v)
|
||||
end
|
||||
end
|
||||
|
||||
loadAttachments("weapons/mg_base/modules/attachmentss")
|
||||
Model = oldModel
|
||||
|
||||
--check baseclass
|
||||
local function checkBaseClassInAttachments()
|
||||
for name, att in pairs(MW_ATTS) do
|
||||
if (istable(name)) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: You may have defined BaseClass twice! "..(name.Name || "error class"))
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
|
||||
if (name != "att_base") then
|
||||
if (att.Base == nil) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: "..name.." doesn't inherit from anything! This will cause problems...")
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
|
||||
if (att.Base == name) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: You are inheriting from self (Base = myself)! This would freeze your game. ("..name..")")
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
|
||||
if (MW_ATTS[att.Base] == nil) then
|
||||
mw_utils.ErrorPrint("checkBaseClassInAttachments: "..name.." is trying to inherit from missing attachment! ("..(att.Base || "missing class")..")")
|
||||
MW_ATTS[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
checkBaseClassInAttachments()
|
||||
|
||||
--inherit
|
||||
local function inherit(current, base)
|
||||
for k, v in pairs(base) do
|
||||
if (!istable(v)) then
|
||||
if (current[k] == nil) then
|
||||
current[k] = v
|
||||
end
|
||||
else
|
||||
if (current[k] == nil) then
|
||||
current[k] = {}
|
||||
end
|
||||
inherit(current[k], v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function DoAttachmentInheritance(att)
|
||||
local baseClass = MW_ATTS[att.Base]
|
||||
while (baseClass != nil) do
|
||||
inherit(att, baseClass)
|
||||
baseClass = MW_ATTS[baseClass.Base]
|
||||
end
|
||||
end
|
||||
|
||||
local function finishAttachments()
|
||||
for name, att in pairs(MW_ATTS) do
|
||||
DoAttachmentInheritance(att)
|
||||
end
|
||||
end
|
||||
finishAttachments()
|
||||
10
lua/autorun/mw_assets/favorites.lua
Normal file
10
lua/autorun/mw_assets/favorites.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
AddCSLuaFile()
|
||||
|
||||
if (CLIENT) then
|
||||
MW_FAVORITES = {}
|
||||
|
||||
--load favs
|
||||
if (file.Exists("mwbase/favorites.json", "DATA")) then
|
||||
MW_FAVORITES = util.JSONToTable(file.Read("mwbase/favorites.json", "DATA"))
|
||||
end
|
||||
end
|
||||
29
lua/autorun/mw_assets/injectors.lua
Normal file
29
lua/autorun/mw_assets/injectors.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
|
||||
MW_ATT_INJECTORS = {}
|
||||
|
||||
local function loadInjectors(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
INJECTOR = {}
|
||||
|
||||
local name = string.Replace(v, ".lua", "")
|
||||
if (mw_utils.CompileFile(dir..v)) then
|
||||
|
||||
INJECTOR.ClassName = name
|
||||
|
||||
if (!table.IsEmpty(INJECTOR)) then
|
||||
MW_ATT_INJECTORS[name] = table.Copy(INJECTOR)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadInjectors(dir..v)
|
||||
end
|
||||
end
|
||||
loadInjectors("weapons/mg_base/modules/injectors")
|
||||
68
lua/autorun/mw_assets/presets.lua
Normal file
68
lua/autorun/mw_assets/presets.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
|
||||
MW_PRESETS = {}
|
||||
|
||||
local function loadPresets(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
PRESET = {}
|
||||
|
||||
local name = string.Replace(v, ".lua", "")
|
||||
if (mw_utils.CompileFile(dir..v)) then
|
||||
PRESET.ClassName = name
|
||||
PRESET._bUserGenerated = false
|
||||
|
||||
if (!table.IsEmpty(PRESET)) then
|
||||
MW_PRESETS[name] = table.Copy(PRESET)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadPresets(dir..v)
|
||||
end
|
||||
end
|
||||
loadPresets("weapons/mg_base/modules/presets")
|
||||
|
||||
if (CLIENT) then
|
||||
local function loadPresetsFromData(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "DATA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".json")) then
|
||||
local name = string.Replace(v, ".json", "")
|
||||
local preset = util.JSONToTable(file.Read(dir..v))
|
||||
|
||||
if (preset == nil || table.IsEmpty(preset)) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (preset.Name == nil || preset.SWEP == nil || preset.Attachments == nil) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (!isstring(preset.Name) || !isstring(preset.SWEP)) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (!istable(preset.Attachments)) then
|
||||
continue
|
||||
end
|
||||
|
||||
preset.ClassName = name
|
||||
preset._bUserGenerated = true
|
||||
|
||||
MW_PRESETS[name] = table.Copy(preset)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadPresetsFromData(dir..v)
|
||||
end
|
||||
end
|
||||
loadPresetsFromData("mwbase/presets")
|
||||
end
|
||||
35
lua/autorun/mw_assets/rigs.lua
Normal file
35
lua/autorun/mw_assets/rigs.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
require("mw_utils")
|
||||
AddCSLuaFile()
|
||||
|
||||
MW_RIGS = {}
|
||||
MW_GLOVES = {}
|
||||
|
||||
local function loadRigs(dir)
|
||||
dir = dir .. "/"
|
||||
local File, Directory = file.Find(dir.."*", "LUA")
|
||||
for k, v in ipairs(File) do
|
||||
if (string.EndsWith(v, ".lua")) then
|
||||
RIG = {}
|
||||
GLOVE = {}
|
||||
|
||||
local name = string.Replace(v, ".lua", "")
|
||||
if (mw_utils.CompileFile(dir..v)) then
|
||||
if (!table.IsEmpty(RIG)) then
|
||||
MW_RIGS[name] = table.Copy(RIG)
|
||||
end
|
||||
|
||||
if (!table.IsEmpty(GLOVE)) then
|
||||
MW_GLOVES[name] = table.Copy(GLOVE)
|
||||
end
|
||||
end
|
||||
|
||||
RIG = nil
|
||||
GLOVE = nil
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(Directory) do
|
||||
loadRigs(dir..v)
|
||||
end
|
||||
end
|
||||
loadRigs("weapons/mg_base/modules/rigs")
|
||||
Reference in New Issue
Block a user