From c9534de86842d45b0bd4ee8b14c59399d92b95fc Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 1 Apr 2020 00:01:40 +0100 Subject: [PATCH] Updated Docs --- config/expcore/roles.lua | 4 +- docs/addons/Advanced-Start.html | 41 +- docs/addons/Chat-Popups.html | 41 +- docs/addons/Chat-Reply.html | 41 +- docs/addons/Compilatron.html | 41 +- docs/addons/Damage-Popups.html | 41 +- docs/addons/Death-Logger.html | 41 +- docs/addons/Discord-Alerts.html | 47 +- docs/addons/Player-Colours.html | 47 +- docs/addons/Pollution-Grading.html | 41 +- docs/addons/Scorched-Earth.html | 41 +- docs/addons/Spawn-Area.html | 41 +- docs/addons/Tree-Decon.html | 383 ++ docs/addons/greetings.html | 383 ++ docs/commands/Admin-Chat.html | 41 +- docs/commands/Bonus.html | 41 +- docs/commands/Cheat-Mode.html | 41 +- docs/commands/Clear-Inventory.html | 41 +- docs/commands/Debug.html | 41 +- docs/commands/Find.html | 41 +- docs/commands/Help.html | 41 +- docs/commands/Home.html | 41 +- docs/commands/Interface.html | 41 +- docs/commands/Jail.html | 41 +- docs/commands/Kill.html | 41 +- docs/commands/Me.html | 41 +- docs/commands/Rainbow.html | 41 +- docs/commands/Repair.html | 41 +- docs/commands/Reports.html | 41 +- docs/commands/Roles.html | 47 +- docs/commands/Spawn.html | 41 +- docs/commands/Tag.html | 41 +- docs/commands/Teleport.html | 41 +- docs/commands/Warnings.html | 41 +- docs/config.ld | 2 +- docs/configs/Advanced-Start.html | 41 +- docs/configs/Bonuses.html | 41 +- docs/configs/Chat-Reply.html | 41 +- docs/configs/Commands-Auth-Admin.html | 41 +- docs/configs/Commands-Auth-Roles.html | 41 +- .../Commands-Auth-Runtime-Disable.html | 41 +- docs/configs/Commands-Parse-Roles.html | 41 +- docs/configs/Commands-Parse.html | 41 +- docs/configs/Compilatron.html | 41 +- docs/configs/Death-Logger.html | 41 +- docs/configs/Discord-Alerts.html | 41 +- docs/configs/File-Loader.html | 41 +- docs/configs/Permission-Groups.html | 41 +- docs/configs/Player-List.html | 47 +- docs/configs/Pollution-Grading.html | 41 +- docs/configs/Popup-Messages.html | 41 +- docs/configs/Preset-Player-Colours.html | 41 +- docs/configs/Repair.html | 41 +- docs/configs/Rockets.html | 41 +- docs/configs/Roles.html | 41 +- docs/configs/Science.html | 41 +- docs/configs/Scorched-Earth.html | 41 +- docs/configs/Spawn-Area.html | 41 +- docs/configs/Tasks.html | 41 +- docs/configs/Warnings.html | 41 +- docs/configs/Warps.html | 41 +- docs/control/Jail.html | 41 +- docs/control/Production.html | 389 +- docs/control/Reports.html | 41 +- docs/control/Rockets.html | 41 +- docs/control/Tasks.html | 41 +- docs/control/Warnings.html | 41 +- docs/control/Warps.html | 69 +- docs/core/Async.html | 605 +++ docs/core/Commands.html | 952 +++- docs/core/Common-Library.html | 2600 +++++----- docs/core/Common.html | 2759 ++++++++++ docs/core/Groups.html | 1435 ++++++ docs/core/Gui.html | 4560 +++++++++++------ docs/core/Permissions-Groups.html | 279 +- docs/core/Roles.html | 470 +- docs/core/Store.html | 41 +- docs/guis/Player-List.html | 258 +- docs/guis/Readme.html | 735 +++ docs/guis/Rocket-Info.html | 215 +- docs/guis/Science-Info.html | 109 +- docs/guis/Task-List.html | 111 +- docs/guis/Warps-List.html | 109 +- docs/guis/server-ups.html | 444 ++ docs/index.html | 160 +- docs/modules/Gui.html | 4130 ++++++++++++++- docs/modules/control.html | 97 +- .../modules.addons.station-auto-name.html | 300 ++ docs/modules/overrides.debug.html | 661 +++ docs/modules/overrides.math.html | 360 ++ docs/modules/overrides.table.html | 2015 ++++++++ docs/modules/utils.event.html | 47 +- docs/modules/utils.event_core.html | 41 +- docs/modules/utils.task.html | 41 +- docs/topics/license.html | 41 +- docs/topics/readme.md.html | 43 +- expcore/async.lua | 92 +- expcore/commands.lua | 695 ++- expcore/common.lua | 501 +- expcore/gui.lua | 2 +- expcore/gui/_require.lua | 131 + expcore/gui/core_defines.lua | 2 +- expcore/gui/left_flow.lua | 4 +- expcore/gui/prototype.lua | 164 +- expcore/gui/require.lua | 8 - expcore/gui/top_flow.lua | 2 +- expcore/permission_groups.lua | 262 +- expcore/roles.lua | 661 ++- modules/addons/greetings.lua | 3 +- modules/commands/admin-chat.lua | 2 +- modules/commands/cheat-mode.lua | 2 +- modules/commands/interface.lua | 2 +- modules/commands/roles.lua | 4 +- modules/commands/teleport.lua | 6 +- modules/gui/rocket-info.lua | 2 +- 115 files changed, 23355 insertions(+), 6604 deletions(-) create mode 100644 docs/addons/Tree-Decon.html create mode 100644 docs/addons/greetings.html create mode 100644 docs/core/Async.html create mode 100644 docs/core/Common.html create mode 100644 docs/core/Groups.html create mode 100644 docs/guis/Readme.html create mode 100644 docs/guis/server-ups.html create mode 100644 docs/modules/modules.addons.station-auto-name.html create mode 100644 docs/modules/overrides.debug.html create mode 100644 docs/modules/overrides.math.html create mode 100644 docs/modules/overrides.table.html create mode 100644 expcore/gui/_require.lua delete mode 100644 expcore/gui/require.lua diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index ef3e1c51..236fa347 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -170,7 +170,7 @@ Roles.new_role('Veteran','Vet') :allow{ 'command/chat-bot', } -:set_auto_promote_condition(function(player) +:set_auto_assign_condition(function(player) if player.online_time > 10*216000 then return true end @@ -198,7 +198,7 @@ Roles.new_role('Regular','Reg') 'command/go-to-spawn', 'command/me', } -:set_auto_promote_condition(function(player) +:set_auto_assign_condition(function(player) if player.online_time > 3*216000 then return true end diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index e06593f6..1d717318 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -348,7 +347,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 7cb0c9b2..7f17c3a9 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -349,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 6c368f68..d7927bc8 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -376,7 +375,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index 135ff83a..5b569aae 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -57,10 +57,12 @@ + + @@ -68,13 +70,13 @@ @@ -97,8 +99,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -585,7 +584,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index df0b8737..48df3a68 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -349,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 4f94aece..a7b1b937 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -404,7 +403,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 12bccc87..78f0bcd6 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -247,7 +246,7 @@ utils.game - resources.color_presets + utils.color_presets expcore.common @@ -323,8 +322,8 @@
- # - resources.color_presets + # + utils.color_presets
@@ -460,7 +459,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index 0682c770..a9b88d40 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -241,7 +240,7 @@ - resources.color_presets + utils.color_presets utils.game @@ -267,8 +266,8 @@
- # - resources.color_presets + # + utils.color_presets
@@ -404,7 +403,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 8ecf95bf..d7166cc9 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -320,7 +319,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index 84ea1706..464c0bf3 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -404,7 +403,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index 9cd696ab..27174f1c 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -56,10 +56,12 @@ + + @@ -67,13 +69,13 @@ @@ -96,8 +98,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -376,7 +375,7 @@ generated by LDoc diff --git a/docs/addons/Tree-Decon.html b/docs/addons/Tree-Decon.html new file mode 100644 index 00000000..1ae7cd94 --- /dev/null +++ b/docs/addons/Tree-Decon.html @@ -0,0 +1,383 @@ + + + + + + + + Tree-Decon addon + + + + + + + +
+
+ + + + + + + +
+ + + + + + + + +

Tree-Decon addon

+

Makes trees which are marked for decon "decay" quickly to allow faster building

+

+ + + + + + + + + + + + + +

Dependencies

+ + + + + + + + + + + + + + + + +
utils.event
utils.game
utils.global
expcore.roles
+ + +
+ + +

Dependencies

+
+
+
+
+ # + utils.event +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + utils.game +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + utils.global +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + expcore.roles +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + + +
+
+
+ + + + diff --git a/docs/addons/greetings.html b/docs/addons/greetings.html new file mode 100644 index 00000000..88bcabfb --- /dev/null +++ b/docs/addons/greetings.html @@ -0,0 +1,383 @@ + + + + + + + + greetings addon + + + + + + + +
+
+ + + + + + + +
+ + + + + + + + +

greetings addon

+

Greets players on join

+

+ + + + + + + + + + + + + +

Dependencies

+ + + + + + + + + + + + + + + + +
utils.event
utils.event
config.join_messages
utils.global
+ + +
+ + +

Dependencies

+
+
+
+
+ # + utils.event +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + utils.event +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + config.join_messages +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + utils.global +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + + +
+
+
+ + + + diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 7967ea77..e2928b14 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -388,7 +387,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index f0b1fc7b..b4acd3f8 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -500,7 +499,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index 680b91e8..bd44f024 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -361,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 7026f517..8c73ddea 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -388,7 +387,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 6667e00b..dc8bd630 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -365,7 +364,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index e95e5332..fa39eb7d 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -360,7 +359,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index deb9aa2a..8d75f6db 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -404,7 +403,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index e9b13bfd..512a2ee6 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -458,7 +457,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index 89212f3b..2f43cbd6 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -416,7 +415,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index 2c670b45..f7cdeb46 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -611,7 +610,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index f6e57348..085d3e43 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -389,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 59c4534a..c8286186 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -360,7 +359,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 6c90fe3f..38c038a6 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -388,7 +387,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index 004ec4bd..0a156f7b 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -76,13 +76,13 @@ @@ -111,10 +111,12 @@ + + @@ -123,8 +125,10 @@

Guis

@@ -135,7 +139,6 @@

Configs

@@ -168,18 +172,13 @@

Modules

@@ -321,7 +320,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index 2f71921c..88e9d0d0 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -585,7 +584,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index ba0318c7..9ca693d6 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -250,7 +249,7 @@ expcore.roles - resources.color_presets + utils.color_presets @@ -334,8 +333,8 @@
- # - resources.color_presets + # + utils.color_presets
@@ -557,7 +556,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index fda9f645..479f2750 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -389,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 9cf7157a..c21383cd 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -443,7 +442,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index e9131888..b343424b 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -484,7 +483,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index ac587916..ab2e9aed 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -77,13 +77,13 @@ @@ -112,10 +112,12 @@ + + @@ -124,8 +126,10 @@

Guis

@@ -136,7 +140,6 @@

Configs

@@ -169,18 +173,13 @@

Modules

@@ -569,7 +568,7 @@ generated by LDoc diff --git a/docs/config.ld b/docs/config.ld index 01c7486c..43e5bfdc 100644 --- a/docs/config.ld +++ b/docs/config.ld @@ -2,7 +2,7 @@ file = '../' dir = '../docs' project = 'ExpGaming Scenario' title = 'ExpGaming Scenario' -description = 'Explosive Gaming\'s server scenario for 0.17' +description = 'Explosive Gaming\'s server scenario for 0.18' convert_opt = true sort = false diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index 75ce3491..bb433438 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -506,7 +505,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index cc4d5595..ed9c3bd1 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -42,7 +42,6 @@

Configs

@@ -74,13 +74,13 @@ @@ -109,10 +109,12 @@ + + @@ -121,8 +123,10 @@

Guis

@@ -160,18 +164,13 @@

Modules

@@ -237,7 +236,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index d7ae726a..f7c4bca2 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -51,7 +51,6 @@

Configs

@@ -83,13 +83,13 @@ @@ -118,10 +118,12 @@ + + @@ -130,8 +132,10 @@

Guis

@@ -169,18 +173,13 @@

Modules

@@ -485,7 +484,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 4a48d6da..9da0f411 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -294,7 +293,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index ed1c5b7f..477cb804 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -320,7 +319,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index e72d1a81..1636ab35 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -51,7 +51,6 @@

Configs

@@ -83,13 +83,13 @@ @@ -118,10 +118,12 @@ + + @@ -130,8 +132,10 @@

Guis

@@ -169,18 +173,13 @@

Modules

@@ -442,7 +441,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index f9d62d80..9d4292ca 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -354,7 +353,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index d1d21e74..234392ad 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -338,7 +337,7 @@ see ./expcore/commands.lua for more details

generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index 7dc0e1b5..dec0e529 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -354,7 +353,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index ab9a69db..67857dec 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -416,7 +415,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 40ee9ed3..5ea02120 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -42,7 +42,6 @@

Configs

@@ -74,13 +74,13 @@ @@ -109,10 +109,12 @@ + + @@ -121,8 +123,10 @@

Guis

@@ -160,18 +164,13 @@

Modules

@@ -237,7 +236,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 11aeb9af..3a9716cf 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -42,7 +42,6 @@

Configs

@@ -74,13 +74,13 @@ @@ -109,10 +109,12 @@ + + @@ -121,8 +123,10 @@

Guis

@@ -160,18 +164,13 @@

Modules

@@ -240,7 +239,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 6329eb61..3abffdaa 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -295,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 2d23727d..cfda4261 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -51,7 +51,6 @@

Configs

@@ -83,13 +83,13 @@ @@ -118,10 +118,12 @@ + + @@ -130,8 +132,10 @@

Guis

@@ -169,18 +173,13 @@

Modules

@@ -268,7 +267,7 @@ modules.control.jail - resources.color_presets + utils.color_presets expcore.common @@ -504,8 +503,8 @@
- # - resources.color_presets + # + utils.color_presets
@@ -812,7 +811,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 2c6dc312..6be165c4 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -384,7 +383,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index bf97ecf9..4f9f85b0 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -414,7 +413,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index 3fd3eca5..723391f4 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -324,7 +323,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 82dcaa12..e8582c36 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -414,7 +413,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index a318f0cd..0db5696a 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -834,7 +833,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index c324a6ac..a6816311 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -292,7 +291,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index f5dca812..332659e6 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -354,7 +353,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index f011372b..a55e5c6b 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -388,7 +387,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index fac7d663..66357213 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -744,7 +743,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 4e84ef99..f3bf9416 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -384,7 +383,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 09b6a980..77d8481e 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -355,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index 0353eba6..81f0ffec 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -50,7 +50,6 @@

Configs

@@ -82,13 +82,13 @@ @@ -117,10 +117,12 @@ + + @@ -129,8 +131,10 @@

Guis

@@ -168,18 +172,13 @@

Modules

@@ -774,7 +773,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index 4f02fcb1..f66c2789 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -66,13 +66,13 @@ @@ -87,10 +87,12 @@ + + @@ -99,8 +101,10 @@

Guis

@@ -138,7 +142,6 @@

Configs

@@ -171,18 +175,13 @@

Modules

@@ -1208,7 +1207,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index 301380da..66ab08bb 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -42,9 +42,9 @@

Sections

@@ -66,13 +66,13 @@ @@ -87,10 +87,12 @@ + + @@ -99,8 +101,10 @@

Guis

@@ -138,7 +142,6 @@

Configs

@@ -171,18 +175,13 @@

Modules

@@ -205,9 +204,9 @@

Jump to Section

@@ -275,7 +274,7 @@ - resources.color_presets + utils.color_presets util @@ -284,6 +283,22 @@ +

Formating

+ + + + + + + + + + + + +
get_color(clamp, active_value, passive_value)Returns a color value bassed on the value that was given
format_number(value)Returns three parts used to format a number
+ +

Precision

@@ -334,22 +349,6 @@
- - -

Formating

- - - - - - - - - - - - -
get_color(clamp, active_value, passive_value)Returns a color value bassed on the value that was given
format_number(value)Returns three parts used to format a number

@@ -360,8 +359,8 @@
- # - resources.color_presets + # + utils.color_presets
@@ -400,6 +399,159 @@ + + + + + + +
+ +

Formating

+
+
+
+
+ # + get_color(clamp, active_value, passive_value) +
+
+
+
+ +

Returns a color value bassed on the value that was given

+

+ + + Parameters: + +
    + + + + + +
  • + + clamp + + : + + (number) + + value which seperates the different colours + +
  • + + + + + +
  • + + active_value + + : + + (number) + + first value tested, tested against clamp + +
  • + + + + + +
  • + + passive_value + + : + + (number) + + second value tested, tested against 0 + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + contains r,g,b keys +
  • +
+ + + + + + + + + +
+
+
+
+ # + format_number(value) +
+
+
+
+ +

Returns three parts used to format a number

+

+ + + Parameters: + +
    + + + + + +
  • + + value + + : + + (number) + + the value to format + +
  • + + +
+ + + + + Returns: +
    +
  • + (string) + the sign for the number +
  • +
  • + (string) + the surfix for any unit used +
  • +
+ + + @@ -1154,159 +1306,6 @@ - - - - - - -
-
-

Formating

-
-
-
-
- # - get_color(clamp, active_value, passive_value) -
-
-
-
- -

Returns a color value bassed on the value that was given

-

- - - Parameters: - -
    - - - - - -
  • - - clamp - - : - - (number) - - value which seperates the different colours - -
  • - - - - - -
  • - - active_value - - : - - (number) - - first value tested, tested against clamp - -
  • - - - - - -
  • - - passive_value - - : - - (number) - - second value tested, tested against 0 - -
  • - - -
- - - - - Returns: -
    -
  • - (table) - contains r,g,b keys -
  • -
- - - - - - - - - -
-
-
-
- # - format_number(value) -
-
-
-
- -

Returns three parts used to format a number

-

- - - Parameters: - -
    - - - - - -
  • - - value - - : - - (number) - - the value to format - -
  • - - -
- - - - - Returns: -
    -
  • - (string) - the sign for the number -
  • -
  • - (string) - the surfix for any unit used -
  • -
- - - @@ -1329,7 +1328,7 @@ generated by LDoc
diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 349a872c..09e64549 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -66,13 +66,13 @@ @@ -87,10 +87,12 @@ + + @@ -99,8 +101,10 @@

Guis

@@ -138,7 +142,6 @@

Configs

@@ -171,18 +175,13 @@

Modules

@@ -1110,7 +1109,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 2f5efd39..d1bcf823 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -65,13 +65,13 @@ @@ -86,10 +86,12 @@ + + @@ -98,8 +100,10 @@

Guis

@@ -137,7 +141,6 @@

Configs

@@ -170,18 +174,13 @@

Modules

@@ -984,7 +983,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index 440f1c35..d8fe98bf 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -65,13 +65,13 @@ @@ -86,10 +86,12 @@ + + @@ -98,8 +100,10 @@

Guis

@@ -137,7 +141,6 @@

Configs

@@ -170,18 +174,13 @@

Modules

@@ -998,7 +997,7 @@ Tasks.update_task(task_id,'We need more iron!',game. generated by LDoc diff --git a/docs/control/Warnings.html b/docs/control/Warnings.html index 32c13b69..7465e015 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -65,13 +65,13 @@ @@ -86,10 +86,12 @@ + + @@ -98,8 +100,10 @@

Guis

@@ -137,7 +141,6 @@

Configs

@@ -170,18 +174,13 @@

Modules

@@ -1465,7 +1464,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 5a52b7df..f3a3b9f2 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -66,13 +66,13 @@ @@ -87,10 +87,12 @@ + + @@ -99,8 +101,10 @@

Guis

@@ -138,7 +142,6 @@

Configs

@@ -171,18 +175,13 @@

Modules

@@ -274,9 +273,6 @@ Warps.make_warp_tag(warp_id) config.warps - - expcore.common - @@ -463,31 +459,6 @@ Warps.make_warp_tag(warp_id) - - - - - - - -
-
-
- # - expcore.common -
-
-
-
- - - - - - - - - @@ -1563,7 +1534,7 @@ Warps.make_warp_tag(warp_id) generated by LDoc
diff --git a/docs/core/Async.html b/docs/core/Async.html new file mode 100644 index 00000000..6a6a6a2d --- /dev/null +++ b/docs/core/Async.html @@ -0,0 +1,605 @@ + + + + + + + + Async core + + + + + + + +
+
+ + + + + + + +
+ + + + + + + + +

Async core

+

Core Module - Async +- An extention of task and token to allow a single require to register and run async functions.

+

+ + + + + + +

Usage

+

+-- To use Async you must register the allowed functions when the file is loaded, often this will just be giving access to
+-- some functions within a module if you expect that at part may be blocked by in game permissions or a custom system you have made
+-- you may also want to register functions that you want to have a time delay, such as waiting 2 seconds before printing a message
+
+-- When player.admin is called (either command or gui element event) by a player who isnt admin then it will error
+-- here we register the function to promote the player so that it will run async and outside the player scope
+local promote_player =
+Async.register(function(player)
+    player.admin = true
+end)
+
+-- This will allow us to bypass the error by running one tick later outside of any player scope
+Async(promote_player,game.player)
+
+-- Here we make an sync function that we want to have a delay, note the delay is not defined here
+local print_message =
+Async.register(function(player,message)
+    player.print(message)
+end)
+
+-- We can then call the async function with a delay using the wait function
+Async.wait(60, print_message, game.player, 'One second has passed!')
+ + + + + +
+ +

Dependencies

+ + + + + + + + + + +
utils.task
utils.token
+ + +

Functions

+ + + + + + + + + + + + + + + + +
register(callback)Register a new async function, must called when the file is loaded
run(token[, ...])Runs an async function, you may supply any number of arguments as required by that function
wait(ticks, token[, ...])Runs an async function after the given number of ticks, you may supply any number of arguments as required by that function
+ + +
+ + +

Dependencies

+
+
+
+
+ # + utils.task +
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ # + utils.token +
+
+
+
+ + + + + + + + + + + + + + + +
+
+

Functions

+
+
+
+
+ # + register(callback) +
+
+
+
+ +

Register a new async function, must called when the file is loaded

+

+ + + Parameters: + +
    + + + + + +
  • + + callback + + : + + (function) + + the function that can be called as an async function + +
  • + + +
+ + + + + Returns: +
    +
  • + (string) + the uid of the async function which can be passed to Async.run and Async.wait +
  • +
+ + + + + + + + Usage: +
-- Registering a function to set the admin state of a player
+local set_admin =
+Async.register(function(player, state)
+    if player.valid then
+        player.admin = state
+    end
+end)
+
-- Registering a function to print to a player
+local print_to_player =
+Async.register(function(player, message)
+    if player.valid then
+        player.print(message)
+    end
+end)
+ + +
+
+
+
+ # + run(token[, ...]) +
+
+
+
+ +

Runs an async function, you may supply any number of arguments as required by that function

+

+ + + Parameters: + +
    + + + + + +
  • + + token + + : + + (string) + + the token of the async function you want to run + +
  • + + + + + +
  • + + ... + + : + + (any) + + the other params that you want to pass to your function + + (optional) +
  • + + +
+ + + + + + + + + + + + Usage: +
-- Make a player admin regardless of if you are admin
+Async.run(set_admin, player, true)
+ + +
+
+
+
+ # + wait(ticks, token[, ...]) +
+
+
+
+ +

Runs an async function after the given number of ticks, you may supply any number of arguments as required by that function

+

+ + + Parameters: + +
    + + + + + +
  • + + ticks + + : + + (number) + + the number of ticks that you want the function to run after + +
  • + + + + + +
  • + + token + + : + + (string) + + the token of the async function you want to run + +
  • + + + + + +
  • + + ... + + : + + (any) + + the other params that you want to pass to your function + + (optional) +
  • + + +
+ + + + + + + + + + + + Usage: +
-- Print a message to a player after 5 seconds
+Async.wait(300, print_to_player, 'Hello, World!')
+ + +
+
+ + + + + + + + + + diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 26e2e30e..512c965a 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -29,7 +29,7 @@

ExpGaming Scenario

-

Explosive Gaming's server scenario for 0.17

+

Explosive Gaming's server scenario for 0.18

@@ -42,6 +42,8 @@

Sections

@@ -89,10 +91,12 @@ + + @@ -101,8 +105,10 @@

Guis

@@ -140,7 +146,6 @@

Configs

@@ -173,18 +179,13 @@

Modules

@@ -207,6 +208,8 @@

Jump to Section

+
+

Tables

+
+
+
+
+ # + defines +
+
+
+
+ +

Values returned by the signal functions to cause the command system to react

+

+ + + Fields: + +
    + + + + + +
  • + + error + + + + + +
  • + + + + + +
  • + + unauthorized + + + + + +
  • + + + + + +
  • + + success + + + + + +
  • + + +
+ + + + + + + + + + + + + +
+
+
+
+ # + commands +
+
+
+
+ +

Custom command data will be stored here

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + authorization +
+
+
+
+ +

Custom function are stored here which control who can use what commands

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + parse_functions +
+
+
+
+ +

Used to store default functions which are common parse function such as player or number in range

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + _prototype +
+
+
+
+ +

Used to store functions which gets added to new custom commands

+

+ + + + + + + + + + + + + + +
+
+

Fields

+
+
+
+
+ # + authorization_fail_on_error +
+
+
+
+ +

Set true to have authorize fail if a callback fails to run, more secure

+

+ + + + + + + + @@ -662,10 +921,6 @@ (function) the callback you want to register as an authenticator - callback param - player: LuaPlayer - the player who is trying to use the command - callback param - command: string - the name of the command which is being used - callback param - flags: table - any flags which have been set for the command - callback param - reject: function(error_message?: string) - call to fail authorize with optional error message @@ -689,6 +944,16 @@ + Usage: +
-- Test if a command is admin only and if the player is admin
+local admin_authenticator =
+Commands.add_authenticator(function(player, command, flags, reject)
+    if flags.admin_only then
+        return player.admin or reject('This command is for admins only!')
+    else
+        return true
+    end
+end)
@@ -736,7 +1001,7 @@ @@ -746,6 +1011,9 @@ + Usage: +
-- Removing the admin authenticator, can not be done dueing runtime
+Commands.remove_authenticator(admin_authenticator)
@@ -834,6 +1102,9 @@ + Usage: +
-- Test if a player can use "repeat-name"
+local authorized, status = Commands.authorize(game.player, 'repeat-name')
@@ -850,7 +1121,7 @@
-

Gets all commands that a player is allowed to use, game commands not included

+

Gets all commands that a player is allowed to use, game commands are not included

@@ -895,6 +1166,11 @@ + Usage: +
-- Get the command you are allowed to use
+local commands = Commands.get(game.player)
+
-- Get all commands that are registered
+local commands = Commands.get()
@@ -902,13 +1178,13 @@
# - search(keyword[, allowed_player]) + search(keyword[, player])
-

Searches command names and help messages to find possible commands, game commands included

+

Searches command names and help messages to find possible commands, game commands are included

@@ -928,7 +1204,7 @@ (string) - the word which you are trying to find + the word which you are trying to find in your search @@ -938,7 +1214,7 @@
  • - allowed_player + player : @@ -969,6 +1245,11 @@ + Usage: +
    -- Get all commands which "repeat"
    +local commands = Commands.search('repeat')
    +
    -- Get all commands which "repeat" and you are allowed to use
    +local commands = Commands.search('repeat', game.player)
  • @@ -985,8 +1266,8 @@
    -

    Adds a parse function which can be called by name rather than callback (used in add_param) - nb: this is not needed as you can use the callback directly this just allows it to be called by name

    +

    Adds a parse function which can be called by name (used in add_param) +nb: this is not required as you can use the callback directly this just allows it to be called by name

    @@ -1023,10 +1304,6 @@ (function) the callback that is ran to parse the input - parse param - input: string - the input given by the user for this param - parse param - player: LuaPlayer - the player who is using the command - parse param - reject: function(error_message) - use this function to send a error to the user and fail running - parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run @@ -1050,6 +1327,18 @@ + Usage: +
    -- Adding a parse to validate ints in a given range
    +Commands.add_parse('number-range-int', function(input, player, reject, range_min, range_max)
    +    local rtn = tonumber(input) and math.floor(tonumber(input)) or nil -- converts input to number
    +    if not rtn or rtn < range_min or rtn > range_max then
    +        -- the input is either not a number or is outside the range
    +        return reject('Number entered is not in range: '..range_min..', '..range_max)
    +    else
    +        -- returns the input as a number rather than a string, thus the param is now the correct type
    +        return rtn
    +    end
    +end)
    @@ -1100,6 +1389,9 @@ + Usage: +
    -- Removing a parse
    +Commands.remove_parse('number-range-int')
    @@ -1133,7 +1425,7 @@ (string) - the name of the parse to call, must be registered and cant be a function + the name of the parse to call, must be registered parse @@ -1149,7 +1441,7 @@ (string) - string the input to pass to the parse, will always be a but might not be the original input + string the input to pass to the parse, must be a string but not necessarily the original input @@ -1165,7 +1457,7 @@ (LuaPlayer) - the player that is calling using the command + the player that is using the command @@ -1205,6 +1497,10 @@ + Usage: +
    -- Parsing a int in a given range
    +local parsed_input = Commands.parse('number-range-int', '7', player, reject, 1, 10) -- valid range 1 to 10
    +
    @@ -1221,7 +1517,7 @@
    -

    Creates a new command object to added details to, note this does not register the command to the game

    +

    Creates a new command object to added details to, note this does not register the command to the game api

    @@ -1281,6 +1577,10 @@ + Usage: +
    -- Define a new command
    +local command =
    +Commands.new_command('repeat-name', 'Will repeat you name a number of times in chat.')
    @@ -1364,10 +1664,6 @@ extra args you want to pass to the parse function; for example if the parse is general use - parse param - input: string - the input given by the user for this param - parse param - player: LuaPlayer - the player who is using the command - parse param - reject: function(error_message) - use this function to send a error to the user and fail running - parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run (optional) @@ -1392,6 +1688,14 @@ + Usage: +
    -- Adding a param which has an parse defined
    +command:add_param('repeat-count', false, 'number-range-int', 1, 5)
    +
    -- Adding a param which has a custom parse, see Commands.add_parse for details
    +command:add_param('smiley', true, function(input, player, reject)
    +    if not input then return end
    +    return input:lower() == 'true' or input:lower() == 'yes' or false
    +end)
    @@ -1405,7 +1709,7 @@
    -

    Adds default values to params only matters if the param is optional, if default value is a function it is called with param player

    +

    Add default values to params, only as an effect if the param is optional, if default value is a function it is called with acting player

    @@ -1425,8 +1729,7 @@ (table) - table a keyed by the name of the param with the value as the default value {paramName=defaultValue} - callback param - player: LuaPlayer - the player using the command, default value does not need to be a function callback + table which is keyed by the name of the param and the value is the default value @@ -1450,6 +1753,15 @@ + Usage: +
    -- Adding default values
    +command:set_defaults{
    +    smiley = false,
    +    -- not in example just used to show arguments given
    +    player_name = function(player)
    +        return player.name
    +    end
    +}
    @@ -1457,7 +1769,7 @@
    # - Commands._prototype:set_flag(name, value) + Commands._prototype:set_flag(name[, value=true])
    @@ -1483,7 +1795,7 @@ (string) - the name of the tag to be added; used to keep flags separate + the name of the tag to be added, set to true if no value is given @@ -1500,8 +1812,8 @@ (any) the tag that you want can be anything that the authenticators are expecting - nb: if value is nil then name will be assumed as the value and added at a numbered index + (default: true) @@ -1524,6 +1836,11 @@ + Usage: +
    -- Setting a custom flag
    +command:set_flag('admin_only', true)
    +
    -- When value is true it does not need to be given
    +command:set_flag('admin_only')
    @@ -1537,7 +1854,7 @@
    -

    Adds an alias or multiple that will also be registered with the same callback, eg /teleport can be /tp with both working

    +

    Adds an alias, or multiple, that will also be registered with the same callback, eg /teleport can be used as /tp

    @@ -1582,7 +1899,8 @@ Usage: -
    command:add_alias('aliasOne','aliasTwo','etc')
    +
    -- Added multiple aliases to a command
    +command:add_alias('name', 'rname')
    @@ -1597,8 +1915,8 @@

    Enables auto concatenation of any params on the end so quotes are not needed for last param - nb: this will disable max param checking as they will be concatenated onto the end of that last param - this can be useful for reasons or longs text, can only have one per command

    +nb: this will disable max param checking as they will be concatenated onto the end of that last param +this can be useful for reasons or longs text, can only have one per command

    @@ -1619,6 +1937,9 @@ + Usage: +
    -- Enable auto concat for a command
    +command:enable_auto_concat()
    @@ -1632,8 +1953,8 @@
    -

    Adds the callback to the command and registers all aliases, params and help message with the game - nb: this must be the last function ran on the command and must be done for the command to work

    +

    Adds the callback to the command and registers all aliases, params and help message with the game api +nb: this must be the last function ran on the command and must be done for the command to work

    @@ -1654,9 +1975,6 @@ (function) the callback for the command, will receive the player running command, and params added with add_param - callback param - player: LuaPlayer - the player who used the command - callback param - ... - any params which were registered with add_param in the order they where registered - callback param - raw: string - the raw input from the user, comes after every param added with add_param @@ -1673,6 +1991,16 @@ + Usage: +
    -- Registering your command to the game api
    +command:register(function(player, repeat_count, smiley, _)
    +    local msg = ') '..player.name
    +    if smiley then msg = ':'..msg end
    +
    +    for 1 = 1,repeat_count do
    +        Command.print(1..msg)
    +    end
    +end)
    @@ -1683,15 +2011,14 @@
    # - error([error_message][, play_sound]) + error([error_message=''][, play_sound=utility/wire_pickup])
    -

    Sends an error message to the player and returns a constant to return to command handler to exit execution - nb: this is for non fatal errors meaning there is no log of this event - nb: if reject is giving as a param to the callback use that instead

    +

    Sends an error message to the player and when returned will stop exicution of the command +nb: this is for non fatal errors meaning there is no log of this event, use during register callback

    @@ -1713,7 +2040,7 @@ an optional error message that can be sent to the user - (optional) + (default: '') @@ -1730,7 +2057,7 @@ the sound to play for the error - (optional) + (default: utility/wire_pickup) @@ -1754,7 +2081,8 @@ Usage: -
    return Commands.error()
    +
    -- Send an error message to the player, and stops further code running
    +return Commands.error('The player you selected is offline')
    @@ -1769,7 +2097,7 @@

    Sends an error to the player and logs the error, used with pcall within command handler please avoid direct use - nb: use error(error_message) within your callback to trigger do not trigger directly as the handler may still continue

    +nb: use error(error_message) within your callback to trigger do not trigger directly as code exictuion may still continue

    @@ -1845,6 +2173,12 @@ + Usage: +
    -- Used in the command system to log handler errors
    +local success, err = pcall(command_data.callback, player, unpack(params))
    +if Commands.internal_error(success, command_data.name, err) then
    +    return command_log(player, command_data, 'Internal Error: Command Callback Fail', raw_params, command_event.parameter, err)
    +end
    @@ -1859,7 +2193,7 @@

    Sends a value to the player, followed by a command complete message - nb: either return a value from your callback to trigger or return the return of this to prevent two messages

    +nb: returning any value from your callback will trigger this function, return this function to prevent duplicate messages

    @@ -1904,6 +2238,80 @@ + Usage: +
    -- Print a custom success message
    +return Commands.success('Your message has been printed')
    +
    -- Returning the value has the same result
    +return 'Your message has been printed'
    + + + +
    +
    +
    + # + print(value, colour) +
    +
    +
    +
    + +

    Sends a value to the player, different to success as this does not signal the end of your command

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to return to the player + +
    • + + + + + +
    • + + colour + + : + + (table) + + the colour of the message that the player sees + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Output a message to the player
    +Commands.print('Your command is in progress')
    @@ -1954,6 +2362,8 @@ + Usage: +
    Commands.run_command(event)
    @@ -1972,7 +2382,7 @@ generated by LDoc
    diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index 6b2cd701..8b86b626 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -42,7 +42,10 @@

    Sections

    @@ -50,13 +53,13 @@ @@ -85,10 +88,12 @@ + + @@ -97,8 +102,10 @@

    Guis

    @@ -136,7 +143,6 @@

    Configs

    @@ -169,18 +176,13 @@

    Modules

    @@ -203,7 +205,10 @@

    Jump to Section

    @@ -244,7 +249,7 @@ - resources.color_presets + utils.color_presets utils.game @@ -256,25 +261,77 @@ -

    Functions

    +

    Type Checking

    - + - + - + + + + + + + + + - - + + + + + + + + + + + + +
    type_check(value[, test_type=nil])Compare types faster for faster validation of paramsAsserts the argument is of type test_type
    type_check_error(value, test_type, error_message, level)type_error(value, test_type, error_message, level) Raises an error if the value is of the wrong type
    param_check(value, test_type, param_name, param_number)multi_type_check(value, test_types)Asserts the argument is one of type test_types
    multi_type_error(value, test_types, error_message, level)Raises an error if the value is of the wrong type
    validate_argument_type(value, test_type, param_name, param_number) Raises an error when the value is the incorrect type, uses a consistent error message format
    player_return(value[, colour=defines.colour.white][, player=game.player])Will return a value of any type to the player/server console, allows colour for in-game playersvalidate_argument_multi_type(value, test_types, param_name, param_number)Raises an error when the value is the incorrect type, uses a consistent error message format
    error_if_runtime()Will raise an error if called during runtime
    error_if_runetime_closure(func)Will raise an error if the function is a closure
    + + +

    Value Returns

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -285,8 +342,40 @@ - - + + + + + + + + + + + + +
    string_contains(s, contains)Tests if a string contains a given substring.
    resolve_value(value)Used to resolve a value that could also be a function returning that value
    get_actor()Returns a valid string with the name of the actor of a command.
    cast_bool(var)Converts a varible into its boolean value, nil and false return false
    ternary(c, t, f)Returns either the second or third argument based on the first argument
    comma_value(n)Returns a string for a number with comma seperators
    set_and_return(tbl, key, value)Sets a table element to value while also returning value.
    write_json(path, tbl)Calls a require that will not error if the file is not found
    ext_require(path, ...)Calls a require and returns only the keys given, file must return a tableget_file_path([offset=0])Returns a desync safe file path for the current file
    enum(tbl)Converts a table to an enum
    auto_complete(options, input[, use_key=false][, rtn_key=false])Returns the closest match to the input
    + + +

    Formating

    + + + + + + + + + + + + + + + + + + @@ -296,6 +385,14 @@ string will return a string not a locale string when a denomination is false it will overflow into the next one + +
    format_chat_colour(message, color)Returns a message with valid chat tags to change its colour
    format_chat_colour_localized(message, color)Returns a message with valid chat tags to change its colour, using localization
    format_chat_player_name(player[, raw_string=false])Returns the players name in the players color
    player_return(value[, colour=defines.colour.white][, player=game.player])Will return a value of any type to the player/server console, allows colour for in-game players
    format_time(ticks, options)
    + + +

    Factorio

    + + + @@ -313,66 +410,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    move_items(items[, surface=navies][, position={0][, radius=32][, chest_type=iron-chest]) Moves items to the position and stores them in the closest entity of the type givenclear_flying_text(surface) Clears all flying text entities on a surface
    string_contains(s, contains)Tests if a string contains a given substring.
    extract_keys(tbl, ...)Extracts certain keys from a table
    enum(tbl)Converts a table to an enum
    auto_complete(options, input[, use_key=false][, rtn_key=false])Returns the closest match to the input
    table_values(tbl[, sorted][, as_string])Returns a copy of all of the values in the table.
    table_keys(tbl[, sorted][, as_string])Returns a copy of all of the keys in the table.
    table_alphanumsort(tbl)Returns the list is a sorted way that would be expected by people (this is by key)
    table_keysort(tbl)Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)
    format_chat_colour(message, color)Returns a message with valid chat tags to change its colour
    format_chat_colour_localized(message, color)Returns a message with valid chat tags to change its colour, using localization
    format_chat_player_name(player[, raw_string=false])Returns the players name in the players color
    get_file_path([offset=0])Returns a desync safe file path for the current file
    array_insert(tbl[, start_index], values)Much faster method for inserting items into an array
    table_insert(tbl[, start_index], tbl2)Much faster method for inserting keys into a table
    resolve_value(value)Used to resolve a value that could also be a function returning that value
    @@ -385,8 +422,8 @@
    - # - resources.color_presets + # + utils.color_presets
    @@ -458,7 +495,7 @@
    -

    Functions

    +

    Type Checking

    @@ -470,7 +507,7 @@
    -

    Compare types faster for faster validation of params

    +

    Asserts the argument is of type test_type

    @@ -540,8 +577,8 @@
    - # - type_check_error(value, test_type, error_message, level) + # + type_error(value, test_type, error_message, level)
    @@ -640,15 +677,193 @@ Usage: -
    type_check_error('foo','number','Value must be a number') -- will raise error "Value must be a number"
    +
    type_error('foo','number','Value must be a number') -- will raise error "Value must be a number"
    - # - param_check(value, test_type, param_name, param_number) + # + multi_type_check(value, test_types) +
    +
    +
    +
    + +

    Asserts the argument is one of type test_types

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + + the variable to check + +
    • + + + + + +
    • + + test_types + + : + + + the type as a table of strings + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if value is one of test_types +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + multi_type_error(value, test_types, error_message, level) +
    +
    +
    +
    + +

    Raises an error if the value is of the wrong type

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to test the type of + +
    • + + + + + +
    • + + test_types + + : + + (table) + + the type as a table of strings + +
    • + + + + + +
    • + + error_message + + : + + (string) + + the error message that is returned + +
    • + + + + + +
    • + + level + + : + + (number) + + the level to call the error on (level = 1 means the caller) + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if no error was called +
    • +
    + + + + + + + + Usage: +
    multi_type_error('foo',{'string','table'},'Value must be a string or table') -- will raise error "Value must be a string or table"
    + + +
    +
    +
    +
    + # + validate_argument_type(value, test_type, param_name, param_number)
    @@ -747,21 +962,21 @@ Usage: -
    param_check('foo','number','repeat_count',2) -- will raise error "Invalid param #02 given to <anon>; repeat_count is not of type number"
    +
    validate_argument_type('foo','number','repeat_count',2) -- will raise error "Bad argument #02 to "<anon>"; "repeat_count" is of type string expected number"
    - # - player_return(value[, colour=defines.colour.white][, player=game.player]) + # + validate_argument_multi_type(value, test_types, param_name, param_number)
    -

    Will return a value of any type to the player/server console, allows colour for in-game players

    +

    Raises an error when the value is the incorrect type, uses a consistent error message format

    @@ -779,8 +994,9 @@ : + (any) - any value of any type that will be returned to the player or console + the value that you want to test the type of @@ -790,15 +1006,14 @@
  • - colour + test_types : - (defines.color or string) + (string) - the colour of the text for the player, ignored when printing to console + the types that the value should be - (default: defines.colour.white)
  • @@ -807,15 +1022,116 @@
  • - player + param_name : - (LuaPlayer) + (string) + + the name of the param + +
  • + + + + + +
  • + + param_number + + : + + (number) + + the number param it is + +
  • + + + + + + + + Returns: +
      +
    • + (boolean) + true if no error was raised +
    • +
    + + + + + + + + Usage: +
    validate_argument_type('foo',{'string','table'},'repeat_count',2) -- will raise error "Bad argument #02 to "<anon>"; "repeat_count" is of type string expected string or table"
    + + +
    +
    +
    +
    + # + error_if_runtime() +
    +
    +
    +
    + +

    Will raise an error if called during runtime

    +

    + + + + + + + + + + + + + Usage: +
    error_if_runtime()
    + + +
    +
    +
    +
    + # + error_if_runetime_closure(func) +
    +
    +
    +
    + +

    Will raise an error if the function is a closure

    +

    + + + Parameters: + +
      + + + + + +
    • + + func + + + - the player that return will go to, if no game.player then returns to server - (default: game.player)
    • @@ -832,9 +1148,445 @@ Usage: -
      player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
      -
      player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
      -
      player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
      +
      error_if_runetime_closure(func)
      + + +
    +
    +

    Value Returns

    +
    +
    +
    +
    + # + string_contains(s, contains) +
    +
    +
    +
    + +

    Tests if a string contains a given substring.

    +

    + + + Parameters: + +
      + + + + + +
    • + + s + + : + + (string) + + the string to check for the substring + +
    • + + + + + +
    • + + contains + + : + + (string) + + the substring to test for + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the substring was found in the string +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + resolve_value(value) +
    +
    +
    +
    + +

    Used to resolve a value that could also be a function returning that value

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value which you want to test is not nil and if it is a function then call the function + +
    • + + +
    + + + + + Returns: +
      +
    • + (any) + the value given or returned by value if it is a function +
    • +
    + + + + + + + + Usage: +
    -- Default value handling
    +-- if default value is not a function then it is returned
    +-- if it is a function then it is called with the first argument being self
    +local value = Common.resolve_value(self.defaut_value,self)
    + + +
    +
    +
    +
    + # + get_actor() +
    +
    +
    +
    + +

    Returns a valid string with the name of the actor of a command.

    +

    + + + + + + Returns: +
      +
    • + (string) + the name of the current actor +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + cast_bool(var) +
    +
    +
    +
    + +

    Converts a varible into its boolean value, nil and false return false

    +

    + + + Parameters: + +
      + + + + + +
    • + + var + + + + + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the boolean form of the varible +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + ternary(c, t, f) +
    +
    +
    +
    + +

    Returns either the second or third argument based on the first argument

    +

    + + + Parameters: + +
      + + + + + +
    • + + c + + + + + +
    • + + + + + +
    • + + t + + + + + +
    • + + + + + +
    • + + f + + + + + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + comma_value(n) +
    +
    +
    +
    + +

    Returns a string for a number with comma seperators

    +

    + + + Parameters: + +
      + + + + + +
    • + + n + + : + + (credit http) + + //richard.warburton.it + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + set_and_return(tbl, key, value) +
    +
    +
    +
    + +

    Sets a table element to value while also returning value.

    +

    + + + Parameters: + +
      + + + + + +
    • + + tbl + + : + + + table to change the element of + +
    • + + + + + +
    • + + key + + : + + + string + +
    • + + + + + +
    • + + value + + : + + + nil|boolean|number|string|table to set the element to + +
    • + + +
    + + + + + Returns: +
      +
    • + value +
    • +
    + + + + + + +
    @@ -965,14 +1717,14 @@
    - # - ext_require(path, ...) + # + get_file_path([offset=0])
    -

    Calls a require and returns only the keys given, file must return a table

    +

    Returns a desync safe file path for the current file

    @@ -986,29 +1738,71 @@
  • - path + offset : - (string) + (number) - the path that you want to require + the offset in the stack to get, 0 is current file + (default: 0)
  • + + + + + + Returns: +
      +
    • + (string) + the file path +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + enum(tbl) +
    +
    +
    +
    + +

    Converts a table to an enum

    +

    + + + Parameters: + +
      + +
    • - ... + tbl : - (string) + (table) - the name of the keys that you want returned + table the that will be converted
    • @@ -1021,18 +1815,433 @@ Returns:
      • - the keys in the order given + (table) + the new table that acts like an enum
      + + + + + + +
    +
    +
    +
    + # + auto_complete(options, input[, use_key=false][, rtn_key=false]) +
    +
    +
    +
    + +

    Returns the closest match to the input

    +

    + + + Parameters: + +
      + + + + + +
    • + + options + + : + + (table) + + table a of options for the auto complete + +
    • + + + + + +
    • + + input + + : + + (string) + + string the input that will be completed + +
    • + + + + + +
    • + + use_key + + : + + (boolean) + + when true the keys of options will be used as the options + + (default: false) +
    • + + + + + +
    • + + rtn_key + + : + + (boolean) + + when true the the key will be returned rather than the value + + (default: false) +
    • + + +
    + + + + + Returns: +
      +
    • + the list item found that matches the input +
    • +
    + + + + + + + + + +
    +
    +

    Formating

    +
    +
    +
    +
    + # + format_chat_colour(message, color) +
    +
    +
    +
    + +

    Returns a message with valid chat tags to change its colour

    +

    + + + Parameters: + +
      + + + + + +
    • + + message + + : + + (string) + + the message that will be in the output + +
    • + + + + + +
    • + + color + + : + + (table) + + a color which contains r,g,b as its keys + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the message with the color tags included +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + format_chat_colour_localized(message, color) +
    +
    +
    +
    + +

    Returns a message with valid chat tags to change its colour, using localization

    +

    + + + Parameters: + +
      + + + + + +
    • + + message + + : + + (string or table) + + the message that will be in the output + +
    • + + + + + +
    • + + color + + : + + (table) + + a color which contains r,g,b as its keys + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the message with the color tags included +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + format_chat_player_name(player[, raw_string=false]) +
    +
    +
    +
    + +

    Returns the players name in the players color

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to use the name and color of + +
    • + + + + + +
    • + + raw_string + + : + + (boolean) + + when true a is returned rather than a localized string + + (default: false) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the players name with tags for the players color +
    • +
    + + + + + + + + + +
    +
    +
    +
    + # + player_return(value[, colour=defines.colour.white][, player=game.player]) +
    +
    +
    +
    + +

    Will return a value of any type to the player/server console, allows colour for in-game players

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + + any value of any type that will be returned to the player or console + +
    • + + + + + +
    • + + colour + + : + + (defines.color or string) + + the colour of the text for the player, ignored when printing to console + + (default: defines.colour.white) +
    • + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that return will go to, if no game.player then returns to server + + (default: game.player) +
    • + + +
    + + + + + + + Usage: -
    local extract, param_check = ext_require('expcore.common','extract','param_check') --- @dep expcore.common
    +
    player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
    +
    player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
    +
    player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player
    @@ -1113,6 +2322,9 @@ +
    +

    Factorio

    +
    @@ -1592,1144 +2804,6 @@ - -
    -
    -
    - # - string_contains(s, contains) -
    -
    -
    -
    - -

    Tests if a string contains a given substring.

    -

    - - - Parameters: - -
      - - - - - -
    • - - s - - : - - (string) - - the string to check for the substring - -
    • - - - - - -
    • - - contains - - : - - (string) - - the substring to test for - -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - true if the substring was found in the string -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - extract_keys(tbl, ...) -
    -
    -
    -
    - -

    Extracts certain keys from a table

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - table the which contains the keys - -
    • - - - - - -
    • - - ... - - : - - (string) - - the names of the keys you want extracted - -
    • - - -
    - - - - - Returns: -
      -
    • - the keys in the order given -
    • -
    - - - - - - - - Usage: -
    local key_three, key_one = extract({key_one='foo',key_two='bar',key_three=true},'key_three','key_one')
    - - -
    -
    -
    -
    - # - enum(tbl) -
    -
    -
    -
    - -

    Converts a table to an enum

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - table the that will be converted - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new table that acts like an enum -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - auto_complete(options, input[, use_key=false][, rtn_key=false]) -
    -
    -
    -
    - -

    Returns the closest match to the input

    -

    - - - Parameters: - -
      - - - - - -
    • - - options - - : - - (table) - - table a of options for the auto complete - -
    • - - - - - -
    • - - input - - : - - (string) - - string the input that will be completed - -
    • - - - - - -
    • - - use_key - - : - - (boolean) - - when true the keys of options will be used as the options - - (default: false) -
    • - - - - - -
    • - - rtn_key - - : - - (boolean) - - when true the the key will be returned rather than the value - - (default: false) -
    • - - -
    - - - - - Returns: -
      -
    • - the list item found that matches the input -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - table_values(tbl[, sorted][, as_string]) -
    -
    -
    -
    - -

    Returns a copy of all of the values in the table.

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - the to copy the keys from, or an empty table if tbl is nil - -
    • - - - - - -
    • - - sorted - - : - - (boolean) - - whether to sort the keys (slower) or keep the random order from pairs() - - (optional) -
    • - - - - - -
    • - - as_string - - : - - (boolean) - - whether to try and parse the values as strings, or leave them as their existing type - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (array) - an array with a copy of all the values in the table -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - table_keys(tbl[, sorted][, as_string]) -
    -
    -
    -
    - -

    Returns a copy of all of the keys in the table.

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - the to copy the keys from, or an empty table if tbl is nil - -
    • - - - - - -
    • - - sorted - - : - - (boolean) - - whether to sort the keys (slower) or keep the random order from pairs() - - (optional) -
    • - - - - - -
    • - - as_string - - : - - (boolean) - - whether to try and parse the keys as strings, or leave them as their existing type - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (array) - an array with a copy of all the keys in the table -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - table_alphanumsort(tbl) -
    -
    -
    -
    - -

    Returns the list is a sorted way that would be expected by people (this is by key)

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - the table to be sorted - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the sorted table -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - table_keysort(tbl) -
    -
    -
    -
    - -

    Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - the table to be sorted - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the sorted table -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - format_chat_colour(message, color) -
    -
    -
    -
    - -

    Returns a message with valid chat tags to change its colour

    -

    - - - Parameters: - -
      - - - - - -
    • - - message - - : - - (string) - - the message that will be in the output - -
    • - - - - - -
    • - - color - - : - - (table) - - a color which contains r,g,b as its keys - -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the message with the color tags included -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - format_chat_colour_localized(message, color) -
    -
    -
    -
    - -

    Returns a message with valid chat tags to change its colour, using localization

    -

    - - - Parameters: - -
      - - - - - -
    • - - message - - : - - (string or table) - - the message that will be in the output - -
    • - - - - - -
    • - - color - - : - - (table) - - a color which contains r,g,b as its keys - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the message with the color tags included -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - format_chat_player_name(player[, raw_string=false]) -
    -
    -
    -
    - -

    Returns the players name in the players color

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player to use the name and color of - -
    • - - - - - -
    • - - raw_string - - : - - (boolean) - - when true a is returned rather than a localized string - - (default: false) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the players name with tags for the players color -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - get_file_path([offset=0]) -
    -
    -
    -
    - -

    Returns a desync safe file path for the current file

    -

    - - - Parameters: - -
      - - - - - -
    • - - offset - - : - - (number) - - the offset in the stack to get, 0 is current file - - (default: 0) -
    • - - -
    - - - - - Returns: -
      -
    • - (string) - the file path -
    • -
    - - - - - - - - - -
    -
    -
    -
    - # - array_insert(tbl[, start_index], values) -
    -
    -
    -
    - -

    Much faster method for inserting items into an array

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - the table that will have the values added to it - -
    • - - - - - -
    • - - start_index - - : - - (number) - - the index at which values will be added, nil means end of the array - - (optional) -
    • - - - - - -
    • - - values - - : - - (table) - - the new values that will be added to the table - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the table that was passed as the first argument -
    • -
    - - - - - - - - Usage: -
    -- Adding 1000 values into the middle of the array
    -local tbl = {}
    -local values = {}
    -for i = 1,1000 do tbl[i] = i values[i] = i end
    -Common.array_insert(tbl,500,values) -- around 0.4ms
    - - -
    -
    -
    -
    - # - table_insert(tbl[, start_index], tbl2) -
    -
    -
    -
    - -

    Much faster method for inserting keys into a table

    -

    - - - Parameters: - -
      - - - - - -
    • - - tbl - - : - - (table) - - the table that will have keys added to it - -
    • - - - - - -
    • - - start_index - - : - - (number) - - the index at which values will be added, nil means end of the array, numbered indexs only - - (optional) -
    • - - - - - -
    • - - tbl2 - - : - - (table) - - the table that may contain both string and numbered keys - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the table passed as the first argument -
    • -
    - - - - - - - - Usage: -
    -- Merging two tables
    -local tbl = {}
    -local tbl2 = {}
    -for i = 1,100 do tbl[i] = i tbl['_'..i] = i tbl2[i] = i tbl2['__'..i] = i end
    -Common.table_insert(tbl,50,tbl2)
    - - -
    -
    -
    -
    - # - resolve_value(value) -
    -
    -
    -
    - -

    Used to resolve a value that could also be a function returning that value

    -

    - - - Parameters: - -
      - - - - - -
    • - - value - - : - - (any) - - the value which you want to test is not nil and if it is a function then call the function - -
    • - - -
    - - - - - Returns: -
      -
    • - (any) - the value given or returned by value if it is a function -
    • -
    - - - - - - - - Usage: -
    -- Default value handling
    --- if default value is not a function then it is returned
    --- if it is a function then it is called with the first argument being self
    -local value = Common.resolve_value(self.defaut_value,self)
    - -
    @@ -2746,7 +2820,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Common.html b/docs/core/Common.html new file mode 100644 index 00000000..2adc2dbf --- /dev/null +++ b/docs/core/Common.html @@ -0,0 +1,2759 @@ + + + + + + + + Common core + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    Common core

    +

    Core Module - Common +- Adds some commonly used functions used in many modules

    +

    + + + + + + + + + + + + + +

    Dependencies

    + + + + + + + + + + + + + +
    utils.color_presets
    utils.game
    util
    + + +

    Type Checking

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    type_check(value[, test_type=nil])Asserts the argument is of type test_type
    type_error(value, test_type, error_message, level)Raises an error if the value is of the wrong type
    multi_type_check(value, test_types)Asserts the argument is one of type test_types
    multi_type_error(value, test_types, error_message, level)Raises an error if the value is of the wrong type
    validate_argument_type(value, test_type, param_number[, param_name])Raises an error when the value is the incorrect type, uses a consistent error message format
    validate_argument_multi_type(value, test_types, param_number[, param_name])Raises an error when the value is the incorrect type, uses a consistent error message format
    error_if_runtime()Will raise an error if called during runtime
    error_if_runetime_closure(func)Will raise an error if the function is a closure
    + + +

    Value Returns

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    string_contains(s, contains)Tests if a string contains a given substring.
    resolve_value(value)Used to resolve a value that could also be a function returning that value
    cast_bool(var)Converts a varible into its boolean value, nil and false return false
    ternary(c, t, f)Returns either the second or third argument based on the first argument
    comma_value(n)Returns a string for a number with comma seperators
    set_and_return(tbl, key, value)Sets a table element to value while also returning value.
    write_json(path, tbl)Writes a table object to a file in json format
    opt_require(path)Calls a require that will not error if the file is not found
    get_file_path([offset=0])Returns a desync safe file path for the current file
    enum(tbl)Converts a table to an enum
    auto_complete(options, input[, use_key=false][, rtn_key=false])Returns the closest match to the input
    + + +

    Formating

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    get_actor(player_name)Returns a valid string with the name of the actor of a command.
    format_chat_colour(message, color)Returns a message with valid chat tags to change its colour
    format_chat_colour_localized(message, color)Returns a message with valid chat tags to change its colour, using localization
    format_chat_player_name(player[, raw_string=false])Returns the players name in the players color
    player_return(value[, colour=defines.colour.white][, player=game.player])Will return a value of any type to the player/server console, allows colour for in-game players
    format_time(ticks, options)Formats tick into a clean format, denominations from highest to lowest +-- time will use : separates +-- when a denomination is false it will overflow into the next one
    + + +

    Factorio

    + + + + + + + + + + + + + + + + +
    move_items(items[, surface=navies][, position={0][, radius=32][, chest_type=iron-chest])Moves items to the position and stores them in the closest entity of the type given
    print_grid_value(value, surface, position[, scale=1][, offset=0][, immutable=false])Prints a colored value on a location, color is based on the value.
    clear_flying_text(surface)Clears all flying text entities on a surface
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + utils.color_presets +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + util +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Type Checking

    +
    +
    +
    +
    + # + type_check(value[, test_type=nil]) +
    +
    +
    +
    + +

    Asserts the argument is of type test_type

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value to be tested + +
    • + + + + + +
    • + + test_type + + : + + (string) + + the type to test for if not given then it tests for nil + + (default: nil) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + is v of type test_type +
    • +
    + + + + + + + + Usage: +
    -- Check for a string value
    +local is_string = type_check(value, 'string')
    +
    -- Check for a nil value
    +local is_nil = type_check(value)
    + + +
    +
    +
    +
    + # + type_error(value, test_type, error_message, level) +
    +
    +
    +
    + +

    Raises an error if the value is of the wrong type

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to test the type of + +
    • + + + + + +
    • + + test_type + + : + + (string) + + the type that the value should be + +
    • + + + + + +
    • + + error_message + + : + + (string) + + the error message that is returned + +
    • + + + + + +
    • + + level + + : + + (number) + + the level to call the error on (level = 1 is the caller) + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if no error was called +
    • +
    + + + + + + + + Usage: +
    -- Raise error if value is not a number
    +type_error(value, 'number', 'Value must be a number')
    + + +
    +
    +
    +
    + # + multi_type_check(value, test_types) +
    +
    +
    +
    + +

    Asserts the argument is one of type test_types

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + + the variable to check + +
    • + + + + + +
    • + + test_types + + : + + + the type as a table of strings + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if value is one of test_types +
    • +
    + + + + + + + + Usage: +
    -- Check for a string or table
    +local is_string_or_table = multi_type_check(value, {'string','table'})
    + + +
    +
    +
    +
    + # + multi_type_error(value, test_types, error_message, level) +
    +
    +
    +
    + +

    Raises an error if the value is of the wrong type

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to test the type of + +
    • + + + + + +
    • + + test_types + + : + + (table) + + the type as a table of strings + +
    • + + + + + +
    • + + error_message + + : + + (string) + + the error message that is returned + +
    • + + + + + +
    • + + level + + : + + (number) + + the level to call the error on (level = 1 is the caller) + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if no error was called +
    • +
    + + + + + + + + Usage: +
    -- Raise error if value is not a string or table
    +multi_type_error('foo', {'string','table'}, 'Value must be a string or table')
    + + +
    +
    +
    +
    + # + validate_argument_type(value, test_type, param_number[, param_name]) +
    +
    +
    +
    + +

    Raises an error when the value is the incorrect type, uses a consistent error message format

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to test the type of + +
    • + + + + + +
    • + + test_type + + : + + (string) + + the type that the value should be + +
    • + + + + + +
    • + + param_number + + : + + (number) + + the number param it is + +
    • + + + + + +
    • + + param_name + + : + + (string) + + the name of the param + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if no error was raised +
    • +
    + + + + + + + + Usage: +
    -- Output: "Bad argument #2 to "<anon>"; argument is of type string expected number"
    +validate_argument_type(value, 'number', 2)
    +
    -- Output: "Bad argument #2 to "<anon>"; "repeat_count" is of type string expected number"
    +validate_argument_type(value, 'number', 2, 'repeat_count')
    + + +
    +
    +
    +
    + # + validate_argument_multi_type(value, test_types, param_number[, param_name]) +
    +
    +
    +
    + +

    Raises an error when the value is the incorrect type, uses a consistent error message format

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value that you want to test the type of + +
    • + + + + + +
    • + + test_types + + : + + (string) + + the types that the value should be + +
    • + + + + + +
    • + + param_number + + : + + (number) + + the number param it is + +
    • + + + + + +
    • + + param_name + + : + + (string) + + the name of the param + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if no error was raised +
    • +
    + + + + + + + + Usage: +
    -- Output: "Bad argument #2 to "<anon>"; argument is of type number expected string or table"
    +validate_argument_type(value, {'string','table'}, 2)
    +
    -- Output: "Bad argument #2 to "<anon>"; "player" is of type number expected string or table"
    +validate_argument_type(value, {'string','table'}, 2, 'player')
    + + +
    +
    +
    +
    + # + error_if_runtime() +
    +
    +
    +
    + +

    Will raise an error if called during runtime

    +

    + + + + + + + + + + + + + Usage: +
    error_if_runtime()
    + + +
    +
    +
    +
    + # + error_if_runetime_closure(func) +
    +
    +
    +
    + +

    Will raise an error if the function is a closure

    +

    + + + Parameters: + +
      + + + + + +
    • + + func + + + + + +
    • + + +
    + + + + + + + + + + + + Usage: +
    error_if_runetime_closure(func)
    + + +
    +
    +

    Value Returns

    +
    +
    +
    +
    + # + string_contains(s, contains) +
    +
    +
    +
    + +

    Tests if a string contains a given substring.

    +

    + + + Parameters: + +
      + + + + + +
    • + + s + + : + + (string) + + the string to check for the substring + +
    • + + + + + +
    • + + contains + + : + + (string) + + the substring to test for + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the substring was found in the string +
    • +
    + + + + + + + + Usage: +
    -- Test if a string contains a sub string
    +local found = string_contains(str, 'foo')
    + + +
    +
    +
    +
    + # + resolve_value(value) +
    +
    +
    +
    + +

    Used to resolve a value that could also be a function returning that value

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + the value which you want to test is not nil and if it is a function then call the function + +
    • + + +
    + + + + + Returns: +
      +
    • + (any) + the value given or returned by value if it is a function +
    • +
    + + + + + + + + Usage: +
    -- Default value handling
    +-- if default value is not a function then it is returned
    +-- if default value is a function then it is called with the first argument being self
    +local value = Common.resolve_value(self.defaut_value, self)
    + + +
    +
    +
    +
    + # + cast_bool(var) +
    +
    +
    +
    + +

    Converts a varible into its boolean value, nil and false return false

    +

    + + + Parameters: + +
      + + + + + +
    • + + var + + + + + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the boolean form of the varible +
    • +
    + + + + + + + + Usage: +
    local bool = cast_bool(var)
    + + +
    +
    +
    +
    + # + ternary(c, t, f) +
    +
    +
    +
    + +

    Returns either the second or third argument based on the first argument

    +

    + + + Parameters: + +
      + + + + + +
    • + + c + + + + + +
    • + + + + + +
    • + + t + + + + + +
    • + + + + + +
    • + + f + + + + + +
    • + + +
    + + + + + + + + + + + + Usage: +
    ternary(input_string == 'test', 'Input is test', 'Input is not test')
    + + +
    +
    +
    +
    + # + comma_value(n) +
    +
    +
    +
    + +

    Returns a string for a number with comma seperators

    +

    + + + Parameters: + +
      + + + + + +
    • + + n + + : + + (credit http) + + //richard.warburton.it + +
    • + + +
    + + + + + + + + + + + + Usage: +
    comma_value(input_number)
    + + +
    +
    +
    +
    + # + set_and_return(tbl, key, value) +
    +
    +
    +
    + +

    Sets a table element to value while also returning value.

    +

    + + + Parameters: + +
      + + + + + +
    • + + tbl + + : + + (table) + + to change the element of + +
    • + + + + + +
    • + + key + + : + + (string) + + the key to set the value of + +
    • + + + + + +
    • + + value + + : + + (any) + + the value to set the key as + +
    • + + +
    + + + + + Returns: +
      +
    • + (any) + the value that was set +
    • +
    + + + + + + + + Usage: +
    -- Set and return value
    +local value = set_and_return(players, player.name, player.online_time)
    + + +
    +
    +
    +
    + # + write_json(path, tbl) +
    +
    +
    +
    + +

    Writes a table object to a file in json format

    +

    + + + Parameters: + +
      + + + + + +
    • + + path + + : + + (string) + + the path of the file to write include / to use dir + +
    • + + + + + +
    • + + tbl + + : + + (table) + + the table that will be converted to a json string and wrote to file + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Write a lua table as a json to script-outpt/dump
    +write_json('dump', tbl)
    + + +
    +
    +
    +
    + # + opt_require(path) +
    +
    +
    +
    + +

    Calls a require that will not error if the file is not found

    +

    + + + Parameters: + +
      + + + + + +
    • + + path + + : + + (string) + + the path that you want to require + +
    • + + +
    + + + + + Returns: +
      +
    • + the returns from that file or nil, error if not loaded +
    • +
    + + + + + + + + Usage: +
    local file = opt_require('file.not.present') -- will not cause any error
    +
    -- Require a file without causing errors, for when a file might not exist
    +local Module = opt_require 'expcore.common'
    + + +
    +
    +
    +
    + # + get_file_path([offset=0]) +
    +
    +
    +
    + +

    Returns a desync safe file path for the current file

    +

    + + + Parameters: + +
      + + + + + +
    • + + offset + + : + + (number) + + the offset in the stack to get, 0 is current file + + (default: 0) +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the file path +
    • +
    + + + + + + + + Usage: +
    -- Get the current file path
    +local file_path = get_file_path()
    + + +
    +
    +
    +
    + # + enum(tbl) +
    +
    +
    +
    + +

    Converts a table to an enum

    +

    + + + Parameters: + +
      + + + + + +
    • + + tbl + + : + + (table) + + table the that will be converted + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new table that acts like an enum +
    • +
    + + + + + + + + Usage: +
    -- Make an enum
    +local colors = enum{
    +    'red',
    +    'green',
    +    'blue'
    +}
    + + +
    +
    +
    +
    + # + auto_complete(options, input[, use_key=false][, rtn_key=false]) +
    +
    +
    +
    + +

    Returns the closest match to the input

    +

    + + + Parameters: + +
      + + + + + +
    • + + options + + : + + (table) + + table a of options for the auto complete + +
    • + + + + + +
    • + + input + + : + + (string) + + string the input that will be completed + +
    • + + + + + +
    • + + use_key + + : + + (boolean) + + when true the keys of options will be used as the options + + (default: false) +
    • + + + + + +
    • + + rtn_key + + : + + (boolean) + + when true the the key will be returned rather than the value + + (default: false) +
    • + + +
    + + + + + Returns: +
      +
    • + the list item found that matches the input +
    • +
    + + + + + + + + Usage: +
    -- Get the element that includes "foo"
    +local value = auto_complete(tbl, "foo")
    +
    -- Get the element with a key that includes "foo"
    +local value = auto_complete(tbl, "foo", true)
    +
    -- Get the key with that includes "foo"
    +local key = auto_complete(tbl, "foo", true, true)
    + + +
    +
    +

    Formating

    +
    +
    +
    +
    + # + get_actor(player_name) +
    +
    +
    +
    + +

    Returns a valid string with the name of the actor of a command.

    +

    + + + Parameters: + +
      + + + + + +
    • + + player_name + + : + + (string) + + the name of the player to use rather than server, used only if game.player is nil + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the name of the current actor +
    • +
    + + + + + + + + Usage: +
    -- Get the current actor
    +local player_name = get_actor()
    + + +
    +
    +
    +
    + # + format_chat_colour(message, color) +
    +
    +
    +
    + +

    Returns a message with valid chat tags to change its colour

    +

    + + + Parameters: + +
      + + + + + +
    • + + message + + : + + (string) + + the message that will be in the output + +
    • + + + + + +
    • + + color + + : + + (table) + + a color which contains r,g,b as its keys + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the message with the color tags included +
    • +
    + + + + + + + + Usage: +
    -- Use factorio tags to color a chat message
    +local message = format_chat_colour('Hello, World!', { r=355, g=100, b=100 })
    + + +
    +
    +
    +
    + # + format_chat_colour_localized(message, color) +
    +
    +
    +
    + +

    Returns a message with valid chat tags to change its colour, using localization

    +

    + + + Parameters: + +
      + + + + + +
    • + + message + + : + + (string or table) + + the message that will be in the output + +
    • + + + + + +
    • + + color + + : + + (table) + + a color which contains r,g,b as its keys + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the message with the color tags included +
    • +
    + + + + + + + + Usage: +
    -- Use factorio tags and locale strings to color a chat message
    +local message = format_chat_colour_localized('Hello, World!', { r=355, g=100, b=100 })
    + + +
    +
    +
    +
    + # + format_chat_player_name(player[, raw_string=false]) +
    +
    +
    +
    + +

    Returns the players name in the players color

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to use the name and color of + +
    • + + + + + +
    • + + raw_string + + : + + (boolean) + + when true a string is returned rather than a localized string + + (default: false) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the players name with tags for the players color +
    • +
    + + + + + + + + Usage: +
    -- Format a players name using the players color as a string
    +local message = format_chat_player_name(game.player, true)
    + + +
    +
    +
    +
    + # + player_return(value[, colour=defines.colour.white][, player=game.player]) +
    +
    +
    +
    + +

    Will return a value of any type to the player/server console, allows colour for in-game players

    +

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (any) + + a value of any type that will be returned to the player or console + +
    • + + + + + +
    • + + colour + + : + + (defines.color or string) + + the colour of the text for the player, ignored when printing to console + + (default: defines.colour.white) +
    • + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that return will go to, if no game.player then returns to server + + (default: game.player) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Return a value to the current actor, rcon included
    +player_return('Hello, World!')
    +
    -- Return a value to the current actor, with color
    +player_return('Hello, World!', 'green')
    +
    -- Return to a player other than the current
    +player_return('Hello, World!', nil, player)
    + + +
    +
    +
    +
    + # + format_time(ticks, options) +
    +
    +
    +
    + +

    Formats tick into a clean format, denominations from highest to lowest +-- time will use : separates +-- when a denomination is false it will overflow into the next one

    +

    + + + Parameters: + +
      + + + + + +
    • + + ticks + + : + + (number) + + the number of ticks that represents a time + +
    • + + + + + +
    • + + options + + : + + (table) + + table a of options to use for the format + +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + a locale string that can be used +
    • +
    + + + + + + + + Usage: +
    -- Output: "0h 5m"
    +local time = format_time(18000, { hours=true, minutes=true, string=true })
    +
    -- Output: "0 hours and 5 minutes"
    +local time = format_time(18000, { hours=true, minutes=true, string=true, long=true })
    +
    -- Output: "00:05:00"
    +local time = format_time(18000, { hours=true, minutes=true, seconds=true, string=true })
    +
    -- Output: "--:--:--"
    +local time = format_time(18000, { hours=true, minutes=true, seconds=true, string=true, null=true })
    + + +
    +
    +

    Factorio

    +
    +
    +
    +
    + # + move_items(items[, surface=navies][, position={0][, radius=32][, chest_type=iron-chest]) +
    +
    +
    +
    + +

    Moves items to the position and stores them in the closest entity of the type given

    +

    + + + Parameters: + +
      + + + + + +
    • + + items + + : + + (table) + + items which are to be added to the chests, ['name']=count + +
    • + + + + + +
    • + + surface + + : + + (LuaSurface) + + the surface that the items will be moved to + + (default: navies) +
    • + + + + + +
    • + + position + + : + + (table) + + the position that the items will be moved to {x=100,y=100} + + (default: {0) +
    • + + + + + +
    • + + radius + + : + + (number) + + the radius in which the items are allowed to be placed + + (default: 32) +
    • + + + + + +
    • + + chest_type + + : + + (string) + + the chest type that the items should be moved into + + (default: iron-chest) +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaEntity) + the last chest that had items inserted into it +
    • +
    + + + + + + + + Usage: +
    -- Copy all the items in a players inventory and place them in chests at {0,0}
    +move_items(game.player.get_main_inventory().get_contents())
    + + +
    +
    +
    +
    + # + print_grid_value(value, surface, position[, scale=1][, offset=0][, immutable=false]) +
    +
    +
    +
    + +

    Prints a colored value on a location, color is based on the value.

    +

    +nb: src is below but the gradent has been edited +https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31

    + + + Parameters: + +
      + + + + + +
    • + + value + + : + + (number) + + the value to show must be between -1 and 1, scale can be used to achive this + +
    • + + + + + +
    • + + surface + + : + + (LuaSurface) + + the surface to palce the value on + +
    • + + + + + +
    • + + position + + : + + (table) + + {x, y} the possition to palce the value at + +
    • + + + + + +
    • + + scale + + : + + (number) + + how much to scale the colours by + + (default: 1) +
    • + + + + + +
    • + + offset + + : + + (number) + + the offset in the +x +y direction + + (default: 0) +
    • + + + + + +
    • + + immutable + + : + + (boolean) + + if immutable, only set, never do a surface lookup, values never change + + (default: false) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Place a 0 at {0,0}
    +print_grid_value(0, game.player.surface, { x=0, y=0 })
    + + +
    +
    +
    +
    + # + clear_flying_text(surface) +
    +
    +
    +
    + +

    Clears all flying text entities on a surface

    +

    + + + Parameters: + +
      + + + + + +
    • + + surface + + : + + (LuaSurface) + + the surface to clear + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Remove all flying text on the surface
    +clear_flying_text(game.player.surface)
    + + +
    +
    + + + +
    +
    +
    + + + + diff --git a/docs/core/Groups.html b/docs/core/Groups.html new file mode 100644 index 00000000..fcf6fcc9 --- /dev/null +++ b/docs/core/Groups.html @@ -0,0 +1,1435 @@ + + + + + + + + Groups core + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    Groups core

    +

    Core Module - Permission Groups +- Permission group making for factorio so you never have to make one by hand again

    +

    + + + + + + +

    Usage

    +
    --- Example Group (Allow All)
    +-- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups
    +Permission_Groups.new_group('Admin') -- this defines a new group called "Admin"
    +:allow_all() -- this makes the default to allow any input action unless set other wise
    +:disallow{ -- here we disallow the input action we don't want them to use
    +    'add_permission_group',
    +    'delete_permission_group',
    +    'import_permissions_string',
    +    'map_editor_action',
    +    'toggle_map_editor'
    +}
    +
    --- Example Group (Disallow All)
    +-- here we will create a group that cant do anything but talk in chat
    +Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted"
    +:disallow_all() -- this makes the default to disallow any input action unless set other wise
    +:allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action
    +
    + + + + + + + +

    Dependencies

    + + + + + + + + + + + + + +
    utils.game
    utils.event
    expcore.async
    + + +

    Getters

    + + + + + + + + + + + + + + + + +
    new_group(name)Defines a new permission group that can have it actions set in the config
    get_group_by_name(name)Returns the group with the given name, case sensitive
    get_group_from_player(player)Returns the group that a player is in
    + + +

    Setters

    + + + + + + + + + + + + +
    reload_permissions()Reloads/creates all permission groups and sets them to they configured state
    set_player_group(player, group)Sets a player's group to the one given, a player can only have one group at a time
    + + +

    Actions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Permissions_Groups._prototype:set_action(action, state)Sets the allow state of an action for this group, used internally but is safe to use else where
    Permissions_Groups._prototype:allow(actions)Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime
    Permissions_Groups._prototype:disallow(actions)Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime
    Permissions_Groups._prototype:allow_all()Sets the default state for any actions not given to be allowed, useful with :disallow
    Permissions_Groups._prototype:disallow_all()Sets the default state for any action not given to be disallowed, useful with :allow
    Permissions_Groups._prototype:is_allowed(action)Returns if an input action is allowed for this group
    + + +

    Players

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Permissions_Groups._prototype:create()Creates or updates the permission group with the configured actions, used internally
    Permissions_Groups._prototype:get_raw()Returns the LuaPermissionGroup that was created with this group object, used internally
    Permissions_Groups._prototype:add_player(player)Adds a player to this group
    Permissions_Groups._prototype:remove_player(player)Removes a player from this group
    Permissions_Groups._prototype:get_players([online])Returns all player that are in this group with the option to filter to online/offline only
    Permissions_Groups._prototype:print(message)Prints a message to every player in this group
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.async +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Getters

    +
    +
    +
    +
    + # + new_group(name) +
    +
    +
    +
    + +

    Defines a new permission group that can have it actions set in the config

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the new group + +
    • + + +
    + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype) + the new group made with function to allow and disallow actions +
    • +
    + + + + + + + + Usage: +
    -- Defining a new permission group
    +Groups.new_group('Admin')
    + + +
    +
    +
    +
    + # + get_group_by_name(name) +
    +
    +
    +
    + +

    Returns the group with the given name, case sensitive

    +

    + + + Parameters: + +
      + + + + + +
    • + + name + + : + + (string) + + the name of the group to get + +
    • + + +
    + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype or nil) + the group with that name or nil if non found +
    • +
    + + + + + + + + Usage: +
    -- Getting a permision group
    +local admin_group = Groups.get_group_by_name('Admin')
    + + +
    +
    +
    +
    + # + get_group_from_player(player) +
    +
    +
    +
    + +

    Returns the group that a player is in

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to get the group of can be name index etc + +
    • + + +
    + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype or nil) + the group with that player or nil if non found +
    • +
    + + + + + + + + Usage: +
    -- Get your permission group
    +local group = Groups.get_group_from_player(game.player)
    + + +
    +
    +

    Setters

    +
    +
    +
    +
    + # + reload_permissions() +
    +
    +
    +
    + +

    Reloads/creates all permission groups and sets them to they configured state

    +

    + + + + + + + + + + + + + Usage: +
    -- Reload the permission groups, used internally
    +Groups.reload_permissions()
    + + +
    +
    +
    +
    + # + set_player_group(player, group) +
    +
    +
    +
    + +

    Sets a player's group to the one given, a player can only have one group at a time

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to effect can be name index etc + +
    • + + + + + +
    • + + group + + : + + (string) + + the name of the group to give to the player + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the player was added successfully, false other wise +
    • +
    + + + + + + + + Usage: +
    -- Set your permission group
    +Groups.set_player_group(game.player, 'Admin')
    + + +
    +
    +

    Actions

    +
    +
    +
    +
    + # + Permissions_Groups._prototype:set_action(action, state) +
    +
    +
    +
    + +

    Sets the allow state of an action for this group, used internally but is safe to use else where

    +

    + + + Parameters: + +
      + + + + + +
    • + + action + + : + + (string or defines.input_action) + + the action that you want to set the state of + +
    • + + + + + +
    • + + state + + : + + (boolean) + + the state that you want to set it to, true = allow, false = disallow + +
    • + + +
    + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype) + returns self so function can be chained +
    • +
    + + + + + + + + Usage: +
    -- Set an action to be disalowed
    +group:set_action('toggle_map_editor', false)
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:allow(actions) +
    +
    +
    +
    + +

    Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime

    +

    + + + Parameters: + +
      + + + + + +
    • + + actions + + : + + (string or Array) + + the action or actions that you want to allow for this group + +
    • + + +
    + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype) + returns self so function can be chained +
    • +
    + + + + + + + + Usage: +
    -- Allow some actions
    +group:allow{
    +    'write_to_console'
    +}
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:disallow(actions) +
    +
    +
    +
    + +

    Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime

    +

    + + + Parameters: + +
      + + + + + +
    • + + actions + + : + + (string or Array) + + the action or actions that you want to disallow for this group + +
    • + + +
    + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype) + returns self so function can be chained +
    • +
    + + + + + + + + Usage: +
    -- Disalow some actions
    +group:disallow{
    +    'add_permission_group',
    +    'delete_permission_group',
    +    'import_permissions_string',
    +    'map_editor_action',
    +    'toggle_map_editor'
    +}
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:allow_all() +
    +
    +
    +
    + +

    Sets the default state for any actions not given to be allowed, useful with :disallow

    +

    + + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype) + returns self so function can be chained +
    • +
    + + + + + + + + Usage: +
    -- Allow all actions unless given by disallow
    +group:allow_all()
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:disallow_all() +
    +
    +
    +
    + +

    Sets the default state for any action not given to be disallowed, useful with :allow

    +

    + + + + + + Returns: +
      +
    • + (Permissions_Groups._prototype) + returns self so function can be chained +
    • +
    + + + + + + + + Usage: +
    -- Disallow all actions unless given by allow
    +group:disallow_all()
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:is_allowed(action) +
    +
    +
    +
    + +

    Returns if an input action is allowed for this group

    +

    + + + Parameters: + + + + + + + Returns: +
      +
    • + (boolean) + true if the group is allowed the action, false other wise +
    • +
    + + + + + + + + Usage: +
    -- Test if a group is allowed an action
    +local allowed = group:is_allowed('write_to_console')
    + + +
    +
    +

    Players

    +
    +
    +
    +
    + # + Permissions_Groups._prototype:create() +
    +
    +
    +
    + +

    Creates or updates the permission group with the configured actions, used internally

    +

    + + + + + + Returns: + + + + + + + + + Usage: +
    -- Create the permission group so players can be added, used internally
    +group:create()
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:get_raw() +
    +
    +
    +
    + +

    Returns the LuaPermissionGroup that was created with this group object, used internally

    +

    + + + + + + Returns: + + + + + + + + + Usage: +
    -- Get the factorio api permision group, used internally
    +local permission_group = group:get_raw()
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:add_player(player) +
    +
    +
    +
    + +

    Adds a player to this group

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + LuaPlayer the player you want to add to this group can be name or index etc + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the player was added successfully, false other wise +
    • +
    + + + + + + + + Usage: +
    -- Add a player to this permission group
    +group:add_player(game.player)
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:remove_player(player) +
    +
    +
    +
    + +

    Removes a player from this group

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + LuaPlayer the player you want to remove from this group can be name or index etc + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the player was removed successfully, false other wise +
    • +
    + + + + + + + + Usage: +
    -- Remove a player from this permission group
    +group:remove_player(game.player)
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:get_players([online]) +
    +
    +
    +
    + +

    Returns all player that are in this group with the option to filter to online/offline only

    +

    + + + Parameters: + +
      + + + + + +
    • + + online + + : + + (boolean) + + if nil returns all players, if true online players only, if false returns online players only + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + a table of players that are in this group; filtered if online param is given +
    • +
    + + + + + + + + Usage: +
    -- Get all players in this group
    +local online_players = group:get_players()
    +
    -- Get all online players in this group
    +local online_players = group:get_players(true)
    + + +
    +
    +
    +
    + # + Permissions_Groups._prototype:print(message) +
    +
    +
    +
    + +

    Prints a message to every player in this group

    +

    + + + Parameters: + +
      + + + + + +
    • + + message + + : + + (string) + + the message that you want to send to the players + +
    • + + +
    + + + + + Returns: +
      +
    • + (number) + the number of players that received the message +
    • +
    + + + + + + + + Usage: +
    -- Print a message to all players in thie group
    +group:print('Hello, World!')
    + + +
    +
    + + + +
    +
    +
    + + + + diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 72fc7784..e9480d3c 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -44,11 +44,13 @@ + + + + - - @@ -56,13 +58,13 @@ @@ -91,10 +93,12 @@ + + @@ -103,8 +107,10 @@

    Guis

    @@ -142,7 +148,6 @@

    Configs

    @@ -175,18 +181,13 @@

    Modules

    @@ -211,11 +212,13 @@ + + + + - - @@ -236,7 +239,7 @@

    Gui core

    Core Module - Gui -- Used to define new gui elements and gui event handlers

    +- Used to simplify gui creation using factory functions called element defines

    @@ -245,65 +248,114 @@

    Usage

    -
    -- Defining a button that prints the player's name
    +    
    -- To draw your element you only need to call the factory function
    +-- You are able to pass any other arguments that are used in your custom functions but the first is always the parent element
    +local example_button_element = example_button(parent_element)
    +
    -- Making a factory function for a button with the caption "Example Button"
    +-- This method has all the same features as LuaGuiElement.add
     local example_button =
     Gui.element{
         type = 'button',
         caption = 'Example Button'
    -}
    -:on_click(function(player,element,event)
    -    player.print(player.name)
    -end)
    -
    -- Defining a button with a custom style
    -local example_button =
    -Gui.element{
    -    type = 'button',
    -    caption = 'Example Button'
    -}
    -:style{
    -    height = 25,
    -    width = 100
    -}
    -:on_click(function(player,element,event)
    -    player.print(player.name)
    -end)
    -
    -- Defining a button using a custom function
    +}
    +
    -- Making a factory function for a button which is contained within a flow
    +-- This method is for when you still want to register event handlers but cant use the table method
     local example_flow_with_button =
    -Gui.element(function(event_trigger,parent)
    -    -- Add the flow the button is in
    +Gui.element(function(event_trigger,parent,...)
    +    -- ... shows that all other arguments from the factory call are passed to this function
    +    -- Here we are adding a flow which we will then later add a button to
         local flow =
    -    parent.add{
    -        name = 'example_flow',
    +    parent.add{ -- paraent is the element which is passed to the factory function
    +        name = 'example_flow',
             type = 'flow'
         }
     
    -    -- Get the players name
    -    local player = game.players[parent.player_index]
    -    local player_name = player.name
    -
    -    -- Add the button
    +    -- Now we add the button to the flow that we created earlier
         local element =
         flow.add{
    -        name = event_trigger,
    -        type = 'button',
    -        caption = 'Example Button: '..player_name
    +        name = event_trigger, -- event_trigger should be the name of any elements you want to trigger your event handlers
    +        type = 'button',
    +        caption = 'Example Button'
         }
     
    -    -- Set the style of the button
    -    local style = element.style
    -    style.height = 25
    -    style.width = 100]
    -    style.font_color = player.color
    -
    -    -- Return the element
    +    -- You must return a new element, this is so styles can be applied and returned to the caller
    +    -- You may return any of your elements that you added, consider the context in which it will be used for which should be returned
         return element
    -end)
    -:on_click(function(player,element,event)
    -    player.print(player.name)
     end)
    -
    -- Drawing an element
    -local exmple_button_element = example_button(parent)
    -local example_flow_with_button = example_flow_with_button(parent)
    +
    -- Styles can be added to any element define, simplest way mimics LuaGuiElement.style[key] = value
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button',
    +    style = 'forward_button' -- factorio styles can be applied here
    +}
    +:style{
    +    height = 25, -- same as element.style.height = 25
    +    width = 100 -- same as element.style.width = 25
    +}
    +
    -- Styles can also have a custom function when the style is dynamic and depends on other factors
    +-- Use this method if your style is dynamic and depends on other factors
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button',
    +    style = 'forward_button' -- factorio styles can be applied here
    +}
    +:style(function(style,element,...)
    +    -- style is the current style object for the elemenent
    +    -- element is the element that is being changed
    +    -- ... shows that all other arguments from the factory call are passed to this function
    +    local player = game.players[element.player_index]
    +    style.height = 25
    +    style.width = 100
    +    style.font_color = player.color
    +end)
    +
    -- You are able to register event handlers to your elements, these can be factorio events or custom ones
    +-- All events are checked to be valid before raising any handlers, this means element.valid = true and player.valid = true
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button'
    +}
    +:on_click(function(player,element,event)
    +    -- player is the player who interacted with the element to cause the event
    +    -- element is a refrence to the element which caused the event
    +    -- event is a raw refrence to the event data if player and element are not enough
    +    player.print('Clicked: '..element.name)
    +end)
    +
    -- Example from core_defines, Gui.core_defines.hide_left_flow, called like: hide_left_flow(parent_element)
    +--- Button which hides the elements in the left flow, shows inside the left flow when frames are visible
    +-- @element hide_left_flow
    +local hide_left_flow =
    +Gui.element{
    +    type = 'sprite-button',
    +    sprite = 'utility/close_black',
    +    style = 'tool_button',
    +    tooltip = {'expcore-gui.left-button-tooltip'}
    +}
    +:style{
    +    padding = -3,
    +    width = 18,
    +    height = 20
    +}
    +:on_click(function(player,_,_)
    +    Gui.hide_left_flow(player)
    +end)
    +
    -- Eample from defines, Gui.alignment, called like: Gui.alignment(parent, name, horizontal_align, vertical_align)
    +-- Notice how _ are used to blank arguments that are not needed in that context and how they line up with above
    +Gui.alignment =
    +Gui.element(function(_,parent,name,_,_)
    +    return parent.add{
    +        name = name or 'alignment',
    +        type = 'flow',
    +    }
    +end)
    +:style(function(style,_,_,horizontal_align,vertical_align)
    +    style.padding = {1,2}
    +    style.vertical_align = vertical_align or 'center'
    +    style.horizontal_align = horizontal_align or 'right'
    +    style.vertically_stretchable  = style.vertical_align ~= 'center'
    +    style.horizontally_stretchable = style.horizontal_align ~= 'center'
    +end)
    @@ -330,24 +382,28 @@ Gui.element(function(event_trigger,parent) - top_elements - Contains the uids of the elements that will show on the top flow and the auth function - - - left_elements - Contains the uids of the elements that will show on the left flow and the open on join function + events + String indexed table used to avoid conflict with custom event names, similar to how defines.events works defines - Table of all the elements which have been registed with the draw function and event handlers + Uid indexed array that stores all the factory functions that were defined, no new values will be added during runtime + + + core_defines + An string indexed table of all the defines which are used by the core of the gui system, used for internal refrence file_paths - An index used for debuging to find the file where different elements where registered + Used to store the file names where elements were defined, this can be useful to find the uid of an element, mostly for debuging + + + debug_info + Used to store extra infomation about elements as they get defined such as the params used and event handlers registered to them _prototype_element - The element prototype which is returned from Gui.element + The prototype used to store the functions of an element define _mt_element @@ -363,7 +419,139 @@ Gui.element(function(event_trigger,parent) uid - The current highest uid that is being used, will not increase during runtime + The current highest uid that is being used by a define, will not increase during runtime + + + + + +

    Core Defines

    + + + + + + + + + + + + + + + + +
    hide_top_flowButton which toggles the top flow elements, version which shows inside the top flow when top flow is visible
    show_top_flowButton which toggles the top flow elements, version which shows inside the left flow when top flow is hidden
    hide_left_flowButton which hides the elements in the left flow, shows inside the left flow when frames are visible
    + + +

    Defines

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    alignmentDraw a flow used to align its child elements, default is right align
    scroll_tableDraw a scroll pane that has a table inside of it
    headerUsed to add a frame with the header style, has the option for a right alignment flow for buttons
    footerUsed to add a frame with the footer style, has the option for a right alignment flow for buttons
    containerUsed for left frames to give them a nice boarder
    barUsed to make a solid white bar in a gui
    centered_labelUsed to make a label which is centered and of a certian size
    title_labelUsed to make a title which has two bars on either side
    + + +

    Helper Functions

    + + + + + + + + + + + + + + + + + + + + + + + + +
    get_player_from_element(element)Get the player that owns a gui element
    toggle_enabled_state(element[, state])Will toggle the enabled state of an element or set it to the one given
    toggle_visible_state(element[, state])Will toggle the visible state of an element or set it to the one given
    destroy_if_valid(element)Destory a gui element without causing any errors, often because the element was already removed
    sprite_style(size[, padding=-2][, style])Returns a table to be used as the style for a sprite buttons, produces a sqaure button
    + + +

    Left Flow

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    left_elementsContains the uids of the elements that will shown on the left flow and their join functions
    get_left_flow(player)Gets the flow refered to as the left flow, each player has one left flow
    Gui._prototype_element:add_to_left_flow([open_on_join])Sets an element define to be drawn to the left flow when a player joins, includes optional check
    left_toolbar_button(sprite, tooltip, element_define[, authenticator])Creates a button on the top flow which will toggle the given element define, the define must exist in the left flow
    draw_left_flow(player)Draw all the left elements onto the left flow, internal use only with on join
    update_left_flow(player)Update the visible state of the hide button, can be used to check if any frames are visible
    hide_left_flow(player)Hides all left elements for a player
    get_left_element(player, element_define)Get the element define that is in the left flow, use in events without an element refrence
    toggle_left_element(player, element_define[, state])Toggles the visible state of a left element for a given player, can be used to set the visible state
    @@ -375,19 +563,19 @@ Gui.element(function(event_trigger,parent) element(element_define) - Base function used to define new elements, can be used with a table or with a function + Used to define new elements for your gui, can be used like LuaGuiElement.add or a custom function Gui._prototype_element:style(style_define) - Extension of Gui.element when using the table method, values applied after the element is drawn + Used to extent your element define with a style factory, this style will be applied to your element when created, can also be a custom function - Gui._prototype_element:add_to_top_flow([authenticator]) - Adds an element to be drawn to the top flow when a player joins + Gui._prototype_element:on_custom_event(event_name, handler) + Set the handler which will be called for a custom event, only one handler can be used per event per element - Gui._prototype_element:add_to_left_flow([open_on_join]) - Adds an element to be drawn to the left flow when a player joins + Gui._prototype_element:raise_custom_event(event) + Raise the handler which is attached to an event; external use should be limited to custom events @@ -398,11 +586,11 @@ Gui.element(function(event_trigger,parent) - Gui._prototype_element.on_opened + Gui._prototype_element.on_open Called when the player opens a GUI. - Gui._prototype_element.on_closed + Gui._prototype_element.on_close Called when the player closes the GUI they have open. @@ -438,7 +626,7 @@ Gui.element(function(event_trigger,parent) Called when LuaGuiElement switch state is changed (related to switches). - Gui._prototype_element.on_text_change + Gui._prototype_element.on_text_changed Called when LuaGuiElement text is changed by the player. @@ -454,84 +642,44 @@ Gui.element(function(event_trigger,parent) - toggle_top_flow - Button which toggles the top flow elements + top_elements + Contains the uids of the elements that will shown on the top flow and their auth functions top_flow_button_style The style that should be used for buttons on the top flow + top_flow_button_visible_style + The style that should be used for buttons on the top flow when their flow is visible + + get_top_flow(player) - Gets the flow which contains the elements for the top flow + Gets the flow refered to as the top flow, each player has one top flow + + + Gui._prototype_element:add_to_top_flow([authenticator]) + Sets an element define to be drawn to the top flow when a player joins, includes optional authenticator update_top_flow(player) - Updates the visible states of all the elements on a players top flow + Updates the visible state of all the elements on the players top flow, uses authenticator toggle_top_flow(player[, state]) - Toggles the visible states of all the elements on a players top flow - - - - - -

    Left Flow

    - - - - - - + - - + + - - + + - - - - -
    hide_left_flowButton which hides the elements in the left flowToggles the visible state of all the elements on a players top flow, effects all elements
    get_left_flow(player)Gets the flow which contains the elements for the left flowget_top_element(player, element_define)Get the element define that is in the top flow, use in events without an element refrence
    hide_left_flow(player)Hides all left elements for a playertoolbar_button(sprite, tooltip[, authenticator])Creates a button on the top flow with consistent styling
    toggle_left_element(player, element_define[, state])Toggles the visible state of all a left element for a player
    - - -

    Helper Functions

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
    get_player_from_element(element)Get the player that owns a gui element
    toggle_enabled_state(element[, state])Will toggle the enabled state of an element or set it to the one given
    toggle_visible_state(element[, state])Will toggle the visible state of an element or set it to the one given
    destroy_if_valid(element)Destory a gui element without causing any errors, likly if the element may have already been removed
    alignment(parent[, horizontal_align='right'][, vertical_align='center'][, name='alignment'])Draw a flow that has custom element alignments, default is right align
    scroll_table(parent, height, column_count[, name='scroll'])Draw a scroll pane that has a table inside of it
    header(parent, caption[, tooltip][, add_alignment=false][, name='header'])Used to add a header to a frame, this has the option for a custom right alignment flow for buttonstoolbar_button_style(button, state)Styles a top flow button depending on the state given
    @@ -598,41 +746,14 @@ Gui.element(function(event_trigger,parent)
    - # - top_elements + # + events
    -

    Contains the uids of the elements that will show on the top flow and the auth function

    -

    - - - - - - - - - - - - - - -
    -
    -
    -
    - # - left_elements -
    -
    -
    -
    - -

    Contains the uids of the elements that will show on the left flow and the open on join function

    +

    String indexed table used to avoid conflict with custom event names, similar to how defines.events works

    @@ -659,7 +780,34 @@ Gui.element(function(event_trigger,parent)
    -

    Table of all the elements which have been registed with the draw function and event handlers

    +

    Uid indexed array that stores all the factory functions that were defined, no new values will be added during runtime

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + core_defines +
    +
    +
    +
    + +

    An string indexed table of all the defines which are used by the core of the gui system, used for internal refrence

    @@ -686,7 +834,34 @@ Gui.element(function(event_trigger,parent)
    -

    An index used for debuging to find the file where different elements where registered

    +

    Used to store the file names where elements were defined, this can be useful to find the uid of an element, mostly for debuging

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + debug_info +
    +
    +
    +
    + +

    Used to store extra infomation about elements as they get defined such as the params used and event handlers registered to them

    @@ -713,7 +888,7 @@ Gui.element(function(event_trigger,parent)
    -

    The element prototype which is returned from Gui.element

    +

    The prototype used to store the functions of an element define

    @@ -791,30 +966,10 @@ Gui.element(function(event_trigger,parent)
    -

    The current highest uid that is being used, will not increase during runtime

    +

    The current highest uid that is being used by a define, will not increase during runtime

    - -
      - - - - - -
    • - - uid - - - - - -
    • - - -
    - @@ -829,908 +984,19 @@ Gui.element(function(event_trigger,parent)
    -

    Element Define

    +

    Core Defines

    - # - element(element_define) + # + hide_top_flow
    -

    Base function used to define new elements, can be used with a table or with a function

    -

    - - - Parameters: - -
      - - - - - -
    • - - element_define - - : - - (table or function) - - used to define how the element is draw, using a table is the simplist way of doing this - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new element define that is used to register events to this element -
    • -
    - - - - - - - - Usage: -
    -- Defining an element with a table
    -local example_button =
    -Gui.element{
    -    type = 'button',
    -    caption = 'Example Button'
    -}
    -
    -- Defining an element with a function
    -local example_flow_with_button =
    -Gui.element(function(event_trigger,parent,...)
    -    -- Add the flow the button is in
    -    local flow =
    -    parent.add{
    -        name = 'example_flow',
    -        type = 'flow'
    -    }
    -
    -    -- Add the button
    -    local element =
    -    flow.add{
    -        name = event_trigger,
    -        type = 'button',
    -        caption = 'Example Button'
    -    }
    -
    -    -- Set the style of the button
    -    local style = element.style
    -    style.height = 25
    -    style.width = 100
    -
    -    -- Return the element
    -    return element
    -end)
    - - -
    -
    -
    -
    - # - Gui._prototype_element:style(style_define) -
    -
    -
    -
    - -

    Extension of Gui.element when using the table method, values applied after the element is drawn

    -

    - - - Parameters: - -
      - - - - - -
    • - - style_define - - : - - (table or function) - - used to define how the style is applied, using a table is the simplist way of doing this - -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new element define that is used to register events to this element -
    • -
    - - - - - - - - Usage: -
    -- Setting the height and width of the example button
    -local example_button =
    -Gui.element{
    -    type = 'button',
    -    caption = 'Example Button'
    -}
    -:style{
    -    height = 25,
    -    width = 100
    -}
    -
    -- Using a function to set the style
    -local example_button =
    -Gui.element{
    -    type = 'button',
    -    caption = 'Example Button'
    -}
    -:style(function(style,element,...)
    -    local player = game.players[element.player_index]
    -    style.height = 25
    -    style.width = 100
    -    style.font_color = player.color
    -end)
    - - -
    -
    -
    -
    - # - Gui._prototype_element:add_to_top_flow([authenticator]) -
    -
    -
    -
    - -

    Adds an element to be drawn to the top flow when a player joins

    -

    - - - Parameters: - -
      - - - - - -
    • - - authenticator - - : - - (function) - - called during toggle or update to decide if the element should be visible - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new element define that is used to register events to this element -
    • -
    - - - - - - - - Usage: -
    -- Adding the example button
    -example_button:add_to_top_flow(function(player)
    -    -- example button will only show when game time is less than 1 minute
    -    return player.online_time < 3600
    -end)
    - - -
    -
    -
    -
    - # - Gui._prototype_element:add_to_left_flow([open_on_join]) -
    -
    -
    -
    - -

    Adds an element to be drawn to the left flow when a player joins

    -

    - - - Parameters: - -
      - - - - - -
    • - - open_on_join - - : - - (boolean or function) - - called during first darw to decide if the element is visible - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (table) - the new element define that is used to register events to this element -
    • -
    - - - - - - - - Usage: -
    -- Adding the example button
    -example_flow_with_button:add_to_left_flow(true)
    - - -
    -
    -

    Element Events

    -
    -
    -
    -
    - # - Gui._prototype_element.on_opened -
    -
    -
    -
    - -

    Called when the player opens a GUI.

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_closed -
    -
    -
    -
    - -

    Called when the player closes the GUI they have open.

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_click -
    -
    -
    -
    - -

    Called when LuaGuiElement is clicked.

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_confirmed -
    -
    -
    -
    - -

    Called when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield.

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_checked_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_elem_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement element value is changed (related to choose element buttons).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_location_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement element location is changed (related to frames in player.gui.screen).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_tab_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement selected tab is changed (related to tabbed-panes).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_selection_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement selection state is changed (related to drop-downs and listboxes).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_switch_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement switch state is changed (related to switches).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_text_change -
    -
    -
    -
    - -

    Called when LuaGuiElement text is changed by the player.

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -
    -
    - # - Gui._prototype_element.on_value_changed -
    -
    -
    -
    - -

    Called when LuaGuiElement slider value is changed (related to the slider element).

    -

    - - - -
      - - - - - -
    • - - handler - - : - - (function) - - the event handler which will be called - -
    • - - -
    - - - - - - - - - - - - - -
    -
    -

    Top Flow

    -
    -
    -
    -
    - # - toggle_top_flow -
    -
    -
    -
    - -

    Button which toggles the top flow elements

    +

    Button which toggles the top flow elements, version which shows inside the top flow when top flow is visible

    @@ -1750,14 +1016,14 @@ Gui.element{
    - # - top_flow_button_style + # + show_top_flow
    -

    The style that should be used for buttons on the top flow

    +

    Button which toggles the top flow elements, version which shows inside the left flow when top flow is hidden

    @@ -1777,201 +1043,6 @@ Gui.element{
    - # - get_top_flow(player) -
    -
    -
    -
    - -

    Gets the flow which contains the elements for the top flow

    -

    (player)

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that you want to get the flow for - -
    • - - -
    - - - - - Returns: - - - - - - - - - Usage: -
    -- Geting your top element flow
    -local top_flow = Gui.get_top_flow(game.player)
    - - -
    -
    -
    -
    - # - update_top_flow(player) -
    -
    -
    -
    - -

    Updates the visible states of all the elements on a players top flow

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that you want to update the flow for - -
    • - - -
    - - - - - - - - - - - - Usage: -
    -- Update your flow
    -Gui.update_top_flow(game.player)
    - - -
    -
    -
    -
    - # - toggle_top_flow(player[, state]) -
    -
    -
    -
    - -

    Toggles the visible states of all the elements on a players top flow

    -

    - - - Parameters: - -
      - - - - - -
    • - - player - - : - - (LuaPlayer) - - the player that you want to toggle the flow for - -
    • - - - - - -
    • - - state - - : - - (boolean) - - if given then the state will be set to this state - - (optional) -
    • - - -
    - - - - - Returns: -
      -
    • - (boolean) - the new visible state of the top flow -
    • -
    - - - - - - - - Usage: -
    -- Toggle your flow
    -Gui.toggle_top_flow(game.player)
    -
    -- Open your top flow
    -Gui.toggle_top_flow(game.player,true)
    - - -
    -
    -

    Left Flow

    -
    -
    -
    -
    # hide_left_flow
    @@ -1979,7 +1050,7 @@ Gui.element{
    -

    Button which hides the elements in the left flow

    +

    Button which hides the elements in the left flow, shows inside the left flow when frames are visible

    @@ -1996,21 +1067,24 @@ Gui.element{
    +
    +

    Defines

    +
    - # - get_left_flow(player) + # + alignment
    -

    Gets the flow which contains the elements for the left flow

    -

    (player)

    +

    Draw a flow used to align its child elements, default is right align

    +

    - Parameters: + Properties / Events:
      @@ -2020,59 +1094,15 @@ Gui.element{
    • - player + parent : - (LuaPlayer) - - the player that you want to get the flow for - -
    • - - -
    - - - - - Returns: -
      -
    • (LuaGuiElement) - the left element flow + + the parent element to which the alignment will be added +
    • -
    - - - - - - - - Usage: -
    -- Geting your left element flow
    -local left_flow = Gui.get_left_flow(game.player)
    - - -
    -
    -
    -
    - # - hide_left_flow(player) -
    -
    -
    -
    - -

    Hides all left elements for a player

    -

    - - - Parameters: - -
      @@ -2080,14 +1110,49 @@ Gui.element{
    • - player + name : - (LuaPlayer) + (string) - the player to hide the elements for + the name of the alignment flow which is added + (default: 'alignment') +
    • + + + + + +
    • + + horizontal_align + + : + + (string) + + the horizontal alignment of the elements in the flow + + (default: 'right') +
    • + + + + + +
    • + + vertical_align + + : + + (string) + + the vertical alignment of the elements in the flow + + (default: 'center')
    • @@ -2104,26 +1169,28 @@ Gui.element{ Usage: -
      -- Hide your left elements
      -Gui.hide_left_flow(game.player)
      +
      -- Adding a right align flow
      +local alignment = Gui.alignment(element,'example_right_alignment')
      +
      -- Adding a horizontal center and top align flow
      +local alignment = Gui.alignment(element,'example_center_top_alignment','center','top')
    - # - toggle_left_element(player, element_define[, state]) + # + scroll_table
    -

    Toggles the visible state of all a left element for a player

    +

    Draw a scroll pane that has a table inside of it

    - Parameters: + Properties / Events:
      @@ -2133,13 +1200,13 @@ Gui.element{
    • - player + parent : - (LuaPlayer) + (LuaGuiElement) - the player that you want to toggle the element for + the parent element to which the scroll table will be added
    • @@ -2149,13 +1216,13 @@ Gui.element{
    • - element_define + height : - (table) + (number) - the element that you want to toggle for the player + the maximum height for the scroll pane
    • @@ -2165,13 +1232,533 @@ Gui.element{
    • - state + column_count + + : + + (number) + + the number of columns that the table will have + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the scroll pane that is added, the table is always called "table" + + (default: 'scroll') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a scroll table with max height of 200 and column count of 3
    +local scroll_table = Gui.scroll_table(element,200,3)
    + + +
    +
    +
    +
    + # + header +
    +
    +
    +
    + +

    Used to add a frame with the header style, has the option for a right alignment flow for buttons

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the header will be added + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the header + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the header + + (optional) +
    • + + + + + +
    • + + add_alignment : (boolean) - if given then the state will be set to this state + when true an alignment flow will be added to the header + + (default: false) +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the header that is being added, the alignment is always called "alignment" + + (default: 'header') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a custom header with a label
    +local header = Gui.header(
    +    element,
    +    'Example Caption',
    +    'Example Tooltip'
    +)
    + + +
    +
    +
    +
    + # + footer +
    +
    +
    +
    + +

    Used to add a frame with the footer style, has the option for a right alignment flow for buttons

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the footer will be added + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the footer + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the footer + + (optional) +
    • + + + + + +
    • + + add_alignment + + : + + (boolean) + + when true an alignment flow will be added to the footer + + (default: false) +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the footer that is being added, the alignment is always called "alignment" + + (default: 'footer') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a custom footer with a label
    +local footer = Gui.footer(
    +    element,
    +    'Example Caption',
    +    'Example Tooltip'
    +)
    + + +
    +
    +
    +
    + # + container +
    +
    +
    +
    + +

    Used for left frames to give them a nice boarder

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the container will be added + +
    • + + + + + +
    • + + name + + : + + (string) + + the name that you want to give to the outer frame, often just event_trigger + +
    • + + + + + +
    • + + width + + : + + (number) + + the minimal width that the frame will have + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a container as a base
    +local container = Gui.container(parent,'my_container',200)
    + + +
    +
    +
    +
    + # + bar +
    +
    +
    +
    + +

    Used to make a solid white bar in a gui

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the bar will be added + +
    • + + + + + +
    • + + width + + : + + (number) + + the width of the bar that will be made, if not given bar will strech to fill the parent + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a bar to a gui
    +local bar = Gui.bar(parent, 100)
    + + +
    +
    +
    +
    + # + centered_label +
    +
    +
    +
    + +

    Used to make a label which is centered and of a certian size

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the label will be added + +
    • + + + + + +
    • + + width + + : + + (number) + + the width of the label, must be given in order to center the caption + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the label + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the label (optional)
    • @@ -2182,13 +1769,6 @@ Gui.element{ - Returns: -
        -
      • - (boolean) - the new visible state of the element -
      • -
      @@ -2197,10 +1777,110 @@ Gui.element{ Usage: -
      -- Toggle your example button
      -Gui.toggle_top_flow(game.player,example_flow_with_button)
      -
      -- Open your example button
      -Gui.toggle_top_flow(game.player,example_flow_with_button,true)
      +
      -- Adding a centered label
      +local label = Gui.centered_label(parent, 100, 'This is centered')
      + + +
    +
    +
    +
    + # + title_label +
    +
    +
    +
    + +

    Used to make a title which has two bars on either side

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the label will be added + +
    • + + + + + +
    • + + width + + : + + (number) + + the width of the first bar, this can be used to position the label + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the label + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the label + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a centered label
    +local label = Gui.centered_label(parent, 100, 'This is centered')
    @@ -2237,7 +1917,7 @@ Gui.element{ (LuaGuiElement) - the element that you want to get the owner of + the element to get the owner of @@ -2297,7 +1977,7 @@ Gui.element{ (LuaGuiElement) - the element that you want to toggle the state of + the element to toggle/set the enabled state of @@ -2313,7 +1993,7 @@ Gui.element{ (boolean) - the state that you want to set + with given will set the state, else state will be toggled (optional) @@ -2374,7 +2054,7 @@ Gui.element{ (LuaGuiElement) - the element that you want to toggle the state of + the element to toggle/set the visible state of @@ -2390,7 +2070,7 @@ Gui.element{ (boolean) - the state that you want to set + with given will set the state, else state will be toggled (optional) @@ -2431,7 +2111,7 @@ Gui.element{
    -

    Destory a gui element without causing any errors, likly if the element may have already been removed

    +

    Destory a gui element without causing any errors, often because the element was already removed

    @@ -2476,7 +2156,7 @@ Gui.element{ Usage: -
    -- Likely use case for element not existing
    +    
    -- Remove a child element if it exists
     Gui.destroy_if_valid(element[child_name])
    @@ -2484,14 +2164,14 @@ Gui.element{
    - # - alignment(parent[, horizontal_align='right'][, vertical_align='center'][, name='alignment']) + # + sprite_style(size[, padding=-2][, style])
    -

    Draw a flow that has custom element alignments, default is right align

    +

    Returns a table to be used as the style for a sprite buttons, produces a sqaure button

    @@ -2505,13 +2185,13 @@ Gui.element{
  • - parent + size : - (LuaGuiElement) + (number) - the parent element that the alignment flow will be added to + the size that you want the button to be
  • @@ -2521,15 +2201,15 @@ Gui.element{
  • - horizontal_align + padding : - (string) + (number) - the horizontal alignment of the elements in the flow + the padding that you want on the sprite - (default: 'right') + (default: -2)
  • @@ -2538,32 +2218,110 @@ Gui.element{
  • - vertical_align + style : - (string) + (table) - the vertical alignment of the elements in the flow + any extra style settings that you want to have - (default: 'center') + (optional)
  • + + + + + + Returns: +
      +
    • + (table) + the style table to be used with element_define:style() +
    • +
    + + + + + + + + Usage: +
    -- Adding a sprite button with size 20
    +local button =
    +Gui.element{
    +    type = 'sprite-button',
    +    sprite = 'entity/inserter'
    +}
    +:style(Gui.sprite_style(20))
    + + +
    +
    +

    Left Flow

    +
    +
    +
    +
    + # + left_elements +
    +
    +
    +
    + +

    Contains the uids of the elements that will shown on the left flow and their join functions

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + get_left_flow(player) +
    +
    +
    +
    + +

    Gets the flow refered to as the left flow, each player has one left flow

    +

    (player)

    + + + Parameters: + +
      + +
    • - name + player : - (string) + (LuaPlayer) - the name of the alignment flow + the player that you want to get the left flow for - (default: 'alignment')
    • @@ -2576,7 +2334,7 @@ Gui.element{
      • (LuaGuiElement) - the alignment flow that was created + the left element flow
      @@ -2587,24 +2345,22 @@ Gui.element{ Usage: -
      -- Adding a right align flow
      -local alignment = Gui.alignment(element,'example_right_alignment')
      -
      -- Adding a horizontal center and top align flow
      -local alignment = Gui.alignment(element,'example_center_top_alignment','center','top')
      +
      -- Geting your left flow
      +local left_flow = Gui.get_left_flow(game.player)
    - # - scroll_table(parent, height, column_count[, name='scroll']) + # + Gui._prototype_element:add_to_left_flow([open_on_join])
    -

    Draw a scroll pane that has a table inside of it

    +

    Sets an element define to be drawn to the left flow when a player joins, includes optional check

    @@ -2618,63 +2374,15 @@ Gui.element{
  • - parent + open_on_join : - (LuaGuiElement) + (boolean or function) - the parent element that the scroll table will be added to + called during first darw to decide if the element should be visible -
  • - - - - - -
  • - - height - - : - - (number) - - the maximum height for the scroll pane - -
  • - - - - - -
  • - - column_count - - : - - (number) - - the number of columns that the table will have - -
  • - - - - - -
  • - - name - - : - - (string) - - the name of the scroll pane that is added, the table is always called 'table' - - (default: 'scroll') + (optional)
  • @@ -2686,8 +2394,8 @@ Gui.element{ Returns:
    • - (LuaGuiElement) - the table that was created + (table) + the new element define that is used to register events to this element
    @@ -2698,22 +2406,22 @@ Gui.element{ Usage: -
    -- Adding a scroll table with max height of 200 and column count of 3
    -local scroll_table = Gui.scroll_table(element,'example_scroll_table',200,3)
    +
    -- Adding the example button
    +example_flow_with_button:add_to_left_flow(true)
    - # - header(parent, caption[, tooltip][, add_alignment=false][, name='header']) + # + left_toolbar_button(sprite, tooltip, element_define[, authenticator])
    -

    Used to add a header to a frame, this has the option for a custom right alignment flow for buttons

    +

    Creates a button on the top flow which will toggle the given element define, the define must exist in the left flow

    @@ -2727,29 +2435,13 @@ Gui.element{
  • - parent + sprite : - (LuaGuiElement) + (string) - the parent element that the header will be added to - -
  • - - - - - -
  • - - caption - - : - - (string or LocalizedString) - - the caption that will be shown on the header + the sprite that you want to use on the button
  • @@ -2765,26 +2457,263 @@ Gui.element{ (string or LocalizedString) - the tooltip that will be shown on the header + the tooltip that you want the button to have + + + + + + + +
  • + + element_define + + : + + (table) + + the element define that you want to have toggled by this button, define must exist on the left flow + +
  • + + + + + +
  • + + authenticator + + : + + (function) + + used to decide if the button should be visible to a player (optional)
  • + + + + + + + + + + + + + Usage: +
    -- Add a button to toggle a left element
    +local toolbar_button =
    +Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', example_flow_with_button, function(player)
    +    return player.admin
    +end)
    + + +
    +
    +
    +
    + # + draw_left_flow(player) +
    +
    +
    +
    + +

    Draw all the left elements onto the left flow, internal use only with on join

    +

    + + + Parameters: + +
      + +
    • - add_alignment + player : + (LuaPlayer) + + the player that you want to draw the elements for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Draw all the left elements
    +Gui.draw_left_flow(player)
    + + +
    +
    +
    +
    + # + update_left_flow(player) +
    +
    +
    +
    + +

    Update the visible state of the hide button, can be used to check if any frames are visible

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the left flow for + +
    • + + +
    + + + + + Returns: +
      +
    • (boolean) + true if any left element is visible +
    • +
    + - when true an alignment flow will be added for buttons - (default: false) + + + + + Usage: +
    -- Check if any left elements are visible
    +local visible = Gui.update_left_flow(player)
    + + +
    +
    +
    +
    + # + hide_left_flow(player) +
    +
    +
    +
    + +

    Hides all left elements for a player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to hide the elements for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Hide your left elements
    +Gui.hide_left_flow(game.player)
    + + +
    +
    +
    +
    + # + get_left_element(player, element_define) +
    +
    +
    +
    + +

    Get the element define that is in the left flow, use in events without an element refrence

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the element for +
    • @@ -2793,15 +2722,14 @@ Gui.element{
    • - name + element_define : - (string) + (table) - the name of the header that is being added, the alignment is always called 'alignment' + the element that you want to get - (default: 'header')
    • @@ -2814,7 +2742,7 @@ Gui.element{
      • (LuaGuiElement) - either the header or the header alignment if add_alignment is true + the gui element linked to this define for this player
      @@ -2825,14 +2753,1640 @@ Gui.element{ Usage: -
      -- Adding a custom header
      -local header_alignment = Gui.header(
      -    element,
      -    'example_header',
      -    'Example Caption',
      -    'Example Tooltip',
      -    true
      -)
      +
      -- Get your left element
      +local frame = Gui.get_left_element(game.player, example_flow_with_button)
      + + +
    +
    +
    +
    + # + toggle_left_element(player, element_define[, state]) +
    +
    +
    +
    + +

    Toggles the visible state of a left element for a given player, can be used to set the visible state

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to toggle the element for + +
    • + + + + + +
    • + + element_define + + : + + (table) + + the element that you want to toggle + +
    • + + + + + +
    • + + state + + : + + (boolean) + + with given will set the state, else state will be toggled + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new visible state of the element +
    • +
    + + + + + + + + Usage: +
    -- Toggle your example button
    +Gui.toggle_top_flow(game.player, example_flow_with_button)
    +
    -- Show your example button
    +Gui.toggle_top_flow(game.player, example_flow_with_button, true)
    + + +
    +
    +

    Element Define

    +
    +
    +
    +
    + # + element(element_define) +
    +
    +
    +
    + +

    Used to define new elements for your gui, can be used like LuaGuiElement.add or a custom function

    +

    + + + Parameters: + +
      + + + + + +
    • + + element_define + + : + + (table or function) + + the define information for the gui element, same data as LuaGuiElement.add, or a custom function may be used + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new element define, this can be considered a factory for the element which can be called to draw the element to any other element +
    • +
    + + + + + + + + Usage: +
    -- Using element defines like LuaGuiElement.add
    +-- This returns a factory function to draw a button with the caption "Example Button"
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button'
    +}
    +
    -- Using element defines with a custom factory function
    +-- This method can be used if you still want to be able register event handlers but it is too complex to be compatible with LuaGuiElement.add
    +local example_flow_with_button =
    +Gui.element(function(event_trigger,parent,...)
    +    -- ... shows that all other arguments from the factory call are passed to this function
    +    -- parent is the element which was passed to the factory function where you should add your new element
    +    -- here we are adding a flow which we will then later add a button to
    +    local flow =
    +    parent.add{
    +        name = 'example_flow',
    +        type = 'flow'
    +    }
    +
    +    -- event_trigger should be the name of any elements you want to trigger your event handlers, such as on_click or on_state_changed
    +    -- now we add the button to the flow that we created earlier
    +    local element =
    +    flow.add{
    +        name = event_trigger,
    +        type = 'button',
    +        caption = 'Example Button'
    +    }
    +
    +    -- you must return your new element, this is so styles can be applied and returned to the caller
    +    -- you may return any of your elements that you add, consider the context in which it will be used for what should be returned
    +    return element
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:style(style_define) +
    +
    +
    +
    + +

    Used to extent your element define with a style factory, this style will be applied to your element when created, can also be a custom function

    +

    + + + Parameters: + +
      + + + + + +
    • + + style_define + + : + + (table or function) + + style table where each key and value pair is treated like LuaGuiElement.style[key] = value, a custom function can be used + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define is returned to allow for event handlers to be registered +
    • +
    + + + + + + + + Usage: +
    -- Using the table method of setting the style
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button',
    +    style = 'forward_button' -- factorio styles can be applied here
    +}
    +:style{
    +    height = 25, -- same as element.style.height = 25
    +    width = 100 -- same as element.style.width = 25
    +}
    +
    -- Using the function method to set the style
    +-- Use this method if your style is dynamic and depends on other factors
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button',
    +    style = 'forward_button' -- factorio styles can be applied here
    +}
    +:style(function(style,element,...)
    +    -- style is the current style object for the elemenent
    +    -- element is the element that is being changed
    +    -- ... shows that all other arguments from the factory call are passed to this function
    +    local player = game.players[element.player_index]
    +    style.height = 25
    +    style.width = 100
    +    style.font_color = player.color
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:on_custom_event(event_name, handler) +
    +
    +
    +
    + +

    Set the handler which will be called for a custom event, only one handler can be used per event per element

    +

    + + + Parameters: + +
      + + + + + +
    • + + event_name + + : + + (string) + + the name of the event you want to handler to be called on, often from Gui.events + +
    • + + + + + +
    • + + handler + + : + + (function) + + the handler that you want to be called when the event is raised + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define so more handleres can be registered +
    • +
    + + + + + + + + Usage: +
    -- Register a handler to "my_custom_event" for this element
    +element_deinfe:on_custom_event('my_custom_event', function(event)
    +    event.player.print(player.name)
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:raise_custom_event(event) +
    +
    +
    +
    + +

    Raise the handler which is attached to an event; external use should be limited to custom events

    +

    + + + Parameters: + +
      + + + + + +
    • + + event + + : + + (table) + + the event table passed to the handler, must contain fields: name, element + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define so more events can be raised +
    • +
    + + + + + + + + Usage: +
     Raising a custom event
    +element_define:raise_custom_event{
    +    name = 'my_custom_event',
    +    element = element
    +}
    + + +
    +
    +

    Element Events

    +
    +
    +
    +
    + # + Gui._prototype_element.on_open +
    +
    +
    +
    + +

    Called when the player opens a GUI.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_open(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_close +
    +
    +
    +
    + +

    Called when the player closes the GUI they have open.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_close(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_click +
    +
    +
    +
    + +

    Called when LuaGuiElement is clicked.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_click(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_confirmed +
    +
    +
    +
    + +

    Called when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_confirmed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_checked_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_checked_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_elem_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement element value is changed (related to choose element buttons).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_elem_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_location_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement element location is changed (related to frames in player.gui.screen).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_location_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_tab_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement selected tab is changed (related to tabbed-panes).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_tab_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_selection_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement selection state is changed (related to drop-downs and listboxes).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_selection_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_switch_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement switch state is changed (related to switches).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_switch_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_text_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement text is changed by the player.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_text_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element.on_value_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement slider value is changed (related to the slider element).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + Usage: +
     element_define:on_value_changed(function(event)
    +  event.player.print(table.inspect(event))
    +end)
    + + +
    +
    +

    Top Flow

    +
    +
    +
    +
    + # + top_elements +
    +
    +
    +
    + +

    Contains the uids of the elements that will shown on the top flow and their auth functions

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + top_flow_button_style +
    +
    +
    +
    + +

    The style that should be used for buttons on the top flow

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + top_flow_button_visible_style +
    +
    +
    +
    + +

    The style that should be used for buttons on the top flow when their flow is visible

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + get_top_flow(player) +
    +
    +
    +
    + +

    Gets the flow refered to as the top flow, each player has one top flow

    +

    (player)

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the flow for + +
    • + + +
    + + + + + Returns: + + + + + + + + + Usage: +
    -- Geting your top flow
    +local top_flow = Gui.get_top_flow(game.player)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:add_to_top_flow([authenticator]) +
    +
    +
    +
    + +

    Sets an element define to be drawn to the top flow when a player joins, includes optional authenticator

    +

    + + + Parameters: + +
      + + + + + +
    • + + authenticator + + : + + (function) + + called during toggle or update to decide weather the element should be visible + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new element define to allow event handlers to be registered +
    • +
    + + + + + + + + Usage: +
    -- Adding an element to the top flow on join
    +example_button:add_to_top_flow(function(player)
    +    -- example button will only be shown if the player is an admin
    +    -- note button will not update its state when player.admin is changed Gui.update_top_flow must be called for this
    +    return player.admin
    +end)
    + + +
    +
    +
    +
    + # + update_top_flow(player) +
    +
    +
    +
    + +

    Updates the visible state of all the elements on the players top flow, uses authenticator

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to update the top flow for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Update your top flow
    +Gui.update_top_flow(game.player)
    + + +
    +
    +
    +
    + # + toggle_top_flow(player[, state]) +
    +
    +
    +
    + +

    Toggles the visible state of all the elements on a players top flow, effects all elements

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to toggle the top flow for + +
    • + + + + + +
    • + + state + + : + + (boolean) + + if given then the state will be set to this + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new visible state of the top flow +
    • +
    + + + + + + + + Usage: +
    -- Toggle your flow
    +Gui.toggle_top_flow(game.player)
    +
    -- Open your top flow
    +Gui.toggle_top_flow(game.player,true)
    + + +
    +
    +
    +
    + # + get_top_element(player, element_define) +
    +
    +
    +
    + +

    Get the element define that is in the top flow, use in events without an element refrence

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the element for + +
    • + + + + + +
    • + + element_define + + : + + (table) + + the element that you want to get + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the gui element linked to this define for this player +
    • +
    + + + + + + + + Usage: +
    -- Get your top element
    +local button = Gui.get_top_element(game.player, example_button)
    + + +
    +
    +
    +
    + # + toolbar_button(sprite, tooltip[, authenticator]) +
    +
    +
    +
    + +

    Creates a button on the top flow with consistent styling

    +

    + + + Parameters: + +
      + + + + + +
    • + + sprite + + : + + (string) + + the sprite that you want to use on the button + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that you want the button to have + +
    • + + + + + +
    • + + authenticator + + : + + (function) + + used to decide if the button should be visible to a player + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Add a button to the toolbar
    +local toolbar_button =
    +Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', function(player)
    +    return player.admin
    +end)
    + + +
    +
    +
    +
    + # + toolbar_button_style(button, state) +
    +
    +
    +
    + +

    Styles a top flow button depending on the state given

    +

    + + + Parameters: + +
      + + + + + +
    • + + button + + : + + (LuaGuiElement) + + the button element to style + +
    • + + + + + +
    • + + state + + : + + (boolean) + + The state the button is in + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Sets the button to the visible style
    +Gui.toolbar_button_style(button, true)
    +
    -- Sets the button to the hidden style
    +Gui.toolbar_button_style(button, false)
    @@ -2851,7 +4405,7 @@ Gui.element{ generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index dc36167e..41fde465 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -53,13 +53,13 @@ @@ -88,10 +88,12 @@ + + @@ -100,8 +102,10 @@

    Guis

    @@ -139,7 +143,6 @@

    Configs

    @@ -172,18 +176,13 @@

    Modules

    @@ -230,7 +229,7 @@

    Permissions-Groups core

    Core Module - Permission Groups - - Permission group making for factorio so you never have to make one by hand again

    +- Permission group making for factorio so you never have to make one by hand again

    @@ -239,26 +238,22 @@

    Usage

    -
    
    ----- Example Group (Allow All)
    -
    -    -- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups
    -    Permission_Groups.new_group('Admin') -- this defines a new group called "Admin"
    -    :allow_all() -- this makes the default to allow any input action unless set other wise
    -    :disallow{ -- here we disallow the input action we don't want them to use
    -        'add_permission_group',
    -        'delete_permission_group',
    -        'import_permissions_string',
    -        'map_editor_action',
    -        'toggle_map_editor'
    -    }
    -
    
    ----- Example Group (Disallow All)
    -
    -    -- here we will create a group that cant do anything but talk in chat
    -    Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted"
    -    :disallow_all() -- this makes the default to disallow any input action unless set other wise
    -    :allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action
    +    
    --- Example Group (Allow All)
    +-- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups
    +Permission_Groups.new_group('Admin') -- this defines a new group called "Admin"
    +:allow_all() -- this makes the default to allow any input action unless set other wise
    +:disallow{ -- here we disallow the input action we don't want them to use
    +    'add_permission_group',
    +    'delete_permission_group',
    +    'import_permissions_string',
    +    'map_editor_action',
    +    'toggle_map_editor'
    +}
    +
    --- Example Group (Disallow All)
    +-- here we will create a group that cant do anything but talk in chat
    +Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted"
    +:disallow_all() -- this makes the default to disallow any input action unless set other wise
    +:allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action
     
    @@ -278,7 +273,7 @@ utils.event - expcore.sudo + expcore.async @@ -313,10 +308,6 @@ Reloads/creates all permission groups and sets them to they configured state - lockdown_permissions(exempt) - Removes all permissions from every permission group except for "Default" and any passed as exempt - - set_player_group(player, group) Sets a player's group to the one given, a player can only have one group at a time @@ -361,14 +352,14 @@ - Permissions_Groups._prototype:get_raw() - Returns the LuaPermissionGroup that was created with this group object, used internally - - Permissions_Groups._prototype:create() Creates or updates the permission group with the configured actions, used internally + Permissions_Groups._prototype:get_raw() + Returns the LuaPermissionGroup that was created with this group object, used internally + + Permissions_Groups._prototype:add_player(player) Adds a player to this group @@ -446,8 +437,8 @@
    - # - expcore.sudo + # + expcore.async
    @@ -525,6 +516,9 @@ + Usage: +
    -- Defining a new permission group
    +Groups.new_group('Admin')
    @@ -582,6 +576,9 @@ + Usage: +
    -- Getting a permision group
    +local admin_group = Groups.get_group_by_name('Admin')
    @@ -639,6 +636,9 @@ + Usage: +
    -- Get your permission group
    +local group = Groups.get_group_from_player(game.player)
    @@ -669,63 +669,9 @@ - - - -
    -
    -
    - # - lockdown_permissions(exempt) -
    -
    -
    -
    - -

    Removes all permissions from every permission group except for "Default" and any passed as exempt

    -

    - - - Parameters: - -
      - - - - - -
    • - - exempt - - : - - (string or Array) - - groups that you want to be except, "Default" is always exempt - -
    • - - -
    - - - - - Returns: -
      -
    • - (number) - the number of groups that had they permissions removed -
    • -
    - - - - - - - + Usage: +
    -- Reload the permission groups, used internally
    +Groups.reload_permissions()
    @@ -799,6 +745,9 @@ + Usage: +
    -- Set your permission group
    +Groups.set_player_group(game.player, 'Admin')
    @@ -875,6 +824,9 @@ + Usage: +
    -- Set an action to be disalowed
    +group:set_action('toggle_map_editor', false)
    @@ -932,6 +884,11 @@ + Usage: +
    -- Allow some actions
    +group:allow{
    +    'write_to_console'
    +}
    @@ -989,6 +946,15 @@ + Usage: +
    -- Disalow some actions
    +group:disallow{
    +    'add_permission_group',
    +    'delete_permission_group',
    +    'import_permissions_string',
    +    'map_editor_action',
    +    'toggle_map_editor'
    +}
    @@ -1023,6 +989,9 @@ + Usage: +
    -- Allow all actions unless given by disallow
    +group:allow_all()
    @@ -1057,6 +1026,9 @@ + Usage: +
    -- Disallow all actions unless given by allow
    +group:disallow_all()
    @@ -1114,6 +1086,9 @@ + Usage: +
    -- Test if a group is allowed an action
    +local allowed = group:is_allowed('write_to_console')
    @@ -1123,40 +1098,6 @@
    - # - Permissions_Groups._prototype:get_raw() -
    -
    -
    -
    - -

    Returns the LuaPermissionGroup that was created with this group object, used internally

    -

    - - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    # Permissions_Groups._prototype:create()
    @@ -1185,6 +1126,46 @@ + Usage: +
    -- Create the permission group so players can be added, used internally
    +group:create()
    + + + +
    +
    +
    + # + Permissions_Groups._prototype:get_raw() +
    +
    +
    +
    + +

    Returns the LuaPermissionGroup that was created with this group object, used internally

    +

    + + + + + + Returns: + + + + + + + + + Usage: +
    -- Get the factorio api permision group, used internally
    +local permission_group = group:get_raw()
    @@ -1242,6 +1223,9 @@ + Usage: +
    -- Add a player to this permission group
    +group:add_player(game.player)
    @@ -1299,6 +1283,9 @@ + Usage: +
    -- Remove a player from this permission group
    +group:remove_player(game.player)
    @@ -1357,6 +1344,11 @@ + Usage: +
    -- Get all players in this group
    +local online_players = group:get_players()
    +
    -- Get all online players in this group
    +local online_players = group:get_players(true)
    @@ -1414,6 +1406,9 @@ + Usage: +
    -- Print a message to all players in thie group
    +group:print('Hello, World!')
    @@ -1432,7 +1427,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index 25ceecf4..5a2def19 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -57,13 +57,13 @@ @@ -92,10 +92,12 @@ + + @@ -104,8 +106,10 @@

    Guis

    @@ -143,7 +147,6 @@

    Configs

    @@ -176,18 +180,13 @@

    Modules

    @@ -238,7 +237,7 @@

    Roles core

    Core Module - Roles - - Factorio role system to manage custom permissions.

    +- Factorio role system to manage custom permissions.

    @@ -247,111 +246,107 @@

    Usage

    -
    
    ----- Using Role System (Frontend):
    -    When a map first starts you will want to define on mass all the players you expect to join and the roles to give them:
    -    Roles.override_player_roles{
    -        Cooldude2606 = {'Owner','Admin','Member'},
    -        NotCooldude2606 = {'Member'}
    -    }
    +    
    --- Using Role System (assignment):
    +--When a map first starts you will want to define on mass all the players you expect to join and the roles to give them:
    +Roles.override_player_roles{
    +    Cooldude2606 = {'Owner','Admin','Member'},
    +    NotCooldude2606 = {'Member'}
    +}
     
    -    Once the game is running you still want to be able to give role and remove them which is when you would use:
    -    Roles.assign_player(player,'Admin',by_player_name) -- this will give the "Admin" role to the player
    -    Roles.unassign_player(player,{'Admin','Moderator'},by_player_name) -- this will remove "Admin" and "Moderator" role in one go
    +--Once the game is running you still want to be able to give role and remove them which is when you would use:
    +Roles.assign_player(player,'Admin',by_player_name) -- this will give the "Admin" role to the player
    +Roles.unassign_player(player,{'Admin','Moderator'},by_player_name) -- this will remove "Admin" and "Moderator" role in one go
     
    -
    
    ----- Using Role System (Backend):
    -    To comparer two players you can comparer the index of they highest roles, can be used when you want to allow a "write" down type system:
    -    Roles.get_player_highest_role(playerOne).index < Roles.get_player_highest_role(playerTwo).index -- remember that less means a higher role
    +    
    --- Using Role System (role testing):
    +--To comparer two players you can comparer the index of they highest roles, can be used when you want to allow a "write" down type system:
    +Roles.get_player_highest_role(playerOne).index < Roles.get_player_highest_role(playerTwo).index -- remember that less means a higher role
     
    -    Listing all of a players roles can also be useful which is when you would want to use:
    -    Roles.get_player_roles(player) -- the return is an array that can be looped over however this is not in particular order
    +--Listing all of a players roles can also be useful which is when you would want to use:
    +Roles.get_player_roles(player) -- the return is an array that can be looped over however this is not in particular order
     
    -    Finally you may want to test if a player has a certain role, flag or action allowed which is when you would use:
    -    Roles.player_has_role(player,'Admin') -- you can provide a role name if you only want a name based system
    -    Roles.player_has_flag(player,'is_donator') -- your roles can be grouped together with flags such as is_donator
    -    Roles.player_allowed(player,'game modifiers') -- or you can have an action based system where each action is something the player can do
    +--Finally you may want to test if a player has a certain role, flag or action allowed which is when you would use:
    +Roles.player_has_role(player,'Admin') -- you can provide a role name if you only want a name based system
    +Roles.player_has_flag(player,'is_donator') -- your roles can be grouped together with flags such as is_donator
    +Roles.player_allowed(player,'game modifiers') -- or you can have an action based system where each action is something the player can do
     
    -
    
    ----- Example Flag Define:
    -    Flags can be used to group multiple roles and actions under one catch all, for example if you want a piece of code to only
    -    be active for your donators then you would add a "is_donator" flag to all your donator roles and then in the code test if
    -    a player has that tag present:
    +    
    --- Example Flag Define:
    +--Flags can be used to group multiple roles and actions under one catch all, for example if you want a piece of code to only
    +--be active for your donators then you would add a "is_donator" flag to all your donator roles and then in the code test if
    +--a player has that tag present:
    +
    +-- give you donators a speed boost when they join; these functions aren't required but can be useful
    +Roles.define_flag_trigger('is_donator',function(player,state)
    +    if state then
    +        player.character_running_speed_modifier = 1.5
    +    else
    +        player.character_running_speed_modifier = 1
    +    end
    +end)
     
    -    -- give you donators a speed boost when they join; these functions aren't required but can be useful
    -    Roles.define_flag_trigger('is_donator',function(player,state)
    -        if state then
    -            player.character_running_speed_modifier = 1.5
    -        else
    -            player.character_running_speed_modifier = 1
    -        end
    -    end)
    +-- then on all your donator roles you would add
    +Roles.new_role('Donator')
    +:set_flag('is_donator')
     
    -    -- then on all your donator roles you would add
    -    Roles.new_role('Donator')
    -    :set_flag('is_donator')
    +-- and in your code you would test for
    +if Roles.player_has_flag(player,'is_donator') then
    +    -- some donator only code
    +end
    +
    --- Example Role Define:
    +--You can't use a role system without any roles so first you must define your roles; each role has a minimum of a name with
    +--the option for a shorthand:
    +Roles.new_role('Administrator','Admin')
     
    -    -- and in your code you would test for
    -    if Roles.player_has_flag(player,'is_donator') then
    -        -- some donator only code
    -    end
    -
    
    ----- Example Role Define:
    -    You can't use a role system without any roles so first you must define your roles; each role has a minimum of a name with
    -    the option for a shorthand:
    -    Roles.new_role('Administrator','Admin')
    +--Next you will want to add any extras you want to have, such as a tag, colour, permission group or any custom flags:
    +Roles.new_role('Administrator','Admin')
    +:set_custom_tag('[Admin]')
    +:set_custom_color('red') -- this can be {r=0,g=0,b=0} or a predefined value
    +:set_permission_group('Staff') -- a second argument can be added if you have not used the custom permission group config
    +:set_flag('is_admin')
     
    -    Next you will want to add any extras you want to have, such as a tag, colour, permission group or any custom flags:
    -    Roles.new_role('Administrator','Admin')
    -    :set_custom_tag('[Admin]')
    -    :set_custom_color('red') -- this can be {r=0,g=0,b=0} or a predefined value
    -    :set_permission_group('Staff') -- a second argument can be added if you have not used the custom permission group config
    -    :set_flag('is_admin')
    +--You will then want to decide if you want to allow all actions, this should of course be used sparely:
    +Roles.new_role('Administrator','Admin')
    +...extras...
    +:set_allow_all()
     
    -    You will then want to decide if you want to allow all actions, this should of course be used sparely:
    -    Roles.new_role('Administrator','Admin')
    -    ...extras...
    -    :set_allow_all()
    +--If you don't do this want this as i would advise you do then you will want to define what the role can do; this comes with
    +--an optional inheritance system if you like those sort of things in which case disallow may also be of some use to you:
    +Roles.new_role('Administrator','Admin')
    +...extras...
    +:set_parent('Moderator') -- the admin can do anything that a moderator can do
    +:allow{ -- these actions can be anything just try to keep them without conflicts
    +    'command/kill',
    +    'gui/game settings'
    +}
     
    -    If you don't do this want this as i would advise you do then you will want to define what the role can do; this comes with
    -    an optional inheritance system if you like those sort of things in which case disallow may also be of some use to you:
    -    Roles.new_role('Administrator','Admin')
    -    ...extras...
    -    :set_parent('Moderator') -- the admin can do anything that a moderator can do
    -    :allow{ -- these actions can be anything just try to keep them without conflicts
    -        'command/kill',
    -        'gui/game settings'
    -    }
    +--Here is what the finished admin role would look like:
    +Roles.new_role('Administrator','Admin')
    +:set_custom_tag('[Admin]')
    +:set_custom_color('red')
    +:set_permission_group('Staff')
    +:set_flag('is_admin')
    +:set_parent('Moderator')
    +:allow{
    +    'command/kill',
    +    'gui/game settings'
    +}
    +
    --- Example System Define:
    +--Once all roles are defined these steps must be done to ensure the system is ready to use, this includes setting a default
    +--role, assigning a root (all permission) role that the server/system will use and the linear order that the roles fall into:
    +
    +Roles.set_default('Guest')
    +Roles.set_root('System')
     
    -    Here is what the finished admin role would look like:
    -    Roles.new_role('Administrator','Admin')
    -    :set_custom_tag('[Admin]')
    -    :set_custom_color('red')
    -    :set_permission_group('Staff')
    -    :set_flag('is_admin')
    -    :set_parent('Moderator')
    -    :allow{
    -        'command/kill',
    -        'gui/game settings'
    -    }
    -
    
    ----- Example System Define:
    -    Once all roles are defined these steps must be done to ensure the system is ready to use, this includes setting a default
    -    role, assigning a root (all permission) role that the server/system will use and the linear order that the roles fall into:
    +Roles.define_role_order{
    +    'System',
    +    'Administrator',
    +    'Moderator',
    +    'Donator',
    +    'Guest'
    +}
     
    -    Roles.set_default('Guest')
    -    Roles.set_root('System')
    -
    -    Roles.define_role_order{
    -        'System',
    -        'Administrator',
    -        'Moderator',
    -        'Donator',
    -        'Guest'
    -    }
    -
    -    Just remember that in this example all these roles have not been defined; so make sure all your roles that are used are defined
    -    before hand; a config file on load is useful for this to ensure that its loaded before the first player even joins.
    +--Just remember that in this example all these roles have not been defined; so make sure all your roles that are used are defined +--before hand; a config file on load is useful for this to ensure that its loaded before the first player even joins. +
    @@ -376,10 +371,10 @@ expcore.permission_groups - expcore.sudo + expcore.async - resources.color_presets + utils.color_presets expcore.common @@ -419,7 +414,7 @@ get_role_from_any(any) Gets a role from a name,index or role object (where it is just returned) - nb: this function is used for the input for most outward facing functions +nb: this function is used for the input for most outward facing functions get_player_roles(player) @@ -438,15 +433,15 @@ - assign_player(player, roles[, by_player_name=][, silent=false]) + assign_player(player, roles[, by_player_name=][, skip_checks=false][, silent=false]) Gives a player the given role(s) with an option to pass a by player name used in the log - unassign_player(player, roles[, by_player_name=][, silent=false]) + unassign_player(player, roles[, by_player_name=][, skip_checks=false][, silent=false]) Removes a player from the given role(s) with an option to pass a by player name used in the log - override_player_roles(roles) + override_player_roles([player_name], roles) Overrides all player roles with the given table of roles, useful to mass set roles on game start @@ -480,7 +475,7 @@ define_role_order(order) Used to set the role order, higher in the list is better, must be called at least once in config - nb: function also re links parents due to expected position in the config file +-- nb: function also re links parents due to expected position in the config file define_flag_trigger(name, callback) @@ -565,16 +560,16 @@ Roles._prototype:set_parent(role) Sets the parent for a role, any action not in allow or disallow will be looked for in its parents - nb: this is a recursive action, and changing the allows and disallows will effect all children roles +nb: this is a recursive action, and changing the allows and disallows will effect all children roles - Roles._prototype:set_auto_promote_condition(callback) - Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will receive the role - nb: this is one way, failing false after already gaining the role will not revoke the role + Roles._prototype:set_auto_assign_condition(callback) + Sets an auto assign condition that is checked every 60 seconds, if true is returned then the player will receive the role +nb: this is one way, failing false after already gaining the role will not revoke the role Roles._prototype:set_block_auto_promote([state=true]) - Sets the role to not allow players to have auto promote effect them, useful to keep people locked to a punishment + Sets the role to not allow players to have auto assign effect them, useful to keep people locked to a role @@ -712,8 +707,8 @@
    - # - expcore.sudo + # + expcore.async
    @@ -737,8 +732,8 @@
    - # - resources.color_presets + # + utils.color_presets
    @@ -818,6 +813,9 @@ + Usage: +
    -- Print the debug string
    +game.player.print(Roles.debug())
    @@ -884,6 +882,9 @@ + Usage: +
    -- Print a message to the given roles
    +Roles.print_to_roles({'Administrator','Moderator'}, 'Hello, World!')
    @@ -950,6 +951,9 @@ + Usage: +
    -- Print a message to the roles above this role, includes the given role
    +Roles.print_to_roles_higher('Moderator', 'Hello, World!')
    @@ -1016,6 +1020,9 @@ + Usage: +
    -- Print a message to the roles below this role, includes the given role
    +Roles.print_to_roles_higher('Moderator', 'Hello, World!')
    @@ -1073,6 +1080,9 @@ + Usage: +
    -- Get a role by its name
    +local role = Roles.get_role_by_name('Moderator')
    @@ -1130,6 +1140,9 @@ + Usage: +
    -- Get a role by its index in the order list
    +local role = Roles.get_role_by_name(2)
    @@ -1144,7 +1157,7 @@

    Gets a role from a name,index or role object (where it is just returned) - nb: this function is used for the input for most outward facing functions

    +nb: this function is used for the input for most outward facing functions

    @@ -1188,6 +1201,9 @@ + Usage: +
    -- Get a role by its name or order
    +local role = Roles.get_role_from_any('Moderator')
    @@ -1245,6 +1261,9 @@ + Usage: +
    -- Get the roles that a player has
    +local roles = Roles.get_player_roles(game.player)
    @@ -1302,6 +1321,9 @@ + Usage: +
    -- Get the highest role that a player has
    +local role = Roles.get_player_highest_role(game.player)
    @@ -1312,7 +1334,7 @@
    # - assign_player(player, roles[, by_player_name=][, silent=false]) + assign_player(player, roles[, by_player_name=][, skip_checks=false][, silent=false])
    @@ -1379,6 +1401,23 @@ +
  • + + skip_checks + + : + + (boolean) + + when true there will be no checks are done for if the player is valid + + (default: false) +
  • + + + + +
  • silent @@ -1405,6 +1444,11 @@ + Usage: +
    -- Assign a player to the Moderator role
    +Roles.assign_player(game.player,  'Moderator')
    +
    -- Assign a player to the Moderator role, even if the player has never been on the map
    +Roles.assign_player('Cooldude2606',  'Moderator', nil, true)
  • @@ -1412,7 +1456,7 @@
    # - unassign_player(player, roles[, by_player_name=][, silent=false]) + unassign_player(player, roles[, by_player_name=][, skip_checks=false][, silent=false])
    @@ -1479,6 +1523,23 @@ +
  • + + skip_checks + + : + + (boolean) + + when true there will be no checks are done for if the player is valid + + (default: false) +
  • + + + + +
  • silent @@ -1505,6 +1566,11 @@ + Usage: +
    -- Unassign a player from the Moderator role
    +Roles.unassign_player(game.player,  'Moderator')
    +
    -- Unassign a player from the Moderator role, even if the player has never been on the map
    +Roles.unassign_player('Cooldude2606',  'Moderator', nil, true)
  • @@ -1512,7 +1578,7 @@
    # - override_player_roles(roles) + override_player_roles([player_name], roles)
    @@ -1530,6 +1596,23 @@ +
  • + + player_name + + : + + (string) + + the player to set the roles for, if not given all roles are overriden + + (optional) +
  • + + + + +
  • roles @@ -1555,6 +1638,14 @@ + Usage: +
    -- Override the roles of a single player, other users are not effected
    +Roles.override_player_roles('Cooldude2606', {'Moderator'})
    +
    -- Override all existing roles, effects all users not just ones listed
    +Roles.override_player_roles{
    +    ['Cooldude2606'] = {'Administrator','Moderator'},
    +    ['arty714'] = {'Administrator','Moderator'},
    +}
  • @@ -1631,6 +1722,9 @@ + Usage: +
    -- Test if a player has a role
    +local has_role = Roles.player_has_role(game.player, 'Moderator')
    @@ -1704,6 +1798,9 @@ + Usage: +
    -- Test if a player has a role
    +local has_flag = Roles.player_has_flag(game.player, 'is_donator')
    @@ -1777,6 +1874,9 @@ + Usage: +
    -- Test if a player has a role
    +local has_flag = Roles.player_has_flag(game.player, 'is_donator')
    @@ -1794,7 +1894,7 @@

    Used to set the role order, higher in the list is better, must be called at least once in config - nb: function also re links parents due to expected position in the config file

    +-- nb: function also re links parents due to expected position in the config file

    @@ -1831,6 +1931,15 @@ + Usage: +
    -- Define which roles are higher than others
    +Roles.define_role_order{
    +    'System',
    +    'Administrator',
    +    'Moderator',
    +    'Donator',
    +    'Guest'
    +}
    @@ -1881,8 +1990,6 @@ (function) the function that is called when roles are assigned - flag param - player - the player that has had they roles changed - flag param - state - the state of the flag, aka if the flag is present @@ -1899,6 +2006,11 @@ + Usage: +
    -- Defineing a flag trigger
    +Roles.define_flag_trigger('is_donator', function(player, state)
    +    player.character_running_speed_modifier = state and 1.5 or 1
    +end)
    @@ -1949,6 +2061,9 @@ + Usage: +
    -- Setting the default role
    +Roles.set_default('Guest')
    @@ -1999,6 +2114,9 @@ + Usage: +
    -- Setting the root role
    +Roles.set_root('System')
    @@ -2073,6 +2191,9 @@ + Usage: +
    -- Defineing a new role
    +local role = Roles.new_role('Moderator', 'Mod')
    @@ -2134,6 +2255,9 @@ + Usage: +
    -- Allow all actions for this role, useful for root like roles
    +role:set_allow_all()
    @@ -2191,6 +2315,12 @@ + Usage: +
    -- Allow some actions for a role
    +role:allow{
    +    'command/kill',
    +    'gui/game settings'
    +}
    @@ -2248,6 +2378,12 @@ + Usage: +
    -- Disalow an action for a role, useful if inherit an action from a parent
    +role:disallow{
    +    'command/kill',
    +    'gui/game settings'
    +}
    @@ -2305,6 +2441,9 @@ + Usage: +
    -- Test if a role is allowed an action
    +local allowed = role:is_allowed('command/kill')
    @@ -2382,6 +2521,9 @@ + Usage: +
    -- Set a flag for a role
    +role:set_flag('is_admin')
    @@ -2416,6 +2558,9 @@ + Usage: +
    -- Remove all flags from a role
    +role:clear_flags()
    @@ -2473,6 +2618,9 @@ + Usage: +
    -- Test if a role has a flag
    +local has_flag = role:has_flag('is_admin')
    @@ -2533,6 +2681,9 @@ + Usage: +
    -- Set a custom tag for this role, other code is required to set the tag
    +role:set_custom_tag('Mod')
    @@ -2590,6 +2741,9 @@ + Usage: +
    -- Set a custom colour for this role, other code is required to use this value
    +role:set_custom_color{ r=255, g=100, b=100}
    @@ -2664,6 +2818,9 @@ + Usage: +
    -- Set the permission group for this role, see permission_groups.lua
    +role:set_permission_group('Admin')
    @@ -2678,7 +2835,7 @@

    Sets the parent for a role, any action not in allow or disallow will be looked for in its parents - nb: this is a recursive action, and changing the allows and disallows will effect all children roles

    +nb: this is a recursive action, and changing the allows and disallows will effect all children roles

    @@ -2722,21 +2879,24 @@ + Usage: +
    -- Set the parent for this role to inherit all actions allowed
    +role:set_parent('Guest')
    - # - Roles._prototype:set_auto_promote_condition(callback) + # + Roles._prototype:set_auto_assign_condition(callback)
    -

    Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will receive the role - nb: this is one way, failing false after already gaining the role will not revoke the role

    +

    Sets an auto assign condition that is checked every 60 seconds, if true is returned then the player will receive the role +nb: this is one way, failing false after already gaining the role will not revoke the role

    @@ -2780,6 +2940,11 @@ + Usage: +
    -- Give this role to a user if there are admin, ran every 60 seconds
    +role:set_auto_assign_condition(function(player)
    +    return player.admin
    +end)
    @@ -2793,7 +2958,7 @@
    -

    Sets the role to not allow players to have auto promote effect them, useful to keep people locked to a punishment

    +

    Sets the role to not allow players to have auto assign effect them, useful to keep people locked to a role

    @@ -2813,7 +2978,7 @@ (boolean) - when true the players with this role will not be auto promoted + when true the players with this role will not be auto assigned to other roles (default: true) @@ -2838,6 +3003,9 @@ + Usage: +
    -- Make a role stop players from being auto assigned to other roles
    +role:set_block_auto_promote()
    @@ -2930,6 +3098,9 @@ + Usage: +
    -- Assign a player to this role
    +role:add_player(game.player)
    @@ -3019,6 +3190,9 @@ + Usage: +
    -- Unassign a player from this role
    +role:remove_player(game.player)
    @@ -3077,6 +3251,11 @@ + Usage: +
    -- Get all the players with this role
    +local players = role:get_players()
    +
    -- Get all online players with this role
    +local players = role:get_players(true)
    @@ -3134,6 +3313,9 @@ + Usage: +
    -- Print a message to all players with this role
    +role:print('Hello, World!')
    @@ -3152,7 +3334,7 @@ generated by LDoc
    diff --git a/docs/core/Store.html b/docs/core/Store.html index fd876dbc..51907502 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -53,13 +53,13 @@ @@ -88,10 +88,12 @@ + + @@ -100,8 +102,10 @@

    Guis

    @@ -139,7 +143,6 @@

    Configs

    @@ -172,18 +176,13 @@

    Modules

    @@ -1481,7 +1480,7 @@ Store.set(player_scores,game.player,10) generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 0dbdaafd..f6a07252 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -51,8 +51,10 @@

    Guis

    @@ -62,13 +64,13 @@ @@ -97,10 +99,12 @@ + + @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -224,7 +223,7 @@

    Player-List gui

    Gui Module - Player List - - Adds a player list to show names and play time; also includes action buttons which can apply to players

    + - Adds a player list to show names and play time; also includes action buttons which can preform actions to players

    @@ -259,14 +258,14 @@ utils.event + config.gui.player_list_actions + + + utils.color_presets + + expcore.common - - config.action_buttons - - - resources.color_presets - @@ -288,8 +287,20 @@ - - + + + + + + + + + + + + + +
    Button used to confirm a reason
    player_listRegisters the player listadd_player_baseSet of elements that are used to make up a row of the player table
    add_action_barAdds all the buttons and flows that make up the action bar
    player_list_containerMain player list container for the left flow
    toggle_left_elementButton on the top flow used to toggle the player list container
    @@ -418,6 +429,56 @@ + + + + + + + +
    +
    +
    + # + config.gui.player_list_actions +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.color_presets +
    +
    +
    +
    + + + + + + + + + @@ -443,56 +504,6 @@ - - - - - - -
    -
    -
    -
    - # - config.action_buttons -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - resources.color_presets -
    -
    -
    -
    - - - - - - - - - @@ -587,14 +598,95 @@
    - # - player_list + # + add_player_base
    -

    Registers the player list

    +

    Set of elements that are used to make up a row of the player table

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + add_action_bar +
    +
    +
    +
    + +

    Adds all the buttons and flows that make up the action bar

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + player_list_container +
    +
    +
    +
    + +

    Main player list container for the left flow

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + toggle_left_element +
    +
    +
    +
    + +

    Button on the top flow used to toggle the player list container

    @@ -626,7 +718,7 @@ generated by LDoc
    diff --git a/docs/guis/Readme.html b/docs/guis/Readme.html new file mode 100644 index 00000000..beecc8d1 --- /dev/null +++ b/docs/guis/Readme.html @@ -0,0 +1,735 @@ + + + + + + + + Readme gui + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    Readme gui

    +

    Gui Module - Readme + - Adds a main gui that contains lots of important information about our server

    +

    + + + + + + + + + + + + + +

    Dependencies

    + + + + + + + + + + + + + + + + + + + +
    expcore.gui
    expcore.roles
    expcore.commands
    utils.event
    utils.game
    + + +

    Elements

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    sub_contentSub content area used within the content areas
    title_tableTable which has a title above it above it
    title_table_scrollScroll to be used with Gui.title_label tables
    welcome_contentContent area for the welcome tab
    rules_contentContent area for the rules tab
    commands_contentContent area for the commands tab
    servers_contentContent area for the servers tab
    backers_contentContent area for the servers tab
    readmeMain readme container for the center flow
    readme_toggleToggle button for the readme gui
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.roles +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.commands +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.game +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Elements

    +
    +
    +
    +
    + # + sub_content +
    +
    +
    +
    + +

    Sub content area used within the content areas

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + title_table +
    +
    +
    +
    + +

    Table which has a title above it above it

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + title_table_scroll +
    +
    +
    +
    + +

    Scroll to be used with Gui.title_label tables

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + welcome_content +
    +
    +
    +
    + +

    Content area for the welcome tab

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + rules_content +
    +
    +
    +
    + +

    Content area for the rules tab

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + commands_content +
    +
    +
    +
    + +

    Content area for the commands tab

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + servers_content +
    +
    +
    +
    + +

    Content area for the servers tab

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + backers_content +
    +
    +
    +
    + +

    Content area for the servers tab

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + readme +
    +
    +
    +
    + +

    Main readme container for the center flow

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + readme_toggle +
    +
    +
    +
    + +

    Toggle button for the readme gui

    +

    + + + + + + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 3de18001..b112fb6a 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -51,8 +51,10 @@

    Guis

    @@ -62,13 +64,13 @@ @@ -97,10 +99,12 @@ + + @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -253,17 +252,17 @@ utils.event - config.rockets + config.gui.rockets - expcore.common - - - resources.color_presets + utils.color_presets modules.control.rockets + + expcore.common + @@ -273,24 +272,32 @@ - - + + - + - - + + - - + + - - + + + + + + + + + +
    zoom_to_mapUsed on the name label to allow zoom to maptoggle_launchButton to toggle the auto launch on a rocket silo
    launch_rocketUsed to launch the rocket, when it is readyButton to remotely launch a rocket from a silo
    toggle_rocketUsed to toggle the auto launch on a rocketsilo_cordsXY cords that allow zoom to map when pressed
    toggle_sectionUsed to toggle the visibility of the different sectionsrocket_entryBase element for each rocket in the progress list
    rocket_infoRegisters the rocket infodata_labelData label which contains a name and a value label pair
    rocket_list_containerMain gui container for the left flow
    toggle_left_elementButton on the top flow used to toggle the container
    @@ -379,8 +386,8 @@
    - # - config.rockets + # + config.gui.rockets
    @@ -404,33 +411,8 @@
    - # - expcore.common -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - resources.color_presets + # + utils.color_presets
    @@ -469,6 +451,31 @@ + + + + + + +
    +
    +
    +
    + # + expcore.common +
    +
    +
    +
    + + + + + + + + + @@ -482,14 +489,14 @@
    - # - zoom_to_map + # + toggle_launch
    -

    Used on the name label to allow zoom to map

    +

    Button to toggle the auto launch on a rocket silo

    @@ -516,7 +523,7 @@
    -

    Used to launch the rocket, when it is ready

    +

    Button to remotely launch a rocket from a silo

    @@ -536,14 +543,14 @@
    - # - toggle_rocket + # + silo_cords
    -

    Used to toggle the auto launch on a rocket

    +

    XY cords that allow zoom to map when pressed

    @@ -563,14 +570,14 @@
    - # - toggle_section + # + rocket_entry
    -

    Used to toggle the visibility of the different sections

    +

    Base element for each rocket in the progress list

    @@ -590,14 +597,68 @@
    - # - rocket_info + # + data_label
    -

    Registers the rocket info

    +

    Data label which contains a name and a value label pair

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + rocket_list_container +
    +
    +
    +
    + +

    Main gui container for the left flow

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + toggle_left_element +
    +
    +
    +
    + +

    Button on the top flow used to toggle the container

    @@ -629,7 +690,7 @@ generated by LDoc
    diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 5d2fbcd2..3b409eb2 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -51,8 +51,10 @@

    Guis

    @@ -62,13 +64,13 @@ @@ -97,10 +99,12 @@ + + @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -253,14 +252,14 @@ utils.event - expcore.common - - - config.science + config.gui.science modules.control.production + + expcore.common + @@ -282,7 +281,7 @@ - + @@ -372,33 +371,8 @@
    - # - expcore.common -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - config.science + # + config.gui.science
    @@ -437,6 +411,31 @@ + + + + + + +
    +
    +
    +
    + # + expcore.common +
    +
    +
    +
    + + + + + + + + + @@ -531,8 +530,8 @@
    - # - task_list_toggle + # + toggle_left_element
    @@ -570,7 +569,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 8e546493..c9d42c26 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -51,8 +51,10 @@

    Guis

    @@ -62,13 +64,13 @@ @@ -97,10 +99,12 @@ + + @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -224,7 +223,7 @@

    Task-List gui

    Gui Module - Task List - - Adds a task list to the game which players can add remove and edit items on

    + - Adds a task list to the game which players can add, remove and edit items on

    @@ -253,14 +252,14 @@
    - - - - + + + +
    Main task list container for the left flow
    task_list_toggletoggle_left_element Button on the top flow used to toggle the task list container
    expcore.roles
    config.tasks
    expcore.commonconfig.gui.tasks
    modules.control.tasks
    expcore.common
    @@ -306,7 +305,7 @@ - + @@ -396,33 +395,8 @@
    - # - config.tasks -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.common + # + config.gui.tasks
    @@ -461,6 +435,31 @@ + + + + + + +
    +
    +
    +
    + # + expcore.common +
    +
    +
    +
    + + + + + + + + + @@ -717,8 +716,8 @@
    - # - task_list_toggle + # + toggle_left_element
    @@ -756,7 +755,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 2f4ac049..0eaf7808 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -51,8 +51,10 @@

    Guis

    @@ -62,13 +64,13 @@ @@ -97,10 +99,12 @@ + + @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -262,17 +261,17 @@
    - + - - - - + + + +
    Main task list container for the left flow
    task_list_toggletoggle_left_element Button on the top flow used to toggle the task list container
    expcore.roles
    resources.color_presetsutils.color_presets
    config.warps
    expcore.commonconfig.gui.warps
    modules.control.warps
    expcore.common
    @@ -495,8 +494,8 @@
    - # - resources.color_presets + # + utils.color_presets
    @@ -520,33 +519,8 @@
    - # - config.warps -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.common + # + config.gui.warps
    @@ -585,6 +559,31 @@ + + + + + + +
    +
    +
    +
    + # + expcore.common +
    +
    +
    +
    + + + + + + + + + @@ -961,7 +960,7 @@ generated by LDoc
    diff --git a/docs/guis/server-ups.html b/docs/guis/server-ups.html new file mode 100644 index 00000000..3acdff7b --- /dev/null +++ b/docs/guis/server-ups.html @@ -0,0 +1,444 @@ + + + + + + + + server-ups gui + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    server-ups gui

    +

    Gui Module - Server UPS + - Adds a server ups counter in the top right and a command to toggle is

    +

    + + + + + + + + + + + +
    + +

    Dependencies

    + + + + + + + + + + + + + +
    expcore.gui
    utils.event
    expcore.commands
    + + +

    Elements

    + + + + + + + + +
    server_upsLabel to show the server ups
    + + +

    Commands

    + + + + + + + + +
    server-upsToggles if the server ups is visbile
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + expcore.gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + expcore.commands +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Elements

    +
    +
    +
    +
    + # + server_ups +
    +
    +
    +
    + +

    Label to show the server ups

    +

    + + + + + + + + + + + + + + +
    +
    +

    Commands

    +
    +
    +
    +
    + # + server-ups +
    +
    +
    +
    + +

    Toggles if the server ups is visbile

    +

    + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + diff --git a/docs/index.html b/docs/index.html index 2b553d42..266d509e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -45,39 +45,39 @@

    Core

    - - + + - - + + + + + + +- Used to simplify gui creation using factory functions called element defines - + +- Permission group making for factorio so you never have to make one by hand again +- Factorio role system to manage custom permissions. - - - -
    CommandsCore Module - Commands - - Factorio command making module that makes commands with better parse and more modularityAsyncCore Module - Async +- An extention of task and token to allow a single require to register and run async functions.
    Common-LibraryCore Module - Common Library - - Adds some commonly used functions used in many modulesCommandsCore Module - Commands +- Factorio command making module that makes commands with better parse and more modularity
    CommonCore Module - Common +- Adds some commonly used functions used in many modules
    Gui Core Module - Gui -- Used to define new gui elements and gui event handlers
    Permissions-GroupsGroups Core Module - Permission Groups - - Permission group making for factorio so you never have to make one by hand again
    Roles Core Module - Roles - - Factorio role system to manage custom permissions.
    Store Core Module - Store - Used to store and watch for updates for values in the global table
    SudoCore Module - Sudo - - An extention of task and token to allow a single require to register and run functions bypassing all permissions.

    Control

    @@ -151,6 +151,10 @@ Sends alert messages to our discord server when certain events are triggered + greetings + Greets players on join + + Pollution-Grading Makes polution look much nice of the map, ie not one big red mess @@ -166,13 +170,22 @@ Spawn-Area Adds a custom spawn area with chests and afk turrets + + Tree-Decon + Makes trees which are marked for decon "decay" quickly to allow faster building +

    Guis

    + - Adds a player list to show names and play time; also includes action buttons which can preform actions to players + + + + @@ -185,9 +198,14 @@ - Adds a science info gui that shows production usage and net for the different science packs as well as an eta + + + + + - Adds a task list to the game which players can add, remove and edit items on @@ -306,14 +324,6 @@ to stop a file from loading add "--" in front of it, remove the "--" to have the file be loaded; config files should be loaded after all modules are loaded; core files should be required by modules and not be present in this list; - - - - @@ -350,11 +360,6 @@ - - - - @@ -367,6 +372,11 @@ see ./expcore/commands.lua for more details + + + + @@ -374,6 +384,34 @@ see ./expcore/commands.lua for more details start with Permission_Groups.new_group('name'); then use either :allow_all() or :disallow_all() to set the default for non specified actions; then use :allow{} and :disallow{} to specify certain actions to allow/disallow + + + + + + + + + + + + + + + + + + + + + + + + @@ -392,18 +430,6 @@ see ./expcore/commands.lua for more details - - - - - - - - - - - - @@ -412,17 +438,9 @@ see ./expcore/commands.lua for more details - - - - - - - -
    Player-List Gui Module - Player List - - Adds a player list to show names and play time; also includes action buttons which can apply to players
    ReadmeGui Module - Readme + - Adds a main gui that contains lots of important information about our server
    Rocket-Info
    server-upsGui Module - Server UPS + - Adds a server ups counter in the top right and a command to toggle is
    Task-List Gui Module - Task List - - Adds a task list to the game which players can add remove and edit items on
    Warps-List
    Player-ListConfig for the different action buttons that show on the player list; - each button has the button define(s) given along side an auth function, and optional reason callback; - if a reason callback is used then Store.set(action_name_store,player.name,'BUTTON_NAME') should be called during on_click; - buttons can be removed from the gui by commenting them out of the config at the bottom of this file; - the key used for the name of the button is the permission name used by the role system;
    Advanced-Start
    Commands-Auth-Roles This will make commands only work if the role has been allowed it in the role config
    Commands-Auth-Runtime-DisableThis config for command auth allows commands to be globally enabled and disabled during runtime; - this config adds Commands.disable and Commands.enable to enable and disable commands for all users
    Commands-Parse
    Commands-Parse-Roles Adds some parse functions that can be used with the role system
    Commands-Auth-Runtime-DisableThis config for command auth allows commands to be globally enabled and disabled during runtime; + this config adds Commands.disable and Commands.enable to enable and disable commands for all users
    Permission-Groups
    RolesThis is the main config file for the role system; file includes defines for roles and role flags and default values
    Player-ListConfig for the different action buttons that show on the player list; + each button has the button define(s) given along side an auth function, and optional reason callback; + if a reason callback is used then Store.set(action_name_store,player.name,'BUTTON_NAME') should be called during on_click; + buttons can be removed from the gui by commenting them out of the config at the bottom of this file; + the key used for the name of the button is the permission name used by the role system;
    RocketsThis file controls what will show in each section of the rocket info gui
    ScienceConfig file for the science info gui
    TasksConfig file for the tasks gui
    WarpsThis file contains all the different settings for the warp system and gui
    Pollution-Grading Config file for the repair command
    RocketsThis file controls what will show in each section of the rocket info gui
    RolesThis is the main config file for the role system; file includes defines for roles and role flags and default values
    ScienceConfig file for the science info gui
    Scorched-Earth This file controls the placement/degrading of tiles as players build and walk
    Used to config the spawn generation settings yes there is alot here i know just ignore the long tables at the end (they were generated with a command)
    TasksConfig file for the tasks gui
    Warnings Config file for the warning system, this is very similar to reports but is for the use of moderators rather than normal users.
    WarpsThis file contains all the different settings for the warp system and gui

    Modules

    @@ -434,21 +452,20 @@ see ./expcore/commands.lua for more details this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development - - + + - - + - + + - - + + @@ -459,30 +476,9 @@ see ./expcore/commands.lua for more details - - - - - - - - - - - - - - - - - - - -
    utils.alien_evolution_progressinfo - Original (javascript) version: https://hastebin.com/udakacavap.js - Can be tested against: https://wiki.factorio.com/Enemies#Spawn_chances_by_evolution_factormodules.addons.station-auto-nameLuaPlayerBuiltEntityEventFilters +Events.set_event_filter(defines.events.on_built_entity, {{filter = "name", name = "fast-inserter"}})
    utils.coreThis file contains core utilities used by the redmew scenario.overrides.debug
    utils.debugoverrides.mathTakes two points and calculates the slope of a line
    utils.dump_envA small debugging tool that writes the contents of _ENV to a file when the game loads.overrides.tableSearches a table to remove a specific element without an index
    utils.event Do not use this function, use Event.add instead as it has safety checks.
    utils.mathTakes two points and calculates the slope of a line
    utils.recipe_lockerA module to prevent recipes from being unlocked by research.
    utils.state_machineThis module provides a classical mealy/moore state machine.
    utils.tableSearches a table to remove a specific element without an index
    utils.task Threading simulation module Task.sleep()
    utils.timestampsource https://github.com/daurnimator/luatz/blob/master/luatz/timetable.lua - edited down to just what is needed.

    Topics

    @@ -511,7 +507,7 @@ see ./expcore/commands.lua for more details generated by LDoc diff --git a/docs/modules/Gui.html b/docs/modules/Gui.html index 7f2d9a40..4ff9023c 100644 --- a/docs/modules/Gui.html +++ b/docs/modules/Gui.html @@ -41,7 +41,16 @@ @@ -51,18 +60,13 @@ @@ -70,12 +74,26 @@ + + @@ -90,10 +108,26 @@ + + + + + + @@ -126,36 +160,9 @@ - - @@ -201,7 +209,16 @@ @@ -221,7 +238,8 @@

    Gui module

    -

    Core Module - Gui

    +

    Core Module - Gui +- Gui defines that are used internally by the gui system

    @@ -236,17 +254,329 @@ -

    Functions

    +

    Dependencies

    - - + - - + + + + + + + + + +
    on_custom_event(handler)Adds a custom event handler, replace with the name of the eventutils.event
    set_custom_property(value)Sets a new value for a property, triggers setter method if provided, replace with property namemod-gui
    utils.event
    mod-gui
    + + +

    Tables

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    eventsString indexed table used to avoid conflict with custom event names, similar to how defines.events works
    definesUid indexed array that stores all the factory functions that were defined, no new values will be added during runtime
    core_definesAn string indexed table of all the defines which are used by the core of the gui system, used for internal refrence
    file_pathsUsed to store the file names where elements were defined, this can be useful to find the uid of an element, mostly for debuging
    debug_infoUsed to store extra infomation about elements as they get defined such as the params used and event handlers registered to them
    _prototype_elementThe prototype used to store the functions of an element define
    _mt_elementThe prototype metatable applied to new element defines
    + + +

    Fields

    + + + + + + + + +
    uidThe current highest uid that is being used by a define, will not increase during runtime
    + + +

    Core Defines

    + + + + + + + + + + + + + + + + +
    hide_top_flowButton which toggles the top flow elements, version which shows inside the top flow when top flow is visible
    show_top_flowButton which toggles the top flow elements, version which shows inside the left flow when top flow is hidden
    hide_left_flowButton which hides the elements in the left flow, shows inside the left flow when frames are visible
    + + +

    Defines

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    alignmentDraw a flow used to align its child elements, default is right align
    scroll_tableDraw a scroll pane that has a table inside of it
    headerUsed to add a frame with the header style, has the option for a right alignment flow for buttons
    footerUsed to add a frame with the footer style, has the option for a right alignment flow for buttons
    containerUsed for left frames to give them a nice boarder
    barUsed to make a solid white bar in a gui
    centered_labelUsed to make a label which is centered and of a certian size
    title_labelUsed to make a title which has two bars on either side
    + + +

    Helper Functions

    + + + + + + + + + + + + + + + + + + + + + + + + +
    get_player_from_element(element)Get the player that owns a gui element
    toggle_enabled_state(element[, state])Will toggle the enabled state of an element or set it to the one given
    toggle_visible_state(element[, state])Will toggle the visible state of an element or set it to the one given
    destroy_if_valid(element)Destory a gui element without causing any errors, often because the element was already removed
    sprite_style(size[, padding=-2][, style])Returns a table to be used as the style for a sprite buttons, produces a sqaure button
    + + +

    Left Flow

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    left_elementsContains the uids of the elements that will shown on the left flow and their join functions
    get_left_flow(player)Gets the flow refered to as the left flow, each player has one left flow
    Gui._prototype_element:add_to_left_flow([open_on_join])Sets an element define to be drawn to the left flow when a player joins, includes optional check
    left_toolbar_button(sprite, tooltip, element_define[, authenticator])Creates a button on the top flow which will toggle the given element define, the define must exist in the left flow
    draw_left_flow(player)Draw all the left elements onto the left flow, internal use only with on join
    update_left_flow(player)Update the visible state of the hide button, can be used to check if any frames are visible
    hide_left_flow(player)Hides all left elements for a player
    get_left_element(player, element_define)Get the element define that is in the left flow, use in events without an element refrence
    toggle_left_element(player, element_define[, state])Toggles the visible state of a left element for a given player, can be used to set the visible state
    + + +

    Element Define

    + + + + + + + + + + + + + + + + + + + + +
    element(element_define)Used to define new elements for your gui, can be used like LuaGuiElement.add or a custom function
    Gui._prototype_element:style(style_define)Used to extent your element define with a style factory, this style will be applied to your element when created, can also be a custom function
    Gui._prototype_element:on_custom_event(event_name, handler)Set the handler which will be called for a custom event, only one handler can be used per event per element
    Gui._prototype_element:raise_custom_event(event)Raise the handler which is attached to an event; external use should be limited to custom events
    + + +

    Element Events

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Gui._prototype_element.on_openCalled when the player opens a GUI.
    Gui._prototype_element.on_closeCalled when the player closes the GUI they have open.
    Gui._prototype_element.on_clickCalled when LuaGuiElement is clicked.
    Gui._prototype_element.on_confirmedCalled when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield.
    Gui._prototype_element.on_checked_changedCalled when LuaGuiElement checked state is changed (related to checkboxes and radio buttons).
    Gui._prototype_element.on_elem_changedCalled when LuaGuiElement element value is changed (related to choose element buttons).
    Gui._prototype_element.on_location_changedCalled when LuaGuiElement element location is changed (related to frames in player.gui.screen).
    Gui._prototype_element.on_tab_changedCalled when LuaGuiElement selected tab is changed (related to tabbed-panes).
    Gui._prototype_element.on_selection_changedCalled when LuaGuiElement selection state is changed (related to drop-downs and listboxes).
    Gui._prototype_element.on_switch_changedCalled when LuaGuiElement switch state is changed (related to switches).
    Gui._prototype_element.on_text_changedCalled when LuaGuiElement text is changed by the player.
    Gui._prototype_element.on_value_changedCalled when LuaGuiElement slider value is changed (related to the slider element).
    + + +

    Top Flow

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    top_elementsContains the uids of the elements that will shown on the top flow and their auth functions
    top_flow_button_styleThe style that should be used for buttons on the top flow
    top_flow_button_visible_styleThe style that should be used for buttons on the top flow when their flow is visible
    get_top_flow(player)Gets the flow refered to as the top flow, each player has one top flow
    Gui._prototype_element:add_to_top_flow([authenticator])Sets an element define to be drawn to the top flow when a player joins, includes optional authenticator
    update_top_flow(player)Updates the visible state of all the elements on the players top flow, uses authenticator
    toggle_top_flow(player[, state])Toggles the visible state of all the elements on a players top flow, effects all elements
    get_top_element(player, element_define)Get the element define that is in the top flow, use in events without an element refrence
    toolbar_button(sprite, tooltip[, authenticator])Creates a button on the top flow with consistent styling
    toolbar_button_style(button, state)Styles a top flow button depending on the state given
    @@ -255,56 +585,23 @@
    -

    Functions

    +

    Dependencies

    - # - on_custom_event(handler) + # + utils.event
    -

    Adds a custom event handler, replace with the name of the event

    -

    - Parameters: - -
      - - - - - -
    • - - handler - - : - - (function) - - the function which will recive the event - -
    • - - -
    - - Returns: -
      -
    • - (GuiConcept) - to allow chaing of functions -[[@usage -
    • -
    @@ -318,14 +615,1256 @@
    - # - set_custom_property(value) + # + mod-gui
    -

    Sets a new value for a property, triggers setter method if provided, replace with property name

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +
    +
    + # + mod-gui +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Tables

    +
    +
    +
    +
    + # + events +
    +
    +
    +
    + +

    String indexed table used to avoid conflict with custom event names, similar to how defines.events works

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + defines +
    +
    +
    +
    + +

    Uid indexed array that stores all the factory functions that were defined, no new values will be added during runtime

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + core_defines +
    +
    +
    +
    + +

    An string indexed table of all the defines which are used by the core of the gui system, used for internal refrence

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + file_paths +
    +
    +
    +
    + +

    Used to store the file names where elements were defined, this can be useful to find the uid of an element, mostly for debuging

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + debug_info +
    +
    +
    +
    + +

    Used to store extra infomation about elements as they get defined such as the params used and event handlers registered to them

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + _prototype_element +
    +
    +
    +
    + +

    The prototype used to store the functions of an element define

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + _mt_element +
    +
    +
    +
    + +

    The prototype metatable applied to new element defines

    +

    + + + Fields: + +
      + + + + + +
    • + + __call + + + + + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +

    Fields

    +
    +
    +
    +
    + # + uid +
    +
    +
    +
    + +

    The current highest uid that is being used by a define, will not increase during runtime

    +

    + + + +
      + + + + + +
    • + + uid + + + + + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +

    Core Defines

    +
    +
    +
    +
    + # + hide_top_flow +
    +
    +
    +
    + +

    Button which toggles the top flow elements, version which shows inside the top flow when top flow is visible

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + show_top_flow +
    +
    +
    +
    + +

    Button which toggles the top flow elements, version which shows inside the left flow when top flow is hidden

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + hide_left_flow +
    +
    +
    +
    + +

    Button which hides the elements in the left flow, shows inside the left flow when frames are visible

    +

    + + + + + + + + + + + + + + +
    +
    +

    Defines

    +
    +
    +
    +
    + # + alignment +
    +
    +
    +
    + +

    Draw a flow used to align its child elements, default is right align

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the alignment will be added + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the alignment flow which is added + + (default: 'alignment') +
    • + + + + + +
    • + + horizontal_align + + : + + (string) + + the horizontal alignment of the elements in the flow + + (default: 'right') +
    • + + + + + +
    • + + vertical_align + + : + + (string) + + the vertical alignment of the elements in the flow + + (default: 'center') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a right align flow
    +local alignment = Gui.alignment(element,'example_right_alignment')
    +
    -- Adding a horizontal center and top align flow
    +local alignment = Gui.alignment(element,'example_center_top_alignment','center','top')
    + + +
    +
    +
    +
    + # + scroll_table +
    +
    +
    +
    + +

    Draw a scroll pane that has a table inside of it

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the scroll table will be added + +
    • + + + + + +
    • + + height + + : + + (number) + + the maximum height for the scroll pane + +
    • + + + + + +
    • + + column_count + + : + + (number) + + the number of columns that the table will have + +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the scroll pane that is added, the table is always called "table" + + (default: 'scroll') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a scroll table with max height of 200 and column count of 3
    +local scroll_table = Gui.scroll_table(element,200,3)
    + + +
    +
    +
    +
    + # + header +
    +
    +
    +
    + +

    Used to add a frame with the header style, has the option for a right alignment flow for buttons

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the header will be added + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the header + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the header + + (optional) +
    • + + + + + +
    • + + add_alignment + + : + + (boolean) + + when true an alignment flow will be added to the header + + (default: false) +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the header that is being added, the alignment is always called "alignment" + + (default: 'header') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a custom header with a label
    +local header = Gui.header(
    +    element,
    +    'Example Caption',
    +    'Example Tooltip'
    +)
    + + +
    +
    +
    +
    + # + footer +
    +
    +
    +
    + +

    Used to add a frame with the footer style, has the option for a right alignment flow for buttons

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the footer will be added + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the footer + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the footer + + (optional) +
    • + + + + + +
    • + + add_alignment + + : + + (boolean) + + when true an alignment flow will be added to the footer + + (default: false) +
    • + + + + + +
    • + + name + + : + + (string) + + the name of the footer that is being added, the alignment is always called "alignment" + + (default: 'footer') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a custom footer with a label
    +local footer = Gui.footer(
    +    element,
    +    'Example Caption',
    +    'Example Tooltip'
    +)
    + + +
    +
    +
    +
    + # + container +
    +
    +
    +
    + +

    Used for left frames to give them a nice boarder

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the container will be added + +
    • + + + + + +
    • + + name + + : + + (string) + + the name that you want to give to the outer frame, often just event_trigger + +
    • + + + + + +
    • + + width + + : + + (number) + + the minimal width that the frame will have + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a container as a base
    +local container = Gui.container(parent,'my_container',200)
    + + +
    +
    +
    +
    + # + bar +
    +
    +
    +
    + +

    Used to make a solid white bar in a gui

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the bar will be added + +
    • + + + + + +
    • + + width + + : + + (number) + + the width of the bar that will be made, if not given bar will strech to fill the parent + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a bar to a gui
    +local bar = Gui.bar(parent, 100)
    + + +
    +
    +
    +
    + # + centered_label +
    +
    +
    +
    + +

    Used to make a label which is centered and of a certian size

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the label will be added + +
    • + + + + + +
    • + + width + + : + + (number) + + the width of the label, must be given in order to center the caption + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the label + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the label + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a centered label
    +local label = Gui.centered_label(parent, 100, 'This is centered')
    + + +
    +
    +
    +
    + # + title_label +
    +
    +
    +
    + +

    Used to make a title which has two bars on either side

    +

    + + + Properties / Events: + +
      + + + + + +
    • + + parent + + : + + (LuaGuiElement) + + the parent element to which the label will be added + +
    • + + + + + +
    • + + width + + : + + (number) + + the width of the first bar, this can be used to position the label + +
    • + + + + + +
    • + + caption + + : + + (string or LocalizedString) + + the caption that will be shown on the label + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that will be shown on the label + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a centered label
    +local label = Gui.centered_label(parent, 100, 'This is centered')
    + + +
    +
    +

    Helper Functions

    +
    +
    +
    +
    + # + get_player_from_element(element) +
    +
    +
    +
    + +

    Get the player that owns a gui element

    @@ -339,13 +1878,13 @@
  • - value + element : - (any) + (LuaGuiElement) - the value that you want to set for this property + the element to get the owner of
  • @@ -358,9 +1897,8 @@ Returns:
    • - (GuiConcept) - to allow chaing of functions -[[@usage + (LuaPlayer) + the player that owns this element
    @@ -370,6 +1908,2404 @@ + Usage: +
    -- Geting the owner of an element
    +local player = Gui.get_player_from_element(element)
    + + +
    +
    +
    +
    + # + toggle_enabled_state(element[, state]) +
    +
    +
    +
    + +

    Will toggle the enabled state of an element or set it to the one given

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to toggle/set the enabled state of + +
    • + + + + + +
    • + + state + + : + + (boolean) + + with given will set the state, else state will be toggled + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new enabled state that the element has +
    • +
    + + + + + + + + Usage: +
    -- Toggling the the enabled state
    +local new_enabled_state = Gui.toggle_enabled_state(element)
    + + +
    +
    +
    +
    + # + toggle_visible_state(element[, state]) +
    +
    +
    +
    + +

    Will toggle the visible state of an element or set it to the one given

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element to toggle/set the visible state of + +
    • + + + + + +
    • + + state + + : + + (boolean) + + with given will set the state, else state will be toggled + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new visible state that the element has +
    • +
    + + + + + + + + Usage: +
    -- Toggling the the visible state
    +local new_visible_state = Gui.toggle_visible_state(element)
    + + +
    +
    +
    +
    + # + destroy_if_valid(element) +
    +
    +
    +
    + +

    Destory a gui element without causing any errors, often because the element was already removed

    +

    + + + Parameters: + +
      + + + + + +
    • + + element + + : + + (LuaGuiElement) + + the element that you want to remove + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the element was valid and has been removed +
    • +
    + + + + + + + + Usage: +
    -- Remove a child element if it exists
    +Gui.destroy_if_valid(element[child_name])
    + + +
    +
    +
    +
    + # + sprite_style(size[, padding=-2][, style]) +
    +
    +
    +
    + +

    Returns a table to be used as the style for a sprite buttons, produces a sqaure button

    +

    + + + Parameters: + +
      + + + + + +
    • + + size + + : + + (number) + + the size that you want the button to be + +
    • + + + + + +
    • + + padding + + : + + (number) + + the padding that you want on the sprite + + (default: -2) +
    • + + + + + +
    • + + style + + : + + (table) + + any extra style settings that you want to have + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the style table to be used with element_define:style() +
    • +
    + + + + + + + + Usage: +
    -- Adding a sprite button with size 20
    +local button =
    +Gui.element{
    +    type = 'sprite-button',
    +    sprite = 'entity/inserter'
    +}
    +:style(Gui.sprite_style(20))
    + + +
    +
    +

    Left Flow

    +
    +
    +
    +
    + # + left_elements +
    +
    +
    +
    + +

    Contains the uids of the elements that will shown on the left flow and their join functions

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + get_left_flow(player) +
    +
    +
    +
    + +

    Gets the flow refered to as the left flow, each player has one left flow

    +

    (player)

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the left flow for + +
    • + + +
    + + + + + Returns: + + + + + + + + + Usage: +
    -- Geting your left flow
    +local left_flow = Gui.get_left_flow(game.player)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:add_to_left_flow([open_on_join]) +
    +
    +
    +
    + +

    Sets an element define to be drawn to the left flow when a player joins, includes optional check

    +

    + + + Parameters: + +
      + + + + + +
    • + + open_on_join + + : + + (boolean or function) + + called during first darw to decide if the element should be visible + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new element define that is used to register events to this element +
    • +
    + + + + + + + + Usage: +
    -- Adding the example button
    +example_flow_with_button:add_to_left_flow(true)
    + + +
    +
    +
    +
    + # + left_toolbar_button(sprite, tooltip, element_define[, authenticator]) +
    +
    +
    +
    + +

    Creates a button on the top flow which will toggle the given element define, the define must exist in the left flow

    +

    + + + Parameters: + +
      + + + + + +
    • + + sprite + + : + + (string) + + the sprite that you want to use on the button + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that you want the button to have + +
    • + + + + + +
    • + + element_define + + : + + (table) + + the element define that you want to have toggled by this button, define must exist on the left flow + +
    • + + + + + +
    • + + authenticator + + : + + (function) + + used to decide if the button should be visible to a player + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Add a button to toggle a left element
    +local toolbar_button =
    +Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', example_flow_with_button, function(player)
    +    return player.admin
    +end)
    + + +
    +
    +
    +
    + # + draw_left_flow(player) +
    +
    +
    +
    + +

    Draw all the left elements onto the left flow, internal use only with on join

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to draw the elements for + +
    • + + +
    + + + + + + + + + + + + Usage: +
     Draw all the left elements
    +Gui.draw_left_flow(player)
    + + +
    +
    +
    +
    + # + update_left_flow(player) +
    +
    +
    +
    + +

    Update the visible state of the hide button, can be used to check if any frames are visible

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to update the left flow for + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if any left element is visible +
    • +
    + + + + + + + + Usage: +
    -- Check if any left elements are visible
    +local visible = Gui.update_left_flow(player)
    + + +
    +
    +
    +
    + # + hide_left_flow(player) +
    +
    +
    +
    + +

    Hides all left elements for a player

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player to hide the elements for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Hide your left elements
    +Gui.hide_left_flow(game.player)
    + + +
    +
    +
    +
    + # + get_left_element(player, element_define) +
    +
    +
    +
    + +

    Get the element define that is in the left flow, use in events without an element refrence

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the element for + +
    • + + + + + +
    • + + element_define + + : + + (table) + + the element that you want to get + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the gui element linked to this define for this player +
    • +
    + + + + + + + + Usage: +
    -- Get your left element
    +local frame = Gui.get_left_element(game.player, example_flow_with_button)
    + + +
    +
    +
    +
    + # + toggle_left_element(player, element_define[, state]) +
    +
    +
    +
    + +

    Toggles the visible state of a left element for a given player, can be used to set the visible state

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to toggle the element for + +
    • + + + + + +
    • + + element_define + + : + + (table) + + the element that you want to toggle + +
    • + + + + + +
    • + + state + + : + + (boolean) + + with given will set the state, else state will be toggled + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new visible state of the element +
    • +
    + + + + + + + + Usage: +
    -- Toggle your example button
    +Gui.toggle_top_flow(game.player, example_flow_with_button)
    +
    -- Show your example button
    +Gui.toggle_top_flow(game.player, example_flow_with_button, true)
    + + +
    +
    +

    Element Define

    +
    +
    +
    +
    + # + element(element_define) +
    +
    +
    +
    + +

    Used to define new elements for your gui, can be used like LuaGuiElement.add or a custom function

    +

    + + + Parameters: + +
      + + + + + +
    • + + element_define + + : + + (table or function) + + the define information for the gui element, same data as LuaGuiElement.add, or a custom function may be used + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new element define, this can be considered a factory for the element which can be called to draw the element to any other element +
    • +
    + + + + + + + + Usage: +
    -- Using element defines like LuaGuiElement.add
    +-- This returns a factory function to draw a button with the caption "Example Button"
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button'
    +}
    +
    -- Using element defines with a custom factory function
    +-- This method can be used if you still want to be able register event handlers but it is too complex to be compatible with LuaGuiElement.add
    +local example_flow_with_button =
    +Gui.element(function(event_trigger,parent,...)
    +    -- ... shows that all other arguments from the factory call are passed to this function
    +    -- parent is the element which was passed to the factory function where you should add your new element
    +    -- here we are adding a flow which we will then later add a button to
    +    local flow =
    +    parent.add{
    +        name = 'example_flow',
    +        type = 'flow'
    +    }
    +
    +    -- event_trigger should be the name of any elements you want to trigger your event handlers, such as on_click or on_state_changed
    +    -- now we add the button to the flow that we created earlier
    +    local element =
    +    flow.add{
    +        name = event_trigger,
    +        type = 'button',
    +        caption = 'Example Button'
    +    }
    +
    +    -- you must return your new element, this is so styles can be applied and returned to the caller
    +    -- you may return any of your elements that you add, consider the context in which it will be used for what should be returned
    +    return element
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:style(style_define) +
    +
    +
    +
    + +

    Used to extent your element define with a style factory, this style will be applied to your element when created, can also be a custom function

    +

    + + + Parameters: + +
      + + + + + +
    • + + style_define + + : + + (table or function) + + style table where each key and value pair is treated like LuaGuiElement.style[key] = value, a custom function can be used + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define is returned to allow for event handlers to be registered +
    • +
    + + + + + + + + Usage: +
    -- Using the table method of setting the style
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button',
    +    style = 'forward_button' -- factorio styles can be applied here
    +}
    +:style{
    +    height = 25, -- same as element.style.height = 25
    +    width = 100 -- same as element.style.width = 25
    +}
    +
    -- Using the function method to set the style
    +-- Use this method if your style is dynamic and depends on other factors
    +local example_button =
    +Gui.element{
    +    type = 'button',
    +    caption = 'Example Button',
    +    style = 'forward_button' -- factorio styles can be applied here
    +}
    +:style(function(style,element,...)
    +    -- style is the current style object for the elemenent
    +    -- element is the element that is being changed
    +    -- ... shows that all other arguments from the factory call are passed to this function
    +    local player = game.players[element.player_index]
    +    style.height = 25
    +    style.width = 100
    +    style.font_color = player.color
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:on_custom_event(event_name, handler) +
    +
    +
    +
    + +

    Set the handler which will be called for a custom event, only one handler can be used per event per element

    +

    + + + Parameters: + +
      + + + + + +
    • + + event_name + + : + + (string) + + the name of the event you want to handler to be called on, often from Gui.events + +
    • + + + + + +
    • + + handler + + : + + (function) + + the handler that you want to be called when the event is raised + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define so more handleres can be registered +
    • +
    + + + + + + + + Usage: +
    -- Register a handler to "my_custom_event" for this element
    +element_deinfe:on_custom_event('my_custom_event', function(event)
    +    event.player.print(player.name)
    +end)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:raise_custom_event(event) +
    +
    +
    +
    + +

    Raise the handler which is attached to an event; external use should be limited to custom events

    +

    + + + Parameters: + +
      + + + + + +
    • + + event + + : + + (table) + + the event table passed to the handler, must contain fields: name, element + +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the element define so more events can be raised +
    • +
    + + + + + + + + Usage: +
     Raising a custom event
    +element_define:raise_custom_event{
    +    name = 'my_custom_event',
    +    element = element
    +}
    + + +
    +
    +

    Element Events

    +
    +
    +
    +
    + # + Gui._prototype_element.on_open +
    +
    +
    +
    + +

    Called when the player opens a GUI.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_close +
    +
    +
    +
    + +

    Called when the player closes the GUI they have open.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_click +
    +
    +
    +
    + +

    Called when LuaGuiElement is clicked.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_confirmed +
    +
    +
    +
    + +

    Called when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_checked_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_elem_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement element value is changed (related to choose element buttons).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_location_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement element location is changed (related to frames in player.gui.screen).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_tab_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement selected tab is changed (related to tabbed-panes).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_selection_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement selection state is changed (related to drop-downs and listboxes).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_switch_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement switch state is changed (related to switches).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_text_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement text is changed by the player.

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Gui._prototype_element.on_value_changed +
    +
    +
    +
    + +

    Called when LuaGuiElement slider value is changed (related to the slider element).

    +

    + + + +
      + + + + + +
    • + + handler + + : + + (function) + + the event handler which will be called + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +

    Top Flow

    +
    +
    +
    +
    + # + top_elements +
    +
    +
    +
    + +

    Contains the uids of the elements that will shown on the top flow and their auth functions

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + top_flow_button_style +
    +
    +
    +
    + +

    The style that should be used for buttons on the top flow

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + top_flow_button_visible_style +
    +
    +
    +
    + +

    The style that should be used for buttons on the top flow when their flow is visible

    +

    + + + + + + + + + + + + + + +
    +
    +
    +
    + # + get_top_flow(player) +
    +
    +
    +
    + +

    Gets the flow refered to as the top flow, each player has one top flow

    +

    (player)

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the flow for + +
    • + + +
    + + + + + Returns: + + + + + + + + + Usage: +
    -- Geting your top flow
    +local top_flow = Gui.get_top_flow(game.player)
    + + +
    +
    +
    +
    + # + Gui._prototype_element:add_to_top_flow([authenticator]) +
    +
    +
    +
    + +

    Sets an element define to be drawn to the top flow when a player joins, includes optional authenticator

    +

    + + + Parameters: + +
      + + + + + +
    • + + authenticator + + : + + (function) + + called during toggle or update to decide weather the element should be visible + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (table) + the new element define to allow event handlers to be registered +
    • +
    + + + + + + + + Usage: +
    -- Adding an element to the top flow on join
    +example_button:add_to_top_flow(function(player)
    +    -- example button will only be shown if the player is an admin
    +    -- note button will not update its state when player.admin is changed Gui.update_top_flow must be called for this
    +    return player.admin
    +end)
    + + +
    +
    +
    +
    + # + update_top_flow(player) +
    +
    +
    +
    + +

    Updates the visible state of all the elements on the players top flow, uses authenticator

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to update the top flow for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Update your top flow
    +Gui.update_top_flow(game.player)
    + + +
    +
    +
    +
    + # + toggle_top_flow(player[, state]) +
    +
    +
    +
    + +

    Toggles the visible state of all the elements on a players top flow, effects all elements

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to toggle the top flow for + +
    • + + + + + +
    • + + state + + : + + (boolean) + + if given then the state will be set to this + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + the new visible state of the top flow +
    • +
    + + + + + + + + Usage: +
    -- Toggle your flow
    +Gui.toggle_top_flow(game.player)
    +
    -- Open your top flow
    +Gui.toggle_top_flow(game.player,true)
    + + +
    +
    +
    +
    + # + get_top_element(player, element_define) +
    +
    +
    +
    + +

    Get the element define that is in the top flow, use in events without an element refrence

    +

    + + + Parameters: + +
      + + + + + +
    • + + player + + : + + (LuaPlayer) + + the player that you want to get the element for + +
    • + + + + + +
    • + + element_define + + : + + (table) + + the element that you want to get + +
    • + + +
    + + + + + Returns: +
      +
    • + (LuaGuiElement) + the gui element linked to this define for this player +
    • +
    + + + + + + + + Usage: +
    -- Get your top element
    +local button = Gui.get_top_element(game.player, example_button)
    + + +
    +
    +
    +
    + # + toolbar_button(sprite, tooltip[, authenticator]) +
    +
    +
    +
    + +

    Creates a button on the top flow with consistent styling

    +

    + + + Parameters: + +
      + + + + + +
    • + + sprite + + : + + (string) + + the sprite that you want to use on the button + +
    • + + + + + +
    • + + tooltip + + : + + (string or LocalizedString) + + the tooltip that you want the button to have + +
    • + + + + + +
    • + + authenticator + + : + + (function) + + used to decide if the button should be visible to a player + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Add a button to the toolbar
    +local toolbar_button =
    +Gui.left_toolbar_button('entity/inserter', 'Nothing to see here', function(player)
    +    return player.admin
    +end)
    + + +
    +
    +
    +
    + # + toolbar_button_style(button, state) +
    +
    +
    +
    + +

    Styles a top flow button depending on the state given

    +

    + + + Parameters: + +
      + + + + + +
    • + + button + + : + + (LuaGuiElement) + + the button element to style + +
    • + + + + + +
    • + + state + + : + + (boolean) + + The state the button is in + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Sets the button to the visible style
    +Gui.toolbar_button_style(button, true)
    +
    -- Sets the button to the hidden style
    +Gui.toolbar_button_style(button, false)
    @@ -388,7 +4324,7 @@ generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 4fc84050..3542b831 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -50,18 +50,13 @@

    Modules

    @@ -69,13 +64,13 @@ @@ -104,10 +99,12 @@ + + @@ -116,8 +113,10 @@

    Guis

    @@ -155,7 +154,6 @@

    Configs

    @@ -244,12 +243,6 @@ - utils.debug - - - expcore.common.ext_require - - config._file_loader @@ -264,56 +257,6 @@
    - # - utils.debug -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    - # - expcore.common.ext_require -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    -
    -
    -
    # config._file_loader
    @@ -351,7 +294,7 @@ generated by LDoc diff --git a/docs/modules/modules.addons.station-auto-name.html b/docs/modules/modules.addons.station-auto-name.html new file mode 100644 index 00000000..e5d0e142 --- /dev/null +++ b/docs/modules/modules.addons.station-auto-name.html @@ -0,0 +1,300 @@ + + + + + + + + modules.addons.station-auto-name module + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    modules.addons.station-auto-name module

    +

    LuaPlayerBuiltEntityEventFilters +Events.set_event_filter(defines.events.on_built_entity, {{filter = "name", name = "fast-inserter"}})

    +

    + + + + + + + + + + + + + +

    Dependencies

    + + + + + + + +
    utils.event
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + utils.event +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + diff --git a/docs/modules/overrides.debug.html b/docs/modules/overrides.debug.html new file mode 100644 index 00000000..3e5221fc --- /dev/null +++ b/docs/modules/overrides.debug.html @@ -0,0 +1,661 @@ + + + + + + + + overrides.debug module + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    overrides.debug module

    +

    +

    + + + + + + + + + + + + + +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Debug.print(message, trace_levels)Shows the given message if debug is enabled.
    Debug.get_meta_value(object, key)Returns the value of the key inside the object + or 'InvalidLuaObject' if the LuaObject is invalid.
    Debug.object_type(object)Returns the Lua data type or the factorio LuaObject type + or 'NoHelpLuaObject' if the LuaObject does not have a help function + or 'InvalidLuaObject' if the LuaObject is invalid.
    Debug.print_position(position, message)Shows the given message if debug is on.
    Debug.cheat(callback)Executes the given callback if cheating is enabled.
    Debug.is_closure(func)Returns true if the function is a closure, false otherwise.
    + + +
    + + +

    Functions

    +
    +
    +
    +
    + # + Debug.print(message, trace_levels) +
    +
    +
    +
    + +

    Shows the given message if debug is enabled.

    +

    Uses serpent to print non scalars.

    + + + Parameters: + +
      + + + + + +
    • + + message + + : + + + + +
    • + + + + + +
    • + + trace_levels + + : + + + levels of stack trace to give, defaults to 1 level if nil + +
    • + + +
    + + + + + + + + + + + + + +
    +
    +
    +
    + # + Debug.get_meta_value(object, key) +
    +
    +
    +
    + +

    Returns the value of the key inside the object + or 'InvalidLuaObject' if the LuaObject is invalid.

    +

    + or 'InvalidLuaObjectKey' if the LuaObject does not have an entry at that key

    + + + Parameters: + +
    +
    +
    + + + + diff --git a/docs/modules/overrides.table.html b/docs/modules/overrides.table.html new file mode 100644 index 00000000..20f2ea68 --- /dev/null +++ b/docs/modules/overrides.table.html @@ -0,0 +1,2015 @@ + + + + + + + + overrides.table module + + + + + + + +
    +
    + + + + + + + +
    + + + + + + + + +

    overrides.table module

    +

    Searches a table to remove a specific element without an index

    +

    + + + + + + + + + + + + + +

    Dependencies

    + + + + + + + +
    overrides.inspect
    + + +

    Functions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    remove_index(tbl, index)Removes an item from an array in O(1) time.
    merge_table(t1, t2)Adds the contents of table t2 to table t1
    array_insert(tbl[, start_index], values)Much faster method for inserting items into an array
    table_insert(tbl[, start_index], tbl2)Much faster method for inserting keys into a table
    get_key(t, e)Checks if a table contains an element
    get_index(t, e)Checks if the arrayed portion of a table contains an element
    contains(t, e)Checks if a table contains an element
    array_contains(t, e)Checks if the arrayed portion of a table contains an element
    extract_keys(tbl, ...)Extracts certain keys from a table
    set(t, index, element)Adds an element into a specific index position while shuffling the rest down
    get_random_dictionary_entry(t, key)Chooses a random entry from a table + because this uses math.random, it cannot be used outside of events
    get_random_weighted(weighted_table, item_index, weight_index)Chooses a random entry from a weighted table + because this uses math.random, it cannot be used outside of events
    clear_table(t, array)Clears all existing entries in a table
    shuffle_table(t, rng)Creates a fisher-yates shuffle of a sequential number-indexed table + because this uses math.random, it cannot be used outside of events if no rng is supplied + from: http://www.sdknews.com/cross-platform/corona/tutorial-how-to-shuffle-table-items
    get_values(tbl[, sorted][, as_string])Returns a copy of all of the values in the table.
    get_keys(tbl[, sorted][, as_string])Returns a copy of all of the keys in the table.
    alphanumsort(tbl)Returns the list is a sorted way that would be expected by people (this is by key)
    keysort(tbl)Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)
    + + +

    Fields

    + + + + + + + + + + + + + + + + + + + + + + + + +
    inspectSimilar to serpent.block, returns a string with a pretty representation of a table.
    sizeTakes a table and returns the number of entries in the table.
    deep_copyCreates a deepcopy of a table.
    mergeMerges multiple tables.
    equalsDetermines if two tables are structurally equal.
    + + +
    + + +

    Dependencies

    +
    +
    +
    +
    + # + overrides.inspect +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    +
    +

    Functions

    +
    +
    +
    +
    + # + remove_index(tbl, index) +
    +
    +
    +
    + +

    Removes an item from an array in O(1) time.

    +

    + The catch is that fast_remove doesn't guarantee to maintain the order of items in the array.

    + + + Parameters: + +
      + + + + + +
    • + + tbl + + : + + + arrayed table + + + + + + + +
    • + + index + + : + + + Must be >= 0. The case where index > #tbl is handled. + +
    • + + + + + + + + + + + + + + + + + +
      +
      +
      + # + merge_table(t1, t2) +
      +
      +
      +
      + +

      Adds the contents of table t2 to table t1

      +

      + + + Parameters: + +
        + + + + + +
      • + + t1 + + : + + +
      to insert into + + + + + + + +
    • + + t2 + + : + + +
    • to insert from + + + + + + + + + + + + + + + + + + + +
      +
      +
      + # + array_insert(tbl[, start_index], values) +
      +
      +
      +
      + +

      Much faster method for inserting items into an array

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + the table that will have the values added to it + +
      • + + + + + +
      • + + start_index + + : + + (number) + + the index at which values will be added, nil means end of the array + + (optional) +
      • + + + + + +
      • + + values + + : + + (table) + + the new values that will be added to the table + +
      • + + +
      + + + + + Returns: +
        +
      • + (table) + the table that was passed as the first argument +
      • +
      + + + + + + + + Usage: +
      -- Adding 1000 values into the middle of the array
      +local tbl = {}
      +local values = {}
      +for i = 1,1000 do tbl[i] = i values[i] = i end
      +table.array_insert(tbl,500,values) -- around 0.4ms
      + + +
      +
      +
      +
      + # + table_insert(tbl[, start_index], tbl2) +
      +
      +
      +
      + +

      Much faster method for inserting keys into a table

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + the table that will have keys added to it + +
      • + + + + + +
      • + + start_index + + : + + (number) + + the index at which values will be added, nil means end of the array, numbered indexs only + + (optional) +
      • + + + + + +
      • + + tbl2 + + : + + (table) + + the table that may contain both string and numbered keys + +
      • + + +
      + + + + + Returns: +
        +
      • + (table) + the table passed as the first argument +
      • +
      + + + + + + + + Usage: +
      -- Merging two tables
      +local tbl = {}
      +local tbl2 = {}
      +for i = 1,100 do tbl[i] = i tbl['_'..i] = i tbl2[i] = i tbl2['__'..i] = i end
      +table.table_insert(tbl,50,tbl2)
      + + +
      +
      +
      +
      + # + get_key(t, e) +
      +
      +
      +
      + +

      Checks if a table contains an element

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      + + + + + + + +
    • + + e + + : + + + table element + +
    • + + + + + + + + Returns: +
        +
      • + the index of the element or nil +
      • +
      + + + + + + + + + + +
      +
      +
      + # + get_index(t, e) +
      +
      +
      +
      + +

      Checks if the arrayed portion of a table contains an element

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      + + + + + + + +
    • + + e + + : + + + table element + +
    • + + + + + + + + Returns: +
        +
      • + the index of the element or nil +
      • +
      + + + + + + + + + + +
      +
      +
      + # + contains(t, e) +
      +
      +
      +
      + +

      Checks if a table contains an element

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      + + + + + + + +
    • + + e + + : + + + table element + +
    • + + + + + + + + Returns: +
        +
      • + indicating success +
      • +
      + + + + + + + + + + +
      +
      +
      + # + array_contains(t, e) +
      +
      +
      +
      + +

      Checks if the arrayed portion of a table contains an element

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      + + + + + + + +
    • + + e + + : + + + table element + +
    • + + + + + + + + Returns: +
        +
      • + indicating success +
      • +
      + + + + + + + + + + +
      +
      +
      + # + extract_keys(tbl, ...) +
      +
      +
      +
      + +

      Extracts certain keys from a table

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + table the which contains the keys + +
      • + + + + + +
      • + + ... + + : + + (string) + + the names of the keys you want extracted + +
      • + + +
      + + + + + Returns: +
        +
      • + the keys in the order given +
      • +
      + + + + + + + + Usage: +
      local key_three, key_one = extract({key_one='foo',key_two='bar',key_three=true},'key_three','key_one')
      + + +
      +
      +
      +
      + # + set(t, index, element) +
      +
      +
      +
      + +

      Adds an element into a specific index position while shuffling the rest down

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      to add into + + + + + + + +
    • + + index + + : + + + the position in the table to add to + +
    • + + + + + +
    • + + element + + : + + + to add to the table + +
    • + + + + + + + + + + + + + + + + + +
      +
      +
      + # + get_random_dictionary_entry(t, key) +
      +
      +
      +
      + +

      Chooses a random entry from a table + because this uses math.random, it cannot be used outside of events

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      + + + + + + + +
    • + + key + + : + + + to indicate whether to return the key or value + +
    • + + + + + + + + Returns: +
        +
      • + a random element of table t +
      • +
      + + + + + + + + + + +
      +
      +
      + # + get_random_weighted(weighted_table, item_index, weight_index) +
      +
      +
      +
      + +

      Chooses a random entry from a weighted table + because this uses math.random, it cannot be used outside of events

      +

      + + + Parameters: + +
        + + + + + +
      • + + weighted_table + + : + + +
      of tables with items and their weights + + + + + + + +
    • + + item_index + + : + + + of the index of items, defaults to 1 + +
    • + + + + + +
    • + + weight_index + + : + + + of the index of the weights, defaults to 2 + +
    • + + + + + + + + Returns: +
        +
      • + table element +
      • +
      + + + + + + + + + + +
      +
      +
      + # + clear_table(t, array) +
      +
      +
      +
      + +

      Clears all existing entries in a table

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      to clear + + + + + + + +
    • + + array + + : + + + to indicate whether the table is an array or not + +
    • + + + + + + + + + + + + + + + + + +
      +
      +
      + # + shuffle_table(t, rng) +
      +
      +
      +
      + +

      Creates a fisher-yates shuffle of a sequential number-indexed table + because this uses math.random, it cannot be used outside of events if no rng is supplied + from: http://www.sdknews.com/cross-platform/corona/tutorial-how-to-shuffle-table-items

      +

      + + + Parameters: + +
        + + + + + +
      • + + t + + : + + +
      to shuffle + + + + + + + +
    • + + rng + + : + + + to provide random numbers + +
    • + + + + + + + + + + + + + + + + + +
      +
      +
      + # + get_values(tbl[, sorted][, as_string]) +
      +
      +
      +
      + +

      Returns a copy of all of the values in the table.

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + the to copy the keys from, or an empty table if tbl is nil + +
      • + + + + + +
      • + + sorted + + : + + (boolean) + + whether to sort the keys (slower) or keep the random order from pairs() + + (optional) +
      • + + + + + +
      • + + as_string + + : + + (boolean) + + whether to try and parse the values as strings, or leave them as their existing type + + (optional) +
      • + + +
      + + + + + Returns: +
        +
      • + (array) + an array with a copy of all the values in the table +
      • +
      + + + + + + + + + +
      +
      +
      +
      + # + get_keys(tbl[, sorted][, as_string]) +
      +
      +
      +
      + +

      Returns a copy of all of the keys in the table.

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + the to copy the keys from, or an empty table if tbl is nil + +
      • + + + + + +
      • + + sorted + + : + + (boolean) + + whether to sort the keys (slower) or keep the random order from pairs() + + (optional) +
      • + + + + + +
      • + + as_string + + : + + (boolean) + + whether to try and parse the keys as strings, or leave them as their existing type + + (optional) +
      • + + +
      + + + + + Returns: +
        +
      • + (array) + an array with a copy of all the keys in the table +
      • +
      + + + + + + + + + +
      +
      +
      +
      + # + alphanumsort(tbl) +
      +
      +
      +
      + +

      Returns the list is a sorted way that would be expected by people (this is by key)

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + the table to be sorted + +
      • + + +
      + + + + + Returns: +
        +
      • + (table) + the sorted table +
      • +
      + + + + + + + + + +
      +
      +
      +
      + # + keysort(tbl) +
      +
      +
      +
      + +

      Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)

      +

      + + + Parameters: + +
        + + + + + +
      • + + tbl + + : + + (table) + + the table to be sorted + +
      • + + +
      + + + + + Returns: +
        +
      • + (table) + the sorted table +
      • +
      + + + + + + + + + +
      + +

      Fields

      +
      +
      +
      +
      + # + inspect +
      +
      +
      +
      + +

      Similar to serpent.block, returns a string with a pretty representation of a table.

      +

      + Notice: This method is not appropriate for saving/restoring tables. It is meant to be used by the programmer mainly while debugging a program. + depth sets the maximum depth that will be printed out. When the max depth is reached, inspect will stop parsing tables and just return {...} + process is a function which allow altering the passed object before transforming it into a string. + A typical way to use it would be to remove certain values so that they don't appear at all. + return the prettied table

      + + + +
        + + + + + +
      • + + table + + : + + +
      the table to serialize + + + + + + + +
    • + + options + + : + + +
    • options are depth, newline, indent, process + + + + + + + + + + + + + + + + + + + +
      +
      +
      + # + size +
      +
      +
      +
      + +

      Takes a table and returns the number of entries in the table.

      +

      (Slower than #table, faster than iterating via pairs)

      + + + + + + + + + + + + + + +
      +
      +
      +
      + # + deep_copy +
      +
      +
      +
      + +

      Creates a deepcopy of a table.

      +

      Metatables and LuaObjects inside the table are shallow copies. + Shallow copies meaning it copies the reference to the object instead of the object itself.

      + + + +
        + + + + + +
      • + + object + + : + + +
      the object to copy + + + + + + + + + + + + + + + + + + + +
      +
      +
      + # + merge +
      +
      +
      +
      + +

      Merges multiple tables.

      +

      Tables later in the list will overwrite entries from tables earlier in the list. + Ex. merge({{1, 2, 3}, {[2] = 0}, {[3] = 0}}) will return {1, 0, 0}

      + + + +
        + + + + + +
      • + + tables + + : + + +
      takes a table of tables to merge + + + + + + + + + + + + + + + + + + + +
      +
      +
      + # + equals +
      +
      +
      +
      + +

      Determines if two tables are structurally equal.

      +

      + Notice: tables that are LuaObjects or contain LuaObjects won't be compared correctly, use == operator for LuaObjects

      + + + +
        + + + + + +
      • + + tbl1 + + : + + +
      + + + + + + + +
    • + + tbl2 + + : + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index 0613535f..beaa2b20 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -29,7 +29,7 @@

      ExpGaming Scenario

      -

      Explosive Gaming's server scenario for 0.17

      +

      Explosive Gaming's server scenario for 0.18

      @@ -51,18 +51,13 @@

      Modules

      @@ -70,13 +65,13 @@ @@ -105,10 +100,12 @@ + + @@ -117,8 +114,10 @@

      Guis

      @@ -156,7 +155,6 @@

      Configs

      @@ -343,7 +342,7 @@ - +
      utils.token
      utils.debugoverrides.debug
      @@ -488,8 +487,8 @@
      - # - utils.debug + # + overrides.debug
      @@ -1292,7 +1291,7 @@ generated by LDoc
    diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index 4714e6ed..c270c6ce 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -50,18 +50,13 @@

    Modules

    @@ -69,13 +64,13 @@ @@ -104,10 +99,12 @@ + + @@ -116,8 +113,10 @@

    Guis

    @@ -155,7 +154,6 @@

    Configs

    @@ -434,7 +433,7 @@ generated by LDoc
    diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index 4d025c24..43b62a10 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -51,18 +51,13 @@

    Modules

    @@ -70,13 +65,13 @@ @@ -105,10 +100,12 @@ + + @@ -117,8 +114,10 @@

    Guis

    @@ -156,7 +155,6 @@

    Configs

    @@ -651,7 +650,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 6d78546c..293edf6c 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -50,13 +50,13 @@ @@ -85,10 +85,12 @@ + + @@ -97,8 +99,10 @@

    Guis

    @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -789,7 +788,7 @@ Public License instead of this License. But first, please read generated by LDoc diff --git a/docs/topics/readme.md.html b/docs/topics/readme.md.html index 488a3235..d9e08d04 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -29,7 +29,7 @@

    ExpGaming Scenario

    -

    Explosive Gaming's server scenario for 0.17

    +

    Explosive Gaming's server scenario for 0.18

    @@ -50,13 +50,13 @@ @@ -85,10 +85,12 @@ + + @@ -97,8 +99,10 @@

    Guis

    @@ -136,7 +140,6 @@

    Configs

    @@ -169,18 +173,13 @@

    Modules

    @@ -240,7 +239,7 @@

    6) The scenario will now load all the selected modules and start the map, any errors or exceptions raised in the scenario should not cause a game/server crash, so if any features do not work as expected then it may be returning an error in the log. Please report these errors to [the issues page](issues).

    ## Contributing -

    All are welcome to make pull requests and issues for this scenario, if you are in any doubt, please ask someone in our [discord]. If you do not know lua and don't feel like learning you can always make a [feature request]. All our docs can be found [here][docs]. Please keep in mind while making code changes: +

    All are welcome to make pull requests and issues for this scenario, if you are in any doubt, please ask someone in our [discord]. If you do not know lua and don't feel like learning you can always make a [feature request]. To find out what we already have please read our [docs]. Please keep in mind while making code changes:

    * New features should have the branch names: `feature/feature-name` * New features are merged into `dev` after it has been completed, this can be done through a pull request. * After a number of features have been added a release branch is made: `release/X.Y.0` @@ -338,7 +337,7 @@ Please report these errors to [the issues page](issues). generated by LDoc

    diff --git a/expcore/async.lua b/expcore/async.lua index a988563b..473580ae 100644 --- a/expcore/async.lua +++ b/expcore/async.lua @@ -1,31 +1,31 @@ --[[-- Core Module - Async - - An extention of task and token to allow a single require to register and run async functions. - @core Async - @alias Async +- An extention of task and token to allow a single require to register and run async functions. +@core Async +@alias Async - @usage - -- To use Async you must register the allowed functions when the files are loaded, often this will just be giving access to - -- some functions within a module if you expect that some parts may be blocked by in game permissions or a custom system you have made - -- you may also want to register functions that you want to have a delayed call, such as waiting 2 seconds before printing a message +@usage +-- To use Async you must register the allowed functions when the file is loaded, often this will just be giving access to +-- some functions within a module if you expect that at part may be blocked by in game permissions or a custom system you have made +-- you may also want to register functions that you want to have a time delay, such as waiting 2 seconds before printing a message - -- This player.admin is called (command or gui element event) by a player who isnt admin then it will error - -- here we register the function to promote the player so that it will run async - local promote_player = - Async.register(function(player) - player.admin = true - end) +-- When player.admin is called (either command or gui element event) by a player who isnt admin then it will error +-- here we register the function to promote the player so that it will run async and outside the player scope +local promote_player = +Async.register(function(player) + player.admin = true +end) - -- This will allow us to bypass this by running one tick later outside of any player scope - Async(promote_player,game.player) +-- This will allow us to bypass the error by running one tick later outside of any player scope +Async(promote_player,game.player) - -- Here we make an sync function that we want to have a delay, note the delay is not defined here - local print_message = - Async.register(function(player,message) - player.print(message) - end) +-- Here we make an sync function that we want to have a delay, note the delay is not defined here +local print_message = +Async.register(function(player,message) + player.print(message) +end) - -- We can then call the async function with a delay using the wait function - Async.wait(60,print_message,game.player,'One second has passed!') +-- We can then call the async function with a delay using the wait function +Async.wait(60, print_message, game.player, 'One second has passed!') ]] local Task = require 'utils.task' --- @dep utils.task @@ -39,13 +39,38 @@ Token.register(function(params) return func(unpack(params.params)) end) ---- Register a new async function, must called when the file is loaded --- @tparam function callback the function that will become an async function +--[[-- Register a new async function, must called when the file is loaded +@function register +@tparam function callback the function that can be called as an async function +@treturn string the uid of the async function which can be passed to Async.run and Async.wait + +@usage-- Registering a function to set the admin state of a player +local set_admin = +Async.register(function(player, state) + if player.valid then + player.admin = state + end +end) + +@usage-- Registering a function to print to a player +local print_to_player = +Async.register(function(player, message) + if player.valid then + player.print(message) + end +end) + +]] Async.register = Token.register ---- Runs the async function linked to this token, you may supply any number of params as needed --- @tparam string token the token of the async function you want to run --- @tparam[opt] any ... the other params that you want to pass to your function +--[[-- Runs an async function, you may supply any number of arguments as required by that function +@tparam string token the token of the async function you want to run +@tparam[opt] any ... the other params that you want to pass to your function + +@usage-- Make a player admin regardless of if you are admin +Async.run(set_admin, player, true) + +]] function Async.run(token,...) Task.queue_task(internal_run, { token = token, @@ -53,10 +78,15 @@ function Async.run(token,...) }) end ---- Runs the async function linked to this token after the given number of ticks, you may supply any number of params as needed --- @tparam number ticks the number of ticks that you want the function to run after --- @tparam string token the token of the async function you want to run --- @tparam[opt] any ... the other params that you want to pass to your function +--[[-- Runs an async function after the given number of ticks, you may supply any number of arguments as required by that function +@tparam number ticks the number of ticks that you want the function to run after +@tparam string token the token of the async function you want to run +@tparam[opt] any ... the other params that you want to pass to your function + +@usage-- Print a message to a player after 5 seconds +Async.wait(300, print_to_player, 'Hello, World!') + +]] function Async.wait(ticks,token,...) Task.set_timeout_in_ticks(ticks, internal_run, { token = token, diff --git a/expcore/commands.lua b/expcore/commands.lua index b84adea4..a249ee93 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -1,197 +1,193 @@ --[[-- Core Module - Commands - - Factorio command making module that makes commands with better parse and more modularity - @core Commands - @alias Commands +- Factorio command making module that makes commands with better parse and more modularity +@core Commands +@alias Commands - @usage ----- Example Authenticator: - -- The command system is most useful when you can control who can use commands; to do this would would need to - -- define an authenticator which is ran every time a command is run; in this example I will show a simple one - -- that requires some commands to require the user to be a game admin: +@usage--- Full code example, see below for explaination +Commands.new_command('repeat-name', 'Will repeat you name a number of times in chat.') +:add_param('repeat-count', false, 'number-range-int', 1, 5) -- required int in range 1 to 5 inclusive +:add_param('smiley', true, function(input, player, reject) -- optional boolean default false + if not input then return end + if input:lower() == 'true' or input:lower() == 'yes' then + return true + else + return false + end +end) +:set_defaults{ smiley=false } +:set_flag('admin_only', true) -- command is admin only +:add_alias('name', 'rname') -- allow alias: name and rname +:register(function(player, repeat_count, smiley, raw) + game.print(player.name..' used a command with input: '..raw) - -- When the authenticator is called be the command handler it will be passed 4 vales: - -- 1) the player who used the command - -- 2) the name of the command that is being used - -- 3) any flags which have been set for this command, this is a table of values set using :set_flag(name,value) - -- 4) the reject function which is the preferred method to prevent execution of the command + local msg = ') '..player.name + if smiley then + msg = ':'..msg + end - -- For our admin only example we will set a flag to true when we want it do be admin only so when we define the - -- command will will use :set_flag('admin_only',true) and then inside the authenticator we will test if the flag - -- is present using: if flags.admin_only then + for 1 = 1,repeat_count do + Command.print(1..msg) + end +end) - -- Although no return is required to allow the command to execute it is best practice to return true; we do this in - -- two cases in our authenticator: - -- 1) when the "admin_only" flag is not set, which we take to mean any one can use it - -- 2) when the "admin_only" flag is set, and the player is admin +@usage--- Example Command: +-- How for the fun part making the commands, the commands can be set up with any number of params and flags that you want, +-- you can add aliases for the commands and set default values for optional params and of course register your command callback +-- in our example we will just have a command that will repeat the users name in chat X amount of times and only allow admins to use it. - -- Now when the user is not an admin and the command requires you to be an admin then we must reject the request: - -- 1) return false -- this is the most basic block and should only be used while testing - -- 2) return reject -- returning the reject function is only an option as a fail safe, same as returning false - -- 3) reject() -- this will block execution without returning to allow further code to be ran in the authenticator - -- 4) reject('This command is for admins only!') -- Using reject as a function allows a error message to be returned - -- 5) return reject() -- using return on either case above is best practice as you should execute all code before rejecting +-- First we create the new command, nb this will not register the command to the game this is done at the end, we will call +-- the command "repeat-name" and set the help message as follows: +Commands.new_command('repeat-name', 'Will repeat you name a number of times in chat.') - -- Example Code: - Commands.add_authenticator(function(player,command,flags,reject) - if flags.admin_only then -- our test for the "admin_only" flag - if player.admin then - return true -- true return 2 - else - return reject('This command is for admins only!') -- reject return 5 with a custom error message - end - else - return true -- true return 1 - end - end) +-- Now for our first param we will call "repeat-count" and it will be a required value between 1 and 5 inclusive: +:add_param('repeat-count', false, 'number-range-int', 1, 5) - @usage ----- Example Parse: - -- Before you go making commands it is important to understand the most powerful feature of this command handler, - -- when you define a command you are able to type the params and have then be parsed by an handler so before your - -- command is ever executed you can be sure that all the params are valid. This module should be paired with a general - -- command parse but you may want to create your own: +-- Our second param we need a custom parse for but we have not defined it, this is an option for when it is unlikely for +-- any other command to use the same input type; however in our case it will just be a boolean which should be noted as being +-- included in the general command parse config. As for the param its self it will be called "smiley" and will be optional with +-- a default value of false: +:add_param('smiley', true, function(input, player, reject) + -- since it is optional the input can be nil, in which case we just return + if not input then return end + -- if it is not nil then we check for a truthy value + if input:lower() == 'true' or input:lower() == 'yes' then + return true + else + -- note that because we did not return nil or reject then false will be passed to command callback, see example parse + return false + end +end) - -- For our example we will create a parse to accept only integer numbers in a given range: - -- 1) we will give it the name "number-range-int" this is the "type" that the input is expected to be - -- 2) when we define the type we will also define the min and max of the range so we can use the function more than once - -- Example parse usage: - :add_param('repeat_count',false,'number-range-int',5,10) -- range 5 to 10 inclusive +-- Once all params are defined you can now define some default values if you have optional params, the default value will be used only +-- when no value is given as input, if an invalid value is given then the command will still fail and this value will not be used, the +-- default can also be a function which is passed the player using the command and returns a value. Here we set the default for "smiley" to false: +:set_defaults{smiley=false} - -- The command parse will be passed 3 params and any other you define, in our case: - -- 1) the input that has been given by the user for this param, the role of this function is to transform this value - -- nb: the input is a string but can be nil if the param is marked as optional - -- 2) the player who is using the command, this is always present - -- 3) the reject function to throw an error to the user, this is always present - -- 4) the range min, this is user defined and has the value given when the param is defined - -- 5) the range max, this is user defined and has the value given when the param is defined +-- Another example of defaults if we have: item, amount[opt], player[opt] +:set_defaults{ + amount = 50, -- more than one value can be set at a time + player = function(player) + return player -- default is the player using the command + end +} - -- When returning from the param parse you again have a few options with how to do this: - -- 1) you return the new value for the param (any non nil value) this value is then passed to the command callback - -- 2) not returning will cause a generic invalid error and the command callback is blocked, not recommenced - -- 3) return reject -- this is just a failsafe in case the function is not called, same as no return - -- 4) return reject() -- will give a shorter error message as you pass a nil custom error - -- 5) return reject('Number entered is not in range: '..range_min..', '..range_max) -- returns a custom error the the user - -- nb: if you do not return reject after you call it then you are still returning nil so there will be a duplicate message +-- Now the params are set up we can alter how the command works, we can set auth flags, add aliases to this command or enable "auto concat" +-- which is when you want all extra words to be concatenated onto the end of the last param, useful for reason or messages: +:set_flag('admin_only', true) -- in our case we want "admin_only" to be set to true so only admins can use the command +:add_alias('name', 'rname') -- we also add two aliases here: "name" and "rname" which point to this command +-- :enable_auto_concat() we do not use this in our case but this can also be used to enable the "auto concat" feature - -- It should be noted that if you want to expand on an existing parse you can use Commands.parse(type,input,player,reject) - -- and this value will either return a new value for the input or nil, if it is nil you should return nil to prevent double - -- messages to the user: - input = Commands.parse('number-int',input,player,reject) - if not input then return end -- nil check +-- And finally we want to register a callback to this command, the callback is what defines what the command does, can be as complex as you +-- want it to be to as simple as our example; the command receives two params plus all that you have defines: +-- 1) the player who used the command +-- 2) in our case repeat_count which will be a number +-- 3) in our case smiley which will be a boolean +-- 4) the raw input; this param is always last as is always present as a catch all +:register(function(player, repeat_count, smiley, raw) + -- this is to show the value for raw as this is an example command, the log file will also show this + game.print(player.name..' used a command with input: '..raw) + local msg = ') '..player.name + if smiley then + -- this is where that smiley param is used + msg = ':'..msg + end + for 1 = 1,repeat_count do + -- this print function will return ANY value to the user in a desync safe manor, this includes if the command was used through rcon + Command.print(1..msg) + end + -- see below for what else can be used here +end) - -- Example Code: - Commands.add_parse('number-range-int',function(input,player,reject,range_min,range_max) - local rtn = tonumber(input) and math.floor(tonumber(input)) or nil -- converts input to number - if not rtn or rtn < range_min or rtn > range_max then - -- the input is either not a number or is outside the range - return reject('Number entered is not in range: '..range_min..', '..range_max) - else - -- returns the input as a number value rather than a string, thus the param is now the correct type - return rtn - end - end) +-- Other values that can be returned from register +Commands.print(any,colour[opt]) -- this will return any value value to the user including if it is ran through rcon console +Commands.error(message[opt]) -- this returns a warning to the user, aka an error that does not prevent execution of the command +return Commands.error(message[opt]) -- this returns an error to the user, and will halt the command execution, ie no success message is returned +Commands.success(message[opt]) -- used to return a success message however don't use this method see below +return Commands.success(message[opt]) -- will return the success message to the user and your given message, halts execution +return -- if any value is returned then it will be returned to the player via a Commands.success call - @usage ----- Example Command: - -- How for the fun part making the commands, the commands can be set up with any number of params and flags that you want, - -- you can add aliases for the commands and set default values for optional params and of course register your command callback - -- in our example we will just have a command that will repeat the users name in chat X amount of times and only allow admins to use it. +@usage--- Example Authenticator: +-- The command system is best used when you can control who uses commands; +-- to do this would would need to define an authenticator which is ran every time a command is run; +-- in this example I will show a simple one that requires certain commands to require the user to be a game admin. - -- First we create the new command, nb this will not register the command to the game this is done at the end, we will call - -- the command "repeat-name" and set the help message as follows: - Commands.new_command('repeat-name','Will repeat you name a number of times in chat.') +-- For our admin only example we will set a flag to true when we want it to be admin only; +-- when we define the command will will use :set_flag('admin_only', true); +-- then inside the authenticator we will test if the flag is present using: if flags.admin_only then - -- Now for our first param we will call "repeat-count" and it will be a required value between 1 and 5 inclusive: - :add_param('repeat-count',false,'number-range-int',1,5) +-- When the authenticator is called by the command handler it will be passed 4 arguments: +-- 1) player - the player who used the command +-- 2) command - the name of the command that is being used +-- 3) flags - the flags which have been set for this command, flags are set with :set_flag(name, value) +-- 4) reject - the reject function which is the preferred method to prevent execution of the command - -- Our second param we need a custom parse for but we have not defined it, this is an option for when it is unlikely for - -- any other command to use the same input type; however in our case it will just be a boolean which should be noted as being - -- included in the general command parse config. As for the param its self it will be called "smiley" and will be optional with - -- a default value of false: - :add_param('smiley',true,function(input,player,reject) - -- since it is optional the input can be nil, in which case we just return - if not input then return end - -- if it is not nil then we check for a truthy value - if input:lower() == 'true' or input:lower() == 'yes' then - return true - else - -- note that because we did not return nil or reject then false will be passed to command callback, see example parse - return false - end - end) +-- No return is required to allow the command to execute but it is best practice to return true; +-- we do this in two cases in our authenticator: +-- 1) when the "admin_only" flag is not set, which we take assume that any one can use it +-- 2) when the "admin_only" flag is set, and the player is admin - -- Once all params are defined you can now define some default values if you have optional params, the default value will be used only - -- when no value is given as input, if an invalid value is given then the command will still fail and this value will not be used, the - -- default can also be a function which is passed the player using the command and returns a value. Here we set the default for "smiley" to false: - :set_defaults{smiley=false} +-- When want to prevent exicution of the command we must reject it, listed is how that can be done: +-- 1) return false -- this is the most basic rejection and should only be used while testing +-- 2) return reject -- returning the reject function is as a fail safe in case you forget to call it, same as returning false +-- 3) reject() -- this will block execution without to allowing further code to be ran in your authenticator +-- 4) reject('This command is for admins only!') -- Using reject as a function allows a error message to be returned +-- 5) return reject() -- using return on either case above is best practice as you should execute all your code before rejecting - -- Another example of defaults if we have: item, amount[opt], player[opt] - :set_defaults{ - amount = 50, -- more than one value can be set at a time - player = function(player) - return player -- default is the player using the command - end - } +-- Example Code: +Commands.add_authenticator(function(player, command, flags, reject) + -- Check if the command is admin only + if flags.admin_only then + -- Return true if player is admin, or reject and return error message + return player.admin or reject('This command is for admins only!') + else + -- Return true if command was not admin only + return true + end +end) - -- Now the params are set up we can alter how the command works, we can set auth flags, add aliases to this command or enable "auto concat" - -- which is when you want all extra words to be concatenated onto the end of the last param, useful for reason or messages: - :set_flag('admin_only',true) -- in our case we want "admin_only" to be set to true so only admins can use the command - :add_alias('name','rname') -- we also add two aliases here: "name" and "rname" which point to this command - -- :enable_auto_concat() we do not use this in our case but this can also be used to enable the "auto concat" feature +@usage--- Example Parse: +-- Before you make a command it is important to understand the most powerful feature of this command handler; +-- when you define a command you are able to type the params and have then be parsed and validated before your command is executed; +-- This module should is paired with a general command parse but you may want to create your own. - -- And finally we want to register a callback to this command, the callback is what defines what the command does, can be as complex as you - -- want it to be to as simple as our example; the command receives two params plus all that you have defines: - -- 1) the player who used the command - -- 2) in our case repeat_count which will be a number - -- 3) in our case smiley which will be a boolean - -- 4) the raw input; this param is always last as is always present as a catch all - :register(function(player,repeat_count,smiley,raw) - -- this is to show the value for raw as this is an example command, the log file will also show this - game.print(player.name..' used a command with input: '..raw) - local msg = ') '..player.name - if smiley then - -- this is where that smiley param is used - msg = ':'..msg - end - for 1 = 1,repeat_count do - -- this print function will return ANY value to the user in a desync safe manor, this includes if the command was used through rcon - Command.print(1..msg) - end - -- see below for what else can be used here - end) +-- For our example we will create a parse to accept only integer numbers in a given range: +-- 1) we will give it the name "number-range-int" this is the "type" that the input is expected to be +-- 2) when we define the type we will also define the min and max of the range so we can use the function more than once +:add_param('repeat_count', false, 'number-range-int', 5, 10) -- "repeat_count" is required "number-range-int" in a range 5 to 10 inclusive - -- Some other useful functions that can be used are: - Commands.print(any,colour[opt]) -- this will return any value value to the user including if it is ran through rcon console - Commands.error(message[opt]) -- this returns a warning to the user, aka an error that does not prevent execution of the command - return Commands.error(message[opt]) -- this returns an error to the user, and will halt the command execution, ie no success message is returned - Commands.success(message[opt]) -- used to return a success message however don't use this method see below - return Commands.success(message[opt]) -- will return the success message to the user and your given message, halts execution - return if any value is returned then it will be returned to the player via a Commands.success call +-- The command parse will be passed 3 arguments plus any other which you define, in our case: +-- 1) input - the input that has been given by the user for this param, the role of this function is to transform this value +-- nb: the input is a string but can be nil if the param is marked as optional +-- 2) player - the player who is using the command, this is always present +-- 3) reject - the reject function to throw an error to the user, this is always present +-- 4) range_min - the range min, this is user defined and has the value given when the param is defined +-- 5) range_max - the range max, this is user defined and has the value given when the param is defined - -- Example Code: - Commands.new_command('repeat-name','Will repeat you name a number of times in chat.') - :add_param('repeat-count',false,'number-range-int',1,5) -- required int in range 1 to 5 inclusive - :add_param('smiley',true,function(input,player,reject) -- optional boolean default false - if not input then return end - if input:lower() == 'true' or input:lower() == 'yes' then - return true - else - return false - end - end) - :set_defaults{smiley=false} - :set_flag('admin_only',true) -- command is admin only - :add_alias('name','rname') -- allow alias: name and rname - :register(function(player,repeat_count,smiley,raw) - game.print(player.name..' used a command with input: '..raw) - local msg = ') '..player.name - if smiley then - msg = ':'..msg - end - for 1 = 1,repeat_count do - Command.print(1..msg) - end - end) +-- When returning from the param parse you have a few options with how to do this: +-- 1) you return the new value for the param (any non nil value) this value is then passed to the command callback +-- 2) not returning will cause a generic invalid error and the command is rejected, not recommenced +-- 3) return reject -- this is just a failsafe in case the function is not called, same as no return +-- 4) return reject() -- will give a shorter error message as you pass a nil custom error +-- 5) return reject('Number entered is not in range: '..range_min..', '..range_max) -- returns a custom error to the user +-- nb: if you do not return reject after you call it then you will still be returning nil so there will be a duplicate error message + +-- It should be noted that if you want to expand on an existing parse you can use Commands.parse(type, input, player, reject) +-- this function will either return a new value for the input or nil, if it is nil you should return nil to prevent duplicate +-- error messages to the user: +input = Commands.parse('number-int', input, player, reject) +if not input then return end -- nil check + +-- Example Code: +Commands.add_parse('number-range-int',function(input, player, reject, range_min, range_max) + local rtn = tonumber(input) and math.floor(tonumber(input)) or nil -- converts input to number + if not rtn or rtn < range_min or rtn > range_max then + -- the input is either not a number or is outside the range + return reject('Number entered is not in range: '..range_min..', '..range_max) + else + -- returns the input as a number value rather than a string, thus the param is now the correct type + return rtn + end +end) ]] @@ -199,38 +195,58 @@ local Game = require 'utils.game' --- @dep utils.game local player_return,write_json = _C.player_return, _C.write_json --- @dep expcore.common local Commands = { - defines={ -- common values are stored error like signals + --- Values returned by the signal functions to cause the command system to react + defines = { error='CommandError', unauthorized='CommandErrorUnauthorized', success='CommandSuccess' }, - commands={}, -- custom command data will be stored here - authorization_fail_on_error=false, -- set true to have authorize fail if a callback fails to run, more secure - authorization={}, -- custom function are stored here which control who can use what commands - parse_functions={}, -- used to store default functions which are common parse function such as player or number in range - print=player_return, -- short cut so player_return does not need to be required in every module - _prototype={}, -- used to store functions which gets added to new custom commands + --- Custom command data will be stored here + commands={}, + --- Set true to have authorize fail if a callback fails to run, more secure + authorization_fail_on_error=false, + --- Custom function are stored here which control who can use what commands + authorization={}, + --- Used to store default functions which are common parse function such as player or number in range + parse_functions={}, + -- Sends a value to the player, different to success as this does not signal the end of your command + print=player_return, + --- Used to store functions which gets added to new custom commands + _prototype={}, } --- Authenication. -- Functions that control who can use commands -- @section auth ---- Adds an authorization callback, function used to check if a player if allowed to use a command --- @tparam function callback the callback you want to register as an authenticator --- callback param - player: LuaPlayer - the player who is trying to use the command --- callback param - command: string - the name of the command which is being used --- callback param - flags: table - any flags which have been set for the command --- callback param - reject: function(error_message?: string) - call to fail authorize with optional error message --- @treturn number the index it was inserted at use to remove the callback, if anon function used +--[[-- Adds an authorization callback, function used to check if a player if allowed to use a command +@tparam function callback the callback you want to register as an authenticator +@treturn number the index it was inserted at use to remove the callback, if anon function used + +@usage-- Test if a command is admin only and if the player is admin +local admin_authenticator = +Commands.add_authenticator(function(player, command, flags, reject) + if flags.admin_only then + return player.admin or reject('This command is for admins only!') + else + return true + end +end) + +]] function Commands.add_authenticator(callback) table.insert(Commands.authorization,callback) return #Commands.authorization end ---- Removes an authorization callback --- @tparam function|number callback the callback to remove, an index returned by add_authenticator can be passed --- @treturn boolean was the callback found and removed +--[[-- Removes an authorization callback +@tparam function|number callback the callback to remove, an index returned by add_authenticator can be passed +@treturn boolean if the callback found and removed successfuly + +@usage-- Removing the admin authenticator, can not be done dueing runtime +Commands.remove_authenticator(admin_authenticator) + +]] function Commands.remove_authenticator(callback) if type(callback) == 'number' then -- if a number is passed then it is assumed to be the index @@ -256,13 +272,18 @@ function Commands.remove_authenticator(callback) return false end ---- Mostly used internally, calls all authorization callbacks, returns if the player is authorized --- @tparam LuaPlayer player the player that is using the command, passed to callbacks --- @tparam string command_name the command that is being used, passed to callbacks --- @treturn[1] boolean true player is authorized --- @treturn[1] string commands const for success --- @treturn[2] boolean false player is unauthorized --- @treturn[2] string|locale_string the reason given by the authenticator +--[[-- Mostly used internally, calls all authorization callbacks, returns if the player is authorized +@tparam LuaPlayer player the player that is using the command, passed to callbacks +@tparam string command_name the command that is being used, passed to callbacks +@treturn[1] boolean true player is authorized +@treturn[1] string commands const for success +@treturn[2] boolean false player is unauthorized +@treturn[2] string|locale_string the reason given by the authenticator + +@usage-- Test if a player can use "repeat-name" +local authorized, status = Commands.authorize(game.player, 'repeat-name') + +]] function Commands.authorize(player,command_name) local failed if not player then return true end @@ -300,13 +321,22 @@ function Commands.authorize(player,command_name) return true, Commands.defines.success end end + --- Getters. -- Functions that get commands -- @section getters ---- Gets all commands that a player is allowed to use, game commands not included --- @tparam[opt] LuaPlayer player the player that you want to get commands of, nil will return all commands --- @treturn table all commands that that player is allowed to use, or all commands +--[[-- Gets all commands that a player is allowed to use, game commands are not included +@tparam[opt] LuaPlayer player the player that you want to get commands of, nil will return all commands +@treturn table all commands that that player is allowed to use, or all commands + +@usage-- Get the command you are allowed to use +local commands = Commands.get(game.player) + +@usage-- Get all commands that are registered +local commands = Commands.get() + +]] function Commands.get(player) player = Game.get_player_from_any(player) if not player then return Commands.commands end @@ -319,12 +349,20 @@ function Commands.get(player) return allowed end ---- Searches command names and help messages to find possible commands, game commands included --- @tparam string keyword the word which you are trying to find --- @tparam[opt] LuaPlayer allowed_player the player to get allowed commands of, if nil all commands are searched --- @treturn table all commands that contain the key word, and allowed by player if player given -function Commands.search(keyword,allowed_player) - local custom_commands = Commands.get(allowed_player) +--[[-- Searches command names and help messages to find possible commands, game commands are included +@tparam string keyword the word which you are trying to find in your search +@tparam[opt] LuaPlayer player the player to get allowed commands of, if nil all commands are searched +@treturn table all commands that contain the key word, and allowed by player if player given + +@usage-- Get all commands which "repeat" +local commands = Commands.search('repeat') + +@usage-- Get all commands which "repeat" and you are allowed to use +local commands = Commands.search('repeat', game.player) + +]] +function Commands.search(keyword,player) + local custom_commands = Commands.get(player) local matches = {} keyword = keyword:lower() -- loops over custom commands @@ -354,15 +392,25 @@ end -- Functions that help with parsing -- @section parse ---- Adds a parse function which can be called by name rather than callback (used in add_param) --- nb: this is not needed as you can use the callback directly this just allows it to be called by name --- @tparam string name the name of the parse, should be the type like player or player_alive, must be unique --- @tparam function callback the callback that is ran to parse the input --- parse param - input: string - the input given by the user for this param --- parse param - player: LuaPlayer - the player who is using the command --- parse param - reject: function(error_message) - use this function to send a error to the user and fail running --- parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run --- @treturn boolean was the parse added will be false if the name is already used +--[[-- Adds a parse function which can be called by name (used in add_param) +nb: this is not required as you can use the callback directly this just allows it to be called by name +@tparam string name the name of the parse, should be the type like player or player_alive, must be unique +@tparam function callback the callback that is ran to parse the input +@treturn boolean was the parse added will be false if the name is already used + +@usage-- Adding a parse to validate ints in a given range +Commands.add_parse('number-range-int', function(input, player, reject, range_min, range_max) + local rtn = tonumber(input) and math.floor(tonumber(input)) or nil -- converts input to number + if not rtn or rtn < range_min or rtn > range_max then + -- the input is either not a number or is outside the range + return reject('Number entered is not in range: '..range_min..', '..range_max) + else + -- returns the input as a number rather than a string, thus the param is now the correct type + return rtn + end +end) + +]] function Commands.add_parse(name,callback) if Commands.parse_functions[name] then return false @@ -372,18 +420,28 @@ function Commands.add_parse(name,callback) end end ---- Removes a parse function, see add_parse for adding them --- @tparam string name the name of the parse to remove +--[[-- Removes a parse function, see add_parse for adding them +@tparam string name the name of the parse to remove + +@usage-- Removing a parse +Commands.remove_parse('number-range-int') + +]] function Commands.remove_parse(name) Commands.parse_functions[name] = nil end ---- Intended to be used within other parse functions, runs a parse and returns success and new value --- @tparam string name the name of the parse to call, must be registered and cant be a function --- @tparam string input string the input to pass to the parse, will always be a but might not be the original input --- @tparam LuaPlayer player the player that is calling using the command --- @tparam function reject the reject function that was passed by the command hander --- @treturn any the new value for the input, may be nil, if nil then either there was an error or input was nil +--[[-- Intended to be used within other parse functions, runs a parse and returns success and new value +@tparam string name the name of the parse to call, must be registered parse +@tparam string input string the input to pass to the parse, must be a string but not necessarily the original input +@tparam LuaPlayer player the player that is using the command +@tparam function reject the reject function that was passed by the command hander +@treturn any the new value for the input, may be nil, if nil then either there was an error or input was nil + +@usage-- Parsing a int in a given range +local parsed_input = Commands.parse('number-range-int', '7', player, reject, 1, 10) -- valid range 1 to 10 + +]] function Commands.parse(name,input,player,reject,...) if not Commands.parse_functions[name] then return end local success,rtn = pcall(Commands.parse_functions[name],input,player,reject,...) @@ -397,10 +455,16 @@ end -- Functions that create a new command -- @section creation ---- Creates a new command object to added details to, note this does not register the command to the game --- @tparam string name the name of the command to be created --- @tparam string help the help message for the command --- @treturn Commands._prototype this will be used with other functions to generate the command functions +--[[-- Creates a new command object to added details to, note this does not register the command to the game api +@tparam string name the name of the command to be created +@tparam string help the help message for the command +@treturn Commands._prototype this will be used with other functions to generate the command functions + +@usage-- Define a new command +local command = +Commands.new_command('repeat-name', 'Will repeat you name a number of times in chat.') + +]] function Commands.new_command(name,help) local command = setmetatable({ name=name, @@ -419,16 +483,23 @@ function Commands.new_command(name,help) return command end ---- Adds a new param to the command this will be displayed in the help and used to parse the input --- @tparam string name the name of the new param that is being added to the command --- @tparam[opt=false] boolean optional is this param required for this command, these must be after all required params --- @tparam[opt=pass function through] ?string|function parse this function will take the input and return a new (or same) value --- @param[opt] ... extra args you want to pass to the parse function; for example if the parse is general use --- parse param - input: string - the input given by the user for this param --- parse param - player: LuaPlayer - the player who is using the command --- parse param - reject: function(error_message) - use this function to send a error to the user and fail running --- parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run --- @treturn Commands._prototype pass through to allow more functions to be called +--[[-- Adds a new param to the command this will be displayed in the help and used to parse the input +@tparam string name the name of the new param that is being added to the command +@tparam[opt=false] boolean optional is this param required for this command, these must be after all required params +@tparam[opt=pass function through] ?string|function parse this function will take the input and return a new (or same) value +@param[opt] ... extra args you want to pass to the parse function; for example if the parse is general use +@treturn Commands._prototype pass through to allow more functions to be called + +@usage-- Adding a param which has an parse defined +command:add_param('repeat-count', false, 'number-range-int', 1, 5) + +@usage-- Adding a param which has a custom parse, see Commands.add_parse for details +command:add_param('smiley', true, function(input, player, reject) + if not input then return end + return input:lower() == 'true' or input:lower() == 'yes' or false +end) + +]] function Commands._prototype:add_param(name,optional,parse,...) local parse_args = {...} if type(optional) ~= 'boolean' then @@ -449,10 +520,20 @@ function Commands._prototype:add_param(name,optional,parse,...) return self end ---- Adds default values to params only matters if the param is optional, if default value is a function it is called with param player --- @tparam table defaults table a keyed by the name of the param with the value as the default value {paramName=defaultValue} --- callback param - player: LuaPlayer - the player using the command, default value does not need to be a function callback --- @treturn Commands._prototype pass through to allow more functions to be called +--[[-- Add default values to params, only as an effect if the param is optional, if default value is a function it is called with acting player +@tparam table defaults table which is keyed by the name of the param and the value is the default value +@treturn Commands._prototype pass through to allow more functions to be called + +@usage-- Adding default values +command:set_defaults{ + smiley = false, + -- not in example just used to show arguments given + player_name = function(player) + return player.name + end +} + +]] function Commands._prototype:set_defaults(defaults) for name,value in pairs(defaults) do if self.params[name] then @@ -462,26 +543,32 @@ function Commands._prototype:set_defaults(defaults) return self end ---- Adds a tag to the command which is passed via the flags param to the authenticators, can be used to assign command roles or type --- @tparam string name the name of the tag to be added; used to keep flags separate --- @tparam any value the tag that you want can be anything that the authenticators are expecting --- nb: if value is nil then name will be assumed as the value and added at a numbered index --- @treturn Commands._prototype pass through to allow more functions to be called +--[[-- Adds a tag to the command which is passed via the flags param to the authenticators, can be used to assign command roles or type +@tparam string name the name of the tag to be added, set to true if no value is given +@tparam[opt=true] any value the tag that you want can be anything that the authenticators are expecting +@treturn Commands._prototype pass through to allow more functions to be called + +@usage-- Setting a custom flag +command:set_flag('admin_only', true) + +@usage-- When value is true it does not need to be given +command:set_flag('admin_only') + +]] function Commands._prototype:set_flag(name,value) - if not value then - -- value not given so name is the value - table.insert(self.flags,name) - else - -- name is given so its key: value - self.flags[name] = value - end + value = value or true + self.flags[name] = value return self end ---- Adds an alias or multiple that will also be registered with the same callback, eg /teleport can be /tp with both working --- @usage command:add_alias('aliasOne','aliasTwo','etc') --- @tparam string any ... amount of aliases that you want this command to be callable with --- @treturn Commands._prototype pass through to allow more functions to be called +--[[-- Adds an alias, or multiple, that will also be registered with the same callback, eg /teleport can be used as /tp +@tparam string any ... amount of aliases that you want this command to be callable with +@treturn Commands._prototype pass through to allow more functions to be called + +@usage-- Added multiple aliases to a command +command:add_alias('name', 'rname') + +]] function Commands._prototype:add_alias(...) for _,alias in pairs({...}) do table.insert(self.aliases,alias) @@ -490,21 +577,35 @@ function Commands._prototype:add_alias(...) return self end ---- Enables auto concatenation of any params on the end so quotes are not needed for last param --- nb: this will disable max param checking as they will be concatenated onto the end of that last param --- this can be useful for reasons or longs text, can only have one per command --- @treturn Commands._prototype pass through to allow more functions to be called +--[[-- Enables auto concatenation of any params on the end so quotes are not needed for last param +nb: this will disable max param checking as they will be concatenated onto the end of that last param +this can be useful for reasons or longs text, can only have one per command +@treturn Commands._prototype pass through to allow more functions to be called + +@usage-- Enable auto concat for a command +command:enable_auto_concat() + +]] function Commands._prototype:enable_auto_concat() self.auto_concat = true return self end ---- Adds the callback to the command and registers all aliases, params and help message with the game --- nb: this must be the last function ran on the command and must be done for the command to work --- @tparam function callback the callback for the command, will receive the player running command, and params added with add_param --- callback param - player: LuaPlayer - the player who used the command --- callback param - ... - any params which were registered with add_param in the order they where registered --- callback param - raw: string - the raw input from the user, comes after every param added with add_param +--[[-- Adds the callback to the command and registers all aliases, params and help message with the game api +nb: this must be the last function ran on the command and must be done for the command to work +@tparam function callback the callback for the command, will receive the player running command, and params added with add_param + +@usage-- Registering your command to the game api +command:register(function(player, repeat_count, smiley, _) + local msg = ') '..player.name + if smiley then msg = ':'..msg end + + for 1 = 1,repeat_count do + Command.print(1..msg) + end +end) + +]] function Commands._prototype:register(callback) -- generates a description to be used self.callback = callback @@ -538,13 +639,16 @@ end -- Functions that indicate status -- @section status ---- Sends an error message to the player and returns a constant to return to command handler to exit execution --- nb: this is for non fatal errors meaning there is no log of this event --- nb: if reject is giving as a param to the callback use that instead --- @usage return Commands.error() --- @tparam[opt] string error_message an optional error message that can be sent to the user --- @tparam[opt] string play_sound the sound to play for the error --- @treturn Commands.defines.error return this to command handler to exit execution +--[[-- Sends an error message to the player and when returned will stop exicution of the command +nb: this is for non fatal errors meaning there is no log of this event, use during register callback +@tparam[opt=''] string error_message an optional error message that can be sent to the user +@tparam[opt=utility/wire_pickup] string play_sound the sound to play for the error +@treturn Commands.defines.error return this to command handler to exit execution + +@usage-- Send an error message to the player, and stops further code running +return Commands.error('The player you selected is offline') + +]] function Commands.error(error_message,play_sound) error_message = error_message or '' player_return({'expcore-commands.command-fail',error_message},'orange_red') @@ -555,12 +659,20 @@ function Commands.error(error_message,play_sound) return Commands.defines.error end ---- Sends an error to the player and logs the error, used with pcall within command handler please avoid direct use --- nb: use error(error_message) within your callback to trigger do not trigger directly as the handler may still continue --- @tparam boolean success the success value returned from pcall, or just false to trigger error --- @tparam string command_name the name of the command this is used within the log --- @tparam string error_message the error returned by pcall or some other error, this is logged and not returned to player --- @treturn boolean the opposite of success so true means to cancel execution, used internally +--[[-- Sends an error to the player and logs the error, used with pcall within command handler please avoid direct use +nb: use error(error_message) within your callback to trigger do not trigger directly as code exictuion may still continue +@tparam boolean success the success value returned from pcall, or just false to trigger error +@tparam string command_name the name of the command this is used within the log +@tparam string error_message the error returned by pcall or some other error, this is logged and not returned to player +@treturn boolean the opposite of success so true means to cancel execution, used internally + +@usage-- Used in the command system to log handler errors +local success, err = pcall(command_data.callback, player, unpack(params)) +if Commands.internal_error(success, command_data.name, err) then + return command_log(player, command_data, 'Internal Error: Command Callback Fail', raw_params, command_event.parameter, err) +end + +]] function Commands.internal_error(success,command_name,error_message) if not success then Commands.error('Internal Error, Please contact an admin','utility/cannot_build') @@ -569,16 +681,34 @@ function Commands.internal_error(success,command_name,error_message) return not success end ---- Sends a value to the player, followed by a command complete message --- nb: either return a value from your callback to trigger or return the return of this to prevent two messages --- @tparam[opt] any value the value to return to the player, if nil then only success message returned --- @treturn Commands.defines.success return this to the command handler to prevent two success messages +--[[-- Sends a value to the player, followed by a command complete message +nb: returning any value from your callback will trigger this function, return this function to prevent duplicate messages +@tparam[opt] any value the value to return to the player, if nil then only success message returned +@treturn Commands.defines.success return this to the command handler to prevent two success messages + +@usage-- Print a custom success message +return Commands.success('Your message has been printed') + +@usage-- Returning the value has the same result +return 'Your message has been printed' + +]] function Commands.success(value) if value ~= nil then player_return(value) end player_return({'expcore-commands.command-ran'},'cyan') return Commands.defines.success end +--[[-- Sends a value to the player, different to success as this does not signal the end of your command +@function print +@tparam any value the value that you want to return to the player +@tparam table colour the colour of the message that the player sees + +@usage-- Output a message to the player +Commands.print('Your command is in progress') + +]] + -- logs command usage to file local function command_log(player,command,comment,params,raw,details) local player_name = player and player.name or '' @@ -594,6 +724,7 @@ end --- Main event function that is ran for all commands, used internally please avoid direct use -- @tparam table command_event passed directly from command event from the add_command function +-- @usage Commands.run_command(event) function Commands.run_command(command_event) local command_data = Commands.commands[command_event.name] -- player can be nil when it is the server diff --git a/expcore/common.lua b/expcore/common.lua index 983cae4d..e51b3edb 100644 --- a/expcore/common.lua +++ b/expcore/common.lua @@ -1,46 +1,59 @@ ---[[-- Core Module - Common Library - - Adds some commonly used functions used in many modules - @core Common-Library - @alias Common +--[[-- Core Module - Common +- Adds some commonly used functions used in many modules +@core Common +@alias Common ]] local Colours = require 'utils.color_presets' --- @dep utils.color_presets local Game = require 'utils.game' --- @dep utils.game local Util = require 'util' --- @dep util -require 'overrides.table' -require 'overrides.math' local Common = {} --- Type Checking. -- @section typeCheck ---- Asserts the argument is of type test_type --- @usage type_check('foo','string') -- return true --- @usage type_check('foo') -- return false --- @tparam any value the value to be tested --- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil --- @treturn boolean is v of type test_type +--[[-- Asserts the argument is of type test_type +@tparam any value the value to be tested +@tparam[opt=nil] string test_type the type to test for if not given then it tests for nil +@treturn boolean is v of type test_type + +@usage-- Check for a string value +local is_string = type_check(value, 'string') + +@usage-- Check for a nil value +local is_nil = type_check(value) + +]] function Common.type_check(value, test_type) return test_type and value and type(value) == test_type or not test_type and not value or false end ---- Raises an error if the value is of the wrong type --- @usage type_error('foo','number','Value must be a number') -- will raise error "Value must be a number" --- @tparam any value the value that you want to test the type of --- @tparam string test_type the type that the value should be --- @tparam string error_message the error message that is returned --- @tparam number level the level to call the error on (level = 1 means the caller) --- @treturn boolean true if no error was called +--[[-- Raises an error if the value is of the wrong type +@tparam any value the value that you want to test the type of +@tparam string test_type the type that the value should be +@tparam string error_message the error message that is returned +@tparam number level the level to call the error on (level = 1 is the caller) +@treturn boolean true if no error was called + +@usage-- Raise error if value is not a number +type_error(value, 'number', 'Value must be a number') + +]] function Common.type_error(value, test_type, error_message, level) level = level and level+1 or 2 return Common.type_check(value,test_type) or error(error_message,level) end ---- Asserts the argument is one of type test_types --- @param value the variable to check --- @param test_types the type as a table of strings --- @treturn boolean true if value is one of test_types +--[[-- Asserts the argument is one of type test_types +@param value the variable to check +@param test_types the type as a table of strings +@treturn boolean true if value is one of test_types + +@usage-- Check for a string or table +local is_string_or_table = multi_type_check(value, {'string','table'}) + +]] function Common.multi_type_check(value, test_types) local vtype = type(value) for _, arg_type in ipairs(test_types) do @@ -51,45 +64,73 @@ function Common.multi_type_check(value, test_types) return false end ---- Raises an error if the value is of the wrong type --- @usage multi_type_error('foo',{'string','table'},'Value must be a string or table') -- will raise error "Value must be a string or table" --- @tparam any value the value that you want to test the type of --- @tparam table test_types the type as a table of strings --- @tparam string error_message the error message that is returned --- @tparam number level the level to call the error on (level = 1 means the caller) --- @treturn boolean true if no error was called +--[[-- Raises an error if the value is of the wrong type +@tparam any value the value that you want to test the type of +@tparam table test_types the type as a table of strings +@tparam string error_message the error message that is returned +@tparam number level the level to call the error on (level = 1 is the caller) +@treturn boolean true if no error was called + +@usage-- Raise error if value is not a string or table +multi_type_error('foo', {'string','table'}, 'Value must be a string or table') + +]] function Common.multi_type_error(value, test_types, error_message, level) level = level and level+1 or 2 return Common.mult_type_check(value, test_types) or error(error_message,level) end ---- Raises an error when the value is the incorrect type, uses a consistent error message format --- @usage validate_argument_type('foo','number','repeat_count',2) -- will raise error "Bad argument #02 to ""; "repeat_count" is of type string expected number" --- @tparam any value the value that you want to test the type of --- @tparam string test_type the type that the value should be --- @tparam string param_name the name of the param --- @tparam number param_number the number param it is --- @treturn boolean true if no error was raised -function Common.validate_argument_type(value, test_type, param_name, param_number) +--[[-- Raises an error when the value is the incorrect type, uses a consistent error message format +@tparam any value the value that you want to test the type of +@tparam string test_type the type that the value should be +@tparam number param_number the number param it is +@tparam[opt] string param_name the name of the param +@treturn boolean true if no error was raised + +@usage-- Output: "Bad argument #2 to ""; argument is of type string expected number" +validate_argument_type(value, 'number', 2) + +@usage-- Output: "Bad argument #2 to ""; "repeat_count" is of type string expected number" +validate_argument_type(value, 'number', 2, 'repeat_count') + +]] +function Common.validate_argument_type(value, test_type, param_number, param_name) if not Common.test_type(value,test_type) then local function_name = debug.getinfo(2,'n').name or '' - local error_message = string.format('Bad argument #%2d to %q; %q is of type %s expected %s', param_number, function_name, param_name, type(value), test_type) + local error_message + if param_name then + error_message = string.format('Bad argument #%d to %q; %q is of type %s expected %s', param_number, function_name, param_name, type(value), test_type) + else + error_message = string.format('Bad argument #%d to %q; argument is of type %s expected %s', param_number, function_name, type(value), test_type) + end return error(error_message,3) end return true end ---- Raises an error when the value is the incorrect type, uses a consistent error message format --- @usage validate_argument_type('foo',{'string','table'},'repeat_count',2) -- will raise error "Bad argument #02 to ""; "repeat_count" is of type string expected string or table" --- @tparam any value the value that you want to test the type of --- @tparam string test_types the types that the value should be --- @tparam string param_name the name of the param --- @tparam number param_number the number param it is --- @treturn boolean true if no error was raised -function Common.validate_argument_multi_type(value, test_types, param_name, param_number) +--[[-- Raises an error when the value is the incorrect type, uses a consistent error message format +@tparam any value the value that you want to test the type of +@tparam string test_types the types that the value should be +@tparam number param_number the number param it is +@tparam[opt] string param_name the name of the param +@treturn boolean true if no error was raised + +@usage-- Output: "Bad argument #2 to ""; argument is of type number expected string or table" +validate_argument_type(value, {'string','table'}, 2) + +@usage-- Output: "Bad argument #2 to ""; "player" is of type number expected string or table" +validate_argument_type(value, {'string','table'}, 2, 'player') + +]] +function Common.validate_argument_multi_type(value, test_types, param_number, param_name) if not Common.multi_type_check(value,test_types) then local function_name = debug.getinfo(2,'n').name or '' - local error_message = string.format('Bad argument #%2d to %q; %q is of type %s expected %s', param_number, function_name, param_name, type(value), table.concat(test_types,' or ')) + local error_message + if param_name then + error_message = string.format('Bad argument #%2d to %q; %q is of type %s expected %s', param_number, function_name, param_name, type(value), table.concat(test_types,' or ')) + else + error_message = string.format('Bad argument #%2d to %q; argument is of type %s expected %s', param_number, function_name, type(value), table.concat(test_types,' or ')) + end return error(error_message,3) end return true @@ -116,10 +157,15 @@ end --- Value Returns. -- @section valueReturns ---- Tests if a string contains a given substring. --- @tparam string s the string to check for the substring --- @tparam string contains the substring to test for --- @treturn boolean true if the substring was found in the string +--[[-- Tests if a string contains a given substring. +@tparam string s the string to check for the substring +@tparam string contains the substring to test for +@treturn boolean true if the substring was found in the string + +@usage-- Test if a string contains a sub string +local found = string_contains(str, 'foo') + +]] function Common.string_contains(s, contains) return s and string.find(s, contains) ~= nil end @@ -127,82 +173,104 @@ end --[[-- Used to resolve a value that could also be a function returning that value @tparam any value the value which you want to test is not nil and if it is a function then call the function @treturn any the value given or returned by value if it is a function + @usage-- Default value handling -- if default value is not a function then it is returned --- if it is a function then it is called with the first argument being self -local value = Common.resolve_value(self.defaut_value,self) +-- if default value is a function then it is called with the first argument being self +local value = Common.resolve_value(self.defaut_value, self) + ]] function Common.resolve_value(value,...) - if value then - if type(value) == 'function' then - return value(...) - else - return value - end - end -end - ---- Returns a valid string with the name of the actor of a command. --- @treturns string the name of the current actor -function Common.get_actor() - return game.player and game.player.name or '' + return value and type(value) == 'function' and value(...) or value end --- Converts a varible into its boolean value, nil and false return false -- @treturn boolean the boolean form of the varible +-- @usage local bool = cast_bool(var) function Common.cast_bool(var) return var and true or false end --- Returns either the second or third argument based on the first argument +-- @usage ternary(input_string == 'test', 'Input is test', 'Input is not test') function Common.ternary(c, t, f) return c and t or f end --- Returns a string for a number with comma seperators +-- @usage comma_value(input_number) function Common.comma_value(n) -- credit http://richard.warburton.it local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$') return left .. (num:reverse():gsub('(%d%d%d)', '%1,'):reverse()) .. right end ---- Sets a table element to value while also returning value. --- @param tbl table to change the element of --- @param key string --- @param value nil|boolean|number|string|table to set the element to --- @return value +--[[-- Sets a table element to value while also returning value. +@tparam table tbl to change the element of +@tparam string key the key to set the value of +@tparam any value the value to set the key as +@treturn any the value that was set + +@usage-- Set and return value +local value = set_and_return(players, player.name, player.online_time) + +]] function Common.set_and_return(tbl, key, value) tbl[key] = value return value end ---- Writes a table object to a file in json format --- @tparam string path the path of the file to write include / to use dir --- @tparam table tbl the table that will be converted to a json string and wrote to file +--[[-- Writes a table object to a file in json format +@tparam string path the path of the file to write include / to use dir +@tparam table tbl the table that will be converted to a json string and wrote to file + +@usage-- Write a lua table as a json to script-outpt/dump +write_json('dump', tbl) + +]] function Common.write_json(path,tbl) game.write_file(path,game.table_to_json(tbl)..'\n',true,0) end ---- Calls a require that will not error if the file is not found --- @usage local file = opt_require('file.not.present') -- will not cause any error --- @tparam string path the path that you want to require --- @return the returns from that file or nil, error if not loaded +--[[-- Calls a require that will not error if the file is not found +@usage local file = opt_require('file.not.present') -- will not cause any error +@tparam string path the path that you want to require +@return the returns from that file or nil, error if not loaded + +@usage-- Require a file without causing errors, for when a file might not exist +local Module = opt_require 'expcore.common' + +]] function Common.opt_require(path) local success, rtn = pcall(require,path) if success then return rtn else return nil,rtn end end ---- Returns a desync safe file path for the current file --- @tparam[opt=0] number offset the offset in the stack to get, 0 is current file --- @treturn string the file path +--[[-- Returns a desync safe file path for the current file +@tparam[opt=0] number offset the offset in the stack to get, 0 is current file +@treturn string the file path + +@usage-- Get the current file path +local file_path = get_file_path() + +]] function Common.get_file_path(offset) offset = offset or 0 return debug.getinfo(offset+2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) end ---- Converts a table to an enum --- @tparam table tbl table the that will be converted --- @treturn table the new table that acts like an enum +--[[-- Converts a table to an enum +@tparam table tbl table the that will be converted +@treturn table the new table that acts like an enum + +@usage-- Make an enum +local colors = enum{ + 'red', + 'green', + 'blue' +} + +]] function Common.enum(tbl) local rtn = {} for k,v in pairs(tbl) do @@ -221,12 +289,23 @@ function Common.enum(tbl) return rtn end ---- Returns the closest match to the input --- @tparam table options table a of options for the auto complete --- @tparam string input string the input that will be completed --- @tparam[opt=false] boolean use_key when true the keys of options will be used as the options --- @tparam[opt=false] boolean rtn_key when true the the key will be returned rather than the value --- @return the list item found that matches the input +--[[-- Returns the closest match to the input +@tparam table options table a of options for the auto complete +@tparam string input string the input that will be completed +@tparam[opt=false] boolean use_key when true the keys of options will be used as the options +@tparam[opt=false] boolean rtn_key when true the the key will be returned rather than the value +@return the list item found that matches the input + +@usage-- Get the element that includes "foo" +local value = auto_complete(tbl, "foo") + +@usage-- Get the element with a key that includes "foo" +local value = auto_complete(tbl, "foo", true) + +@usage-- Get the key with that includes "foo" +local key = auto_complete(tbl, "foo", true, true) + +]] function Common.auto_complete(options,input,use_key,rtn_key) local rtn = {} if type(input) ~= 'string' then return end @@ -234,40 +313,65 @@ function Common.auto_complete(options,input,use_key,rtn_key) for key,value in pairs(options) do local check = use_key and key or value if Common.string_contains(string.lower(check),input) then - local result = rtn_key and key or value - table.insert(rtn,result) + return rtn_key and key or value end end - return rtn[1] end --- Formating. -- @section formating ---- Returns a message with valid chat tags to change its colour --- @tparam string message the message that will be in the output --- @tparam table color a color which contains r,g,b as its keys --- @treturn string the message with the color tags included +--[[-- Returns a valid string with the name of the actor of a command. +@tparam string player_name the name of the player to use rather than server, used only if game.player is nil +@treturn string the name of the current actor + +@usage-- Get the current actor +local player_name = get_actor() + +]] +function Common.get_actor(player_name) + return game.player and game.player.name or player_name or '' +end + +--[[-- Returns a message with valid chat tags to change its colour +@tparam string message the message that will be in the output +@tparam table color a color which contains r,g,b as its keys +@treturn string the message with the color tags included + +@usage-- Use factorio tags to color a chat message +local message = format_chat_colour('Hello, World!', { r=355, g=100, b=100 }) + +]] function Common.format_chat_colour(message,color) color = color or Colours.white local color_tag = '[color='..math.round(color.r,3)..','..math.round(color.g,3)..','..math.round(color.b,3)..']' return string.format('%s%s[/color]',color_tag,message) end ---- Returns a message with valid chat tags to change its colour, using localization --- @tparam ?string|table message the message that will be in the output --- @tparam table color a color which contains r,g,b as its keys --- @treturn table the message with the color tags included +--[[-- Returns a message with valid chat tags to change its colour, using localization +@tparam ?string|table message the message that will be in the output +@tparam table color a color which contains r,g,b as its keys +@treturn table the message with the color tags included + +@usage-- Use factorio tags and locale strings to color a chat message +local message = format_chat_colour_localized('Hello, World!', { r=355, g=100, b=100 }) + +]] function Common.format_chat_colour_localized(message,color) color = color or Colours.white color = math.round(color.r,3)..','..math.round(color.g,3)..','..math.round(color.b,3) return {'color-tag',color,message} end ---- Returns the players name in the players color --- @tparam LuaPlayer player the player to use the name and color of --- @tparam[opt=false] boolean raw_string when true a is returned rather than a localized string --- @treturn table the players name with tags for the players color +--[[-- Returns the players name in the players color +@tparam LuaPlayer player the player to use the name and color of +@tparam[opt=false] boolean raw_string when true a string is returned rather than a localized string +@treturn table the players name with tags for the players color + +@usage-- Format a players name using the players color as a string +local message = format_chat_player_name(game.player, true) + +]] function Common.format_chat_player_name(player,raw_string) player = Game.get_player_from_any(player) local player_name = player and player.name or '' @@ -279,13 +383,21 @@ function Common.format_chat_player_name(player,raw_string) end end ---- Will return a value of any type to the player/server console, allows colour for in-game players --- @usage player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console --- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console --- @usage player_return('Hello, World!',nil,player) -- returns 'Hello, World!' to the given player --- @param value any value of any type that will be returned to the player or console --- @tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ignored when printing to console --- @tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server +--[[-- Will return a value of any type to the player/server console, allows colour for in-game players +@tparam any value a value of any type that will be returned to the player or console +@tparam[opt=defines.colour.white] ?defines.color|string colour the colour of the text for the player, ignored when printing to console +@tparam[opt=game.player] LuaPlayer player the player that return will go to, if no game.player then returns to server + +@usage-- Return a value to the current actor, rcon included +player_return('Hello, World!') + +@usage-- Return a value to the current actor, with color +player_return('Hello, World!', 'green') + +@usage-- Return to a player other than the current +player_return('Hello, World!', nil, player) + +]] function Common.player_return(value,colour,player) colour = Common.type_check(colour,'table') and colour or Colours[colour] ~= Colours.white and Colours[colour] or Colours.white player = player or game.player @@ -320,14 +432,26 @@ function Common.player_return(value,colour,player) else rcon.print(returnAsString) end end ---- Formats tick into a clean format, denominations from highest to lowest --- long will use words rather than letters +--[[-- Formats tick into a clean format, denominations from highest to lowest -- time will use : separates --- string will return a string not a locale string -- when a denomination is false it will overflow into the next one --- @tparam number ticks the number of ticks that represents a time --- @tparam table options table a of options to use for the format --- @treturn string a locale string that can be used +@tparam number ticks the number of ticks that represents a time +@tparam table options table a of options to use for the format +@treturn string a locale string that can be used + +@usage-- Output: "0h 5m" +local time = format_time(18000, { hours=true, minutes=true, string=true }) + +@usage-- Output: "0 hours and 5 minutes" +local time = format_time(18000, { hours=true, minutes=true, string=true, long=true }) + +@usage-- Output: "00:05:00" +local time = format_time(18000, { hours=true, minutes=true, seconds=true, string=true }) + +@usage-- Output: "--:--:--" +local time = format_time(18000, { hours=true, minutes=true, seconds=true, string=true, null=true }) + +]] function Common.format_time(ticks,options) -- Sets up the options options = options or { @@ -415,12 +539,18 @@ end --- Factorio. -- @section factorio ---- Moves items to the position and stores them in the closest entity of the type given --- @tparam table items items which are to be added to the chests, ['name']=count --- @tparam[opt=navies] LuaSurface surface the surface that the items will be moved to --- @tparam[opt={0,0}] table position the position that the items will be moved to {x=100,y=100} --- @tparam[opt=32] number radius the radius in which the items are allowed to be placed --- @tparam[opt=iron-chest] string chest_type the chest type that the items should be moved into +--[[-- Moves items to the position and stores them in the closest entity of the type given +@tparam table items items which are to be added to the chests, ['name']=count +@tparam[opt=navies] LuaSurface surface the surface that the items will be moved to +@tparam[opt={0,0}] table position the position that the items will be moved to {x=100,y=100} +@tparam[opt=32] number radius the radius in which the items are allowed to be placed +@tparam[opt=iron-chest] string chest_type the chest type that the items should be moved into +@treturn LuaEntity the last chest that had items inserted into it + +@usage-- Copy all the items in a players inventory and place them in chests at {0,0} +move_items(game.player.get_main_inventory().get_contents()) + +]] function Common.move_items(items,surface,position,radius,chest_type) chest_type = chest_type or 'iron-chest' surface = surface or game.surfaces[1] @@ -466,14 +596,19 @@ function Common.move_items(items,surface,position,radius,chest_type) return last_chest end ---[[-- https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31 - Prints a colored value on a location. - @param value between -1 and 1 - @param surface LuaSurface - @param position Position {x, y} - @param scale float - @param offset float - @param immutable bool if immutable, only set, never do a surface lookup, values never change +--[[-- Prints a colored value on a location, color is based on the value. +nb: src is below but the gradent has been edited +https://github.com/Refactorio/RedMew/blob/9184b2940f311d8c9c891e83429fc57ec7e0c4a2/map_gen/maps/diggy/debug.lua#L31 +@tparam number value the value to show must be between -1 and 1, scale can be used to achive this +@tparam LuaSurface surface the surface to palce the value on +@tparam table position {x, y} the possition to palce the value at +@tparam[opt=1] number scale how much to scale the colours by +@tparam[opt=0] number offset the offset in the +x +y direction +@tparam[opt=false] boolean immutable if immutable, only set, never do a surface lookup, values never change + +@usage-- Place a 0 at {0,0} +print_grid_value(0, game.player.surface, { x=0, y=0 }) + ]] function Common.print_grid_value(value, surface, position, scale, offset, immutable) local is_string = type(value) == 'string' @@ -488,23 +623,9 @@ function Common.print_grid_value(value, surface, position, scale, offset, immuta scale = scale or 1 offset = offset or 0 position = {x = position.x + offset, y = position.y + offset} - local r = math.max(1, value) / scale - local g = 1 - math.abs(value) / scale - local b = math.min(1, value) / scale - - if (r > 0) then - r = 0 - end - - if (b < 0) then - b = 0 - end - - if (g < 0) then - g = 0 - end - - r = math.abs(r) + local r = math.clamp(-value/scale, 0, 1) + local g = math.clamp(1-math.abs(value)/scale, 0, 1) + local b = math.clamp(value/scale, 0, 1) color = { r = r, g = g, b = b} @@ -534,81 +655,13 @@ function Common.print_grid_value(value, surface, position, scale, offset, immuta }.active = false end ---[[-- - Prints a colored value on a location. When given a color_value and a delta_color, - will change the color of the text from the base to base + value * delta. This will - make the color of the text range from 'base_color' to 'base_color + delta_color' - as the color_value ranges from 0 to 1 - @param value of number to be displayed - @param surface LuaSurface - @param position Position {x, y} - @param offset float position offset - @param immutable bool if immutable, only set, never do a surface lookup, values never change - @param color_value float How far along the range of values of colors the value is to be displayed - @param base_color {r,g,b} The color for the text to be if color_value is 0 - @param delta_color {r,g,b} The amount to correct the base_color if color_value is 1 - @param under_bound {r,g,b} The color to be used if color_value < 0 - @param over_bound {r,g,b} The color to be used if color_value > 1 +--[[-- Clears all flying text entities on a surface +@tparam LuaSurface surface the surface to clear + +@usage-- Remove all flying text on the surface +clear_flying_text(game.player.surface) + ]] -function Common.print_colored_grid_value(value, surface, position, offset, immutable, - color_value, base_color, delta_color, under_bound, over_bound) - local is_string = type(value) == 'string' - -- default values: - local color = base_color or Colours.white - local d_color = delta_color or Colours.black - local u_color = under_bound or color - local o_color = over_bound or color - - if (color_value < 0) then - color = u_color - elseif (color_value > 1) then - color = o_color - else - color = { - r = color.r + color_value * d_color.r, - g = color.g + color_value * d_color.g, - b = color.b + color_value * d_color.b - } - end - - local text = value - - if type(immutable) ~= 'boolean' then - immutable = false - end - - if not is_string then - offset = offset or 0 - position = {x = position.x + offset, y = position.y + offset} - - -- round at precision of 2 - text = math.floor(100 * value) * 0.01 - - if (0 == text) then - text = '0.00' - end - end - - if not immutable then - local text_entity = surface.find_entity('flying-text', position) - - if text_entity then - text_entity.text = text - text_entity.color = color - return - end - end - - surface.create_entity{ - name = 'flying-text', - color = color, - text = text, - position = position - }.active = false -end - ---- Clears all flying text entities on a surface --- @tparam LuaSurface surface the surface to clear function Common.clear_flying_text(surface) local entities = surface.find_entities_filtered{name ='flying-text'} for _,entity in pairs(entities) do diff --git a/expcore/gui.lua b/expcore/gui.lua index eaa22047..70817151 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -1 +1 @@ -return require 'expcore.gui.require' \ No newline at end of file +return require 'expcore.gui._require' \ No newline at end of file diff --git a/expcore/gui/_require.lua b/expcore/gui/_require.lua new file mode 100644 index 00000000..306c354d --- /dev/null +++ b/expcore/gui/_require.lua @@ -0,0 +1,131 @@ +--[[-- Core Module - Gui +- Used to simplify gui creation using factory functions called element defines +@core Gui +@alias Gui + +@usage-- To draw your element you only need to call the factory function +-- You are able to pass any other arguments that are used in your custom functions but the first is always the parent element +local example_button_element = example_button(parent_element) + +@usage-- Making a factory function for a button with the caption "Example Button" +-- This method has all the same features as LuaGuiElement.add +local example_button = +Gui.element{ + type = 'button', + caption = 'Example Button' +} + +@usage-- Making a factory function for a button which is contained within a flow +-- This method is for when you still want to register event handlers but cant use the table method +local example_flow_with_button = +Gui.element(function(event_trigger,parent,...) + -- ... shows that all other arguments from the factory call are passed to this function + -- Here we are adding a flow which we will then later add a button to + local flow = + parent.add{ -- paraent is the element which is passed to the factory function + name = 'example_flow', + type = 'flow' + } + + -- Now we add the button to the flow that we created earlier + local element = + flow.add{ + name = event_trigger, -- event_trigger should be the name of any elements you want to trigger your event handlers + type = 'button', + caption = 'Example Button' + } + + -- You must return a new element, this is so styles can be applied and returned to the caller + -- You may return any of your elements that you added, consider the context in which it will be used for which should be returned + return element +end) + +@usage-- Styles can be added to any element define, simplest way mimics LuaGuiElement.style[key] = value +local example_button = +Gui.element{ + type = 'button', + caption = 'Example Button', + style = 'forward_button' -- factorio styles can be applied here +} +:style{ + height = 25, -- same as element.style.height = 25 + width = 100 -- same as element.style.width = 25 +} + +@usage-- Styles can also have a custom function when the style is dynamic and depends on other factors +-- Use this method if your style is dynamic and depends on other factors +local example_button = +Gui.element{ + type = 'button', + caption = 'Example Button', + style = 'forward_button' -- factorio styles can be applied here +} +:style(function(style,element,...) + -- style is the current style object for the elemenent + -- element is the element that is being changed + -- ... shows that all other arguments from the factory call are passed to this function + local player = game.players[element.player_index] + style.height = 25 + style.width = 100 + style.font_color = player.color +end) + +@usage-- You are able to register event handlers to your elements, these can be factorio events or custom ones +-- All events are checked to be valid before raising any handlers, this means element.valid = true and player.valid = true +Gui.element{ + type = 'button', + caption = 'Example Button' +} +:on_click(function(player,element,event) + -- player is the player who interacted with the element to cause the event + -- element is a refrence to the element which caused the event + -- event is a raw refrence to the event data if player and element are not enough + player.print('Clicked: '..element.name) +end) + +@usage-- Example from core_defines, Gui.core_defines.hide_left_flow, called like: hide_left_flow(parent_element) +--- Button which hides the elements in the left flow, shows inside the left flow when frames are visible +-- @element hide_left_flow +local hide_left_flow = +Gui.element{ + type = 'sprite-button', + sprite = 'utility/close_black', + style = 'tool_button', + tooltip = {'expcore-gui.left-button-tooltip'} +} +:style{ + padding = -3, + width = 18, + height = 20 +} +:on_click(function(player,_,_) + Gui.hide_left_flow(player) +end) + +@usage-- Eample from defines, Gui.alignment, called like: Gui.alignment(parent, name, horizontal_align, vertical_align) +-- Notice how _ are used to blank arguments that are not needed in that context and how they line up with above +Gui.alignment = +Gui.element(function(_,parent,name,_,_) + return parent.add{ + name = name or 'alignment', + type = 'flow', + } +end) +:style(function(style,_,_,horizontal_align,vertical_align) + style.padding = {1,2} + style.vertical_align = vertical_align or 'center' + style.horizontal_align = horizontal_align or 'right' + style.vertically_stretchable = style.vertical_align ~= 'center' + style.horizontally_stretchable = style.horizontal_align ~= 'center' +end) + +]] + +local Gui = require 'expcore.gui.prototype' +require 'expcore.gui.core_defines' +require 'expcore.gui.top_flow' +require 'expcore.gui.left_flow' +require 'expcore.gui.helper_functions' +require 'expcore.gui.defines' + +return Gui \ No newline at end of file diff --git a/expcore/gui/core_defines.lua b/expcore/gui/core_defines.lua index 8ae38fbe..0a545a34 100644 --- a/expcore/gui/core_defines.lua +++ b/expcore/gui/core_defines.lua @@ -4,7 +4,7 @@ ]] local Gui = require 'expcore.gui.prototype' -local Event = require 'utils.event' --- @dep utils.event +local Event = require 'utils.event' --- Core Defines. -- @section coreDefines diff --git a/expcore/gui/left_flow.lua b/expcore/gui/left_flow.lua index 03fba9ab..f57dac1a 100644 --- a/expcore/gui/left_flow.lua +++ b/expcore/gui/left_flow.lua @@ -4,7 +4,7 @@ ]] local Gui = require 'expcore.gui.prototype' -local mod_gui = require 'mod-gui' --- @dep mod-gui +local mod_gui = require 'mod-gui' local hide_left_flow = Gui.core_defines.hide_left_flow.name @@ -82,7 +82,7 @@ end --[[-- Draw all the left elements onto the left flow, internal use only with on join @tparam LuaPlayer player the player that you want to draw the elements for -@usage Draw all the left elements +@usage-- Draw all the left elements Gui.draw_left_flow(player) ]] diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 526d27b0..f7803602 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -1,152 +1,26 @@ --[[-- Core Module - Gui - Used to simplify gui creation using factory functions called element defines -@core Gui -@alias Gui - -@usage-- To draw your element you only need to call the factory function --- You are able to pass any other arguments that are used in your custom functions but the first is always the parent element -local example_button_element = example_button(parent_element) - -@usage-- Making a factory function for a button with the caption "Example Button" --- This method has all the same features as LuaGuiElement.add -local example_button = -Gui.element{ - type = 'button', - caption = 'Example Button' -} - -@usage-- Making a factory function for a button which is contained within a flow --- This method is for when you still want to register event handlers but cant use the table method -local example_flow_with_button = -Gui.element(function(event_trigger,parent,...) - -- ... shows that all other arguments from the factory call are passed to this function - -- Here we are adding a flow which we will then later add a button to - local flow = - parent.add{ -- paraent is the element which is passed to the factory function - name = 'example_flow', - type = 'flow' - } - - -- Now we add the button to the flow that we created earlier - local element = - flow.add{ - name = event_trigger, -- event_trigger should be the name of any elements you want to trigger your event handlers - type = 'button', - caption = 'Example Button' - } - - -- You must return a new element, this is so styles can be applied and returned to the caller - -- You may return any of your elements that you added, consider the context in which it will be used for which should be returned - return element -end) - -@usage-- Styles can be added to any element define, simplest way mimics LuaGuiElement.style[key] = value -local example_button = -Gui.element{ - type = 'button', - caption = 'Example Button', - style = 'forward_button' -- factorio styles can be applied here -} -:style{ - height = 25, -- same as element.style.height = 25 - width = 100 -- same as element.style.width = 25 -} - -@usage-- Styles can also have a custom function when the style is dynamic and depends on other factors --- Use this method if your style is dynamic and depends on other factors -local example_button = -Gui.element{ - type = 'button', - caption = 'Example Button', - style = 'forward_button' -- factorio styles can be applied here -} -:style(function(style,element,...) - -- style is the current style object for the elemenent - -- element is the element that is being changed - -- ... shows that all other arguments from the factory call are passed to this function - local player = game.players[element.player_index] - style.height = 25 - style.width = 100 - style.font_color = player.color -end) - -@usage-- You are able to register event handlers to your elements, these can be factorio events or custom ones --- All events are checked to be valid before raising any handlers, this means element.valid = true and player.valid = true -Gui.element{ - type = 'button', - caption = 'Example Button' -} -:on_click(function(player,element,event) - -- player is the player who interacted with the element to cause the event - -- element is a refrence to the element which caused the event - -- event is a raw refrence to the event data if player and element are not enough - player.print('Clicked: '..element.name) -end) - -@usage-- Example from core_defines, Gui.core_defines.hide_left_flow, called like: hide_left_flow(parent_element) ---- Button which hides the elements in the left flow, shows inside the left flow when frames are visible --- @element hide_left_flow -local hide_left_flow = -Gui.element{ - type = 'sprite-button', - sprite = 'utility/close_black', - style = 'tool_button', - tooltip = {'expcore-gui.left-button-tooltip'} -} -:style{ - padding = -3, - width = 18, - height = 20 -} -:on_click(function(player,_,_) - Gui.hide_left_flow(player) -end) - -@usage-- Eample from defines, Gui.alignment, called like: Gui.alignment(parent, name, horizontal_align, vertical_align) --- Notice how _ are used to blank arguments that are not needed in that context and how they line up with above -Gui.alignment = -Gui.element(function(_,parent,name,_,_) - return parent.add{ - name = name or 'alignment', - type = 'flow', - } -end) -:style(function(style,_,_,horizontal_align,vertical_align) - style.padding = {1,2} - style.vertical_align = vertical_align or 'center' - style.horizontal_align = horizontal_align or 'right' - style.vertically_stretchable = style.vertical_align ~= 'center' - style.horizontally_stretchable = style.horizontal_align ~= 'center' -end) - +@module Gui ]] local Event = require 'utils.event' --- @dep utils.event local Gui = { --- The current highest uid that is being used by a define, will not increase during runtime - -- @field uid uid = 0, --- String indexed table used to avoid conflict with custom event names, similar to how defines.events works - -- @table events events = {}, --- Uid indexed array that stores all the factory functions that were defined, no new values will be added during runtime - -- @table defines defines = {}, --- An string indexed table of all the defines which are used by the core of the gui system, used for internal refrence - -- @table core_defines core_defines = {}, --- Used to store the file names where elements were defined, this can be useful to find the uid of an element, mostly for debuging - -- @table file_paths file_paths = {}, --- Used to store extra infomation about elements as they get defined such as the params used and event handlers registered to them - -- @table debug_info debug_info = {}, --- The prototype used to store the functions of an element define - -- @table _prototype_element _prototype_element = {}, --- The prototype metatable applied to new element defines - -- @table _mt_element _mt_element = { __call = function(self,parent,...) local element = self._draw(self.name,parent,...) @@ -365,50 +239,86 @@ end --- Called when the player opens a GUI. -- @tparam function handler the event handler which will be called +-- @usage element_define:on_open(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_open = event_handler_factory(defines.events.on_gui_opened) --- Called when the player closes the GUI they have open. -- @tparam function handler the event handler which will be called +-- @usage element_define:on_close(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_close = event_handler_factory(defines.events.on_gui_closed) --- Called when LuaGuiElement is clicked. -- @tparam function handler the event handler which will be called +-- @usage element_define:on_click(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_click = event_handler_factory(defines.events.on_gui_click) --- Called when a LuaGuiElement is confirmed, for example by pressing Enter in a textfield. -- @tparam function handler the event handler which will be called +-- @usage element_define:on_confirmed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_confirmed = event_handler_factory(defines.events.on_gui_confirmed) --- Called when LuaGuiElement checked state is changed (related to checkboxes and radio buttons). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_checked_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_checked_changed = event_handler_factory(defines.events.on_gui_checked_state_changed) --- Called when LuaGuiElement element value is changed (related to choose element buttons). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_elem_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_elem_changed = event_handler_factory(defines.events.on_gui_elem_changed) --- Called when LuaGuiElement element location is changed (related to frames in player.gui.screen). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_location_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_location_changed = event_handler_factory(defines.events.on_gui_location_changed) --- Called when LuaGuiElement selected tab is changed (related to tabbed-panes). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_tab_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_tab_changed = event_handler_factory(defines.events.on_gui_selected_tab_changed) --- Called when LuaGuiElement selection state is changed (related to drop-downs and listboxes). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_selection_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_selection_changed = event_handler_factory(defines.events.on_gui_selection_state_changed) --- Called when LuaGuiElement switch state is changed (related to switches). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_switch_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_switch_changed = event_handler_factory(defines.events.on_gui_switch_state_changed) --- Called when LuaGuiElement text is changed by the player. -- @tparam function handler the event handler which will be called +-- @usage element_define:on_text_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_text_changed = event_handler_factory(defines.events.on_gui_text_changed) --- Called when LuaGuiElement slider value is changed (related to the slider element). -- @tparam function handler the event handler which will be called +-- @usage element_define:on_value_changed(function(event) +-- event.player.print(table.inspect(event)) +--end) Gui._prototype_element.on_value_changed = event_handler_factory(defines.events.on_gui_value_changed) -- Module return diff --git a/expcore/gui/require.lua b/expcore/gui/require.lua deleted file mode 100644 index 26fcf0d6..00000000 --- a/expcore/gui/require.lua +++ /dev/null @@ -1,8 +0,0 @@ -local Gui = require 'expcore.gui.prototype' -require 'expcore.gui.core_defines' -require 'expcore.gui.top_flow' -require 'expcore.gui.left_flow' -require 'expcore.gui.helper_functions' -require 'expcore.gui.defines' - -return Gui \ No newline at end of file diff --git a/expcore/gui/top_flow.lua b/expcore/gui/top_flow.lua index f06dea2e..1f50fc47 100644 --- a/expcore/gui/top_flow.lua +++ b/expcore/gui/top_flow.lua @@ -145,7 +145,7 @@ function Gui.toolbar_button(sprite,tooltip,authenticator) end --[[-- Styles a top flow button depending on the state given -@tparam LuaGuiElement the button element to style +@tparam LuaGuiElement button the button element to style @tparam boolean state The state the button is in @usage-- Sets the button to the visible style diff --git a/expcore/permission_groups.lua b/expcore/permission_groups.lua index 136717e0..5b88331f 100644 --- a/expcore/permission_groups.lua +++ b/expcore/permission_groups.lua @@ -1,29 +1,25 @@ --[[-- Core Module - Permission Groups - - Permission group making for factorio so you never have to make one by hand again - @core Permissions-Groups - @alias Permissions_Groups +- Permission group making for factorio so you never have to make one by hand again +@core Groups +@alias Permissions_Groups - @usage ----- Example Group (Allow All) +@usage--- Example Group (Allow All) +-- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups +Permission_Groups.new_group('Admin') -- this defines a new group called "Admin" +:allow_all() -- this makes the default to allow any input action unless set other wise +:disallow{ -- here we disallow the input action we don't want them to use + 'add_permission_group', + 'delete_permission_group', + 'import_permissions_string', + 'map_editor_action', + 'toggle_map_editor' +} - -- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups - Permission_Groups.new_group('Admin') -- this defines a new group called "Admin" - :allow_all() -- this makes the default to allow any input action unless set other wise - :disallow{ -- here we disallow the input action we don't want them to use - 'add_permission_group', - 'delete_permission_group', - 'import_permissions_string', - 'map_editor_action', - 'toggle_map_editor' - } - - @usage ----- Example Group (Disallow All) - - -- here we will create a group that cant do anything but talk in chat - Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted" - :disallow_all() -- this makes the default to disallow any input action unless set other wise - :allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action +@usage--- Example Group (Disallow All) +-- here we will create a group that cant do anything but talk in chat +Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted" +:disallow_all() -- this makes the default to disallow any input action unless set other wise +:allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action ]] @@ -55,9 +51,14 @@ Permissions_Groups.async_token_remove_from_permission_group = remove_from_permis -- Functions that get permission groups -- @section getters ---- Defines a new permission group that can have it actions set in the config --- @tparam string name the name of the new group --- @treturn Permissions_Groups._prototype the new group made with function to allow and disallow actions +--[[-- Defines a new permission group that can have it actions set in the config +@tparam string name the name of the new group +@treturn Permissions_Groups._prototype the new group made with function to allow and disallow actions + +@usage-- Defining a new permission group +Groups.new_group('Admin') + +]] function Permissions_Groups.new_group(name) local group = setmetatable({ name=name, @@ -70,16 +71,26 @@ function Permissions_Groups.new_group(name) return group end ---- Returns the group with the given name, case sensitive --- @tparam string name the name of the group to get --- @treturn ?Permissions_Groups._prototype|nil the group with that name or nil if non found +--[[-- Returns the group with the given name, case sensitive +@tparam string name the name of the group to get +@treturn ?Permissions_Groups._prototype|nil the group with that name or nil if non found + +@usage-- Getting a permision group +local admin_group = Groups.get_group_by_name('Admin') + +]] function Permissions_Groups.get_group_by_name(name) return Permissions_Groups.groups[name] end ---- Returns the group that a player is in --- @tparam LuaPlayer player the player to get the group of can be name index etc --- @treturn ?Permissions_Groups._prototype|nil the group with that player or nil if non found +--[[-- Returns the group that a player is in +@tparam LuaPlayer player the player to get the group of can be name index etc +@treturn ?Permissions_Groups._prototype|nil the group with that player or nil if non found + +@usage-- Get your permission group +local group = Groups.get_group_from_player(game.player) + +]] function Permissions_Groups.get_group_from_player(player) player = Game.get_player_from_any(player) if not player then return end @@ -93,43 +104,27 @@ end -- Functions that control all groups -- @section players ---- Reloads/creates all permission groups and sets them to they configured state +--[[-- Reloads/creates all permission groups and sets them to they configured state + +@usage-- Reload the permission groups, used internally +Groups.reload_permissions() + +]] function Permissions_Groups.reload_permissions() for _,group in pairs(Permissions_Groups.groups) do group:create() end end ---- Removes all permissions from every permission group except for "Default" and any passed as exempt --- @tparam ?string|Array exempt groups that you want to be except, "Default" is always exempt --- @treturn number the number of groups that had they permissions removed -function Permissions_Groups.lockdown_permissions(exempt) - local count = 0 - if type(exempt) ~= 'table' then - exempt = {exempt} - end - for _,group in pairs(exempt) do - if type(group) == 'string' then - exempt[group:lower()] = true - elseif type(group) == 'table' then - exempt[group.name:lower()] = true - end - end - for _,group in pairs(game.permissions.groups) do - if not exempt[group.name:lower()] and not group.name == 'Default' then - count = count +1 - for _,action in pairs(defines.input_action) do - group.set_allows_action(action,false) - end - end - end - return count -end +--[[-- Sets a player's group to the one given, a player can only have one group at a time +@tparam LuaPlayer player the player to effect can be name index etc +@tparam string group the name of the group to give to the player +@treturn boolean true if the player was added successfully, false other wise ---- Sets a player's group to the one given, a player can only have one group at a time --- @tparam LuaPlayer player the player to effect can be name index etc --- @tparam string group the name of the group to give to the player --- @treturn boolean true if the player was added successfully, false other wise +@usage-- Set your permission group +Groups.set_player_group(game.player, 'Admin') + +]] function Permissions_Groups.set_player_group(player,group) player = Game.get_player_from_any(player) group = Permissions_Groups.get_group_by_name(group) @@ -142,10 +137,15 @@ end -- Functions that control group actions -- @section actions ---- Sets the allow state of an action for this group, used internally but is safe to use else where --- @tparam ?string|defines.input_action action the action that you want to set the state of --- @tparam boolean state the state that you want to set it to, true = allow, false = disallow --- @treturn Permissions_Groups._prototype returns self so function can be chained +--[[-- Sets the allow state of an action for this group, used internally but is safe to use else where +@tparam ?string|defines.input_action action the action that you want to set the state of +@tparam boolean state the state that you want to set it to, true = allow, false = disallow +@treturn Permissions_Groups._prototype returns self so function can be chained + +@usage-- Set an action to be disalowed +group:set_action('toggle_map_editor', false) + +]] function Permissions_Groups._prototype:set_action(action,state) if type(action) == 'string' then action = defines.input_action[action] @@ -154,9 +154,16 @@ function Permissions_Groups._prototype:set_action(action,state) return self end ---- Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime --- @tparam string|Array actions the action or actions that you want to allow for this group --- @treturn Permissions_Groups._prototype returns self so function can be chained +--[[-- Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime +@tparam string|Array actions the action or actions that you want to allow for this group +@treturn Permissions_Groups._prototype returns self so function can be chained + +@usage-- Allow some actions +group:allow{ + 'write_to_console' +} + +]] function Permissions_Groups._prototype:allow(actions) if type(actions) ~= 'table' then actions = {actions} @@ -167,9 +174,20 @@ function Permissions_Groups._prototype:allow(actions) return self end ---- Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime --- @tparam string|Array actions the action or actions that you want to disallow for this group --- @treturn Permissions_Groups._prototype returns self so function can be chained +--[[-- Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime +@tparam string|Array actions the action or actions that you want to disallow for this group +@treturn Permissions_Groups._prototype returns self so function can be chained + +@usage-- Disalow some actions +group:disallow{ + 'add_permission_group', + 'delete_permission_group', + 'import_permissions_string', + 'map_editor_action', + 'toggle_map_editor' +} + +]] function Permissions_Groups._prototype:disallow(actions) if type(actions) ~= 'table' then actions = {actions} @@ -180,23 +198,38 @@ function Permissions_Groups._prototype:disallow(actions) return self end ---- Sets the default state for any actions not given to be allowed, useful with :disallow --- @treturn Permissions_Groups._prototype returns self so function can be chained +--[[-- Sets the default state for any actions not given to be allowed, useful with :disallow +@treturn Permissions_Groups._prototype returns self so function can be chained + +@usage-- Allow all actions unless given by disallow +group:allow_all() + +]] function Permissions_Groups._prototype:allow_all() self.allow_all_actions = true return self end ---- Sets the default state for any action not given to be disallowed, useful with :allow --- @treturn Permissions_Groups._prototype returns self so function can be chained +--[[-- Sets the default state for any action not given to be disallowed, useful with :allow +@treturn Permissions_Groups._prototype returns self so function can be chained + +@usage-- Disallow all actions unless given by allow +group:disallow_all() + +]] function Permissions_Groups._prototype:disallow_all() self.allow_all_actions = false return self end ---- Returns if an input action is allowed for this group --- @tparam ?string|defines.input_action action the action that you want to test for --- @treturn boolean true if the group is allowed the action, false other wise +--[[-- Returns if an input action is allowed for this group +@tparam ?string|defines.input_action action the action that you want to test for +@treturn boolean true if the group is allowed the action, false other wise + +@usage-- Test if a group is allowed an action +local allowed = group:is_allowed('write_to_console') + +]] function Permissions_Groups._prototype:is_allowed(action) if type(action) == 'string' then action = defines.input_action[action] @@ -212,14 +245,13 @@ end -- Functions that control group players -- @section players ---- Returns the LuaPermissionGroup that was created with this group object, used internally --- @treturn LuaPermissionGroup the raw lua permission group -function Permissions_Groups._prototype:get_raw() - return game.permissions.get_group(self.name) -end +--[[-- Creates or updates the permission group with the configured actions, used internally +@treturn LuaPermissionGroup the permission group that was created ---- Creates or updates the permission group with the configured actions, used internally --- @treturn LuaPermissionGroup the permission group that was created +@usage-- Create the permission group so players can be added, used internally +group:create() + +]] function Permissions_Groups._prototype:create() local group = self:get_raw() if not group then @@ -231,9 +263,25 @@ function Permissions_Groups._prototype:create() return group end ---- Adds a player to this group --- @tparam LuaPlayer player LuaPlayer the player you want to add to this group can be name or index etc --- @treturn boolean true if the player was added successfully, false other wise +--[[-- Returns the LuaPermissionGroup that was created with this group object, used internally +@treturn LuaPermissionGroup the raw lua permission group + +@usage-- Get the factorio api permision group, used internally +local permission_group = group:get_raw() + +]] +function Permissions_Groups._prototype:get_raw() + return game.permissions.get_group(self.name) +end + +--[[-- Adds a player to this group +@tparam LuaPlayer player LuaPlayer the player you want to add to this group can be name or index etc +@treturn boolean true if the player was added successfully, false other wise + +@usage-- Add a player to this permission group +group:add_player(game.player) + +]] function Permissions_Groups._prototype:add_player(player) player = Game.get_player_from_any(player) local group = self:get_raw() @@ -242,9 +290,14 @@ function Permissions_Groups._prototype:add_player(player) return true end ---- Removes a player from this group --- @tparam LuaPlayer player LuaPlayer the player you want to remove from this group can be name or index etc --- @treturn boolean true if the player was removed successfully, false other wise +--[[-- Removes a player from this group +@tparam LuaPlayer player LuaPlayer the player you want to remove from this group can be name or index etc +@treturn boolean true if the player was removed successfully, false other wise + +@usage-- Remove a player from this permission group +group:remove_player(game.player) + +]] function Permissions_Groups._prototype:remove_player(player) player = Game.get_player_from_any(player) local group = self:get_raw() @@ -253,9 +306,17 @@ function Permissions_Groups._prototype:remove_player(player) return true end ---- Returns all player that are in this group with the option to filter to online/offline only --- @tparam[opt] boolean online if nil returns all players, if true online players only, if false returns online players only --- @treturn table a table of players that are in this group; filtered if online param is given +--[[-- Returns all player that are in this group with the option to filter to online/offline only +@tparam[opt] boolean online if nil returns all players, if true online players only, if false returns online players only +@treturn table a table of players that are in this group; filtered if online param is given + +@usage-- Get all players in this group +local online_players = group:get_players() + +@usage-- Get all online players in this group +local online_players = group:get_players(true) + +]] function Permissions_Groups._prototype:get_players(online) local players = {} local group = self:get_raw() @@ -273,9 +334,14 @@ function Permissions_Groups._prototype:get_players(online) return players end ---- Prints a message to every player in this group --- @tparam string message the message that you want to send to the players --- @treturn number the number of players that received the message +--[[-- Prints a message to every player in this group +@tparam string message the message that you want to send to the players +@treturn number the number of players that received the message + +@usage-- Print a message to all players in thie group +group:print('Hello, World!') + +]] function Permissions_Groups._prototype:print(message) local players = self:get_players(true) for _,player in pairs(players) do diff --git a/expcore/roles.lua b/expcore/roles.lua index 8c245ec8..5cd0610f 100644 --- a/expcore/roles.lua +++ b/expcore/roles.lua @@ -1,115 +1,111 @@ --[[-- Core Module - Roles - - Factorio role system to manage custom permissions. - @core Roles - @alias Roles +- Factorio role system to manage custom permissions. +@core Roles +@alias Roles - @usage ----- Using Role System (Frontend): - When a map first starts you will want to define on mass all the players you expect to join and the roles to give them: - Roles.override_player_roles{ - Cooldude2606 = {'Owner','Admin','Member'}, - NotCooldude2606 = {'Member'} - } +@usage--- Using Role System (assignment): +--When a map first starts you will want to define on mass all the players you expect to join and the roles to give them: +Roles.override_player_roles{ + Cooldude2606 = {'Owner','Admin','Member'}, + NotCooldude2606 = {'Member'} +} - Once the game is running you still want to be able to give role and remove them which is when you would use: - Roles.assign_player(player,'Admin',by_player_name) -- this will give the "Admin" role to the player - Roles.unassign_player(player,{'Admin','Moderator'},by_player_name) -- this will remove "Admin" and "Moderator" role in one go +--Once the game is running you still want to be able to give role and remove them which is when you would use: +Roles.assign_player(player,'Admin',by_player_name) -- this will give the "Admin" role to the player +Roles.unassign_player(player,{'Admin','Moderator'},by_player_name) -- this will remove "Admin" and "Moderator" role in one go - @usage ----- Using Role System (Backend): - To comparer two players you can comparer the index of they highest roles, can be used when you want to allow a "write" down type system: - Roles.get_player_highest_role(playerOne).index < Roles.get_player_highest_role(playerTwo).index -- remember that less means a higher role +@usage--- Using Role System (role testing): +--To comparer two players you can comparer the index of they highest roles, can be used when you want to allow a "write" down type system: +Roles.get_player_highest_role(playerOne).index < Roles.get_player_highest_role(playerTwo).index -- remember that less means a higher role - Listing all of a players roles can also be useful which is when you would want to use: - Roles.get_player_roles(player) -- the return is an array that can be looped over however this is not in particular order +--Listing all of a players roles can also be useful which is when you would want to use: +Roles.get_player_roles(player) -- the return is an array that can be looped over however this is not in particular order - Finally you may want to test if a player has a certain role, flag or action allowed which is when you would use: - Roles.player_has_role(player,'Admin') -- you can provide a role name if you only want a name based system - Roles.player_has_flag(player,'is_donator') -- your roles can be grouped together with flags such as is_donator - Roles.player_allowed(player,'game modifiers') -- or you can have an action based system where each action is something the player can do +--Finally you may want to test if a player has a certain role, flag or action allowed which is when you would use: +Roles.player_has_role(player,'Admin') -- you can provide a role name if you only want a name based system +Roles.player_has_flag(player,'is_donator') -- your roles can be grouped together with flags such as is_donator +Roles.player_allowed(player,'game modifiers') -- or you can have an action based system where each action is something the player can do - @usage ----- Example Flag Define: - Flags can be used to group multiple roles and actions under one catch all, for example if you want a piece of code to only - be active for your donators then you would add a "is_donator" flag to all your donator roles and then in the code test if - a player has that tag present: +@usage--- Example Flag Define: +--Flags can be used to group multiple roles and actions under one catch all, for example if you want a piece of code to only +--be active for your donators then you would add a "is_donator" flag to all your donator roles and then in the code test if +--a player has that tag present: - -- give you donators a speed boost when they join; these functions aren't required but can be useful - Roles.define_flag_trigger('is_donator',function(player,state) - if state then - player.character_running_speed_modifier = 1.5 - else - player.character_running_speed_modifier = 1 - end - end) - - -- then on all your donator roles you would add - Roles.new_role('Donator') - :set_flag('is_donator') - - -- and in your code you would test for - if Roles.player_has_flag(player,'is_donator') then - -- some donator only code +-- give you donators a speed boost when they join; these functions aren't required but can be useful +Roles.define_flag_trigger('is_donator',function(player,state) + if state then + player.character_running_speed_modifier = 1.5 + else + player.character_running_speed_modifier = 1 end +end) - @usage ----- Example Role Define: - You can't use a role system without any roles so first you must define your roles; each role has a minimum of a name with - the option for a shorthand: - Roles.new_role('Administrator','Admin') +-- then on all your donator roles you would add +Roles.new_role('Donator') +:set_flag('is_donator') - Next you will want to add any extras you want to have, such as a tag, colour, permission group or any custom flags: - Roles.new_role('Administrator','Admin') - :set_custom_tag('[Admin]') - :set_custom_color('red') -- this can be {r=0,g=0,b=0} or a predefined value - :set_permission_group('Staff') -- a second argument can be added if you have not used the custom permission group config - :set_flag('is_admin') +-- and in your code you would test for +if Roles.player_has_flag(player,'is_donator') then + -- some donator only code +end - You will then want to decide if you want to allow all actions, this should of course be used sparely: - Roles.new_role('Administrator','Admin') - ...extras... - :set_allow_all() +@usage--- Example Role Define: +--You can't use a role system without any roles so first you must define your roles; each role has a minimum of a name with +--the option for a shorthand: +Roles.new_role('Administrator','Admin') - If you don't do this want this as i would advise you do then you will want to define what the role can do; this comes with - an optional inheritance system if you like those sort of things in which case disallow may also be of some use to you: - Roles.new_role('Administrator','Admin') - ...extras... - :set_parent('Moderator') -- the admin can do anything that a moderator can do - :allow{ -- these actions can be anything just try to keep them without conflicts - 'command/kill', - 'gui/game settings' - } +--Next you will want to add any extras you want to have, such as a tag, colour, permission group or any custom flags: +Roles.new_role('Administrator','Admin') +:set_custom_tag('[Admin]') +:set_custom_color('red') -- this can be {r=0,g=0,b=0} or a predefined value +:set_permission_group('Staff') -- a second argument can be added if you have not used the custom permission group config +:set_flag('is_admin') - Here is what the finished admin role would look like: - Roles.new_role('Administrator','Admin') - :set_custom_tag('[Admin]') - :set_custom_color('red') - :set_permission_group('Staff') - :set_flag('is_admin') - :set_parent('Moderator') - :allow{ - 'command/kill', - 'gui/game settings' - } +--You will then want to decide if you want to allow all actions, this should of course be used sparely: +Roles.new_role('Administrator','Admin') +...extras... +:set_allow_all() - @usage ----- Example System Define: - Once all roles are defined these steps must be done to ensure the system is ready to use, this includes setting a default - role, assigning a root (all permission) role that the server/system will use and the linear order that the roles fall into: +--If you don't do this want this as i would advise you do then you will want to define what the role can do; this comes with +--an optional inheritance system if you like those sort of things in which case disallow may also be of some use to you: +Roles.new_role('Administrator','Admin') +...extras... +:set_parent('Moderator') -- the admin can do anything that a moderator can do +:allow{ -- these actions can be anything just try to keep them without conflicts + 'command/kill', + 'gui/game settings' +} - Roles.set_default('Guest') - Roles.set_root('System') +--Here is what the finished admin role would look like: +Roles.new_role('Administrator','Admin') +:set_custom_tag('[Admin]') +:set_custom_color('red') +:set_permission_group('Staff') +:set_flag('is_admin') +:set_parent('Moderator') +:allow{ + 'command/kill', + 'gui/game settings' +} - Roles.define_role_order{ - 'System', - 'Administrator', - 'Moderator', - 'Donator', - 'Guest' - } +@usage--- Example System Define: +--Once all roles are defined these steps must be done to ensure the system is ready to use, this includes setting a default +--role, assigning a root (all permission) role that the server/system will use and the linear order that the roles fall into: + +Roles.set_default('Guest') +Roles.set_root('System') + +Roles.define_role_order{ + 'System', + 'Administrator', + 'Moderator', + 'Donator', + 'Guest' +} + +--Just remember that in this example all these roles have not been defined; so make sure all your roles that are used are defined +--before hand; a config file on load is useful for this to ensure that its loaded before the first player even joins. - Just remember that in this example all these roles have not been defined; so make sure all your roles that are used are defined - before hand; a config file on load is useful for this to ensure that its loaded before the first player even joins. ]] local Game = require 'utils.game' --- @dep utils.game @@ -196,8 +192,13 @@ local function emit_player_roles_updated(player,type,roles,by_player_name,skip_g }) end ---- Returns a string which contains all roles in index order displaying all data for them --- @treturn string the debug output string +--[[-- Returns a string which contains all roles in index order displaying all data for them +@treturn string the debug output string + +@usage-- Print the debug string +game.player.print(Roles.debug()) + +]] function Roles.debug() local output = '' for index,role_name in pairs(Roles.config.order) do @@ -209,9 +210,14 @@ function Roles.debug() return output end ---- Prints a message to all players in the given roles, may send duplicate message however factorio blocks spam --- @tparam table roles table a of roles which to send the message to --- @tparam string message the message to send to the players +--[[-- Prints a message to all players in the given roles, may send duplicate message however factorio blocks spam +@tparam table roles table a of roles which to send the message to +@tparam string message the message to send to the players + +@usage-- Print a message to the given roles +Roles.print_to_roles({'Administrator','Moderator'}, 'Hello, World!') + +]] function Roles.print_to_roles(roles,message) for _,role in pairs(roles) do role = Roles.get_role_from_any(role) @@ -219,9 +225,14 @@ function Roles.print_to_roles(roles,message) end end ---- Prints a message to all players who have the given role or one which is higher (excluding default) --- @tparam string role the name of the role to send the message to --- @tparam string message the message to send to the players +--[[-- Prints a message to all players who have the given role or one which is higher (excluding default) +@tparam string role the name of the role to send the message to +@tparam string message the message to send to the players + +@usage-- Print a message to the roles above this role, includes the given role +Roles.print_to_roles_higher('Moderator', 'Hello, World!') + +]] function Roles.print_to_roles_higher(role,message) role = Roles.get_role_from_any(role) if not role then return end @@ -234,9 +245,14 @@ function Roles.print_to_roles_higher(role,message) Roles.print_to_roles(roles,message) end ---- Prints a message to all players who have the given role or one which is lower (excluding default) --- @tparam string role the name of the role to send the message to --- @tparam string message the message to send to the players +--[[-- Prints a message to all players who have the given role or one which is lower (excluding default) +@tparam string role the name of the role to send the message to +@tparam string message the message to send to the players + +@usage-- Print a message to the roles below this role, includes the given role +Roles.print_to_roles_higher('Moderator', 'Hello, World!') + +]] function Roles.print_to_roles_lower(role,message) role = Roles.get_role_from_any(role) if not role then return end @@ -249,25 +265,40 @@ function Roles.print_to_roles_lower(role,message) Roles.print_to_roles(roles,message) end ---- Get a role for the given name --- @tparam string name the name of the role to get --- @treturn Roles._prototype the role with that name or nil +--[[-- Get a role for the given name +@tparam string name the name of the role to get +@treturn Roles._prototype the role with that name or nil + +@usage-- Get a role by its name +local role = Roles.get_role_by_name('Moderator') + +]] function Roles.get_role_by_name(name) return Roles.config.roles[name] end ---- Get a role with the given order index --- @tparam number index the place in the order list of the role to get --- @treturn Roles._prototype the role with that index in the order list or nil +--[[-- Get a role with the given order index +@tparam number index the place in the order list of the role to get +@treturn Roles._prototype the role with that index in the order list or nil + +@usage-- Get a role by its index in the order list +local role = Roles.get_role_by_name(2) + +]] function Roles.get_role_by_order(index) local name = Roles.config.order[index] return Roles.config.roles[name] end ---- Gets a role from a name,index or role object (where it is just returned) --- nb: this function is used for the input for most outward facing functions --- @tparam ?number|string|table any the value used to find the role --- @treturn Roles._prototype the role that was found or nil see above +--[[-- Gets a role from a name,index or role object (where it is just returned) +nb: this function is used for the input for most outward facing functions +@tparam ?number|string|table any the value used to find the role +@treturn Roles._prototype the role that was found or nil see above + +@usage-- Get a role by its name or order +local role = Roles.get_role_from_any('Moderator') + +]] function Roles.get_role_from_any(any) local t_any = type(any) if t_any == 'number' or tonumber(any) then @@ -280,9 +311,14 @@ function Roles.get_role_from_any(any) end end ---- Gets all the roles of the given player, this will always contain the default role --- @tparam LuaPlayer player the player to get the roles of --- @treturn table a table where the values are the roles which the player has +--[[-- Gets all the roles of the given player, this will always contain the default role +@tparam LuaPlayer player the player to get the roles of +@treturn table a table where the values are the roles which the player has + +@usage-- Get the roles that a player has +local roles = Roles.get_player_roles(game.player) + +]] function Roles.get_player_roles(player) player = Game.get_player_from_any(player) if not player then return {Roles.config.roles[Roles.config.internal.root]} end @@ -295,9 +331,14 @@ function Roles.get_player_roles(player) return rtn end ---- Gets the highest role which the player has, can be used to compeer one player to another --- @tparam LuaPlayer player the player to get the highest role of --- @treturn the role with the highest order index which this player has +--[[-- Gets the highest role which the player has, can be used to compeer one player to another +@tparam LuaPlayer player the player to get the highest role of +@treturn the role with the highest order index which this player has + +@usage-- Get the highest role that a player has +local role = Roles.get_player_highest_role(game.player) + +]] function Roles.get_player_highest_role(player) local roles = Roles.get_player_roles(player) if not roles then return end @@ -314,12 +355,20 @@ end -- Functions for changing player's roles -- @section assinment ---- Gives a player the given role(s) with an option to pass a by player name used in the log --- @tparam LuaPlayer player the player that will be assigned the roles --- @tparam table roles table a of roles that the player will be given, can be one role and can be role names --- @tparam[opt=] string by_player_name the name of the player that will be shown in the log --- @tparam[opt=false] boolean skip_checks when true there will be no checks are done for if the player is valid --- @tparam[opt=false] boolean silent when true there will be no game message printed +--[[-- Gives a player the given role(s) with an option to pass a by player name used in the log +@tparam LuaPlayer player the player that will be assigned the roles +@tparam table roles table a of roles that the player will be given, can be one role and can be role names +@tparam[opt=] string by_player_name the name of the player that will be shown in the log +@tparam[opt=false] boolean skip_checks when true there will be no checks are done for if the player is valid +@tparam[opt=false] boolean silent when true there will be no game message printed + +@usage-- Assign a player to the Moderator role +Roles.assign_player(game.player, 'Moderator') + +@usage-- Assign a player to the Moderator role, even if the player has never been on the map +Roles.assign_player('Cooldude2606', 'Moderator', nil, true) + +]] function Roles.assign_player(player,roles,by_player_name,skip_checks,silent) local valid_player = Game.get_player_from_any(player) if not skip_checks and not valid_player then return end @@ -337,12 +386,20 @@ function Roles.assign_player(player,roles,by_player_name,skip_checks,silent) end end ---- Removes a player from the given role(s) with an option to pass a by player name used in the log --- @tparam LuaPlayer player the player that will have the roles removed --- @tparam table roles table a of roles to be removed from the player, can be one role and can be role names --- @tparam[opt=] string by_player_name the name of the player that will be shown in the logs --- @tparam[opt=false] boolean skip_checks when true there will be no checks are done for if the player is valid --- @tparam[opt=false] boolean silent when true there will be no game message printed +--[[-- Removes a player from the given role(s) with an option to pass a by player name used in the log +@tparam LuaPlayer player the player that will have the roles removed +@tparam table roles table a of roles to be removed from the player, can be one role and can be role names +@tparam[opt=] string by_player_name the name of the player that will be shown in the logs +@tparam[opt=false] boolean skip_checks when true there will be no checks are done for if the player is valid +@tparam[opt=false] boolean silent when true there will be no game message printed + +@usage-- Unassign a player from the Moderator role +Roles.unassign_player(game.player, 'Moderator') + +@usage-- Unassign a player from the Moderator role, even if the player has never been on the map +Roles.unassign_player('Cooldude2606', 'Moderator', nil, true) + +]] function Roles.unassign_player(player,roles,by_player_name,skip_checks,silent) local valid_player = Game.get_player_from_any(player) if not skip_checks and not valid_player then return end @@ -361,20 +418,41 @@ function Roles.unassign_player(player,roles,by_player_name,skip_checks,silent) end end ---- Overrides all player roles with the given table of roles, useful to mass set roles on game start --- @tparam table roles table a which is indexed by case sensitive player names and has the value of a table of role names -function Roles.override_player_roles(roles) - Roles.config.players = roles +--[[-- Overrides all player roles with the given table of roles, useful to mass set roles on game start +@tparam[opt] string player_name the player to set the roles for, if not given all roles are overriden +@tparam table roles table a which is indexed by case sensitive player names and has the value of a table of role names + +@usage-- Override the roles of a single player, other users are not effected +Roles.override_player_roles('Cooldude2606', {'Moderator'}) + +@usage-- Override all existing roles, effects all users not just ones listed +Roles.override_player_roles{ + ['Cooldude2606'] = {'Administrator','Moderator'}, + ['arty714'] = {'Administrator','Moderator'}, +} + +]] +function Roles.override_player_roles(player_name,roles) + if not roles then + Roles.config.players = player_name + else + Roles.config.players[player_name] = roles + end end --- Checks. -- Functions for checking player's roles -- @section checks ---- A test for weather a player has the given role --- @tparam LuaPlayer player the player to test the roles of --- @tparam ?string|number|table search_role a pointer to the role that is being searched for --- @treturn boolean true if the player has the role, false otherwise, nil for errors +--[[-- A test for weather a player has the given role +@tparam LuaPlayer player the player to test the roles of +@tparam ?string|number|table search_role a pointer to the role that is being searched for +@treturn boolean true if the player has the role, false otherwise, nil for errors + +@usage-- Test if a player has a role +local has_role = Roles.player_has_role(game.player, 'Moderator') + +]] function Roles.player_has_role(player,search_role) local roles = Roles.get_player_roles(player) if not roles then return end @@ -386,10 +464,15 @@ function Roles.player_has_role(player,search_role) return false end ---- A test for weather a player has the given flag true for at least one of they roles --- @tparam LuaPlayer player the player to test the roles of --- @tparam string flag_name the name of the flag that is being looked for --- @treturn boolean true if the player has at least one role which has the flag set to true, false otherwise, nil for errors +--[[-- A test for weather a player has the given flag true for at least one of they roles +@tparam LuaPlayer player the player to test the roles of +@tparam string flag_name the name of the flag that is being looked for +@treturn boolean true if the player has at least one role which has the flag set to true, false otherwise, nil for errors + +@usage-- Test if a player has a role +local has_flag = Roles.player_has_flag(game.player, 'is_donator') + +]] function Roles.player_has_flag(player,flag_name) local roles = Roles.get_player_roles(player) if not roles then return end @@ -401,10 +484,15 @@ function Roles.player_has_flag(player,flag_name) return false end ---- A test for weather a player has at least one role which is allowed the given action --- @tparam LuaPlayer player the player to test the roles of --- @tparam string action the name of the action that is being tested for --- @treturn boolean true if the player has at least one role which is allowed this action, false otherwise, nil for errors +--[[-- A test for weather a player has at least one role which is allowed the given action +@tparam LuaPlayer player the player to test the roles of +@tparam string action the name of the action that is being tested for +@treturn boolean true if the player has at least one role which is allowed this action, false otherwise, nil for errors + +@usage-- Test if a player has a role +local has_flag = Roles.player_has_flag(game.player, 'is_donator') + +]] function Roles.player_allowed(player,action) local roles = Roles.get_player_roles(player) if not roles then return end @@ -420,9 +508,20 @@ end -- Functions which are used to define roles -- @section checks ---- Used to set the role order, higher in the list is better, must be called at least once in config +--[[-- Used to set the role order, higher in the list is better, must be called at least once in config -- nb: function also re links parents due to expected position in the config file --- @tparam table order table a which is keyed only by numbers (start 1) and values are roles in order with highest first +@tparam table order table a which is keyed only by numbers (start 1) and values are roles in order with highest first + +@usage-- Define which roles are higher than others +Roles.define_role_order{ + 'System', + 'Administrator', + 'Moderator', + 'Donator', + 'Guest' +} + +]] function Roles.define_role_order(order) -- Clears and then rebuilds the order table _C.error_if_runtime() @@ -457,26 +556,41 @@ function Roles.define_role_order(order) end end ---- Defines a new trigger for when a tag is added or removed from a player --- @tparam string name the name of the flag which the roles will have --- @tparam function callback the function that is called when roles are assigned --- flag param - player - the player that has had they roles changed --- flag param - state - the state of the flag, aka if the flag is present +--[[-- Defines a new trigger for when a tag is added or removed from a player +@tparam string name the name of the flag which the roles will have +@tparam function callback the function that is called when roles are assigned + +@usage-- Defineing a flag trigger +Roles.define_flag_trigger('is_donator', function(player, state) + player.character_running_speed_modifier = state and 1.5 or 1 +end) + +]] function Roles.define_flag_trigger(name,callback) _C.error_if_runtime() Roles.config.flags[name] = Async.register(callback) end ---- Sets the default role which every player will have, this needs to be called at least once --- @tparam string name the name of the default role +--[[-- Sets the default role which every player will have, this needs to be called at least once +@tparam string name the name of the default role + +@usage-- Setting the default role +Roles.set_default('Guest') + +]] function Roles.set_default(name) local role = Roles.config.roles[name] if not role then return end Roles.config.internal.default = name end ---- Sets the root role which will always have all permissions, any server actions act from this role --- @tparam string name the name of the root role +--[[-- Sets the root role which will always have all permissions, any server actions act from this role +@tparam string name the name of the root role + +@usage-- Setting the root role +Roles.set_root('System') + +]] function Roles.set_root(name) local role = Roles.config.roles[name] if not role then return end @@ -484,10 +598,15 @@ function Roles.set_root(name) Roles.config.internal.root = name end ---- Defines a new role and returns the prototype to allow configuration --- @tparam string name the name of the new role, must be unique --- @tparam[opt=name] string short_hand the shortened version of the name --- @treturn Roles._prototype the start of the config chain for this role +--[[-- Defines a new role and returns the prototype to allow configuration +@tparam string name the name of the new role, must be unique +@tparam[opt=name] string short_hand the shortened version of the name +@treturn Roles._prototype the start of the config chain for this role + +@usage-- Defineing a new role +local role = Roles.new_role('Moderator', 'Mod') + +]] function Roles.new_role(name,short_hand) _C.error_if_runtime() if Roles.config.roles[name] then return error('Role name is non unique') end @@ -506,18 +625,31 @@ end -- Functions for using the role action system -- @section actions ---- Sets the default allow state of the role, true will allow all actions --- @tparam[opt=true] boolean state true will allow all actions --- @treturn Roles._prototype allows chaining +--[[-- Sets the default allow state of the role, true will allow all actions +@tparam[opt=true] boolean state true will allow all actions +@treturn Roles._prototype allows chaining + +@usage-- Allow all actions for this role, useful for root like roles +role:set_allow_all() + +]] function Roles._prototype:set_allow_all(state) if state == nil then state = true end self.allow_all_actions = not not state -- not not forces a boolean value return self end ---- Sets the allow actions for this role, actions in this list will be allowed for this role --- @tparam table actions indexed with numbers and is an array of action names, order has no effect --- @treturn Roles._prototype allows chaining +--[[-- Sets the allow actions for this role, actions in this list will be allowed for this role +@tparam table actions indexed with numbers and is an array of action names, order has no effect +@treturn Roles._prototype allows chaining + +@usage-- Allow some actions for a role +role:allow{ + 'command/kill', + 'gui/game settings' +} + +]] function Roles._prototype:allow(actions) if type(actions) ~= 'table' then actions = {actions} @@ -528,9 +660,17 @@ function Roles._prototype:allow(actions) return self end ---- Sets the disallow actions for this role, will prevent actions from being allowed regardless of inheritance --- @tparam table actions indexed with numbers and is an array of action names, order has no effect --- @treturn Roles._prototype allows chaining +--[[-- Sets the disallow actions for this role, will prevent actions from being allowed regardless of inheritance +@tparam table actions indexed with numbers and is an array of action names, order has no effect +@treturn Roles._prototype allows chaining + +@usage-- Disalow an action for a role, useful if inherit an action from a parent +role:disallow{ + 'command/kill', + 'gui/game settings' +} + +]] function Roles._prototype:disallow(actions) if type(actions) ~= 'table' then actions = {actions} @@ -541,9 +681,14 @@ function Roles._prototype:disallow(actions) return self end ---- Test for if a role is allowed the given action, mostly internal see Roles.player_allowed --- @tparam string action the name of the action to test if it is allowed --- @treturn boolean true if action is allowed, false otherwise +--[[-- Test for if a role is allowed the given action, mostly internal see Roles.player_allowed +@tparam string action the name of the action to test if it is allowed +@treturn boolean true if action is allowed, false otherwise + +@usage-- Test if a role is allowed an action +local allowed = role:is_allowed('command/kill') + +]] function Roles._prototype:is_allowed(action) local is_root = Roles.config.internal.root.name == self.name return self.allowed_actions[action] or self.allow_all_actions or is_root @@ -553,26 +698,41 @@ end -- Functions for using the role flag system -- @section flags ---- Sets the state of a flag for a role, flags can be used to apply effects to players --- @tparam string name the name of the flag to set the value of --- @tparam[opt=true] boolean value the state to set the flag to --- @treturn Roles._prototype allows chaining +--[[-- Sets the state of a flag for a role, flags can be used to apply effects to players +@tparam string name the name of the flag to set the value of +@tparam[opt=true] boolean value the state to set the flag to +@treturn Roles._prototype allows chaining + +@usage-- Set a flag for a role +role:set_flag('is_admin') + +]] function Roles._prototype:set_flag(name,value) if value == nil then value = true end self.flags[name] = not not value -- not not forces a boolean value return self end ---- Clears all flags from this role, individual flags can be removed with set_flag(name,false) --- @treturn Roles._prototype allows chaining +--[[-- Clears all flags from this role, individual flags can be removed with set_flag(name,false) +@treturn Roles._prototype allows chaining + +@usage-- Remove all flags from a role +role:clear_flags() + +]] function Roles._prototype:clear_flags() self.flags = {} return self end ---- A test for if the role has a flag set --- @tparam string name the name of the flag to test for --- @treturn boolean true if the flag is set, false otherwise +--[[-- A test for if the role has a flag set +@tparam string name the name of the flag to test for +@treturn boolean true if the flag is set, false otherwise + +@usage-- Test if a role has a flag +local has_flag = role:has_flag('is_admin') + +]] function Roles._prototype:has_flag(name) return self.flags[name] or false end @@ -581,17 +741,27 @@ end -- Functions for chaning other proerties -- @section properties ---- Sets a custom player tag for the role, can be accessed by other code --- @tparam string tag the value that the tag will be --- @treturn Roles._prototype allows chaining +--[[-- Sets a custom player tag for the role, can be accessed by other code +@tparam string tag the value that the tag will be +@treturn Roles._prototype allows chaining + +@usage-- Set a custom tag for this role, other code is required to set the tag +role:set_custom_tag('Mod') + +]] function Roles._prototype:set_custom_tag(tag) self.custom_tag = tag return self end ---- Sets a custom colour for the role, can be accessed by other code --- @tparam table color ?string|table can either be and rgb colour or the name of a colour defined in the presets --- @treturn Roles._prototype allows chaining +--[[-- Sets a custom colour for the role, can be accessed by other code +@tparam table color ?string|table can either be and rgb colour or the name of a colour defined in the presets +@treturn Roles._prototype allows chaining + +@usage-- Set a custom colour for this role, other code is required to use this value +role:set_custom_color{ r=255, g=100, b=100} + +]] function Roles._prototype:set_custom_color(color) if type(color) ~= 'table' then color = Colours[color] @@ -600,10 +770,15 @@ function Roles._prototype:set_custom_color(color) return self end ---- Sets the permission group for this role, players will be moved to the group of they highest role --- @tparam string name the name of the permission group to have players moved to --- @tparam[opt=false] boolean use_factorio_api when true the custom permission group module is ignored --- @treturn Roles._prototype allows chaining +--[[-- Sets the permission group for this role, players will be moved to the group of they highest role +@tparam string name the name of the permission group to have players moved to +@tparam[opt=false] boolean use_factorio_api when true the custom permission group module is ignored +@treturn Roles._prototype allows chaining + +@usage-- Set the permission group for this role, see permission_groups.lua +role:set_permission_group('Admin') + +]] function Roles._prototype:set_permission_group(name,use_factorio_api) _C.error_if_runtime() if use_factorio_api then @@ -616,10 +791,15 @@ function Roles._prototype:set_permission_group(name,use_factorio_api) return self end ---- Sets the parent for a role, any action not in allow or disallow will be looked for in its parents --- nb: this is a recursive action, and changing the allows and disallows will effect all children roles --- @tparam string role the name of the role that will be the parent; has imminent effect if role is already defined --- @treturn Roles._prototype allows chaining +--[[-- Sets the parent for a role, any action not in allow or disallow will be looked for in its parents +nb: this is a recursive action, and changing the allows and disallows will effect all children roles +@tparam string role the name of the role that will be the parent; has imminent effect if role is already defined +@treturn Roles._prototype allows chaining + +@usage-- Set the parent for this role to inherit all actions allowed +role:set_parent('Guest') + +]] function Roles._prototype:set_parent(role) _C.error_if_runtime() self.parent = role @@ -629,19 +809,31 @@ function Roles._prototype:set_parent(role) return self end ---- Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will receive the role --- nb: this is one way, failing false after already gaining the role will not revoke the role --- @tparam function callback receives only one param which is player to promote, return true to promote the player --- @treturn Roles._prototype allows chaining -function Roles._prototype:set_auto_promote_condition(callback) +--[[-- Sets an auto assign condition that is checked every 60 seconds, if true is returned then the player will receive the role +nb: this is one way, failing false after already gaining the role will not revoke the role +@tparam function callback receives only one param which is player to promote, return true to promote the player +@treturn Roles._prototype allows chaining + +@usage-- Give this role to a user if there are admin, ran every 60 seconds +role:set_auto_assign_condition(function(player) + return player.admin +end) + +]] +function Roles._prototype:set_auto_assign_condition(callback) _C.error_if_runetime_closure(callback) self.auto_promote_condition = callback return self end ---- Sets the role to not allow players to have auto promote effect them, useful to keep people locked to a punishment --- @tparam[opt=true] boolean state when true the players with this role will not be auto promoted --- @treturn Roles._prototype allows chaining +--[[-- Sets the role to not allow players to have auto assign effect them, useful to keep people locked to a role +@tparam[opt=true] boolean state when true the players with this role will not be auto assigned to other roles +@treturn Roles._prototype allows chaining + +@usage-- Make a role stop players from being auto assigned to other roles +role:set_block_auto_promote() + +]] function Roles._prototype:set_block_auto_promote(state) if state == nil then state = true end self.block_auto_promote = not not state -- forces a boolean value @@ -652,11 +844,16 @@ end -- Functions that control players in a role -- @section players ---- Adds a player to this role, players can have more than one role at a time, used internally see Roles.assign --- @tparam LuaPlayer player the player that will be given this role --- @tparam boolean skip_check when true player will be taken as the player name (use when player has not yet joined) --- @tparam boolean skip_event when true the event emit will be skipped, this is used internally with Roles.assign --- @treturn boolean true if the player was added successfully +--[[-- Adds a player to this role, players can have more than one role at a time, used internally see Roles.assign +@tparam LuaPlayer player the player that will be given this role +@tparam boolean skip_check when true player will be taken as the player name (use when player has not yet joined) +@tparam boolean skip_event when true the event emit will be skipped, this is used internally with Roles.assign +@treturn boolean true if the player was added successfully + +@usage-- Assign a player to this role +role:add_player(game.player) + +]] function Roles._prototype:add_player(player,skip_check,skip_event) player = Game.get_player_from_any(player) -- Default role cant have players added or removed @@ -686,11 +883,16 @@ function Roles._prototype:add_player(player,skip_check,skip_event) return true end ---- Removes a player from this role, players can have more than one role at a time, used internally see Roles.unassign --- @tparam LuaPlayer player the player that will lose this role --- @tparam boolean skip_check when true player will be taken as the player name (use when player has not yet joined) --- @tparam boolean skip_event when true the event emit will be skipped, this is used internally with Roles.unassign --- @treturn boolean true if the player was removed successfully +--[[-- Removes a player from this role, players can have more than one role at a time, used internally see Roles.unassign +@tparam LuaPlayer player the player that will lose this role +@tparam boolean skip_check when true player will be taken as the player name (use when player has not yet joined) +@tparam boolean skip_event when true the event emit will be skipped, this is used internally with Roles.unassign +@treturn boolean true if the player was removed successfully + +@usage-- Unassign a player from this role +role:remove_player(game.player) + +]] function Roles._prototype:remove_player(player,skip_check,skip_event) player = Game.get_player_from_any(player) -- Default role cant have players added or removed @@ -725,9 +927,17 @@ function Roles._prototype:remove_player(player,skip_check,skip_event) return rtn end ---- Returns an array of all the players who have this role, can be filtered by online status --- @tparam[opt=nil] boolean online when given will filter by this online state, nil will return all players --- @treturn table all the players who have this role, indexed order is meaningless +--[[-- Returns an array of all the players who have this role, can be filtered by online status +@tparam[opt=nil] boolean online when given will filter by this online state, nil will return all players +@treturn table all the players who have this role, indexed order is meaningless + +@usage-- Get all the players with this role +local players = role:get_players() + +@usage-- Get all online players with this role +local players = role:get_players(true) + +]] function Roles._prototype:get_players(online) local players = {} -- Gets all players that have this role @@ -756,9 +966,14 @@ function Roles._prototype:get_players(online) end end ---- Will print a message to all players with this role --- @tparam string message the message that will be printed to the players --- @treturn number the number of players who received the message +--[[-- Will print a message to all players with this role +@tparam string message the message that will be printed to the players +@treturn number the number of players who received the message + +@usage-- Print a message to all players with this role +role:print('Hello, World!') + +]] function Roles._prototype:print(message) local players = self:get_players(true) for _,player in pairs(players) do diff --git a/modules/addons/greetings.lua b/modules/addons/greetings.lua index 068e33e7..4541f42e 100644 --- a/modules/addons/greetings.lua +++ b/modules/addons/greetings.lua @@ -1,4 +1,5 @@ ---greets players on join +--- Greets players on join +-- @addon greetings local Event = require 'utils.event' --- @dep utils.event local Game = require 'utils.game' --- @dep utils.event diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua index faf239f7..19aae6cb 100644 --- a/modules/commands/admin-chat.lua +++ b/modules/commands/admin-chat.lua @@ -13,7 +13,7 @@ require 'config.expcore.command_general_parse' Commands.new_command('admin-chat','Sends a message in chat that only admins can see.') :add_param('message',false) :enable_auto_concat() -:set_flag('admin_only',true) +:set_flag('admin_only') :add_alias('ac') :register(function(player,message,raw) local player_name_colour = format_chat_player_name(player) diff --git a/modules/commands/cheat-mode.lua b/modules/commands/cheat-mode.lua index f3f525df..c2eb462a 100644 --- a/modules/commands/cheat-mode.lua +++ b/modules/commands/cheat-mode.lua @@ -14,7 +14,7 @@ Commands.new_command('toggle-cheat-mode','Toggles cheat mode for your player, or :set_defaults{player=function(player) return player -- default is the user using the command end} -:set_flag('admin_only',true) +:set_flag('admin_only') :register(function(player,action_player,raw) action_player.cheat_mode = not action_player.cheat_mode end) \ No newline at end of file diff --git a/modules/commands/interface.lua b/modules/commands/interface.lua index 67dbd035..5f105d45 100644 --- a/modules/commands/interface.lua +++ b/modules/commands/interface.lua @@ -63,7 +63,7 @@ end Commands.new_command('interface','Sends an innovation to be ran and returns the result.') :add_param('innovation',false) :enable_auto_concat() -:set_flag('admin_only',true) +:set_flag('admin_only') :register(function(player,innovation,raw) if not innovation:find('%s') and not innovation:find('return') then -- if there are no spaces and return is not present then return is appended to the start diff --git a/modules/commands/roles.lua b/modules/commands/roles.lua index af36302a..1005b322 100644 --- a/modules/commands/roles.lua +++ b/modules/commands/roles.lua @@ -15,7 +15,7 @@ local format_chat_player_name, format_chat_colour_localized = _C.format_chat_pla Commands.new_command('assign-role','Assigns a role to a player') :add_param('player',false,'player-role') :add_param('role',false,'role') -:set_flag('admin-only',true) +:set_flag('admin-only') :add_alias('rpromote','assign','role','add-role') :register(function(player,action_player,role,raw) local player_highest = Roles.get_player_highest_role(player) @@ -33,7 +33,7 @@ end) Commands.new_command('unassign-role','Unassigns a role from a player') :add_param('player',false,'player-role') :add_param('role',false,'role') -:set_flag('admin-only',true) +:set_flag('admin-only') :add_alias('rdemote','unassign','rerole','remove-role') :register(function(player,action_player,role,raw) local player_highest = Roles.get_player_highest_role(player) diff --git a/modules/commands/teleport.lua b/modules/commands/teleport.lua index f5e88906..5e8ea3b4 100644 --- a/modules/commands/teleport.lua +++ b/modules/commands/teleport.lua @@ -23,7 +23,7 @@ Commands.new_command('teleport','Teleports a player to another player.') :add_param('from_player',false,'player-alive') :add_param('to_player',false,'player-online') :add_alias('tp') -:set_flag('admin_only',true) +:set_flag('admin_only') :register(function(player,from_player,to_player,raw) if from_player.index == to_player.index then -- return if attempting to teleport to self @@ -40,7 +40,7 @@ end) -- @tparam LuaPlayer player the player that will be teleported, must be alive Commands.new_command('bring','Teleports a player to you.') :add_param('player',false,'player-alive') -:set_flag('admin_only',true) +:set_flag('admin_only') :register(function(player,from_player,raw) if from_player.index == player.index then -- return if attempting to teleport to self @@ -58,7 +58,7 @@ end) Commands.new_command('goto','Teleports you to a player.') :add_param('player',false,'player-online') :add_alias('tp-me','tpme') -:set_flag('admin_only',true) +:set_flag('admin_only') :register(function(player,to_player,raw) if to_player.index == player.index then -- return if attempting to teleport to self diff --git a/modules/gui/rocket-info.lua b/modules/gui/rocket-info.lua index 40656e79..2081cb9e 100644 --- a/modules/gui/rocket-info.lua +++ b/modules/gui/rocket-info.lua @@ -38,7 +38,7 @@ local function check_player_permissions(player,action) end --- Button to toggle the auto launch on a rocket silo --- @elemeent toggle_launch +-- @element toggle_launch local toggle_launch = Gui.element{ type = 'sprite-button',