new documentation and some fixes in code

This commit is contained in:
Evil Factory
2021-09-12 15:58:59 -03:00
parent 3cd5a23af7
commit 656af7df2f
29 changed files with 1861 additions and 5 deletions

2
.gitignore vendored
View File

@@ -42,3 +42,5 @@ desktop.ini
#Merge script
temp.txt
docs/html

View File

@@ -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 });

View File

@@ -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);

View File

@@ -296,7 +296,7 @@ namespace Barotrauma
lua.Globals["Gap"] = UserData.CreateStatic<Gap>();
lua.Globals["ContentPackage"] = UserData.CreateStatic<ContentPackage>();
lua.Globals["ClientPermissions"] = UserData.CreateStatic<ClientPermissions>();
lua.Globals["Signal"] = UserData.CreateStatic<Signal>();
if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader
DoFile("Lua/MoonsharpSetup.lua");

61
config.ld Normal file
View File

@@ -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")

5
docs/build_docs.bat Normal file
View File

@@ -0,0 +1,5 @@
xcopy css html /Y
xcopy js html /Y
cd ..
lua D:\programming\lua\LDoc\ldoc.lua .
cd docs

190
docs/css/highlight.css Normal file
View File

@@ -0,0 +1,190 @@
/*
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
*/
.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;
}

531
docs/css/ldoc.css Normal file
View File

@@ -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;
}

168
docs/js/app.js Normal file
View File

@@ -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);
}
});

2
docs/js/highlight.min.js vendored Normal file

File diff suppressed because one or more lines are too long

19
docs/lua/Character.lua Normal file
View File

@@ -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 = {}

View File

@@ -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

36
docs/lua/Client.lua Normal file
View File

@@ -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 = {}

40
docs/lua/File.lua Normal file
View File

@@ -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

88
docs/lua/Game.lua Normal file
View File

@@ -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

128
docs/lua/Hooks.lua Normal file
View File

@@ -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

22
docs/lua/Item.lua Normal file
View File

@@ -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 = {}

28
docs/lua/ItemPrefab.lua Normal file
View File

@@ -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

16
docs/lua/Networking.lua Normal file
View File

@@ -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

13
docs/lua/Signal.lua Normal file
View File

@@ -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

11
docs/lua/Timer.lua Normal file
View File

@@ -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

28
docs/lua/Vectors.lua Normal file
View File

@@ -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: <br>
<a href="https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199660(v=xnagamestudio.35">XNA Vector2</a> <br>
<a href="https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199670(v=xnagamestudio.35">XNA Vector3</a> <br>
<a href="https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199679(v=xnagamestudio.35">XNA Vector4</a> <br>
Access them via Vector2.\*, Vector3.\*, Vector4.\* <br>
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

View File

@@ -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.

View File

