From 656af7df2f30c11c4d7e9d3f01b6856ea40a35c1 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sun, 12 Sep 2021 15:58:59 -0300 Subject: [PATCH] new documentation and some fixes in code --- .gitignore | 2 + .../Lua/LuaBarotraumaAdditions.cs | 6 +- .../ServerSource/Lua/LuaClasses.cs | 6 +- .../ServerSource/Lua/LuaSetup.cs | 2 +- config.ld | 61 ++ docs/build_docs.bat | 5 + docs/css/highlight.css | 190 +++++++ docs/css/ldoc.css | 531 ++++++++++++++++++ docs/js/app.js | 168 ++++++ docs/js/highlight.min.js | 2 + docs/lua/Character.lua | 19 + docs/lua/CharacterInfo.lua | 13 + docs/lua/Client.lua | 36 ++ docs/lua/File.lua | 40 ++ docs/lua/Game.lua | 88 +++ docs/lua/Hooks.lua | 128 +++++ docs/lua/Item.lua | 22 + docs/lua/ItemPrefab.lua | 28 + docs/lua/Networking.lua | 16 + docs/lua/Signal.lua | 13 + docs/lua/Timer.lua | 11 + docs/lua/Vectors.lua | 28 + docs/manual/getting-started.md | 14 + .../installing-lua-for-barotrauma-manually.md | 17 + docs/manual/lua-examples.md | 110 ++++ docs/templates/landing.ltp | 28 + docs/templates/ldoc.ltp | 90 +++ docs/templates/module.ltp | 123 ++++ docs/templates/sidebar.ltp | 69 +++ 29 files changed, 1861 insertions(+), 5 deletions(-) create mode 100644 config.ld create mode 100644 docs/build_docs.bat create mode 100644 docs/css/highlight.css create mode 100644 docs/css/ldoc.css create mode 100644 docs/js/app.js create mode 100644 docs/js/highlight.min.js create mode 100644 docs/lua/Character.lua create mode 100644 docs/lua/CharacterInfo.lua create mode 100644 docs/lua/Client.lua create mode 100644 docs/lua/File.lua create mode 100644 docs/lua/Game.lua create mode 100644 docs/lua/Hooks.lua create mode 100644 docs/lua/Item.lua create mode 100644 docs/lua/ItemPrefab.lua create mode 100644 docs/lua/Networking.lua create mode 100644 docs/lua/Signal.lua create mode 100644 docs/lua/Timer.lua create mode 100644 docs/lua/Vectors.lua create mode 100644 docs/manual/getting-started.md create mode 100644 docs/manual/installing-lua-for-barotrauma-manually.md create mode 100644 docs/manual/lua-examples.md create mode 100644 docs/templates/landing.ltp create mode 100644 docs/templates/ldoc.ltp create mode 100644 docs/templates/module.ltp create mode 100644 docs/templates/sidebar.ltp diff --git a/.gitignore b/.gitignore index 4dd2d8677..2ee92f352 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ desktop.ini #Merge script temp.txt + +docs/html diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaBarotraumaAdditions.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaBarotraumaAdditions.cs index d2c5d0783..ada742572 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaBarotraumaAdditions.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaBarotraumaAdditions.cs @@ -65,7 +65,7 @@ namespace Barotrauma partial class Item { - public void AddToRemoveQueue(Item item) + public static void AddToRemoveQueue(Item item) { EntitySpawner.Spawner.AddToRemoveQueue(item); } @@ -74,14 +74,14 @@ namespace Barotrauma partial class ItemPrefab { - public void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, object spawned = null) + public static void AddToSpawnQueue(ItemPrefab itemPrefab, Vector2 position, object spawned = null) { EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, position, onSpawned: (Item item) => { GameMain.Lua.CallFunction(spawned, new object[] { item }); }); } - public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, object spawned = null) + public static void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, object spawned = null) { EntitySpawner.Spawner.AddToSpawnQueue(itemPrefab, inventory, onSpawned: (Item item) => { GameMain.Lua.CallFunction(spawned, new object[] { item }); diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs index 97467c1f4..81ca91f69 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs @@ -396,7 +396,6 @@ namespace Barotrauma string name = subElement.GetAttributeString("name", null); enabledPackages.Add(name); } - return enabledPackages; } } @@ -469,6 +468,11 @@ namespace Barotrauma return Directory.Exists(path); } + public static string[] GetFiles(string path) + { + return Directory.GetFiles(path); + } + public static string[] GetDirectories(string path) { return Directory.GetDirectories(path); diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs index 14a71a495..757b4154d 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs @@ -296,7 +296,7 @@ namespace Barotrauma lua.Globals["Gap"] = UserData.CreateStatic(); lua.Globals["ContentPackage"] = UserData.CreateStatic(); lua.Globals["ClientPermissions"] = UserData.CreateStatic(); - + lua.Globals["Signal"] = UserData.CreateStatic(); if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader DoFile("Lua/MoonsharpSetup.lua"); diff --git a/config.ld b/config.ld new file mode 100644 index 000000000..27312d1ff --- /dev/null +++ b/config.ld @@ -0,0 +1,61 @@ + +file = { + "docs/lua" +} + +module_file = { + +} + +dir = "docs/html" +project = "LuaForBarotrauma" +title = "LuaForBarotrauma Documentation" + +no_space_before_args = true +style = "docs/css" +template = "docs/templates" +format = "markdown" +ignore = true +topics = "docs/manual" +use_markdown_titles = true +kind_names = {module = "Classes", topic = "Manual"} +merge = true +sort = true +sort_modules = true + +simple_args_string = true -- we show optionals/defaults outside of the display name +strip_metamethod_prefix = true -- remove the name of the table when displaying metamethod names +no_viewed_topic_at_top = true -- don't put the currently viewed topic at the top +use_new_templates = true -- new templating system +pretty_urls = true -- avoid showing .html in urls +pretty_topic_names = true -- strips extension from manual filenames, this does not check filename collisions + +custom_tags = { + {"realm", hidden = true}, + {"internal", hidden = true} +} + +custom_display_name_handler = function(item, default_handler) + if (item.type == "function" and item.module) then + if (item.module.type == "classmod" or item.module.type == "panel") then + return item.module.mod_name .. ":" .. default_handler(item) + elseif (item.module.type == "hooks") then + return item.module.mod_name:upper() .. ":" .. default_handler(item) + end + end + + return default_handler(item) +end + + +new_type("code", "Code", true) + +tparam_alias("Client", "client") +tparam_alias("Character", "character") +tparam_alias("Submarine", "submarine") +tparam_alias("Item", "item") + +tparam_alias("string", "string") +tparam_alias("bool", "boolean") +tparam_alias("function", "function") +tparam_alias("tab", "table") diff --git a/docs/build_docs.bat b/docs/build_docs.bat new file mode 100644 index 000000000..0d77209c3 --- /dev/null +++ b/docs/build_docs.bat @@ -0,0 +1,5 @@ +xcopy css html /Y +xcopy js html /Y +cd .. +lua D:\programming\lua\LDoc\ldoc.lua . +cd docs \ No newline at end of file diff --git a/docs/css/highlight.css b/docs/css/highlight.css new file mode 100644 index 000000000..10bd5e13f --- /dev/null +++ b/docs/css/highlight.css @@ -0,0 +1,190 @@ +/* + +github.com style (c) Vasily Polovnyov + +*/ + +.hljs { + display: block; + color: white; +} + +.hljs-comment, +.hljs-quote { + color: gray; + font-style: italic; +} + +.hljs-keyword, +.hljs-selector-tag, +.hljs-subst { + color: #0086b3; + font-weight: bold; +} + +.hljs-number, +.hljs-literal, +.hljs-variable, +.hljs-template-variable, +.hljs-tag .hljs-attr { + color: #008080; +} + +.hljs-string, +.hljs-doctag { + color: #d14; +} + +.hljs-title, +.hljs-section, +.hljs-selector-id { + color: #900; + font-weight: bold; +} + +.hljs-subst { + font-weight: normal; +} + +.hljs-type, +.hljs-class .hljs-title { + color: #458; + font-weight: bold; +} + +.hljs-tag, +.hljs-name, +.hljs-attribute { + color: #000080; + font-weight: normal; +} + +.hljs-regexp, +.hljs-link { + color: #009926; +} + +.hljs-symbol, +.hljs-bullet { + color: #990073; +} + +.hljs-built_in, +.hljs-builtin-name { + color: #0086b3; +} + +.hljs-meta { + color: #999; + font-weight: bold; +} + +.hljs-deletion { + background: #fdd; +} + +.hljs-addition { + background: #dfd; +} + +.hljs-emphasis { + font-style: italic; +} + +.hljs-strong { + font-weight: bold; +} + + + + + + + + + +.comment, +.quote { + color: gray; + font-style: italic; +} + +.keyword, +.selector-tag, +.subst { + color: #0086b3; + font-weight: bold; +} + +.number, +.literal, +.variable, +.template-variable, +.tag .hljs-attr { + color: #008080; +} + +.string, +.doctag { + color: #d14; +} + +.title, +.section, +.selector-id { + color: #900; + font-weight: bold; +} + +.subst { + font-weight: normal; +} + +.type, +.class .hljs-title { + color: #458; + font-weight: bold; +} + +.tag, +.name, +.attribute { + color: #000080; + font-weight: normal; +} + +.regexp, +.link { + color: #009926; +} + +.symbol, +.bullet { + color: #990073; +} + +.built_in, +.builtin-name { + color: #0086b3; +} + +.meta { + color: #999; + font-weight: bold; +} + +.deletion { + background: #fdd; +} + +.addition { + background: #dfd; +} + +.emphasis { + font-style: italic; +} + +.strong { + font-weight: bold; +} diff --git a/docs/css/ldoc.css b/docs/css/ldoc.css new file mode 100644 index 000000000..8f37135c2 --- /dev/null +++ b/docs/css/ldoc.css @@ -0,0 +1,531 @@ + +:root { + --content-width: 100%; + --sidebar-width: 25%; + + --padding-big: 48px; + --padding-normal: 24px; + --padding-small: 16px; + --padding-tiny: 10px; + + --font-massive: 32px; + --font-huge: 24px; + --font-big: 18px; + --font-normal: 16px; + --font-tiny: 12px; + + --font-style-normal: Segoe UI, Helvetica, Arial, sans-serif; + --font-style-code: Consolas, monospace; + + --color-accent: rgb(47, 100, 74); + --color-accent-dark: rgb(33, 33, 33); + --color-white: rgb(255, 255, 255); + --color-offwhite: rgb(200, 200, 200); + --color-white-accent: rgb(203, 190, 209); + --color-black: rgb(0, 0, 0); + --color-lightgrey: rgb(160, 160, 160); + --color-background-light: rgb(245, 245, 245); + --color-background-dark: rgb(33, 33, 33); + --color-background-dark-ish: rgb(44, 44, 44); + --color-outline: rgb(149, 34, 160); + --color-good: rgb(204, 34, 34); +} + +* { + padding: 0; + margin: 0; + box-sizing: border-box; +} + +body { + background-color: var(--color-background-dark); + font-family: var(--font-style-normal); + + display: flex; + flex-direction: column; +} + +a { + color: inherit; + text-decoration: inherit; +} + +h1, h2, h3, h4 { + font-weight: 400; +} + +ul li { + margin-left: var(--padding-small); +} + +/* landing */ +.landing { + background-color: var(--color-accent); + color: var(--color-white); + + padding: 128px 0 128px 0; +} + +.landing h1 { + margin: 0; + padding: 0; + border: none; + + font-weight: 100; + font-size: var(--font-massive); + text-align: center; +} + +.wrapper { + padding: var(--padding-small); +} + +details { + user-select: none; +} + +details summary { + outline: none; +} + +code { + font-family: "Source Code Pro", monospace; + font-size: 85%; + white-space: pre; + tab-size: 4; + -moz-tab-size: 4; + padding: 2px 4px; + background-color: rgba(33, 33, 33, 0.1); +} + +pre { + background-color: rgb(99, 99, 99, 0.1); + margin-top: var(--padding-small); + padding: var(--padding-tiny); + overflow: auto; +} + +pre code { + background-color: transparent; +} + +span.realm { + width: 14px; + height: 14px; + border-radius: 3px; + display: inline-block; + margin-right: 6px; +} + +span.realm.shared { + background: linear-gradient(45deg, #f80 0%, #f80 50%, #08f 51%, #08f 100%); +} + +span.realm.client { + background-color: #f80; +} + +span.realm.server { + background-color: #08f; +} + +/* wrapper element for sidebar/content */ +main { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: flex-start; + + width: var(--content-width); + margin: auto; +} + +/* sidebar */ +nav { + color: var(--color-offwhite); + background-color: var(--color-background-dark); + + position: fixed; + display: flex; + flex-direction: column; + + width: var(--sidebar-width); + height: 100%; +} + +/* sidebar header */ +nav header { + color: var(--color-white); + background-color: var(--color-accent); + + padding: var(--padding-small); +} + +nav header h1 { + font-size: var(--font-huge); + font-weight: 100; + text-align: center; + + margin-bottom: var(--padding-small); +} + +#search { + background-color: var(--color-accent-dark); + color: var(--color-white); + + border: none; + font-size: var(--font-normal); + outline: none; + + width: 100%; + padding: 6px; +} + +#search::placeholder { + color: var(--color-white-accent); +} + +#search::-webkit-search-cancel-button { + display: none; +} + +/* sidebar contents */ +nav section { + padding: var(--padding-small); + overflow: auto; +} + +nav section ul { + list-style-type: none; +} + +nav section::-webkit-scrollbar, +pre::-webkit-scrollbar { + width: 8px; + height: 8px; +} + +nav section::-webkit-scrollbar-track, +pre::-webkit-scrollbar-track { + background: transparent; +} + +nav section::-webkit-scrollbar-thumb { + background-color: var(--color-lightgrey); +} + +pre::-webkit-scrollbar-thumb { + background-color: var(--color-lightgrey); +} + +/* sidebar contents category */ +nav section details.category { + padding-top: var(--padding-tiny); +} + +nav section details.category > ul > li { + margin: 0; + line-height: 1.5; +} + +nav section details.category > ul > li a { + display: inline-block; + width: 90%; +} + +nav section details.category:first-of-type { + padding-top: calc(var(--padding-tiny) * -1); +} + +nav section details.category summary::-webkit-details-marker { + opacity: 0.5; + cursor: pointer; +} + +nav section details.category summary h2 { + color: var(--color-accent); + + font-size: var(--font-big); + letter-spacing: 2px; + text-transform: uppercase; + cursor: pointer; + + padding-bottom: var(--padding-tiny); +} + +/* content */ +article { + background-color: var(--color-background-dark-ish); + color: white; + width: calc(100% - var(--sidebar-width)); + min-height: 100vh; + margin-left: var(--sidebar-width); +} + +article .wrapper > *:first-child { + margin-top: 0; +} + +/* header */ +article header { + color: rgb(255, 255, 255); + background-color: var(--color-accent); + padding: var(--padding-tiny); +} + +article header h1 { + border-bottom: 1px solid rgba(255, 255, 255, 0.25); + padding-bottom: 8px; + font-family: var(--font-style-code); + margin: 0; +} + +article header h2 { + padding-top: var(--padding-tiny); + margin: 0; + font-size: var(--font-normal); + font-weight: normal; +} + +article header.module a { + color: white !important; + text-decoration: underline; +} + +details.category > summary { + list-style: none; +} + +details.category > summary::-webkit-details-marker { + display: none; +} + +article h1 { + font-size: 28px; + font-weight: 600; + border-bottom: 1px solid rgba(0, 0, 0, 0.25); + margin-top: 24px; + margin-bottom: 16px; + padding-bottom: 8px; +} + +article h2 { + font-size: 20px; + font-weight: 600; + margin-top: 12px; +} + +article h3 { + color: var(--color-good); + margin-top: var(--padding-tiny); + text-transform: uppercase; +} + +article p { + margin-top: var(--padding-small); +} + +article p a, +article ul li a, +article h1 a, +article h2 a { + color: var(--color-good); + font-weight: 600; +} + +article h1.title { + color: rgb(255, 255, 255); + background-color: var(--color-accent); + margin-top: var(--padding-small); + margin-bottom: 0; + padding: var(--padding-tiny); + + font-size: var(--font-big); + font-weight: 100; + letter-spacing: 2px; + text-transform: uppercase; +} + +a.reference { + color: var(--color-good); + float: right; + margin-top: 8px; + padding-left: 8px; + font-size: 14px; + font-weight: 600; +} + +.notice { + --color-notice-background: var(--color-accent); + --color-notice-text: var(--color-notice-background); + + margin-top: var(--padding-tiny); + border: 2px solid var(--color-notice-background); +} + +.notice.error { + --color-notice-background: rgb(194, 52, 130); +} + +.notice.warning { + --color-notice-background: rgb(224, 169, 112); + --color-notice-text: rgb(167, 104, 37); +} + +.notice .title { + color: var(--color-white); + background-color: var(--color-notice-background); + + padding: var(--padding-tiny); + font-size: var(--font-normal); + + text-transform: uppercase; + letter-spacing: 2px; +} + +.notice p { + color: var(--color-notice-text); + + margin: 0 !important; + padding: var(--padding-tiny); +} + +/* function/table */ +.method { + display: flex; + flex-flow: column; + padding: var(--padding-tiny); + margin-top: var(--padding-small); +} + +.method header { + color: white; + background-color: inherit; + padding: 0; + order: -1; +} + +.method header .anchor { + color: inherit; + text-decoration: inherit; +} + +.method:target { + background-color: var(--color-background-dark); + + outline: solid; + outline-width: 1px; + outline-color: var(--color-accent); +} + +.method header:target { + background-color: var(--color-accent); +} + +.method header h1 { + font-family: "Source Code Pro", monospace; + padding-bottom: var(--padding-tiny); + border-bottom: 1px solid var(--color-accent); + font-size: 20px; +} + +.method header p:first-of-type { + margin-top: var(--padding-tiny); +} + +.method h3 { + color: var(--color-good); + font-size: var(--font-normal); + letter-spacing: 2px; + text-transform: uppercase; +} + +.method pre { + margin-top: var(--padding-tiny); +} + +@media only screen and (max-width: 1100px) { + main nav { + position: inherit; + } + + main article { + margin-left: 0; + } +} + +.method ul { + margin-top: var(--padding-tiny); + background-color: inherit; +} + +.method ul li { + list-style: none; + margin: 4px 0 0 var(--padding-normal); +} + +.method ul li:first-of-type { + margin-top: 0; +} + +.method ul li p { + margin: 4px 0 0 var(--padding-normal); +} + +.method ul li pre { + margin: 4px 0 0 var(--padding-normal); +} + +.method ul li a { + color: rgb(115, 53, 142); + font-weight: 600; +} + +/* we have to manually specify these instead of making a shared class since you cannot customize the parameter class in ldoc */ +.parameter, .type, .default { + display: inline-block; + color: rgb(255, 255, 255) !important; + + padding: 4px; + font-size: 14px; + font-family: "Source Code Pro", monospace; +} + +.parameter { + background-color: rgb(115, 53, 142); +} + +.type { + background-color: rgb(31, 141, 155); +} + +a.type { + font-weight: 300 !important; + text-decoration: underline; +} + +.default { + background-color: rgb(193, 114, 11); +} + +.type a { + padding: 0; +} + +.or { + color: rgba(115, 53, 142, 0.5); + background-color: inherit; + + width: calc(100% - 32px); + height: 8px; + margin: 0 0 8px 32px; + + text-align: center; + font-weight: 600; + border-bottom: 1px solid rgba(115, 53, 142, 0.5); +} + +.or span { + background-color: inherit; + padding: 0 8px 0 8px; +} diff --git a/docs/js/app.js b/docs/js/app.js new file mode 100644 index 000000000..ce0cee1ba --- /dev/null +++ b/docs/js/app.js @@ -0,0 +1,168 @@ + +const skippedCategories = ["manual"]; + +class Node +{ + constructor(name, element, expandable, noAutoCollapse, children = []) + { + this.name = name; + this.element = element; + this.expandable = expandable; + this.noAutoCollapse = noAutoCollapse; + this.children = children; + } + + AddChild(name, element, expandable, noAutoCollapse, children) + { + let newNode = new Node(name, element, expandable, noAutoCollapse, children); + this.children.push(newNode); + + return newNode; + } +} + +class SearchManager +{ + constructor(input, contents) + { + this.input = input; + this.input.addEventListener("input", event => + { + this.OnInputUpdated(this.input.value.toLowerCase().replace(/:/g, ".")); + }); + + // setup search tree + this.tree = new Node("", document.createElement("null"), true, true); + this.entries = {}; + + const categoryElements = contents.querySelectorAll(".category"); + + // iterate each kind (hooks/libraries/classes/etc) + for (const category of categoryElements) + { + const nameElement = category.querySelector(":scope > summary > h2"); + + if (!nameElement) + { + continue; + } + + const categoryName = nameElement.textContent.trim().toLowerCase(); + + if (skippedCategories.includes(categoryName)) + { + continue; + } + + let categoryNode = this.tree.AddChild(categoryName, category, true, true); + const sectionElements = category.querySelectorAll(":scope > ul > li"); + + for (const section of sectionElements) + { + const entryElements = section.querySelectorAll(":scope > details > ul > li > a"); + const sectionName = section.querySelector(":scope > details > summary > a") + .textContent + .trim() + .toLowerCase(); + + let sectionNode = categoryNode.AddChild(sectionName, section.querySelector(":scope > details"), true); + + for (let i = 0; i < entryElements.length; i++) + { + const entryElement = entryElements[i]; + const entryName = entryElement.textContent.trim().toLowerCase(); + + sectionNode.AddChild(sectionName + "." + entryName, entryElement.parentElement); + } + } + } + } + + ResetVisibility(current) + { + current.element.style.display = ""; + + if (current.noAutoCollapse) + { + current.element.open = true; + } + else if (current.expandable) + { + current.element.open = false; + } + + for (let node of current.children) + { + this.ResetVisibility(node); + } + } + + Search(input, current) + { + let matched = false; + + if (current.name.indexOf(input) != -1) + { + matched = true; + } + + for (let node of current.children) + { + let childMatched = this.Search(input, node); + matched = matched || childMatched; + } + + if (matched) + { + current.element.style.display = ""; + + if (current.expandable) + { + current.element.open = true; + } + } + else + { + current.element.style.display = "none"; + + if (current.expandable) + { + current.element.open = false; + } + } + + return matched; + } + + OnInputUpdated(input) + { + if (input.length <= 1) + { + this.ResetVisibility(this.tree); + return; + } + + this.Search(input, this.tree); + } +} + +window.onload = function() +{ + const openDetails = document.querySelector(".category > ul > li > details[open]"); + + if (openDetails) + { + openDetails.scrollIntoView(); + } +} + +document.addEventListener("DOMContentLoaded", function() +{ + const searchInput = document.getElementById("search"); + const contents = document.querySelector("body > main > nav > section"); + + if (searchInput && contents) + { + new SearchManager(searchInput, contents); + } +}); diff --git a/docs/js/highlight.min.js b/docs/js/highlight.min.js new file mode 100644 index 000000000..dd8dd8d78 --- /dev/null +++ b/docs/js/highlight.min.js @@ -0,0 +1,2 @@ +/*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */ +!function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/g,"&").replace(//g,">")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r>n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!==r[0].offset?e[0].offset"}function u(e){s+=""}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&&g.length&&g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&&!e.cached_variants&&(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&&[o(e)]||[e]}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),null==a.r&&(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a>t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&&e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&&r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&&e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&&!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r>0&&(B+=t.r),e&&(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&&(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&&(k=n));do E.cN&&(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&&(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&&(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&&-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&&"\n"===e?"
":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(//g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&&(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&&r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,C="
",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("lua",function(e){var t="\\[=*\\[",a="\\]=*\\]",r={b:t,e:a,c:["self"]},n=[e.C("--(?!"+t+")","$"),e.C("--"+t,a,{c:[r],r:10})];return{l:e.UIR,k:{literal:"true false nil",keyword:"and break do else elseif end for goto if in local not or repeat return then until while",built_in:"_G _ENV _VERSION __index __newindex __mode __call __metatable __tostring __len __gc __add __sub __mul __div __mod __pow __concat __unm __eq __lt __le assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstringmodule next pairs pcall print rawequal rawget rawset require select setfenvsetmetatable tonumber tostring type unpack xpcall arg selfcoroutine resume yield status wrap create running debug getupvalue debug sethook getmetatable gethook setmetatable setlocal traceback setfenv getinfo setupvalue getlocal getregistry getfenv io lines write close flush open output type read stderr stdin input stdout popen tmpfile math log max acos huge ldexp pi cos tanh pow deg tan cosh sinh random randomseed frexp ceil floor rad abs sqrt modf asin min mod fmod log10 atan2 exp sin atan os exit setlocale date getenv difftime remove time clock tmpname rename execute package preload loadlib loaded loaders cpath config path seeall string sub upper len gfind rep find match char dump gmatch reverse byte format gsub lower table setn insert getn foreachi maxn foreach concat sort remove"},c:n.concat([{cN:"function",bK:"function",e:"\\)",c:[e.inherit(e.TM,{b:"([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*"}),{cN:"params",b:"\\(",eW:!0,c:n}].concat(n)},e.CNM,e.ASM,e.QSM,{cN:"string",b:t,e:a,c:[r],r:5}])}}); \ No newline at end of file diff --git a/docs/lua/Character.lua b/docs/lua/Character.lua new file mode 100644 index 000000000..97a086257 --- /dev/null +++ b/docs/lua/Character.lua @@ -0,0 +1,19 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma Character class with some additional functions and fields + +Barotrauma source code: [Character.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs) +]] +-- @code Character + + +--- Creates a CharacterInfo. +-- @treturn CharacterInfo +-- @realm server +function Create(speciesName, name, jobPrefab, ragdollFileName, variant, randSync, npcIdentifier) end + +--- List of all characters. +-- @treturn table +-- @realm shared +CharacterList = {} \ No newline at end of file diff --git a/docs/lua/CharacterInfo.lua b/docs/lua/CharacterInfo.lua new file mode 100644 index 000000000..fcbd342a8 --- /dev/null +++ b/docs/lua/CharacterInfo.lua @@ -0,0 +1,13 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma CharacterInfo class with some additional functions and fields + +Barotrauma source code: [CharacterInfo.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Characters/CharacterInfo.cs) +]] +-- @code CharacterInfo + +--- Creates a Character using CharacterInfo. +-- @treturn Character +-- @realm server +function Create(characterInfo, position, seed, id, isRemotePlayer, hasAi, ragdollParams) end \ No newline at end of file diff --git a/docs/lua/Client.lua b/docs/lua/Client.lua new file mode 100644 index 000000000..e44a6af1f --- /dev/null +++ b/docs/lua/Client.lua @@ -0,0 +1,36 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma Character class with some additional functions and fields + +Barotrauma source code: [Client.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Networking/Client.cs) +]] +-- @code Client + +local myClient = {} + +--- Sets the client character. +-- @realm server +function myClient.SetClientCharacter(character) end + +--- Kick a client. +-- @realm server +function myClient.Kick(reason) end + +--- Ban a client. +-- @realm server +function myClient.Ban(reason, range, seconds) end + +--- Checks permissions, Client.Permissions. +-- @realm server +function myClient.CheckPermission(permissions) end + +--- Unban a client. +-- @realm server +function Unban(player, endpoint) end + + +--- List of all connected clients. +-- @treturn table +-- @realm shared +ClientList = {} \ No newline at end of file diff --git a/docs/lua/File.lua b/docs/lua/File.lua new file mode 100644 index 000000000..fa1991c1c --- /dev/null +++ b/docs/lua/File.lua @@ -0,0 +1,40 @@ +-- luacheck: ignore 111 + +--[[-- +Class providing filesystem functionality. +]] +-- @code File + +--- Read contents from path +-- @treturn string file contents +-- @realm shared +function Read(path) end + +--- Write text to file +-- @realm shared +function Write(path, text) end + +--- Check if file exists. +-- @treturn bool +-- @realm shared +function Exists(path) end + +--- Check if directory exists. +-- @treturn bool +-- @realm shared +function DirectoryExists(path) end + +--- Check if directory exists. +-- @treturn table table containing all files +-- @realm shared +function GetFiles(path) end + +--- List all directories. +-- @treturn table table containing all directories +-- @realm shared +function GetDirectories(path) end + +--- Search directory for all files including sub directories. +-- @treturn table table containing all files +-- @realm shared +function DirSearch(path) end \ No newline at end of file diff --git a/docs/lua/Game.lua b/docs/lua/Game.lua new file mode 100644 index 000000000..361a5084b --- /dev/null +++ b/docs/lua/Game.lua @@ -0,0 +1,88 @@ +-- luacheck: ignore 111 + +--[[-- +Class providing game related things, Access fields and functions like that: Game.* +]] +-- @code Game + +local Game = {} + +--- Is the round started? +-- @realm shared +RoundStarted = true + +--- Is dedicated server? +-- @realm server +IsDedicated = true + +--- Send chat message to every client. +-- @realm server +function SendMessage(msg, messageType, sender, character) end + +--- Send traitor message. +-- @realm server +function SendTraitorMessage(client, msg, missionid, type) end + + +--- Send direct message. +-- @realm server +function SendDirectChatMessage(sendername, text, senderCharacter, chatMessageType, client, iconStyle) end + +--- Send direct message. +-- @realm server +function SendDirectChatMessage(chatMessage, client) end + +--- True to override traitors. +-- @realm server +function OverrideTraitors(override) end + +--- True to override respawn shuttle. +-- @realm server +function OverrideRespawnSub(override) end + +--- True to make wifi chat always work. +-- @realm server +function AllowWifiChat(override) end + +--- True to prevent headsets from transmitting wifi signals. +-- @realm server +function OverrideSignalRadio(override) end + +--- True to disable spam filter. +-- @realm server +function DisableSpamFilter(override) end + +--- Log message to server logs. +-- @realm server +function Log(message, ServerLogMessageType) end + +--- Spawn explosion. +-- @realm server +function Explode(pos, range, force, damage, structureDamage, itemDamage, empStrength, ballastFloraStrength) end + +--- Get respawn shuttle submarine. +--@treturn Submarine Respawn Shuttle +-- @realm shared +function GetRespawnShuttle() end + +--- Dispatch respawn shuttle. +-- @realm server +function DispatchRespawnSub() end + +--- Execute console command. +-- @realm server +function ExecuteCommand(command) end + +--- Starts the game. +-- @realm server +function StartGame() end + +--- Gets all enabled content packages. +--@treturn table Table containing ContentPackages +-- @realm shared +function GetEnabledContentPackages() end + +--- Gets all enabled content packages by reading directly the player xml, useful when your mod doesn't have any xml. +--@treturn table Table containing ContentPackages +-- @realm shared +function GetEnabledPackagesDirectlyFromFile() end \ No newline at end of file diff --git a/docs/lua/Hooks.lua b/docs/lua/Hooks.lua new file mode 100644 index 000000000..bc651c20d --- /dev/null +++ b/docs/lua/Hooks.lua @@ -0,0 +1,128 @@ +-- luacheck: ignore 111 + +--[[-- +Hooks are basically functions that get called when events happen in-game, like chat messages. +]] +-- @code Hooks + +local Hook = {} + + +--- Adds a hook. +-- @tparam string eventname event name +-- @tparam string hookname hook name +-- @tparam function func callback +-- @realm shared +-- @usage +-- Hook.Add("characterDeath", "characterDeathExample", function(character) +-- print(character) +-- end) +function Hook.Add(eventname, hookname, func) end + +--- Removes a hook. +-- @tparam string eventname event name +-- @tparam string hookname hook name +-- @realm shared +-- @usage +-- Hook.Remove("characterDeath", "characterDeathExample") +function Hook.Remove(eventname, hookname) end + +--- Calls a hook. +-- @tparam string eventname event name +-- @tparam table parameters parameters to be passed in +-- @realm shared +-- @usage +-- Hook.Add("think", "happyDebuggingSuckers", function() +-- Hook.Call("characterDead", {}) -- ruin someone's day +-- end) +function Hook.Call(eventname, parameters) end + +--- Gets called everytime someone sends a chat message, return true to cancel message +-- @tparam string message +-- @tparam client sender +-- @realm shared +function chatMessage(message, sender) end + +--- Called every update +-- @realm shared +function think() end + +--- Called when a client connects +-- @tparam client connectedClient +-- @realm shared +function clientConnected(connectedClient) end + +--- Called when a client disconnects +-- @tparam client disconnectedClient +-- @realm shared +function clientDisconnected(disconnectedClient) end + + +--- Called on round start +-- @realm shared +function roundStart() end + +--- Called on round end +-- @realm shared +function roundEnd() end + +--- Gets callled everytime a character is created. +-- @tparam character createdCharacter +-- @realm shared +function characterCreated(createdCharacter) end + +--- Gets called everytime a Character dies. +-- @tparam Character character A dead Character. +-- @realm shared +-- @usage +-- Hook.Add("characterDeath", "characterDeathExample", function(character) +-- print(character) +-- end) +function characterDeath(character) end + +--- +-- @realm shared +function afflictionApplied(affliction, characterHealth, limb) end +--- +-- @realm shared +function afflictionUpdate(affliction, characterHealth, limb) end +--- +-- @realm shared +function itemUse(item, itemUser, targetLimb) end +--- +-- @realm shared +function itemSecondaryUse(item, itemUser) end +--- +-- @realm shared +function itemApplyTreatment(item, usingCharacter, targetCharacter, limb) end + +--- Gets called whenever an item is dropped, You can return true to cancel. +-- @realm shared +function itemDrop(item, character) end + +--- Gets called whenever an item is equipped. Return true to cancel. +-- @realm shared +function itemEquip(item, character) end + + +--- Same as itemEquip, but for unequipping. +-- @realm shared +function itemUnequip() end +--- +-- @realm shared +function changeFallDamage() end +--- +-- @realm shared +function gapOxygenUpdate() end +--- +-- @realm shared +function signalReceived() end +--- +-- @realm shared +function signalReceived.YourComponentIdentifier() end +--- +-- @realm shared +function wifiSignalTransmitted() end +--- +-- @realm shared +function serverLog() end \ No newline at end of file diff --git a/docs/lua/Item.lua b/docs/lua/Item.lua new file mode 100644 index 000000000..49169edf3 --- /dev/null +++ b/docs/lua/Item.lua @@ -0,0 +1,22 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma Item class with some additional functions and fields + +Barotrauma source code: [Item.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs) +]] +-- @code Item + +--- Adds to remove queue, use this instead of Remove, to prevent desync. +-- @realm server +function AddToRemoveQueue(item) end + + +--- Sends a signal. +-- @realm server +function SendSignal(signalOrString, connectionOrConnectionName) end + +--- List of all items. +-- @treturn table +-- @realm shared +ItemList = {} \ No newline at end of file diff --git a/docs/lua/ItemPrefab.lua b/docs/lua/ItemPrefab.lua new file mode 100644 index 000000000..185835a53 --- /dev/null +++ b/docs/lua/ItemPrefab.lua @@ -0,0 +1,28 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma ItemPrefab class with some additional functions and fields + +Barotrauma source code: [ItemPrefab.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Items/ItemPrefab.cs) +]] +-- @code ItemPrefab + +--- Add ItemPrefab to spawn queue and spawns it at the specified position +-- @tparam ItemPrefab itemPrefab +-- @tparam Vector2 position +-- @tparam function spawned +-- @realm server +function AddToSpawnQueue(itemPrefab, position, spawned) end + +--- Add ItemPrefab to spawn queue and spawns it inside the specified inventory +-- @tparam ItemPrefab itemPrefab +-- @tparam Inventory inventory +-- @tparam function spawned +-- @realm server +function AddToSpawnQueue(itemPrefab, inventory, spawned) end + +--- Get a item prefab via name or id +-- @tparam string itemNameOrId +-- @treturn ItemPrefab +-- @realm shared +function GetItemPrefab(itemNameOrId) end \ No newline at end of file diff --git a/docs/lua/Networking.lua b/docs/lua/Networking.lua new file mode 100644 index 000000000..f591bf8a0 --- /dev/null +++ b/docs/lua/Networking.lua @@ -0,0 +1,16 @@ +-- luacheck: ignore 111 + +--[[-- +Class providing networking related tasks. +]] +-- @code Networking + +--- Send a post HTTP Request. +-- treturn string result. +-- @realm server +function RequestPostHTTP(url, textData, contentType) end + +--- Send a get HTTP Request. +-- treturn string result. +-- @realm server +function RequestGetHTTP(url) end \ No newline at end of file diff --git a/docs/lua/Signal.lua b/docs/lua/Signal.lua new file mode 100644 index 000000000..2095fc1d1 --- /dev/null +++ b/docs/lua/Signal.lua @@ -0,0 +1,13 @@ +-- luacheck: ignore 111 + +--[[-- +Barotrauma Signal struct with some additional functions and fields + +Barotrauma source code: [Signal.cs](https://github.com/evilfactory/Barotrauma-lua-attempt/blob/master/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/Signal.cs) +]] +-- @code Signal + +--- Creates a Signal. +-- @treturn Signal +-- @realm shared +function Create(stringValue, stepsTaken, characterSender, itemSource, power, strength) end \ No newline at end of file diff --git a/docs/lua/Timer.lua b/docs/lua/Timer.lua new file mode 100644 index 000000000..e4c133234 --- /dev/null +++ b/docs/lua/Timer.lua @@ -0,0 +1,11 @@ +-- luacheck: ignore 111 + +--[[-- +Class providing timing related things. +]] +-- @code Timer + +--- Get time in seconds. +-- @treturn number current time in seconds +-- @realm shared +function GetTime() end \ No newline at end of file diff --git a/docs/lua/Vectors.lua b/docs/lua/Vectors.lua new file mode 100644 index 000000000..85a8b1b37 --- /dev/null +++ b/docs/lua/Vectors.lua @@ -0,0 +1,28 @@ +-- luacheck: ignore 111 + +--[[-- +Class providing vector functionality. +These are the XNA Vectors, you can find all the functions and fields here:
+XNA Vector2
+XNA Vector3
+XNA Vector4
+ +Access them via Vector2.\*, Vector3.\*, Vector4.\*
+CreateVector2, CreateVector3, CreateVector4 are globals. +]] +-- @code Vectors + +--- Create Vector2 +-- @treturn Vector2 +-- @realm shared +function CreateVector2(path) end + +--- Create Vector3 +-- @treturn Vector3 +-- @realm shared +function CreateVector2(path) end + +--- Create Vector4 +-- @treturn Vector4 +-- @realm shared +function CreateVector2(path) end \ No newline at end of file diff --git a/docs/manual/getting-started.md b/docs/manual/getting-started.md new file mode 100644 index 000000000..56fef0872 --- /dev/null +++ b/docs/manual/getting-started.md @@ -0,0 +1,14 @@ +# Getting started + +If you want to learn how Lua works and the syntax, you can check these websites: [https://www.lua.org/manual/5.2/](https://www.lua.org/manual/5.2/) [https://www.tutorialspoint.com/lua/lua_overview.htm](https://www.tutorialspoint.com/lua/lua_overview.htm) + +## How mods are executed +When the server finishes loading everything, Lua For Barotrauma starts up and reads the file `Lua/MoonsharpSetup.lua` and executes it, this Lua script then looks for Mods in the Mods folder, and tries to execute Lua scripts inside the Lua/Autorun folder, so for example, if you have a Mod named TheTest, and inside this mod you have a file named Lua/Autorun/test.lua, the test.lua will be executed automatically. + +## Creating your first mod +When creating a new Lua mod, you will need to create a new folder on the **Mods** folder, then inside this folder you will need to create a folder called **Lua**, and then inside the Lua folder you create a folder called **Autorun**, inside this folder you can add your lua scripts that will be executed automatically, it will look something like this `Mods/MyMod/Lua/Autorun/test.lua` + +Now you can open **test.lua** in your favorite text editor (vscode recommended) and type in **print("Hello, world")**, now start the server by hosting a game or running the server executable manually, you will see in your console a text appear with the text that you entered in print, you can now type in the server console reloadlua, this will re-execute all the Lua scripts. You can also type in lua (script) to run a short lua snippet, like this `lua print('Hello, world')`, remember to remove double quotes, because Barotrauma console automatically formats those. + +## Learning the libraries +In the sidebar of the documentation, you can see a tab named Code, in there you can check out all the functions and fields that each class has, and learn more about them, but not everything is documented here, theres stuff missing that still needs to be added, if you want to find more in-depth functions and fields in the Barotrauma classes, you should check the Barotrauma source code. \ No newline at end of file diff --git a/docs/manual/installing-lua-for-barotrauma-manually.md b/docs/manual/installing-lua-for-barotrauma-manually.md new file mode 100644 index 000000000..32f0092ed --- /dev/null +++ b/docs/manual/installing-lua-for-barotrauma-manually.md @@ -0,0 +1,17 @@ +## Installing Lua For Barotrauma +1 - Download [latest version of Barotrauma Lua](https://github.com/evilfactory/Barotrauma-lua-attempt/releases/download/latest/barotrauma_lua_windows.zip)
+2 - Extract the zip file, you should get a folder called barotrauma_lua
+3 - Find the Content folder in your original Barotrauma game:
+ + ![](https://cdn.discordapp.com/attachments/799752463619325968/833120013149929492/unknown.png) + ![](https://cdn.discordapp.com/attachments/799752463619325968/833120379378991104/unknown.png) + ![](https://cdn.discordapp.com/attachments/799752463619325968/833120841277374464/unknown.png) + +4 - Copy the Content folder to the barotrauma_lua folder
+ +![](https://cdn.discordapp.com/attachments/799752463619325968/833133217300742154/unknown.png) + +5 - Done! Now run Barotrauma.exe to run the modded game
+ +## Updating +To update you only need to replace the DedicatedServer.dll file from the latest release. diff --git a/docs/manual/lua-examples.md b/docs/manual/lua-examples.md new file mode 100644 index 000000000..acb22c2c5 --- /dev/null +++ b/docs/manual/lua-examples.md @@ -0,0 +1,110 @@ +# Lua Examples + +```lua +Hook.Add('chatMessage', 'suicide_mod', function(msg, client) + if msg == '!suicide' and client.Character ~= nil then + client.Character.Kill(CauseOfDeathType.Unknown) + Game.SendMessage(client.name .. ' killed himself!', ChatMessageType.Server) + return true -- hide message + end +end) +``` + +```lua +local characters = Character.CharacterList +local biteWoundsPrefab + +for k, v in pairs(AfflictionPrefab.ListArray) do + if v.name == "Bite wounds" then + biteWoundsPrefab = v + break + end +end + +for k, v in pairs(characters) do + v.CharacterHealth.ApplyAffliction(v.AnimController.MainLimb, biteWoundsPrefab.Instantiate(100)); +end +``` + +```lua +Hook.Add("itemApplyTreatment", "testItemApplyTreatment", function (item, user, character, targetlimb) + if item.name == "Bandage" then + local pos = character.WorldPosition + Game.Explode(pos, 1, 500, 5000, 5000, 5000) + + Game.RemoveItem(item) + end +end) +``` + +```lua +-- for example: create an item in xml named RandomComponent and add the wiring inputs/outputs trigger_random and random_out +Hook.Add("signalReceived", "signalReceivedTest", function (signal, connection) + if connection.Item.name == "RandomComponent" and connection.Name == "trigger_random" then + connection.Item.SendSignal(tostring(Random.Range(0, 100)), "random_out") + end +end) +``` + +```lua +local discordWebHook = "your discord webhook here" + +local function escapeQuotes(str) + return str:gsub("\"", "\\\"") +end + +Hook.Add("chatMessage", "discordIntegration", function (msg, client) + local escapedName = escapeQuotes(client.name) + local escapedMessage = escapeQuotes(msg) + + Networking.RequestPostHTTP(discordWebHook, '{\"content\": \"'..escapedMessage..'\", \"username\": \"'..escapedName..'\"}') +end) +``` + +```lua +local enabledPackages = Game.GetEnabledContentPackages() +local shouldRun = false + +for key, value in pairs(enabledPackages) do + if value.Name == "MyContentPackage" then + shouldRun = true + end +end + +if Game.IsDedicated then shouldRun = true end + +if not shouldRun then + return +end +``` + +```lua +-- by jimmyl +Hook.Add("chatMessage","controlhuskcommand",function(msg, client) + if msg == "!controlhusk" then + if client.Character ~= nil then + if not client.Character.IsDead then + return true + end + end + if not client.InGame then + return true + end + + local chars = Character.CharacterList + local suitablechars = {} + for i = 1, #chars, 1 do + local charat = chars[i] + if not charat.IsDead and string.match(string.lower(charat.SpeciesName), "husk") and not charat IsRemotelyControlled then + table.insert(suitablechars, charat) + end + end + + if #suitablechars >= 1 then + Player.SetClientCharacter(client, suitablechars[Random.Range(1, #suitablechars)]) + end + + return true -- hide message + end +end) +``` \ No newline at end of file diff --git a/docs/templates/landing.ltp b/docs/templates/landing.ltp new file mode 100644 index 000000000..8aa8ceab5 --- /dev/null +++ b/docs/templates/landing.ltp @@ -0,0 +1,28 @@ + +
+

Lua For Barotrauma Documentation

+
+ +
+

+

Welcome to the Lua For Barotrauma documentation!

+

This is a work in progress documentation, not everything is documented here, but because Barotrauma classes are exposed to lua, you can check the Barotrauma source code for functions and fields that you can access.

+ +

Installing Lua For Barotrauma

+

Downloading and using the Core Content Package from Workshop should be enough to have it installed, but if you want to install it manually, you can check out this guide. +

+ +

Getting Started

+

If you want to get started with Lua For Barotrauma modding, check out this guide. +

+ +

Client-Side support

+

Client-Side support will be supported at some point, but currently it's server-side only. +

+ +

Links

+

+ Github
+ Discord Server +

+
diff --git a/docs/templates/ldoc.ltp b/docs/templates/ldoc.ltp new file mode 100644 index 000000000..da3ef0829 --- /dev/null +++ b/docs/templates/ldoc.ltp @@ -0,0 +1,90 @@ + +{% +local baseUrl = ldoc.css:gsub("ldoc.css", "") +local repo = "https://github.com/nebulouscloud/helix/" +local pageTitle = mod and (ldoc.display_name(mod) .. " - " .. ldoc.title) or ldoc.title + +local oldmarkup = ldoc.markup +function ldoc.markup(text, item) + return oldmarkup(text, item, ldoc.plain) +end + +function ldoc.url(path) + return baseUrl .. path +end + +function ldoc.realm_icon(realm) + return ""; +end + +function ldoc.is_kind_classmethod(kind) + return kind ~= "libraries" +end + +function ldoc.repo_reference(item) + return repo .. "tree/master" .. item.file.filename:gsub(item.file.base, "/gamemode") .. "#L" .. item.lineno +end + +local function moduleDescription(mod) + if (mod.type == "topic") then + return mod.body:gsub(mod.display_name, ""):gsub("#", ""):sub(1, 256) .. "..." + end + + return mod.summary +end +%} + + + + {{pageTitle}} + + + + + + {% if (mod) then %} + + {% else %} + + {% end %} + + + + + + + +
+ {(docs/templates/sidebar.ltp)} + +
+ {% if (ldoc.root) then -- we're rendering the landing page (index.html) %} + {(docs/templates/landing.ltp)} + {% elseif (ldoc.body) then -- we're rendering non-code elements %} +
+ {* ldoc.body *} +
+ {% elseif (module) then -- we're rendering libary contents %} +
+ {(docs/templates/module.ltp)} +
+ {% end %} +
+
+ + + + + + diff --git a/docs/templates/module.ltp b/docs/templates/module.ltp new file mode 100644 index 000000000..ff052e838 --- /dev/null +++ b/docs/templates/module.ltp @@ -0,0 +1,123 @@ + +
+

{{mod.name}}

+

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

+
+ +

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

+ +{% for kind, items in mod.kinds() do %} +

{{kind}}

+ + {% for item in items() do %} +
+
+ +

{* ldoc.realm_icon(item.tags.realm[1]) *}{{ldoc.display_name(item)}}

+
+ + {% if (item.tags.internal) then %} +
+
Internal
+

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

+
+ {% end %} + + {% if (item.module and item.module.type ~= "hooks") then %} + View source » + {% end %} + + {% if (ldoc.descript(item):len() == 0) then %} +
+
Incomplete
+

Documentation for this section is incomplete and needs expanding.

+
+ {% else %} +

{* ldoc.markup(ldoc.descript(item)) *}

+ {% end %} +
+ + {# function arguments #} + {% if (item.params and #item.params > 0) then %} + {% local subnames = mod.kinds:type_of(item).subnames %} + + {% if (subnames) then %} +

{{subnames}}

+ {% end %} + + {% for argument in ldoc.modules.iter(item.params) do %} + {% local argument, sublist = item:subparam(argument) %} + +
    + {% for argumentName in ldoc.modules.iter(argument) do %} + {% local displayName = item:display_name_of(argumentName) %} + {% local type = ldoc.typename(item:type_of_param(argumentName)) %} + {% local default = item:default_of_param(argumentName) %} + +
  • + {{displayName}} + + {% if (type ~= "") then %} + {* type *} + {% end %} + + {% if (default and default ~= true) then %} + default: {{default}} + {% elseif (default) then %} + optional + {% end %} + +

    {* ldoc.markup(item.params.map[argumentName]) *}

    +
  • + {% end %} +
+ {% end %} + {% end %} + + {# function returns #} + {% if ((not ldoc.no_return_or_parms) and item.retgroups) then %} + {% local groups = item.retgroups %} + +

Returns

+
    + {% for i, group in ldoc.ipairs(groups) do %} + {% for returnValue in group:iter() do %} + {% local type, ctypes = item:return_type(returnValue) %} + {% type = ldoc.typename(type) %} + +
  • + {% if (type ~= "") then %} + {* type *} + {% else -- we'll assume that it will return a variable type if none is set %} + any + {% end %} + +

    {* ldoc.markup(returnValue.text) *}

    +
  • + {% end %} + + {% if (i ~= #groups) then %} +
    OR
    + {% end %} + {% end %} +
+ {% end %} + + {% if (item.usage) then -- function usage %} +

Example Usage

+ {% for usage in ldoc.modules.iter(item.usage) do %} +
{* usage *}
+ {% end %} + {% end %} + + {% if (item.see) then %} +

See Also

+
    + {% for see in ldoc.modules.iter(item.see) do %} +
  • {{see.label}}
  • + {% end %} +
+ {% end %} +
+ {% end %} +{% end %} diff --git a/docs/templates/sidebar.ltp b/docs/templates/sidebar.ltp new file mode 100644 index 000000000..2b4642b77 --- /dev/null +++ b/docs/templates/sidebar.ltp @@ -0,0 +1,69 @@ + +{% +local function isKindExpandable(kind) + return kind ~= "Manual" +end +%} + +