organize better default Lua stuff
This commit is contained in:
43
Barotrauma/BarotraumaShared/Lua/DefaultLib/LibClient.lua
Normal file
43
Barotrauma/BarotraumaShared/Lua/DefaultLib/LibClient.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
local defaultLib = {}
|
||||
|
||||
local CreateStatic = LuaSetup.CreateStatic
|
||||
local CreateEnum = LuaUserData.CreateEnumTable
|
||||
|
||||
local localizedStrings = {
|
||||
"LocalizedString", "LimitLString", "WrappedLString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||
}
|
||||
|
||||
for key, value in pairs(localizedStrings) do
|
||||
defaultLib[value] = CreateStatic("Barotrauma." .. value, true)
|
||||
end
|
||||
|
||||
defaultLib["Sprite"] = CreateStatic("Barotrauma.Sprite", true)
|
||||
defaultLib["PlayerInput"] = CreateStatic("Barotrauma.PlayerInput", true)
|
||||
|
||||
defaultLib["Keys"] = CreateStatic("Microsoft.Xna.Framework.Input.Keys", true)
|
||||
|
||||
defaultLib["GUI"] = {
|
||||
GUI = CreateStatic("Barotrauma.GUI", true),
|
||||
GUIStyle = CreateStatic("Barotrauma.GUIStyle", true),
|
||||
RectTransform = CreateStatic("Barotrauma.RectTransform", true),
|
||||
LayoutGroup = CreateStatic("Barotrauma.GUILayoutGroup", true),
|
||||
Button = CreateStatic("Barotrauma.GUIButton", true),
|
||||
TextBox = CreateStatic("Barotrauma.GUITextBox", true),
|
||||
Canvas = CreateStatic("Barotrauma.GUICanvas", true),
|
||||
Frame = CreateStatic("Barotrauma.GUIFrame", true),
|
||||
TextBlock = CreateStatic("Barotrauma.GUITextBlock", true),
|
||||
TickBox = CreateStatic("Barotrauma.GUITickBox", true),
|
||||
Image = CreateStatic("Barotrauma.GUIImage", true),
|
||||
ListBox = CreateStatic("Barotrauma.GUIListBox", true),
|
||||
ScrollBar = CreateStatic("Barotrauma.GUIScrollBar", true),
|
||||
DropDown = CreateStatic("Barotrauma.GUIDropDown", true),
|
||||
NumberInput = CreateStatic("Barotrauma.GUINumberInput", true),
|
||||
|
||||
Screen = CreateStatic("Barotrauma.Screen"),
|
||||
|
||||
Anchor = CreateStatic("Barotrauma.Anchor"),
|
||||
Alignment = CreateStatic("Barotrauma.Alignment"),
|
||||
Pivot = CreateStatic("Barotrauma.Pivot"),
|
||||
}
|
||||
|
||||
return defaultLib
|
||||
14
Barotrauma/BarotraumaShared/Lua/DefaultLib/LibServer.lua
Normal file
14
Barotrauma/BarotraumaShared/Lua/DefaultLib/LibServer.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
local defaultLib = {}
|
||||
|
||||
local CreateStatic = LuaSetup.CreateStatic
|
||||
local CreateEnum = LuaUserData.CreateEnumTable
|
||||
|
||||
local localizedStrings = {
|
||||
"LocalizedString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||
}
|
||||
|
||||
for key, value in pairs(localizedStrings) do
|
||||
defaultLib[value] = CreateStatic("Barotrauma." .. value, true)
|
||||
end
|
||||
|
||||
return defaultLib
|
||||
@@ -1,31 +1,8 @@
|
||||
local defaultLib = {}
|
||||
|
||||
local descriptors = require("DefaultRegister")
|
||||
|
||||
local CreateStatic = function (typeName, addCallMethod)
|
||||
local staticUserdata = LuaUserData.CreateStatic(typeName)
|
||||
|
||||
if addCallMethod then
|
||||
debug.setmetatable(staticUserdata, {
|
||||
__call = function(obj, ...)
|
||||
local success, result = pcall(staticUserdata.__new, ...)
|
||||
|
||||
if not success then
|
||||
error(result, 2)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
return staticUserdata
|
||||
end
|
||||
|
||||
local CreateStatic = LuaSetup.CreateStatic
|
||||
local CreateEnum = LuaUserData.CreateEnumTable
|
||||
|
||||
defaultLib["Descriptors"] = descriptors
|
||||
|
||||
defaultLib["Byte"] = CreateStatic("Barotrauma.LuaByte", true)
|
||||
defaultLib["UShort"] = CreateStatic("Barotrauma.LuaUShort", true)
|
||||
defaultLib["Float"] = CreateStatic("Barotrauma.LuaFloat", true)
|
||||
@@ -115,12 +92,12 @@ defaultLib["AIObjectiveRescue"] = CreateStatic("Barotrauma.AIObjectiveRescue", t
|
||||
defaultLib["AIObjectiveRescueAll"] = CreateStatic("Barotrauma.AIObjectiveRescueAll", true)
|
||||
defaultLib["AIObjectiveReturn"] = CreateStatic("Barotrauma.AIObjectiveReturn", true)
|
||||
|
||||
local barotraumaComponentsToReference = { "DockingPort", "Door", "GeneticMaterial", "Growable", "Holdable", "LevelResource", "ItemComponent", "ItemLabel", "LightComponent", "Controller", "Deconstructor", "Engine", "Fabricator", "OutpostTerminal", "Pump", "Reactor", "Steering", "PowerContainer", "Projectile", "Repairable", "Rope", "Scanner", "ButtonTerminal", "ConnectionPanel", "CustomInterface", "MemoryComponent", "Terminal", "WifiComponent", "Wire", "TriggerComponent", "ElectricalDischarger", "EntitySpawnerComponent", "ProducedItem", "VineTile", "GrowthSideExtension", "IdCard", "MeleeWeapon", "Pickable", "Propulsion", "RangedWeapon", "RepairTool", "Sprayer", "Throwable", "ItemContainer", "Ladder", "LimbPos", "MiniMap", "OxygenGenerator", "Sonar", "SonarTransducer", "Vent", "NameTag", "Planter", "Powered", "PowerTransfer", "Quality", "RemoteController", "AdderComponent", "AndComponent", "ArithmeticComponent", "ColorComponent", "ConcatComponent", "Connection", "DelayComponent", "DivideComponent", "EqualsComponent", "ExponentiationComponent", "FunctionComponent", "GreaterComponent", "ModuloComponent", "MotionSensor", "MultiplyComponent", "NotComponent", "OrComponent", "OscillatorComponent", "OxygenDetector", "RegExFindComponent", "RelayComponent", "SignalCheckComponent", "SmokeDetector", "StringComponent", "SubtractComponent", "TrigonometricFunctionComponent", "WaterDetector", "XorComponent", "StatusHUD", "Turret", "Wearable", "CustomInterface"
|
||||
local componentsToReference = { "DockingPort", "Door", "GeneticMaterial", "Growable", "Holdable", "LevelResource", "ItemComponent", "ItemLabel", "LightComponent", "Controller", "Deconstructor", "Engine", "Fabricator", "OutpostTerminal", "Pump", "Reactor", "Steering", "PowerContainer", "Projectile", "Repairable", "Rope", "Scanner", "ButtonTerminal", "ConnectionPanel", "CustomInterface", "MemoryComponent", "Terminal", "WifiComponent", "Wire", "TriggerComponent", "ElectricalDischarger", "EntitySpawnerComponent", "ProducedItem", "VineTile", "GrowthSideExtension", "IdCard", "MeleeWeapon", "Pickable", "Propulsion", "RangedWeapon", "RepairTool", "Sprayer", "Throwable", "ItemContainer", "Ladder", "LimbPos", "MiniMap", "OxygenGenerator", "Sonar", "SonarTransducer", "Vent", "NameTag", "Planter", "Powered", "PowerTransfer", "Quality", "RemoteController", "AdderComponent", "AndComponent", "ArithmeticComponent", "ColorComponent", "ConcatComponent", "Connection", "DelayComponent", "DivideComponent", "EqualsComponent", "ExponentiationComponent", "FunctionComponent", "GreaterComponent", "ModuloComponent", "MotionSensor", "MultiplyComponent", "NotComponent", "OrComponent", "OscillatorComponent", "OxygenDetector", "RegExFindComponent", "RelayComponent", "SignalCheckComponent", "SmokeDetector", "StringComponent", "SubtractComponent", "TrigonometricFunctionComponent", "WaterDetector", "XorComponent", "StatusHUD", "Turret", "Wearable", "CustomInterface"
|
||||
}
|
||||
|
||||
defaultLib["Components"] = {}
|
||||
|
||||
for key, value in pairs(barotraumaComponentsToReference) do
|
||||
for key, value in pairs(componentsToReference) do
|
||||
defaultLib["Components"][value] = CreateStatic("Barotrauma.Items.Components." .. value, true)
|
||||
end
|
||||
|
||||
@@ -132,37 +109,4 @@ defaultLib["Point"] = CreateStatic("Microsoft.Xna.Framework.Point", true)
|
||||
defaultLib["Rectangle"] = CreateStatic("Microsoft.Xna.Framework.Rectangle", true)
|
||||
defaultLib["Matrix"] = CreateStatic("Microsoft.Xna.Framework.Matrix", true)
|
||||
|
||||
if SERVER then
|
||||
|
||||
elseif CLIENT then
|
||||
defaultLib["Sprite"] = CreateStatic("Barotrauma.Sprite", true)
|
||||
defaultLib["PlayerInput"] = CreateStatic("Barotrauma.PlayerInput", true)
|
||||
|
||||
defaultLib["Keys"] = CreateStatic("Microsoft.Xna.Framework.Input.Keys", true)
|
||||
|
||||
defaultLib["GUI"] = {
|
||||
GUI = CreateStatic("Barotrauma.GUI", true),
|
||||
GUIStyle = CreateStatic("Barotrauma.GUIStyle", true),
|
||||
RectTransform = CreateStatic("Barotrauma.RectTransform", true),
|
||||
LayoutGroup = CreateStatic("Barotrauma.GUILayoutGroup", true),
|
||||
Button = CreateStatic("Barotrauma.GUIButton", true),
|
||||
TextBox = CreateStatic("Barotrauma.GUITextBox", true),
|
||||
Canvas = CreateStatic("Barotrauma.GUICanvas", true),
|
||||
Frame = CreateStatic("Barotrauma.GUIFrame", true),
|
||||
TextBlock = CreateStatic("Barotrauma.GUITextBlock", true),
|
||||
TickBox = CreateStatic("Barotrauma.GUITickBox", true),
|
||||
Image = CreateStatic("Barotrauma.GUIImage", true),
|
||||
ListBox = CreateStatic("Barotrauma.GUIListBox", true),
|
||||
ScrollBar = CreateStatic("Barotrauma.GUIScrollBar", true),
|
||||
DropDown = CreateStatic("Barotrauma.GUIDropDown", true),
|
||||
NumberInput = CreateStatic("Barotrauma.GUINumberInput", true),
|
||||
|
||||
Screen = CreateStatic("Barotrauma.Screen"),
|
||||
|
||||
Anchor = CreateStatic("Barotrauma.Anchor"),
|
||||
Alignment = CreateStatic("Barotrauma.Alignment"),
|
||||
Pivot = CreateStatic("Barotrauma.Pivot"),
|
||||
}
|
||||
end
|
||||
|
||||
return defaultLib
|
||||
@@ -0,0 +1,45 @@
|
||||
local Register = LuaSetup.Register
|
||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
||||
|
||||
local localizedStrings = {
|
||||
"LocalizedString", "LimitLString", "WrappedLString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||
}
|
||||
|
||||
for key, value in pairs(localizedStrings) do
|
||||
RegisterBarotrauma(value)
|
||||
end
|
||||
|
||||
RegisterBarotrauma("Networking.ClientPeer")
|
||||
|
||||
RegisterBarotrauma("ChatBox")
|
||||
RegisterBarotrauma("GUICanvas")
|
||||
RegisterBarotrauma("Anchor")
|
||||
RegisterBarotrauma("Alignment")
|
||||
RegisterBarotrauma("Pivot")
|
||||
RegisterBarotrauma("Key")
|
||||
RegisterBarotrauma("PlayerInput")
|
||||
RegisterBarotrauma("ScalableFont")
|
||||
|
||||
Register("Microsoft.Xna.Framework.Graphics.Texture2D")
|
||||
Register("EventInput.KeyEventArgs")
|
||||
Register("Microsoft.Xna.Framework.Input.Keys")
|
||||
Register("Microsoft.Xna.Framework.Input.KeyboardState")
|
||||
|
||||
RegisterBarotrauma("Sprite")
|
||||
RegisterBarotrauma("GUI")
|
||||
RegisterBarotrauma("GUIStyle")
|
||||
RegisterBarotrauma("GUILayoutGroup")
|
||||
RegisterBarotrauma("GUITextBox")
|
||||
RegisterBarotrauma("GUITextBlock")
|
||||
RegisterBarotrauma("GUIButton")
|
||||
RegisterBarotrauma("RectTransform")
|
||||
RegisterBarotrauma("GUIFrame")
|
||||
RegisterBarotrauma("GUITickBox")
|
||||
RegisterBarotrauma("GUICustomComponent")
|
||||
RegisterBarotrauma("GUIImage")
|
||||
RegisterBarotrauma("GUIListBox")
|
||||
RegisterBarotrauma("GUIScrollBar")
|
||||
RegisterBarotrauma("GUIDropDown")
|
||||
RegisterBarotrauma("GUINumberInput")
|
||||
|
||||
RegisterBarotrauma("Inventory+SlotReference")
|
||||
@@ -0,0 +1,19 @@
|
||||
local Register = LuaSetup.Register
|
||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
||||
|
||||
|
||||
local localizedStrings = {
|
||||
"LocalizedString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||
}
|
||||
|
||||
for key, value in pairs(localizedStrings) do
|
||||
RegisterBarotrauma(value)
|
||||
end
|
||||
|
||||
RegisterBarotrauma("Networking.GameServer")
|
||||
|
||||
RegisterBarotrauma("Networking.ServerPeer")
|
||||
RegisterBarotrauma("Networking.ServerPeer+PendingClient")
|
||||
|
||||
RegisterBarotrauma("Traitor")
|
||||
RegisterBarotrauma("Traitor+TraitorMission")
|
||||
@@ -1,23 +1,8 @@
|
||||
local descriptors = {}
|
||||
|
||||
local function Register(typeName)
|
||||
local descriptor = LuaUserData.RegisterType(typeName)
|
||||
|
||||
descriptors[typeName] = descriptor
|
||||
|
||||
return descriptor
|
||||
end
|
||||
|
||||
local function RegisterBarotrauma(typeName)
|
||||
return Register("Barotrauma." .. typeName)
|
||||
end
|
||||
local Register = LuaSetup.Register
|
||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
||||
|
||||
Register("System.TimeSpan")
|
||||
|
||||
if SERVER then
|
||||
RegisterBarotrauma("Networking.GameServer")
|
||||
end
|
||||
|
||||
RegisterBarotrauma("LuaByte")
|
||||
RegisterBarotrauma("LuaUShort")
|
||||
RegisterBarotrauma("LuaFloat")
|
||||
@@ -26,10 +11,6 @@ RegisterBarotrauma("Level+InterestingPosition")
|
||||
|
||||
RegisterBarotrauma("Identifier")
|
||||
|
||||
RegisterBarotrauma("LocalizedString")
|
||||
RegisterBarotrauma("TagLString")
|
||||
RegisterBarotrauma("RichString")
|
||||
|
||||
RegisterBarotrauma("Job")
|
||||
RegisterBarotrauma("JobPrefab")
|
||||
RegisterBarotrauma("Level")
|
||||
@@ -89,11 +70,11 @@ RegisterBarotrauma("ItemInventory")
|
||||
RegisterBarotrauma("Inventory+ItemSlot")
|
||||
RegisterBarotrauma("FireSource")
|
||||
|
||||
local barotraumaComponentsToRegister = { "DockingPort", "Door", "GeneticMaterial", "Growable", "Holdable", "LevelResource", "ItemComponent", "ItemLabel", "LightComponent", "Controller", "Deconstructor", "Engine", "Fabricator", "OutpostTerminal", "Pump", "Reactor", "Steering", "PowerContainer", "Projectile", "Repairable", "Rope", "Scanner", "ButtonTerminal", "ConnectionPanel", "CustomInterface", "MemoryComponent", "Terminal", "WifiComponent", "Wire", "TriggerComponent", "ElectricalDischarger", "EntitySpawnerComponent", "ProducedItem", "VineTile", "GrowthSideExtension", "IdCard", "MeleeWeapon", "Pickable", "AbilityItemPickingTime", "Propulsion", "RangedWeapon", "AbilityRangedWeapon", "RepairTool", "Sprayer", "Throwable", "ItemContainer", "AbilityItemContainer", "Ladder", "LimbPos", "AbilityDeconstructedItem", "AbilityItemCreationMultiplier", "AbilityItemDeconstructedInventory", "MiniMap", "OxygenGenerator", "Sonar", "SonarTransducer", "Vent", "NameTag", "Planter", "Powered", "PowerTransfer", "Quality", "RemoteController", "AdderComponent", "AndComponent", "ArithmeticComponent", "ColorComponent", "ConcatComponent", "Connection", "DelayComponent", "DivideComponent", "EqualsComponent", "ExponentiationComponent", "FunctionComponent", "GreaterComponent", "ModuloComponent", "MotionSensor", "MultiplyComponent", "NotComponent", "OrComponent", "OscillatorComponent", "OxygenDetector", "RegExFindComponent", "RelayComponent", "SignalCheckComponent", "SmokeDetector", "StringComponent", "SubtractComponent", "TrigonometricFunctionComponent", "WaterDetector", "XorComponent", "StatusHUD", "Turret", "Wearable",
|
||||
local componentsToRegister = { "DockingPort", "Door", "GeneticMaterial", "Growable", "Holdable", "LevelResource", "ItemComponent", "ItemLabel", "LightComponent", "Controller", "Deconstructor", "Engine", "Fabricator", "OutpostTerminal", "Pump", "Reactor", "Steering", "PowerContainer", "Projectile", "Repairable", "Rope", "Scanner", "ButtonTerminal", "ConnectionPanel", "CustomInterface", "MemoryComponent", "Terminal", "WifiComponent", "Wire", "TriggerComponent", "ElectricalDischarger", "EntitySpawnerComponent", "ProducedItem", "VineTile", "GrowthSideExtension", "IdCard", "MeleeWeapon", "Pickable", "AbilityItemPickingTime", "Propulsion", "RangedWeapon", "AbilityRangedWeapon", "RepairTool", "Sprayer", "Throwable", "ItemContainer", "AbilityItemContainer", "Ladder", "LimbPos", "AbilityDeconstructedItem", "AbilityItemCreationMultiplier", "AbilityItemDeconstructedInventory", "MiniMap", "OxygenGenerator", "Sonar", "SonarTransducer", "Vent", "NameTag", "Planter", "Powered", "PowerTransfer", "Quality", "RemoteController", "AdderComponent", "AndComponent", "ArithmeticComponent", "ColorComponent", "ConcatComponent", "Connection", "DelayComponent", "DivideComponent", "EqualsComponent", "ExponentiationComponent", "FunctionComponent", "GreaterComponent", "ModuloComponent", "MotionSensor", "MultiplyComponent", "NotComponent", "OrComponent", "OscillatorComponent", "OxygenDetector", "RegExFindComponent", "RelayComponent", "SignalCheckComponent", "SmokeDetector", "StringComponent", "SubtractComponent", "TrigonometricFunctionComponent", "WaterDetector", "XorComponent", "StatusHUD", "Turret", "Wearable",
|
||||
"GridInfo", "PowerSourceGroup"
|
||||
}
|
||||
|
||||
for key, value in pairs(barotraumaComponentsToRegister) do
|
||||
for key, value in pairs(componentsToRegister) do
|
||||
RegisterBarotrauma("Items.Components." .. value)
|
||||
end
|
||||
|
||||
@@ -228,52 +209,4 @@ Register("Microsoft.Xna.Framework.Vector4")
|
||||
Register("Microsoft.Xna.Framework.Color")
|
||||
Register("Microsoft.Xna.Framework.Point")
|
||||
Register("Microsoft.Xna.Framework.Rectangle")
|
||||
Register("Microsoft.Xna.Framework.Matrix")
|
||||
|
||||
if SERVER then
|
||||
RegisterBarotrauma("Networking.ServerPeer")
|
||||
RegisterBarotrauma("Networking.ServerPeer+PendingClient")
|
||||
|
||||
RegisterBarotrauma("Traitor")
|
||||
RegisterBarotrauma("Traitor+TraitorMission")
|
||||
|
||||
elseif CLIENT then
|
||||
|
||||
RegisterBarotrauma("Networking.ClientPeer")
|
||||
|
||||
RegisterBarotrauma("ChatBox")
|
||||
RegisterBarotrauma("GUICanvas")
|
||||
RegisterBarotrauma("Anchor")
|
||||
RegisterBarotrauma("Alignment")
|
||||
RegisterBarotrauma("Pivot")
|
||||
RegisterBarotrauma("Key")
|
||||
RegisterBarotrauma("PlayerInput")
|
||||
RegisterBarotrauma("ScalableFont")
|
||||
|
||||
Register("Microsoft.Xna.Framework.Graphics.Texture2D")
|
||||
Register("EventInput.KeyEventArgs")
|
||||
Register("Microsoft.Xna.Framework.Input.Keys")
|
||||
Register("Microsoft.Xna.Framework.Input.KeyboardState")
|
||||
|
||||
RegisterBarotrauma("Sprite")
|
||||
RegisterBarotrauma("GUI")
|
||||
RegisterBarotrauma("GUIStyle")
|
||||
RegisterBarotrauma("GUILayoutGroup")
|
||||
RegisterBarotrauma("GUITextBox")
|
||||
RegisterBarotrauma("GUITextBlock")
|
||||
RegisterBarotrauma("GUIButton")
|
||||
RegisterBarotrauma("RectTransform")
|
||||
RegisterBarotrauma("GUIFrame")
|
||||
RegisterBarotrauma("GUITickBox")
|
||||
RegisterBarotrauma("GUICustomComponent")
|
||||
RegisterBarotrauma("GUIImage")
|
||||
RegisterBarotrauma("GUIListBox")
|
||||
RegisterBarotrauma("GUIScrollBar")
|
||||
RegisterBarotrauma("GUIDropDown")
|
||||
RegisterBarotrauma("GUINumberInput")
|
||||
|
||||
RegisterBarotrauma("Inventory+SlotReference")
|
||||
|
||||
end
|
||||
|
||||
return descriptors
|
||||
Register("Microsoft.Xna.Framework.Matrix")
|
||||
@@ -1,115 +1,40 @@
|
||||
-- Config
|
||||
LuaSetup = {}
|
||||
|
||||
LuaSetup.Descriptors = {}
|
||||
|
||||
local path = table.pack(...)[1]
|
||||
|
||||
local modulePaths = {path .. "/?.lua"}
|
||||
setmodulepaths(modulePaths)
|
||||
package.path = {path .. "/?.lua"}
|
||||
|
||||
setmodulepaths(package.path)
|
||||
|
||||
-- Setup Libraries
|
||||
require("UserDataUtils")
|
||||
|
||||
local defaultLib = require("DefaultLib")
|
||||
require("DefaultRegister/RegisterShared")
|
||||
|
||||
for key, value in pairs(defaultLib) do
|
||||
_G[key] = value
|
||||
if SERVER then
|
||||
require("DefaultRegister/RegisterServer")
|
||||
else
|
||||
require("DefaultRegister/RegisterClient")
|
||||
end
|
||||
|
||||
local compatibilityLib = require("CompatibilityLib")
|
||||
|
||||
for key, value in pairs(compatibilityLib) do
|
||||
_G[key] = value
|
||||
local function AddTableToGlobal(tbl)
|
||||
for k, v in pairs(tbl) do
|
||||
_G[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
if SERVER then
|
||||
AddTableToGlobal(require("DefaultLib/LibServer"))
|
||||
else
|
||||
AddTableToGlobal(require("DefaultLib/LibClient"))
|
||||
end
|
||||
|
||||
AddTableToGlobal(require("DefaultLib/LibShared"))
|
||||
|
||||
AddTableToGlobal(require("CompatibilityLib"))
|
||||
|
||||
require("DefaultHook")
|
||||
|
||||
-- Execute Mods
|
||||
|
||||
local allPackages = ContentPackageManager.AllPackages
|
||||
local localPackages = ContentPackageManager.LocalPackages
|
||||
local enabledPackages = ContentPackageManager.EnabledPackages.All
|
||||
|
||||
local function endsWith(str, suffix)
|
||||
return str:sub(-string.len(suffix)) == suffix
|
||||
end
|
||||
|
||||
local function getFileName(file)
|
||||
return file:match("^.+/(.+)$")
|
||||
end
|
||||
|
||||
local function getPath(str)
|
||||
local sep = "/"
|
||||
return str:match("(.*"..sep..")")
|
||||
end
|
||||
|
||||
|
||||
local function executeProtected(s, folder)
|
||||
loadfile(s)(folder)
|
||||
end
|
||||
|
||||
local function runFolder(folder, rootFolder, package)
|
||||
local search = File.DirSearch(folder)
|
||||
for i = 1, #search, 1 do
|
||||
local s = search[i]:gsub("\\", "/")
|
||||
|
||||
if endsWith(s, ".lua") then
|
||||
print(string.format("%s: Executing %s", package.Name, getFileName(s)))
|
||||
local ok, result = pcall(executeProtected, s, rootFolder)
|
||||
if not ok then
|
||||
printerror(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for package in enabledPackages do
|
||||
if package then
|
||||
local d = package.Path:gsub("\\", "/")
|
||||
d = d:gsub("/filelist.xml", "")
|
||||
|
||||
table.insert(modulePaths, (d .. "/Lua/?.lua"))
|
||||
|
||||
if File.DirectoryExists(d .. "/Lua/Autorun") then
|
||||
runFolder(d .. "/Lua/Autorun", d, package)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- we don't want to execute workshop ForcedAutorun if we have a local Package
|
||||
local executedLocalPackages = {}
|
||||
|
||||
for package in localPackages do
|
||||
if package then
|
||||
local d = package.Path:gsub("\\", "/")
|
||||
d = d:gsub("/filelist.xml", "")
|
||||
|
||||
table.insert(modulePaths, (d .. "/Lua/?.lua"))
|
||||
|
||||
if File.DirectoryExists(d .. "/Lua/ForcedAutorun") then
|
||||
runFolder(d .. "/Lua/ForcedAutorun", d, package)
|
||||
|
||||
executedLocalPackages[package.Name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for package in allPackages do
|
||||
if package and executedLocalPackages[package.Name] == nil then
|
||||
local d = package.Path:gsub("\\", "/")
|
||||
d = d:gsub("/filelist.xml", "")
|
||||
|
||||
table.insert(modulePaths, (d .. "/Lua/?.lua"))
|
||||
|
||||
if File.DirectoryExists(d .. "/Lua/ForcedAutorun") then
|
||||
runFolder(d .. "/Lua/ForcedAutorun", d, package)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
setmodulepaths(modulePaths)
|
||||
|
||||
Hook.Add("stop", "luaSetup.stop", function ()
|
||||
print("Stopping Lua...")
|
||||
end)
|
||||
|
||||
Hook.Call("loaded")
|
||||
require("ModLoader")
|
||||
84
Barotrauma/BarotraumaShared/Lua/ModLoader.lua
Normal file
84
Barotrauma/BarotraumaShared/Lua/ModLoader.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
local allPackages = ContentPackageManager.AllPackages
|
||||
local localPackages = ContentPackageManager.LocalPackages
|
||||
local enabledPackages = ContentPackageManager.EnabledPackages.All
|
||||
|
||||
local function EndsWith(str, suffix)
|
||||
return str:sub(-string.len(suffix)) == suffix
|
||||
end
|
||||
|
||||
local function GetFileName(file)
|
||||
return file:match("^.+/(.+)$")
|
||||
end
|
||||
|
||||
local function ExecuteProtected(s, folder)
|
||||
loadfile(s)(folder)
|
||||
end
|
||||
|
||||
local function RunFolder(folder, rootFolder, package)
|
||||
local search = File.DirSearch(folder)
|
||||
for i = 1, #search, 1 do
|
||||
local s = search[i]:gsub("\\", "/")
|
||||
|
||||
if EndsWith(s, ".lua") then
|
||||
print(string.format("%s: Executing %s", package.Name, GetFileName(s)))
|
||||
local ok, result = pcall(ExecuteProtected, s, rootFolder)
|
||||
if not ok then
|
||||
printerror(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for contentPackage in enabledPackages do
|
||||
if contentPackage then
|
||||
local d = contentPackage.Path:gsub("\\", "/")
|
||||
d = d:gsub("/filelist.xml", "")
|
||||
|
||||
table.insert(package.path, (d .. "/Lua/?.lua"))
|
||||
|
||||
if File.DirectoryExists(d .. "/Lua/Autorun") then
|
||||
RunFolder(d .. "/Lua/Autorun", d, contentPackage)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- we don't want to execute workshop ForcedAutorun if we have a local Package
|
||||
local executedLocalPackages = {}
|
||||
|
||||
for contentPackage in localPackages do
|
||||
if contentPackage then
|
||||
local d = contentPackage.Path:gsub("\\", "/")
|
||||
d = d:gsub("/filelist.xml", "")
|
||||
|
||||
table.insert(package.path, (d .. "/Lua/?.lua"))
|
||||
|
||||
if File.DirectoryExists(d .. "/Lua/ForcedAutorun") then
|
||||
RunFolder(d .. "/Lua/ForcedAutorun", d, contentPackage)
|
||||
|
||||
executedLocalPackages[contentPackage.Name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for contentPackage in allPackages do
|
||||
if contentPackage and executedLocalPackages[contentPackage.Name] == nil then
|
||||
local d = contentPackage.Path:gsub("\\", "/")
|
||||
d = d:gsub("/filelist.xml", "")
|
||||
|
||||
table.insert(package.path, (d .. "/Lua/?.lua"))
|
||||
|
||||
if File.DirectoryExists(d .. "/Lua/ForcedAutorun") then
|
||||
RunFolder(d .. "/Lua/ForcedAutorun", d, contentPackage)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
setmodulepaths(package.path)
|
||||
|
||||
Hook.Add("stop", "luaSetup.stop", function ()
|
||||
print("Stopping Lua...")
|
||||
end)
|
||||
|
||||
Hook.Call("loaded")
|
||||
31
Barotrauma/BarotraumaShared/Lua/UserDataUtils.lua
Normal file
31
Barotrauma/BarotraumaShared/Lua/UserDataUtils.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
LuaSetup.Register = function(typeName)
|
||||
local descriptor = LuaUserData.RegisterType(typeName)
|
||||
|
||||
LuaSetup.Descriptors[typeName] = descriptor
|
||||
|
||||
return descriptor
|
||||
end
|
||||
|
||||
LuaSetup.RegisterBarotrauma = function(typeName)
|
||||
return LuaSetup.Register("Barotrauma." .. typeName)
|
||||
end
|
||||
|
||||
LuaSetup.CreateStatic = function(typeName, addCallMethod)
|
||||
local staticUserdata = LuaUserData.CreateStatic(typeName)
|
||||
|
||||
if addCallMethod then
|
||||
debug.setmetatable(staticUserdata, {
|
||||
__call = function(obj, ...)
|
||||
local success, result = pcall(staticUserdata.__new, ...)
|
||||
|
||||
if not success then
|
||||
error(result, 2)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
return staticUserdata
|
||||
end
|
||||
Reference in New Issue
Block a user