From 446686e18ce4f4b34fbfcd07582bec9959a42e98 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sun, 3 Oct 2021 12:13:45 -0300 Subject: [PATCH] docs update and entity.spawner --- .../SharedSource/Lua/LuaClasses.cs | 8 - .../SharedSource/Lua/LuaDocs.cs | 6 + .../SharedSource/Lua/LuaSetup.cs | 3 +- docs/lua/Entity.Spawner.lua | 113 +++++++++++++ docs/lua/Entity.lua | 151 ++++++++++++++++++ docs/lua/Networking.lua | 2 +- docs/templates/module.ltp | 32 +++- 7 files changed, 303 insertions(+), 12 deletions(-) create mode 100644 docs/lua/Entity.Spawner.lua create mode 100644 docs/lua/Entity.lua diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs index ef6c68d13..d7da977a2 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs @@ -64,14 +64,6 @@ namespace Barotrauma } } - public EntitySpawner Spawner - { - get - { - return Entity.Spawner; - } - } - public GameSession GameSession { get diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaDocs.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaDocs.cs index 408f5e676..b0a6bff19 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaDocs.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaDocs.cs @@ -48,6 +48,12 @@ namespace Barotrauma return "table"; } + if (type.StartsWith("Action")) + return "function"; + + if (type.StartsWith("Func")) + return "function"; + return type; } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs index 4a14a950b..02703f3a7 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs @@ -436,6 +436,7 @@ namespace Barotrauma lua.Globals["RandSync"] = UserData.CreateStatic(); lua.Globals["SubmarineInfo"] = UserData.CreateStatic(); lua.Globals["Rectangle"] = UserData.CreateStatic(); + lua.Globals["Entity"] = UserData.CreateStatic(); #if SERVER @@ -462,7 +463,7 @@ namespace Barotrauma lua.Globals["SERVER"] = isServer; lua.Globals["CLIENT"] = !isServer; - LuaDocs.GenerateDocs(typeof(JobPrefab)); + LuaDocs.GenerateDocs(typeof(EntitySpawner)); if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader DoFile("Lua/MoonsharpSetup.lua"); diff --git a/docs/lua/Entity.Spawner.lua b/docs/lua/Entity.Spawner.lua new file mode 100644 index 000000000..59fd86b88 --- /dev/null +++ b/docs/lua/Entity.Spawner.lua @@ -0,0 +1,113 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma EntitySpawner class with some additional functions and fields + +Barotrauma source code: [EntitySpawner.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Networking/EntitySpawner.cs) +]] +-- @code Entity.Spawner +-- @pragma nostrip + +--- CreateNetworkEvent +-- @realm shared +-- @tparam Entity entity +-- @tparam bool remove +function CreateNetworkEvent(entity, remove) end + +--- ServerWrite +-- @realm shared +-- @tparam IWriteMessage message +-- @tparam Client client +-- @tparam Object[] extraData +function ServerWrite(message, client, extraData) end + +--- AddToSpawnQueue +-- @realm shared +-- @tparam ItemPrefab itemPrefab +-- @tparam Vector2 worldPosition +-- @tparam Nullable`1 condition +-- @tparam function onSpawned +function AddToSpawnQueue(itemPrefab, worldPosition, condition, onSpawned) end + +--- AddToSpawnQueue +-- @realm shared +-- @tparam ItemPrefab itemPrefab +-- @tparam Vector2 position +-- @tparam Submarine sub +-- @tparam Nullable`1 condition +-- @tparam function onSpawned +function AddToSpawnQueue(itemPrefab, position, sub, condition, onSpawned) end + +--- AddToSpawnQueue +-- @realm shared +-- @tparam ItemPrefab itemPrefab +-- @tparam Inventory inventory +-- @tparam Nullable`1 condition +-- @tparam function onSpawned +-- @tparam bool spawnIfInventoryFull +-- @tparam bool ignoreLimbSlots +function AddToSpawnQueue(itemPrefab, inventory, condition, onSpawned, spawnIfInventoryFull, ignoreLimbSlots) end + +--- AddToSpawnQueue +-- @realm shared +-- @tparam string speciesName +-- @tparam Vector2 worldPosition +-- @tparam function onSpawn +function AddToSpawnQueue(speciesName, worldPosition, onSpawn) end + +--- AddToSpawnQueue +-- @realm shared +-- @tparam string speciesName +-- @tparam Vector2 position +-- @tparam Submarine sub +-- @tparam function onSpawn +function AddToSpawnQueue(speciesName, position, sub, onSpawn) end + +--- AddToSpawnQueue +-- @realm shared +-- @tparam string speciesName +-- @tparam Vector2 worldPosition +-- @tparam CharacterInfo characterInfo +-- @tparam function onSpawn +function AddToSpawnQueue(speciesName, worldPosition, characterInfo, onSpawn) end + +--- AddToRemoveQueue +-- @realm shared +-- @tparam Entity entity +function AddToRemoveQueue(entity) end + +--- AddToRemoveQueue +-- @realm shared +-- @tparam Item item +function AddToRemoveQueue(item) end + +--- IsInSpawnQueue +-- @realm shared +-- @tparam Predicate`1 predicate +-- @treturn bool +function IsInSpawnQueue(predicate) end + +--- CountSpawnQueue +-- @realm shared +-- @tparam Predicate`1 predicate +-- @treturn number +function CountSpawnQueue(predicate) end + +--- IsInRemoveQueue +-- @realm shared +-- @tparam Entity entity +-- @treturn bool +function IsInRemoveQueue(entity) end + +--- Update +-- @realm shared +-- @tparam bool createNetworkEvents +function Update(createNetworkEvents) end + + + +--- +-- SpawnTime, Field of type number +-- @realm shared +-- @number SpawnTime + diff --git a/docs/lua/Entity.lua b/docs/lua/Entity.lua new file mode 100644 index 000000000..a598baefe --- /dev/null +++ b/docs/lua/Entity.lua @@ -0,0 +1,151 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma Entity class with some additional functions and fields + +Barotrauma source code: [Entity.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Map/Entity.cs) +]] +-- @code Entity +-- @pragma nostrip + +--- Remove +-- @realm shared +function Remove() end + +--- ToString +-- @realm shared +-- @treturn string +function ToString() end + +--- GetEntities +-- @realm shared +-- @treturn IEnumerable`1 +function Entity.GetEntities() end + +--- FindFreeID +-- @realm shared +-- @tparam number idOffset +-- @treturn number +function Entity.FindFreeID(idOffset) end + +--- FindEntityByID +-- @realm shared +-- @tparam number ID +-- @treturn Entity +function Entity.FindEntityByID(ID) end + +--- RemoveAll +-- @realm shared +function Entity.RemoveAll() end + +--- FreeID +-- @realm shared +function FreeID() end + +--- DumpIds +-- @realm shared +-- @tparam number count +-- @tparam string filename +function Entity.DumpIds(count, filename) end + +--- GetType +-- @realm shared +-- @treturn Type +function GetType() end + +--- Equals +-- @realm shared +-- @tparam Object obj +-- @treturn bool +function Equals(obj) end + +--- GetHashCode +-- @realm shared +-- @treturn number +function GetHashCode() end + +--- +-- Entity.EntityCount, Field of type number +-- @realm shared +-- @number Entity.EntityCount + +--- +-- Removed, Field of type bool +-- @realm shared +-- @bool Removed + +--- +-- IdFreed, Field of type bool +-- @realm shared +-- @bool IdFreed + +--- +-- SimPosition, Field of type Vector2 +-- @realm shared +-- @Vector2 SimPosition + +--- +-- Position, Field of type Vector2 +-- @realm shared +-- @Vector2 Position + +--- +-- WorldPosition, Field of type Vector2 +-- @realm shared +-- @Vector2 WorldPosition + +--- +-- DrawPosition, Field of type Vector2 +-- @realm shared +-- @Vector2 DrawPosition + +--- +-- Submarine, Field of type Submarine +-- @realm shared +-- @Submarine Submarine + +--- +-- AiTarget, Field of type AITarget +-- @realm shared +-- @AITarget AiTarget + +--- +-- SpawnTime, Field of type number +-- @realm shared +-- @number SpawnTime + +--- +-- ID, Field of type number +-- @realm shared +-- @number ID + +--- +-- Entity.Spawner, Field of type EntitySpawner +-- @realm shared +-- @EntitySpawner Entity.Spawner + +--- +-- Entity.NullEntityID, Field of type number +-- @realm shared +-- @number Entity.NullEntityID + +--- +-- Entity.EntitySpawnerID, Field of type number +-- @realm shared +-- @number Entity.EntitySpawnerID + +--- +-- Entity.RespawnManagerID, Field of type number +-- @realm shared +-- @number Entity.RespawnManagerID + +--- +-- Entity.DummyID, Field of type number +-- @realm shared +-- @number Entity.DummyID + +--- +-- Entity.ReservedIDStart, Field of type number +-- @realm shared +-- @number Entity.ReservedIDStart + diff --git a/docs/lua/Networking.lua b/docs/lua/Networking.lua index e44deef1f..7c7b1feea 100644 --- a/docs/lua/Networking.lua +++ b/docs/lua/Networking.lua @@ -31,4 +31,4 @@ function Networking.Send(netMessage, connection, deliveryMethod) end --- Adds a function to listen for lua net messages -- @realm shared -function Networking.Receive(netMessageName, callback) end \ No newline at end of file +function Networking.Receive(netMessageName, callback) end diff --git a/docs/templates/module.ltp b/docs/templates/module.ltp index ff052e838..920d99aa3 100644 --- a/docs/templates/module.ltp +++ b/docs/templates/module.ltp @@ -6,10 +6,38 @@

{* ldoc.markup(mod.description) *}

-{% for kind, items in mod.kinds() do %} +{% + local kinds = {} + local kindsIpairs = {} + for kind, items in mod.kinds() do + local name = kind + if kind == "Tables" then + name = "Fields" + end + + for item in items() do + if kinds[name] == nil then + kinds[name] = {} + + local value = {} + value.kind = name + value.items = kinds[name] + table.insert(kindsIpairs, value) + end + kinds[name][item] = true + end + end + + +%} + +{% for i, value in ipairs(kindsIpairs) do + local kind = value.kind + local items = value.items +%}

{{kind}}

- {% for item in items() do %} + {% for item, _ in pairs(items) do %}