@@ -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)<br>
2 - Extract the zip file, you should get a folder called barotrauma_lua <br>
3 - Find the Content folder in your original Barotrauma game: <br>
![](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 <br>
![](https://cdn.discordapp.com/attachments/799752463619325968/833133217300742154/unknown.png)
5 - Done! Now run Barotrauma.exe to run the modded game <br>
## Updating
To update you only need to replace the DedicatedServer.dll file from the latest release.

110
docs/manual/lua-examples.md Normal file
View File

@@ -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)
```

28
docs/templates/landing.ltp vendored Normal file
View File

@@ -0,0 +1,28 @@
<div class="landing">
<h1>Lua For Barotrauma Documentation</h1>
</div>
<div class="wrapper">
<p style="text-align: center;"></p>
<h2>Welcome to the Lua For Barotrauma documentation!</h2>
<p>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.</p>
<h2>Installing Lua For Barotrauma</h2>
<p>Downloading and using the Core Content Package from <a href="https://steamcommunity.com/sharedfiles/filedetails/?id=2559634234" target="_blank">Workshop</a> should be enough to have it installed, but if you want to install it manually, you can check out <a href="{* ldoc.url('manual/installing-lua-for-barotrauma-manually') *}">this guide.</a>
</p>
<h2>Getting Started</h2>
<p>If you want to get started with Lua For Barotrauma modding, check out <a href="{* ldoc.url('manual/getting-started') *}">this guide.</a>
</p>
<h2>Client-Side support</h2>
<p>Client-Side support will be supported at some point, but currently it's server-side only.
</p>
<h2>Links</h2>
<p>
<a href="https://github.com/evilfactory/Barotrauma-lua-attempt" target="_blank">Github</a><br>
<a href="https://discord.gg/f9zvNNuxu9" target="_blank">Discord Server</a>
</p>
</div>

90
docs/templates/ldoc.ltp vendored Normal file
View File

@@ -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 "<span class=\"realm " .. (realm or "") .. "\"></span>";
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
%}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{pageTitle}}</title>
<meta property="og:type" content="website" />
<meta property="og:title" content="{{pageTitle}}" />
<meta property="og:site_name" content="Helix Documentation" />
{% if (mod) then %}
<meta property="og:description" content="{{moduleDescription(mod)}}" />
{% else %}
<meta property="og:description" content="Documentation and function reference for the Helix framework." />
{% end %}
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Code+Pro" />
<link rel="stylesheet" href="{* ldoc.css *}" />
<link rel="stylesheet" href="{* ldoc.url('highlight.css') *}" />
</head>
<body>
<main>
{(docs/templates/sidebar.ltp)}
<article>
{% 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 %}
<div class="wrapper">
{* ldoc.body *}
</div>
{% elseif (module) then -- we're rendering libary contents %}
<div class="wrapper">
{(docs/templates/module.ltp)}
</div>
{% end %}
</article>
</main>
<script type="text/javascript" src="{* ldoc.url('app.js') *}"></script>
<script type="text/javascript" src="{* ldoc.url('highlight.min.js') *}"></script>
<script type="text/javascript">
var elements = document.querySelectorAll("pre code")
hljs.configure({
languages: ["lua"]
});
for (var i = 0; i < elements.length; i++)
{
hljs.highlightBlock(elements[i]);
}
</script>
</body>
</html>

123
docs/templates/module.ltp vendored Normal file
View File

@@ -0,0 +1,123 @@
<header class="module">
<h1>{{mod.name}}</h1>
<h2>{* ldoc.markup(mod.summary) *}</h2>
</header>
<p>{* ldoc.markup(mod.description) *}</p>
{% for kind, items in mod.kinds() do %}
<h1 class="title">{{kind}}</h1>
{% for item in items() do %}
<section class="method" id="{{item.name}}">
<header>
<a class="anchor">
<h1>{* ldoc.realm_icon(item.tags.realm[1]) *}</span>{{ldoc.display_name(item)}}</h1>
</a>
{% if (item.tags.internal) then %}
<div class="notice error">
<div class="title">Internal</div>
<p>This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.</p>
</div>
{% end %}
{% if (item.module and item.module.type ~= "hooks") then %}
<a class="reference" href="{* ldoc.repo_reference(item) *}">View source &raquo;</a>
{% end %}
{% if (ldoc.descript(item):len() == 0) then %}
<div class="notice warning">
<div class="title">Incomplete</div>
<p>Documentation for this section is incomplete and needs expanding.</p>
</div>
{% else %}
<p>{* ldoc.markup(ldoc.descript(item)) *}</p>
{% end %}
</header>
{# function arguments #}
{% if (item.params and #item.params > 0) then %}
{% local subnames = mod.kinds:type_of(item).subnames %}
{% if (subnames) then %}
<h3>{{subnames}}</h3>
{% end %}
{% for argument in ldoc.modules.iter(item.params) do %}
{% local argument, sublist = item:subparam(argument) %}
<ul>
{% 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) %}
<li>
<span class="tag parameter">{{displayName}}</span>
{% if (type ~= "") then %}
<span class="tag">{* type *}</span>
{% end %}
{% if (default and default ~= true) then %}
<span class="tag default">default: {{default}}</span>
{% elseif (default) then %}
<span class="tag default">optional</span>
{% end %}
<p>{* ldoc.markup(item.params.map[argumentName]) *}</p>
</li>
{% end %}
</ul>
{% end %}
{% end %}
{# function returns #}
{% if ((not ldoc.no_return_or_parms) and item.retgroups) then %}
{% local groups = item.retgroups %}
<h3>Returns</h3>
<ul>
{% 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) %}
<li>
{% if (type ~= "") then %}
{* type *}
{% else -- we'll assume that it will return a variable type if none is set %}
<span class="tag type">any</span>
{% end %}
<p>{* ldoc.markup(returnValue.text) *}</p>
</li>
{% end %}
{% if (i ~= #groups) then %}
<div class="or"><span>OR</span></div>
{% end %}
{% end %}
</ul>
{% end %}
{% if (item.usage) then -- function usage %}
<h3>Example Usage</h3>
{% for usage in ldoc.modules.iter(item.usage) do %}
<pre><code>{* usage *}</code></pre>
{% end %}
{% end %}
{% if (item.see) then %}
<h3>See Also</h3>
<ul>
{% for see in ldoc.modules.iter(item.see) do %}
<li><a href="{* ldoc.href(see) *}">{{see.label}}</a></li>
{% end %}
</ul>
{% end %}
</section>
{% end %}
{% end %}

69
docs/templates/sidebar.ltp vendored Normal file
View File

@@ -0,0 +1,69 @@
{%
local function isKindExpandable(kind)
return kind ~= "Manual"
end
%}
<nav>
<header>
{% if (not ldoc.root) then %}
<h1><a href="{* ldoc.url('') *}">Lua For Barotrauma Documentation</a></h1>
{% end %}
<input id="search" type="search" autocomplete="off" placeholder="Search..." />
</header>
<section>
{% for kind, mods, type in ldoc.kinds() do %}
{% if (ldoc.allowed_in_contents(type, mod)) then %}
<details class="category" open>
<summary>
<h2>{{kind}}</h2>
</summary>
<ul>
{% for currentMod in mods() do %}
{% local name = ldoc.display_name(currentMod) %}
<li>
{% if (isKindExpandable(kind)) then %}
<details {{currentMod.name == (mod or {}).name and "open" or ""}}>
<summary><a href="{* ldoc.ref_to_module(currentMod) *}">{{name}}</a></summary>
<ul>
{% else %}
<a href="{* ldoc.ref_to_module(currentMod) *}">{{name}}</a>
{% end %}
{% if (isKindExpandable(kind)) then
currentMod.items:sort(function(a, b)
return a.name < b.name
end)
end %}
{% for k, v in pairs(currentMod.items) do %}
{% if (v.kind == "functions") then %}
<li>
{* ldoc.realm_icon(v.tags.realm[1]) *}
<a href="{* ldoc.ref_to_module(currentMod) *}#{{v.name}}">
{% if (ldoc.is_kind_classmethod(currentMod.kind)) then
echo((v.name:gsub(".+:", "")))
else
echo((v.name:gsub(currentMod.name .. ".", "")))
end %}
</a>
</li>
{% end %}
{% end %}
{% if (isKindExpandable(kind)) then %}
</ul>
</details>
{% end %}
</li>
{% end %}
</ul>
</details>
{% end %}
{% end %}
</section>
</nav>