diff --git a/doc/control/Jail.html b/doc/control/Jail.html index c417034d..d4e42066 100644 --- a/doc/control/Jail.html +++ b/doc/control/Jail.html @@ -58,6 +58,7 @@ + @@ -1163,7 +1164,7 @@ generated by LDoc diff --git a/doc/control/Production.html b/doc/control/Production.html index ff355904..acb4cdbc 100644 --- a/doc/control/Production.html +++ b/doc/control/Production.html @@ -58,6 +58,7 @@ + @@ -1278,7 +1279,7 @@ generated by LDoc diff --git a/doc/control/Reports.html b/doc/control/Reports.html index a0194414..f013b057 100644 --- a/doc/control/Reports.html +++ b/doc/control/Reports.html @@ -58,6 +58,7 @@ + @@ -1027,7 +1028,7 @@ generated by LDoc diff --git a/doc/control/Rockets.html b/doc/control/Rockets.html index 1224cd4f..58c6133b 100644 --- a/doc/control/Rockets.html +++ b/doc/control/Rockets.html @@ -57,6 +57,7 @@ + @@ -936,7 +937,7 @@ generated by LDoc diff --git a/doc/control/Tasks.html b/doc/control/Tasks.html index c47d82cd..7c59bb8f 100644 --- a/doc/control/Tasks.html +++ b/doc/control/Tasks.html @@ -57,6 +57,7 @@ + @@ -991,7 +992,7 @@ generated by LDoc diff --git a/doc/control/Warnings.html b/doc/control/Warnings.html index 815de7b7..5eea7b5d 100644 --- a/doc/control/Warnings.html +++ b/doc/control/Warnings.html @@ -57,6 +57,7 @@ + @@ -1420,7 +1421,7 @@ generated by LDoc diff --git a/doc/control/Warps.html b/doc/control/Warps.html new file mode 100644 index 00000000..a4d89c30 --- /dev/null +++ b/doc/control/Warps.html @@ -0,0 +1,1380 @@ + + + + + + + + Warps control + + + + + + + +
+
+ + + + + + + +
+ + + + + + + + +

Warps control

+

Control Module - Warps + - Stores warps for each force.

+

+ + + + + + +

Usage

+

+    -- import the module from the control modules
+    local Warps = require 'modules.control.warps'
+
+    -- Adding a warp require a force, surface and postion, and the option to set this as the spawn
+    -- this function will also create the warp area unless set other wise
+    Warps.new_warp('player',surface,{x=0,y=0})
+
+    -- You can then update the warp information, name and icon, with the update function
+    Warps.update_warp(warp_id,'Best Warp','iron-plate')
+
+    -- Removeing a warp will restore the land that as under it, and remove any data linked with it
+    Warps.remove_warp(warp_id)
+
+    -- You can get the deatils for a warp which include last edit and postion
+    Warps.get_details(warp_id)
+
+    -- You can teleport a player to a warp, note that there is no limit on this action
+    Warps.teleport_player(warp_id,player)
+ + + + + + + +

Dependencies

+ + + + + + + + + + + + + + + + + + + + + + + + +
expcore.storeAllows storing of warp ids
utils.globalAllows storing of warp details
utils.tokenAllows non conflicting warp ids
expcore.storeConfig for the warps
expcore.commonAccess to table_values and table_keysort
+ + +

Getters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
get_warp_name(warp_id)Gets the name of a warp
get_warp_icon(warp_id)Gets the icon of a warp
get_details(warp_id)Gets the task details stored at this id
get_warps(force_name)Gets all warps for a force
get_all_warps()Gets all warps from all forces
is_editing(warp_id, player_name)Gets if a player is currently editing this warp
teleport_player(warp_id, player)Teleports a player to a warp point
+ + +

Setters

+ + + + + + + + + + + + + + + + +
add_handler(callback)Adds a new handler for when a warp is updated
set_editing(warp_id, player_name[, state])Sets a player to be editing this warp, used with is_editing
update_warp(warp_id, name, icon[, player_name='server'])Updates a warp to a differecnt name and icon, both must be given
+ + +

Generators

+ + + + + + + + + + + + + + + + +
make_chart_tag(warp_id)Adds or updates the chart tag for a warp
new_warp(force_name, surface, postion[, player_name='server'][, warp_name='New warp'][, block_generation=false][, set_spawn=false])Adds a new warp to a force and makes the in game warp area
remove_warp(warp_id)Removes a warp and clears the area where it was added
+ + +
+ + +

Dependencies

+
+
+
+
+ # + expcore.store +
+
+
+
+ +

Allows storing of warp ids

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + utils.global +
+
+
+
+ +

Allows storing of warp details

+

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

Allows non conflicting warp ids

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + expcore.store +
+
+
+
+ +

Config for the warps

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + expcore.common +
+
+
+
+ +

Access to table_values and table_keysort

+

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

Getters

+
+
+
+
+ # + get_warp_name(warp_id) +
+
+
+
+ +

Gets the name of a warp

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp you want to get + +
  • + + +
+ + + + + Returns: +
    +
  • + (string) + the warp name that was stored here +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_warp_icon(warp_id) +
+
+
+
+ +

Gets the icon of a warp

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp you want to get + +
  • + + +
+ + + + + Returns: +
    +
  • + (string) + the warp icon that was stored here +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_details(warp_id) +
+
+
+
+ +

Gets the task details stored at this id

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp you want to get + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + the warp details that was stored here +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_warps(force_name) +
+
+
+
+ +

Gets all warps for a force

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to get the warps for + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + an array of warp ids that belong to this force, spawn key is included +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_all_warps() +
+
+
+
+ +

Gets all warps from all forces

+

+ + + + + + Returns: +
    +
  • + (table) + array of all warp details +
  • +
+ + + + + + + + + +
+
+
+
+ # + is_editing(warp_id, player_name) +
+
+
+
+ +

Gets if a player is currently editing this warp

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp you want to check + +
  • + + + + + +
  • + + player_name + + : + + (string) + + the name of the player that you want to check + +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + weather the player is currently editing this warp +
  • +
+ + + + + + + + + +
+
+
+
+ # + teleport_player(warp_id, player) +
+
+
+
+ +

Teleports a player to a warp point

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp to send the player to + +
  • + + + + + +
  • + + player + + : + + (LuaPlayer) + + the player to teleport to the warp + +
  • + + +
+ + + + + + + + + + + + + +
+
+

Setters

+
+
+
+
+ # + add_handler(callback) +
+
+
+
+ +

Adds a new handler for when a warp is updated

+

+ + + Parameters: + +
    + + + + + +
  • + + callback + + : + + (function) + + the callback which is ran when a warp is updated + +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + true if the callback was added +
  • +
+ + + + + + + + + +
+
+
+
+ # + set_editing(warp_id, player_name[, state]) +
+
+
+
+ +

Sets a player to be editing this warp, used with is_editing

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp that you want to editing for + +
  • + + + + + +
  • + + player_name + + : + + (string) + + the name of the player you want to set editing for + +
  • + + + + + +
  • + + state + + : + + (boolean) + + the new state to set editing to + + (optional) +
  • + + +
+ + + + + + + + + + + + + +
+
+
+
+ # + update_warp(warp_id, name, icon[, player_name='server']) +
+
+
+
+ +

Updates a warp to a differecnt name and icon, both must be given

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp that you want to update + +
  • + + + + + +
  • + + name + + : + + (string) + + the name that you want the warp to have + +
  • + + + + + +
  • + + icon + + : + + (string) + + the new icon that you want the warp to have + +
  • + + + + + +
  • + + player_name + + : + + (string) + + the name of the player that is updating the warp + + (default: 'server') +
  • + + +
+ + + + + + + + + + + + + +
+
+

Generators

+
+
+
+
+ # + make_chart_tag(warp_id) +
+
+
+
+ +

Adds or updates the chart tag for a warp

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp you want to make the chart tag for + +
  • + + +
+ + + + + Returns: +
    +
  • + (boolean) + true if a new tag was made, false if it was updated +
  • +
+ + + + + + + + + +
+
+
+
+ # + new_warp(force_name, surface, postion[, player_name='server'][, warp_name='New warp'][, block_generation=false][, set_spawn=false]) +
+
+
+
+ +

Adds a new warp to a force and makes the in game warp area

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to add a new warp for + +
  • + + + + + +
  • + + surface + + : + + (LuaSurface) + + the surface to add the warp to + +
  • + + + + + +
  • + + postion + + : + + (Position) + + the postion to have the warp go to + +
  • + + + + + +
  • + + player_name + + : + + (string) + + the name of the player who added this warp + + (default: 'server') +
  • + + + + + +
  • + + warp_name + + : + + (string) + + the name of the warp that will be made + + (default: 'New warp') +
  • + + + + + +
  • + + block_generation + + : + + (boolean) + + when true a in game area will not be made + + (default: false) +
  • + + + + + +
  • + + set_spawn + + : + + (boolean) + + when true this warp will become the spawn for the force + + (default: false) +
  • + + +
+ + + + + + + + + + + + + +
+
+
+
+ # + remove_warp(warp_id) +
+
+
+
+ +

Removes a warp and clears the area where it was added

+

+ + + Parameters: + +
    + + + + + +
  • + + warp_id + + : + + (string) + + the uid of the warp that you want to remove + +
  • + + +
+ + + + + + + + + + + + + +
+
+ + + +
+
+
+ + + + diff --git a/doc/index.html b/doc/index.html index f872e710..a552d766 100644 --- a/doc/index.html +++ b/doc/index.html @@ -74,6 +74,11 @@ Control Module - Warnings - Adds a way to give and remove warnings to players. + + Warps + Control Module - Warps + - Stores warps for each force. +

Modules

@@ -396,7 +401,7 @@ generated by LDoc diff --git a/doc/modules/config._file_loader.html b/doc/modules/config._file_loader.html index b03f853a..dbc972de 100644 --- a/doc/modules/config._file_loader.html +++ b/doc/modules/config._file_loader.html @@ -115,6 +115,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/config.action_buttons.html b/doc/modules/config.action_buttons.html index d6e27bf9..6159b590 100644 --- a/doc/modules/config.action_buttons.html +++ b/doc/modules/config.action_buttons.html @@ -115,6 +115,7 @@ + @@ -184,7 +185,7 @@ generated by LDoc diff --git a/doc/modules/config.advanced_start.html b/doc/modules/config.advanced_start.html index 46f86d5d..eefefc7c 100644 --- a/doc/modules/config.advanced_start.html +++ b/doc/modules/config.advanced_start.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.bonuses.html b/doc/modules/config.bonuses.html index 48090971..a27c8ed9 100644 --- a/doc/modules/config.bonuses.html +++ b/doc/modules/config.bonuses.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.chat_reply.html b/doc/modules/config.chat_reply.html index 2229425f..67b88043 100644 --- a/doc/modules/config.chat_reply.html +++ b/doc/modules/config.chat_reply.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.death_logger.html b/doc/modules/config.death_logger.html index 3b58eef0..7d9803ac 100644 --- a/doc/modules/config.death_logger.html +++ b/doc/modules/config.death_logger.html @@ -115,6 +115,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/config.discord_alerts.html b/doc/modules/config.discord_alerts.html index 1ec329a3..584ae0d9 100644 --- a/doc/modules/config.discord_alerts.html +++ b/doc/modules/config.discord_alerts.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.auth_admin.html b/doc/modules/config.expcore-commands.auth_admin.html index e6579a3e..186ebcab 100644 --- a/doc/modules/config.expcore-commands.auth_admin.html +++ b/doc/modules/config.expcore-commands.auth_admin.html @@ -115,6 +115,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.auth_roles.html b/doc/modules/config.expcore-commands.auth_roles.html index d5ec3dc7..7cfdc526 100644 --- a/doc/modules/config.expcore-commands.auth_roles.html +++ b/doc/modules/config.expcore-commands.auth_roles.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.auth_runtime_disable.html b/doc/modules/config.expcore-commands.auth_runtime_disable.html index 4550ddc2..7c550560 100644 --- a/doc/modules/config.expcore-commands.auth_runtime_disable.html +++ b/doc/modules/config.expcore-commands.auth_runtime_disable.html @@ -115,6 +115,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.parse_general.html b/doc/modules/config.expcore-commands.parse_general.html index d6145e86..902f8a4d 100644 --- a/doc/modules/config.expcore-commands.parse_general.html +++ b/doc/modules/config.expcore-commands.parse_general.html @@ -115,6 +115,7 @@ + @@ -184,7 +185,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.parse_roles.html b/doc/modules/config.expcore-commands.parse_roles.html index 02a0dec6..1b36bc56 100644 --- a/doc/modules/config.expcore-commands.parse_roles.html +++ b/doc/modules/config.expcore-commands.parse_roles.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.permission_groups.html b/doc/modules/config.permission_groups.html index dfdff98c..a9de68c5 100644 --- a/doc/modules/config.permission_groups.html +++ b/doc/modules/config.permission_groups.html @@ -115,6 +115,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/config.popup_messages.html b/doc/modules/config.popup_messages.html index 780eb96a..07f369e8 100644 --- a/doc/modules/config.popup_messages.html +++ b/doc/modules/config.popup_messages.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.rockets.html b/doc/modules/config.rockets.html index c100d0ef..cacc61b1 100644 --- a/doc/modules/config.rockets.html +++ b/doc/modules/config.rockets.html @@ -123,6 +123,7 @@ + @@ -269,7 +270,7 @@ generated by LDoc diff --git a/doc/modules/config.roles.html b/doc/modules/config.roles.html index ebc9f4e6..a1e771f9 100644 --- a/doc/modules/config.roles.html +++ b/doc/modules/config.roles.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.scorched_earth.html b/doc/modules/config.scorched_earth.html index 77beab86..c9977ebe 100644 --- a/doc/modules/config.scorched_earth.html +++ b/doc/modules/config.scorched_earth.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.spawn_area.html b/doc/modules/config.spawn_area.html index 6064aa21..27a41651 100644 --- a/doc/modules/config.spawn_area.html +++ b/doc/modules/config.spawn_area.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.warnings.html b/doc/modules/config.warnings.html index 18afe26e..0f79fed5 100644 --- a/doc/modules/config.warnings.html +++ b/doc/modules/config.warnings.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.warps.html b/doc/modules/config.warps.html index ccd58f86..cd96cd9d 100644 --- a/doc/modules/config.warps.html +++ b/doc/modules/config.warps.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/control.html b/doc/modules/control.html index 53371685..0edbea2d 100644 --- a/doc/modules/control.html +++ b/doc/modules/control.html @@ -115,6 +115,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/expcore.commands.html b/doc/modules/expcore.commands.html index 12371423..11ec533f 100644 --- a/doc/modules/expcore.commands.html +++ b/doc/modules/expcore.commands.html @@ -115,6 +115,7 @@ + @@ -184,7 +185,7 @@ generated by LDoc diff --git a/doc/modules/expcore.common.html b/doc/modules/expcore.common.html index a1ab355a..6c0405d7 100644 --- a/doc/modules/expcore.common.html +++ b/doc/modules/expcore.common.html @@ -123,6 +123,7 @@ + @@ -2267,7 +2268,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.center.html b/doc/modules/expcore.gui.concepts.center.html index 789e5d41..9a8406c2 100644 --- a/doc/modules/expcore.gui.concepts.center.html +++ b/doc/modules/expcore.gui.concepts.center.html @@ -123,6 +123,7 @@ + @@ -925,7 +926,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.left.html b/doc/modules/expcore.gui.concepts.left.html index 9d7e8f50..1484b153 100644 --- a/doc/modules/expcore.gui.concepts.left.html +++ b/doc/modules/expcore.gui.concepts.left.html @@ -123,6 +123,7 @@ + @@ -1191,7 +1192,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.popups.html b/doc/modules/expcore.gui.concepts.popups.html index 75c67218..6538f8ff 100644 --- a/doc/modules/expcore.gui.concepts.popups.html +++ b/doc/modules/expcore.gui.concepts.popups.html @@ -124,6 +124,7 @@ + @@ -671,7 +672,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.toolbar.html b/doc/modules/expcore.gui.concepts.toolbar.html index 2b00f1de..af2af765 100644 --- a/doc/modules/expcore.gui.concepts.toolbar.html +++ b/doc/modules/expcore.gui.concepts.toolbar.html @@ -123,6 +123,7 @@ + @@ -378,7 +379,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.core.html b/doc/modules/expcore.gui.core.html index 354bf65d..6ec0d1c1 100644 --- a/doc/modules/expcore.gui.core.html +++ b/doc/modules/expcore.gui.core.html @@ -115,6 +115,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.buttons.html b/doc/modules/expcore.gui.elements.buttons.html index 72738285..698bac8b 100644 --- a/doc/modules/expcore.gui.elements.buttons.html +++ b/doc/modules/expcore.gui.elements.buttons.html @@ -123,6 +123,7 @@ + @@ -521,7 +522,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.checkboxs.html b/doc/modules/expcore.gui.elements.checkboxs.html index 10dd9f2a..de6841e3 100644 --- a/doc/modules/expcore.gui.elements.checkboxs.html +++ b/doc/modules/expcore.gui.elements.checkboxs.html @@ -123,6 +123,7 @@ + @@ -839,7 +840,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.dropdown.html b/doc/modules/expcore.gui.elements.dropdown.html index 982d665a..452ee6db 100644 --- a/doc/modules/expcore.gui.elements.dropdown.html +++ b/doc/modules/expcore.gui.elements.dropdown.html @@ -123,6 +123,7 @@ + @@ -701,7 +702,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.elem-button.html b/doc/modules/expcore.gui.elements.elem-button.html index 5dbe195c..60520283 100644 --- a/doc/modules/expcore.gui.elements.elem-button.html +++ b/doc/modules/expcore.gui.elements.elem-button.html @@ -124,6 +124,7 @@ + @@ -397,7 +398,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.progress-bar.html b/doc/modules/expcore.gui.elements.progress-bar.html index 84edc077..1e1ace09 100644 --- a/doc/modules/expcore.gui.elements.progress-bar.html +++ b/doc/modules/expcore.gui.elements.progress-bar.html @@ -123,6 +123,7 @@ + @@ -1142,7 +1143,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.slider.html b/doc/modules/expcore.gui.elements.slider.html index 879a55ae..e3e95a74 100644 --- a/doc/modules/expcore.gui.elements.slider.html +++ b/doc/modules/expcore.gui.elements.slider.html @@ -123,6 +123,7 @@ + @@ -472,7 +473,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.text.html b/doc/modules/expcore.gui.elements.text.html index 64a31026..bfd88ce8 100644 --- a/doc/modules/expcore.gui.elements.text.html +++ b/doc/modules/expcore.gui.elements.text.html @@ -123,6 +123,7 @@ + @@ -518,7 +519,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.html b/doc/modules/expcore.gui.html index 0c2fdc11..c2a494e8 100644 --- a/doc/modules/expcore.gui.html +++ b/doc/modules/expcore.gui.html @@ -115,6 +115,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.instances.html b/doc/modules/expcore.gui.instances.html index 117eae7f..c121c018 100644 --- a/doc/modules/expcore.gui.instances.html +++ b/doc/modules/expcore.gui.instances.html @@ -115,6 +115,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.prototype.html b/doc/modules/expcore.gui.prototype.html index aeaba45b..9156e2fb 100644 --- a/doc/modules/expcore.gui.prototype.html +++ b/doc/modules/expcore.gui.prototype.html @@ -124,6 +124,7 @@ + @@ -1412,7 +1413,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.test.html b/doc/modules/expcore.gui.test.html index dc444eb2..4551e5b9 100644 --- a/doc/modules/expcore.gui.test.html +++ b/doc/modules/expcore.gui.test.html @@ -115,6 +115,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/expcore.permission_groups.html b/doc/modules/expcore.permission_groups.html index 2ea7cf39..69ac8823 100644 --- a/doc/modules/expcore.permission_groups.html +++ b/doc/modules/expcore.permission_groups.html @@ -123,6 +123,7 @@ + @@ -1220,7 +1221,7 @@ generated by LDoc diff --git a/doc/modules/expcore.roles.html b/doc/modules/expcore.roles.html index cbc0db93..65d26d09 100644 --- a/doc/modules/expcore.roles.html +++ b/doc/modules/expcore.roles.html @@ -123,6 +123,7 @@ + @@ -2692,7 +2693,7 @@ generated by LDoc diff --git a/doc/modules/expcore.store.html b/doc/modules/expcore.store.html index 9a35724b..d3717626 100644 --- a/doc/modules/expcore.store.html +++ b/doc/modules/expcore.store.html @@ -123,6 +123,7 @@ + @@ -767,7 +768,7 @@ generated by LDoc diff --git a/doc/modules/expcore.sudo.html b/doc/modules/expcore.sudo.html index 46843afb..fae79bb1 100644 --- a/doc/modules/expcore.sudo.html +++ b/doc/modules/expcore.sudo.html @@ -115,6 +115,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/modules.addons.advanced-start.html b/doc/modules/modules.addons.advanced-start.html index 82a178fc..378ebfc8 100644 --- a/doc/modules/modules.addons.advanced-start.html +++ b/doc/modules/modules.addons.advanced-start.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/modules.addons.chat-popups.html b/doc/modules/modules.addons.chat-popups.html index 96b0ab72..154bfa82 100644 --- a/doc/modules/modules.addons.chat-popups.html +++ b/doc/modules/modules.addons.chat-popups.html @@ -115,6 +115,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/modules.addons.damage-popups.html b/doc/modules/modules.addons.damage-popups.html index 6037c15f..c2ceb83e 100644 --- a/doc/modules/modules.addons.damage-popups.html +++ b/doc/modules/modules.addons.damage-popups.html @@ -115,6 +115,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.player-list.html b/doc/modules/modules.gui.player-list.html index e0c91910..739b15f8 100644 --- a/doc/modules/modules.gui.player-list.html +++ b/doc/modules/modules.gui.player-list.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.rocket-info.html b/doc/modules/modules.gui.rocket-info.html index 67dedf45..e05e2620 100644 --- a/doc/modules/modules.gui.rocket-info.html +++ b/doc/modules/modules.gui.rocket-info.html @@ -123,6 +123,7 @@ + @@ -238,7 +239,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.science-info.html b/doc/modules/modules.gui.science-info.html index dc452e17..e9b374b5 100644 --- a/doc/modules/modules.gui.science-info.html +++ b/doc/modules/modules.gui.science-info.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.task-list.html b/doc/modules/modules.gui.task-list.html index e92f1e01..8138bb55 100644 --- a/doc/modules/modules.gui.task-list.html +++ b/doc/modules/modules.gui.task-list.html @@ -115,6 +115,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/utils.alien_evolution_progress.html b/doc/modules/utils.alien_evolution_progress.html index 6577ef87..3e6f3529 100644 --- a/doc/modules/utils.alien_evolution_progress.html +++ b/doc/modules/utils.alien_evolution_progress.html @@ -123,6 +123,7 @@ + @@ -265,7 +266,7 @@ fraction will decide a chance to spawn. 1 alien for 2 spawners will have 50% on generated by LDoc diff --git a/doc/modules/utils.core.html b/doc/modules/utils.core.html index 74599b61..5946f90d 100644 --- a/doc/modules/utils.core.html +++ b/doc/modules/utils.core.html @@ -124,6 +124,7 @@ + @@ -972,7 +973,7 @@ generated by LDoc diff --git a/doc/modules/utils.debug.html b/doc/modules/utils.debug.html index f0b0fb4f..6b722d3b 100644 --- a/doc/modules/utils.debug.html +++ b/doc/modules/utils.debug.html @@ -123,6 +123,7 @@ + @@ -597,7 +598,7 @@ generated by LDoc diff --git a/doc/modules/utils.event.html b/doc/modules/utils.event.html index 2d9be1ae..33ca669c 100644 --- a/doc/modules/utils.event.html +++ b/doc/modules/utils.event.html @@ -123,6 +123,7 @@ + @@ -1110,7 +1111,7 @@ generated by LDoc diff --git a/doc/modules/utils.event_core.html b/doc/modules/utils.event_core.html index c905d4c0..43f703ff 100644 --- a/doc/modules/utils.event_core.html +++ b/doc/modules/utils.event_core.html @@ -123,6 +123,7 @@ + @@ -377,7 +378,7 @@ generated by LDoc diff --git a/doc/modules/utils.math.html b/doc/modules/utils.math.html index 1a2d3b35..f64391a5 100644 --- a/doc/modules/utils.math.html +++ b/doc/modules/utils.math.html @@ -123,6 +123,7 @@ + @@ -281,7 +282,7 @@ generated by LDoc diff --git a/doc/modules/utils.recipe_locker.html b/doc/modules/utils.recipe_locker.html index 2b43095d..783c5810 100644 --- a/doc/modules/utils.recipe_locker.html +++ b/doc/modules/utils.recipe_locker.html @@ -123,6 +123,7 @@ + @@ -262,7 +263,7 @@ generated by LDoc diff --git a/doc/modules/utils.state_machine.html b/doc/modules/utils.state_machine.html index dc6fbc2d..9856a564 100644 --- a/doc/modules/utils.state_machine.html +++ b/doc/modules/utils.state_machine.html @@ -123,6 +123,7 @@ + @@ -654,7 +655,7 @@ generated by LDoc diff --git a/doc/modules/utils.table.html b/doc/modules/utils.table.html index 2cff6900..0eaaa743 100644 --- a/doc/modules/utils.table.html +++ b/doc/modules/utils.table.html @@ -124,6 +124,7 @@ + @@ -1284,7 +1285,7 @@ generated by LDoc diff --git a/doc/modules/utils.task.html b/doc/modules/utils.task.html index b1c53dca..db536a94 100644 --- a/doc/modules/utils.task.html +++ b/doc/modules/utils.task.html @@ -123,6 +123,7 @@ + @@ -379,7 +380,7 @@ generated by LDoc diff --git a/doc/modules/utils.timestamp.html b/doc/modules/utils.timestamp.html index c934ba53..9689bc56 100644 --- a/doc/modules/utils.timestamp.html +++ b/doc/modules/utils.timestamp.html @@ -123,6 +123,7 @@ + @@ -385,7 +386,7 @@ generated by LDoc diff --git a/doc/topics/license.html b/doc/topics/license.html index d0c8b83a..26899364 100644 --- a/doc/topics/license.html +++ b/doc/topics/license.html @@ -56,6 +56,7 @@ + @@ -732,7 +733,7 @@ Public License instead of this License. But first, please read generated by LDoc diff --git a/doc/topics/readme.md.html b/doc/topics/readme.md.html index 49c37f5a..113a80de 100644 --- a/doc/topics/readme.md.html +++ b/doc/topics/readme.md.html @@ -56,6 +56,7 @@ + @@ -272,7 +273,7 @@ generated by LDoc diff --git a/modules/control/tasks.lua b/modules/control/tasks.lua index e755b141..db624fc2 100644 --- a/modules/control/tasks.lua +++ b/modules/control/tasks.lua @@ -99,7 +99,7 @@ function Tasks.new_task(force_name,task_number,player_name) task_details[task_id] = { task_id=task_id, force=force_name, - last_edit_player='', + last_edit_player=player_name or '', last_edit_time=game.tick, editing={} } @@ -130,7 +130,7 @@ end function Tasks.update_task(task_id,task,player_name) local details = task_details[task_id] details.last_edit_player = player_name or '' - details.last_edit_player = game.tick + details.last_edit_time = game.tick Store.set(task_store,task_id,task) end diff --git a/modules/control/warps.lua b/modules/control/warps.lua new file mode 100644 index 00000000..bb3f062a --- /dev/null +++ b/modules/control/warps.lua @@ -0,0 +1,366 @@ +--[[-- Control Module - Warps + - Stores warps for each force. + @control Warps + @alias Warps + + @usage + -- import the module from the control modules + local Warps = require 'modules.control.warps' + + -- Adding a warp require a force, surface and postion, and the option to set this as the spawn + -- this function will also create the warp area unless set other wise + Warps.new_warp('player',surface,{x=0,y=0}) + + -- You can then update the warp information, name and icon, with the update function + Warps.update_warp(warp_id,'Best Warp','iron-plate') + + -- Removeing a warp will restore the land that as under it, and remove any data linked with it + Warps.remove_warp(warp_id) + + -- You can get the deatils for a warp which include last edit and postion + Warps.get_details(warp_id) + + -- You can teleport a player to a warp, note that there is no limit on this action + Warps.teleport_player(warp_id,player) + +]] + +--- Allows storing of warp ids +-- @dep expcore.store +local Store = require 'expcore.store' +--- Allows storing of warp details +-- @dep utils.global +local Global = require 'utils.global' +--- Allows non conflicting warp ids +-- @dep utils.token +local Token = require 'utils.token' +--- Config for the warps +-- @dep expcore.store +local config = require 'config.warps' +--- Access to table_values and table_keysort +-- @dep expcore.common +local table_values,table_keysort = ext_require('expcore.common','table_values','table_keysort') + +local Warps = { + store = { + names = 'gui.left.warps.names', + icons = 'gui.left.warps.tags' + }, + details = {}, + forces = {}, + handlers = {} +} + +local warp_details = Warps.details +local force_warps = Warps.forces +Global.register({ + warp_details=warp_details, + force_warps=force_warps +},function(tbl) + force_warps = tbl.force_warps + warp_details = tbl.warp_details +end) + +local warp_names = Warps.store.names +Store.register(warp_names,function(value,warp_id) + local details = warp_details[warp_id] + local force_name = details.force + local force = game.forces[force_name] + local warps = force_warps[force_name] + local spawn_id = warps.spawn + + local names = {} + for _,next_warp_id in pairs(warps) do + local warp_name = Store.get(warp_names,next_warp_id) + if next_warp_id ~= spawn_id then + names[warp_name..next_warp_id] = next_warp_id + end + end + + force_warps[force_name] = table_values(table_keysort(names)) + table.insert(force_warps[force.name],1,spawn_id) + force_warps[force_name].spawn = spawn_id + + for _,handler in pairs(Warps.handlers) do + handler(force,warp_id) + end +end) + +local warp_icons = Warps.store.icons +Store.register(warp_icons,function(value,warp_id) + if value then + Warps.make_chart_tag(warp_id) + else + local warp = warp_details[warp_id] + if warp.tag and warp.tag.valid then warp.tag.destroy() end + end +end) + +--- Generators. +-- functions used to create and alter warps with in the map +-- @section generators + +--- Adds or updates the chart tag for a warp +-- @tparam string warp_id the uid of the warp you want to make the chart tag for +-- @treturn boolean true if a new tag was made, false if it was updated +function Warps.make_chart_tag(warp_id) + local warp = warp_details[warp_id] + + local name = Store.get(warp_names,warp_id) + local icon = Store.get(warp_icons,warp_id) + + if warp.tag and warp.tag.valid then + warp.tag.text = 'Warp: '..name + warp.tag.icon = {type='item',name=icon} + return false + end + + local force = game.forces[warp.force] + local surface = warp.surface + local position = warp.position + + local tag = force.add_chart_tag(surface,{ + position={position.x+0.5,position.y+0.5}, + text='Warp: '..name, + icon={type='item',name=icon} + }) + + warp.tag = tag + return true +end + +--- Adds a new warp to a force and makes the in game warp area +-- @tparam string force_name the name of the force to add a new warp for +-- @tparam LuaSurface surface the surface to add the warp to +-- @tparam Position postion the postion to have the warp go to +-- @tparam[opt='server'] string player_name the name of the player who added this warp +-- @tparam[opt='New warp'] string warp_name the name of the warp that will be made +-- @tparam[opt=false] boolean block_generation when true a in game area will not be made +-- @tparam[opt=false] boolean set_spawn when true this warp will become the spawn for the force +function Warps.new_warp(force_name,surface,position,player_name,warp_name,block_generation,set_spawn) + local warp_id = tostring(Token.uid()) + warp_name = warp_name or 'New warp' + + if not force_warps[force_name] then + force_warps[force_name] = {} + end + table.insert(force_warps[force_name],warp_id) + + warp_details[warp_id] = { + warp_id = warp_id, + force = force_name, + position = { + x=math.floor(position.x), + y=math.floor(position.y) + }, + surface = surface, + last_edit_player=player_name or '', + last_edit_time=game.tick, + editing={} + } + + local warp = warp_details[warp_id] + + if player_name then + warp.editing[player_name] = true + end + + if set_spawn then + force_warps[force_name].spawn = warp_id + game.forces[force_name].set_spawn_position(position,surface) + end + + Store.set(warp_names,warp_id,warp_name) + Store.set(warp_icons,warp_id,config.default_icon) + + if block_generation then return warp_id end + + local posx = position.x + local posy = position.y + local radius = config.activation_range + local radius2 = radius^2 + + local old_tile = surface.get_tile(position).name + warp.old_tile = old_tile + + local base_tile = config.base_tile + local base_tiles = {} + -- this makes a base plate to make the warp point + for x = -radius, radius do + local x2 = x^2 + for y = -radius, radius do + local y2 = y^2 + if x2+y2 < radius2 then + table.insert(base_tiles,{name=base_tile,position={x+posx,y+posy}}) + end + end + end + surface.set_tiles(base_tiles) + + -- this adds the tile pattern + local tiles = {} + for _,pos in pairs(config.tiles) do + table.insert(tiles,{name=base_tile,position={pos[1]+posx,pos[2]+posy}}) + end + surface.set_tiles(tiles) + + -- this adds the enitites + for _,entity in pairs(config.entities) do + entity = surface.create_entity{ + name=entity[1], + position={entity[2]+posx,entity[3]+posy}, + force='neutral' + } + entity.destructible = false + entity.health = 0 + entity.minable = false + entity.rotatable = false + end + + return warp_id +end + +--- Removes a warp and clears the area where it was added +-- @tparam string warp_id the uid of the warp that you want to remove +function Warps.remove_warp(warp_id) + local force_name = warp_details[warp_id].force + local warps = force_warps[force_name] + local key = table.index_of(warps,warp_id) + warps[key] = nil + Store.clear(warp_names,warp_id) + Store.clear(warp_icons,warp_id) + + local warp = warp_details[warp_id] + local position = warp.position + local surface = warp.surface + local radius = config.activation_range + local radius2 = radius^2 + + local base_tile = warp.old_tile + local tiles = {} + -- clears the area where the warp was + for x = -radius, radius do + local x2 = x^2 + for y = -radius, radius do + local y2 = y^2 + if x2+y2 < radius2 then + table.insert(tiles,{name=base_tile,position={x+position.x,y+position.y}}) + end + end + end + surface.set_tiles(tiles) + + -- removes all entites (in the area) on the neutral force + local entities = surface.find_entities_filtered{ + force='neutral', + area={ + {position.x-radius,position.y-radius}, + {position.x+radius,position.y+radius} + } + } + for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end + + warp_details[warp_id] = nil +end + +--- Setters. +-- functions used to created and alter warps +-- @section setters + +--- Adds a new handler for when a warp is updated +-- @tparam function callback the callback which is ran when a warp is updated +-- @treturn boolean true if the callback was added +function Warps.add_handler(callback) + if type(callback) == 'function' then + table.insert(Warps.handlers,callback) + return true + end + return false +end + +--- Sets a player to be editing this warp, used with is_editing +-- @tparam string warp_id the uid of the warp that you want to editing for +-- @tparam string player_name the name of the player you want to set editing for +-- @tparam[opt] boolean state the new state to set editing to +function Warps.set_editing(warp_id,player_name,state) + local details = warp_details[warp_id] + details.editing[player_name] = state +end + +--- Updates a warp to a differecnt name and icon, both must be given +-- @tparam string warp_id the uid of the warp that you want to update +-- @tparam string name the name that you want the warp to have +-- @tparam string icon the new icon that you want the warp to have +-- @tparam[opt='server'] string player_name the name of the player that is updating the warp +function Warps.update_warp(warp_id,name,icon,player_name) + local warp = warp_details[warp_id] + warp.last_edit_player = player_name or '' + warp.last_edit_time = game.tick + Store.set(warp_icons,warp_id,icon) + Store.set(warp_names,warp_id,name) +end + +--- Getters. +-- function used to get information about warps +-- @section getters + +--- Gets the name of a warp +-- @tparam string warp_id the uid of the warp you want to get +-- @treturn string the warp name that was stored here +function Warps.get_warp_name(warp_id) + return Store.get(warp_names,warp_id) +end + +--- Gets the icon of a warp +-- @tparam string warp_id the uid of the warp you want to get +-- @treturn string the warp icon that was stored here +function Warps.get_warp_icon(warp_id) + return Store.get(warp_icons,warp_id) or config.default_icon +end + +--- Gets the task details stored at this id +-- @tparam string warp_id the uid of the warp you want to get +-- @treturn table the warp details that was stored here +function Warps.get_details(warp_id) + return warp_details[warp_id] +end + +--- Gets all warps for a force +-- @tparam string force_name the name of the force to get the warps for +-- @treturn table an array of warp ids that belong to this force, spawn key is included +function Warps.get_warps(force_name) + return force_warps[force_name] or {} +end + +--- Gets all warps from all forces +-- @treturn table array of all warp details +function Warps.get_all_warps() + return warp_details +end + +--- Gets if a player is currently editing this warp +-- @tparam string warp_id the uid of the warp you want to check +-- @tparam string player_name the name of the player that you want to check +-- @treturn boolean weather the player is currently editing this warp +function Warps.is_editing(warp_id,player_name) + local details = warp_details[warp_id] + return details.editing[player_name] +end + +--- Teleports a player to a warp point +-- @tparam string warp_id the uid of the warp to send the player to +-- @tparam LuaPlayer player the player to teleport to the warp +function Warps.teleport_player(warp_id,player) + local warp = warp_details[warp_id] + local surface = warp.surface + local position = { + x=warp.position.x+0.5, + y=warp.position.y+0.5 + } + + local goto_position = surface.find_non_colliding_position('character',position,32,1) + if player.driving then player.driving = false end + player.teleport(goto_position,surface) +end + +return Warps \ No newline at end of file diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index eb9688b6..eb4621d9 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -4,34 +4,25 @@ local Global = require 'utils.global' local Event = require 'utils.event' local Game = require 'utils.game' local Roles = require 'expcore.roles' -local Token = require 'utils.token' local Colors = require 'resources.color_presets' local config = require 'config.warps' -local format_time,table_keys,table_values,table_keysort = ext_require('expcore.common','format_time','table_keys','table_values','table_keysort') +local format_time,table_keys = ext_require('expcore.common','format_time','table_keys') +local Warps = require 'modules.control.warps' -local warp_list -local warp_name_store = 'gui.left.warps.names' -local warp_icon_store = 'gui.left.warps.tags' local warp_player_in_range_store = 'gui.left.warps.in_range' +local warp_list -local warp_details = {} -local force_warps = {} local keep_open = {} -Global.register({ - warp_details=warp_details, - force_warps=force_warps, - keep_open=keep_open -},function(tbl) - force_warps = tbl.force_warps - warp_details = tbl.warp_details - keep_open = tbl.keep_open +Global.register(keep_open,function(tbl) + keep_open = tbl end) --- Returns if a player is allowed to edit the given warp local function player_allowed_edit(player,warp_id) if warp_id then - local details = warp_details[warp_id] - if not details.editing then + local details = Warps.get_details(warp_id) + local warps = Warps.get_warps(player.force.name) + if warps.spawn == warp_id then return false end if config.user_can_edit_own_warps and details.last_edit_player == player.name then @@ -54,196 +45,11 @@ local function player_allowed_edit(player,warp_id) return true end ---- Makes a map marker for this warp; updates it if already present -local function make_warp_tag(warp_id) - local warp = warp_details[warp_id] - if not warp then return end - - local icon = Store.get(warp_icon_store,warp_id) - local name = Store.get(warp_name_store,warp_id) - - if warp.tag and warp.tag.valid then - warp.tag.text = 'Warp: '..name - warp.tag.icon = {type='item',name=icon} - return - end - - local force = game.forces[warp.force] - local surface = warp.surface - local position = warp.position - - local tag = force.add_chart_tag(surface,{ - position={position.x+0.5,position.y+0.5}, - text='Warp: '..name, - icon={type='item',name=icon} - }) - - warp.tag = tag -end - --- This creates the area for the warp; this is not required but helps players know where the warps are -local function make_warp_area(warp_id) - local warp = warp_details[warp_id] - if not warp then return end - - local position = warp.position - local posx = position.x - local posy = position.y - local surface = warp.surface - local radius = config.activation_range - local radius2 = radius^2 - - local old_tile = surface.get_tile(position).name - warp.old_tile = old_tile - - local base_tile = config.base_tile - local base_tiles = {} - -- this makes a base plate to make the warp point - for x = -radius, radius do - local x2 = x^2 - for y = -radius, radius do - local y2 = y^2 - if x2+y2 < radius2 then - table.insert(base_tiles,{name=base_tile,position={x+posx,y+posy}}) - end - end - end - surface.set_tiles(base_tiles) - - -- this adds the tile pattern - local tiles = {} - for _,pos in pairs(config.tiles) do - table.insert(tiles,{name=base_tile,position={pos[1]+posx,pos[2]+posy}}) - end - surface.set_tiles(tiles) - - -- this adds the enitites - for _,entity in pairs(config.entities) do - entity = surface.create_entity{ - name=entity[1], - position={entity[2]+posx,entity[3]+posy}, - force='neutral' - } - entity.destructible = false - entity.health = 0 - entity.minable = false - entity.rotatable = false - end -end - ---- This removes the warp area, also restores the old tile -local function clear_warp_area(warp_id) - local warp = warp_details[warp_id] - if not warp then return end - - local position = warp.position - local surface = warp.surface - local radius = config.activation_range - local radius2 = radius^2 - - local base_tile = warp.old_tile - local tiles = {} - -- clears the area where the warp was - for x = -radius, radius do - local x2 = x^2 - for y = -radius, radius do - local y2 = y^2 - if x2+y2 < radius2 then - table.insert(tiles,{name=base_tile,position={x+position.x,y+position.y}}) - end - end - end - surface.set_tiles(tiles) - - -- removes all entites (in the area) on the neutral force - local entities = surface.find_entities_filtered{ - force='neutral', - area={ - {position.x-radius,position.y-radius}, - {position.x+radius,position.y+radius} - } - } - for _,entity in pairs(entities) do if entity.name ~= 'player' then entity.destroy() end end - - if warp.tag and warp.tag.valid then warp.tag.destroy() end -end - ---- Speaial case for the warps; adds the spawn warp which cant be removed -local function add_spawn(player) - local warp_id = tostring(Token.uid()) - local force = player.force - local force_name = force.name - local surface = player.surface - local spawn = force.get_spawn_position(surface) - - if not force_warps[force_name] then - force_warps[force_name] = {} - end - table.insert(force_warps[force_name],warp_id) - - warp_details[warp_id] = { - warp_id = warp_id, - force = force.name, - position = { - x=math.floor(spawn.x), - y=math.floor(spawn.y) - }, - surface = surface, - last_edit_player='System', - last_edit_time=game.tick, - editing=false - } - - Store.set(warp_name_store,warp_id,'Spawn') - Store.set(warp_icon_store,warp_id,config.default_icon) -end - ---- General case for the warps; will make a new warp and set the player to be editing it -local function add_warp(player) - local warp_id = tostring(Token.uid()) - local force_name = player.force.name - - if not force_warps[force_name] then - add_spawn(player) - end - table.insert(force_warps[force_name],warp_id) - - local position = player.position - - warp_details[warp_id] = { - warp_id = warp_id, - force = force_name, - position = { - x=math.floor(position.x), - y=math.floor(position.y) - }, - surface = player.surface, - last_edit_player=player.name, - last_edit_time=game.tick, - editing={[player.name]=true} - } - - Store.set(warp_name_store,warp_id,'New warp') - Store.set(warp_icon_store,warp_id,config.default_icon) - - make_warp_area(warp_id) -end - ---- Removes all refrences to a warp -local function remove_warp(warp_id) - local force_name = warp_details[warp_id].force - local key = table.index_of(force_warps[force_name],warp_id) - force_warps[force_name][key] = nil - Store.clear(warp_name_store,warp_id) - Store.clear(warp_icon_store,warp_id) - warp_details[warp_id] = nil -end - --- Used on the name label to allow zoom to map local zoom_to_map_name = Gui.uid_name() Gui.on_click(zoom_to_map_name,function(event) local warp_id = event.element.parent.name - local warp = warp_details[warp_id] + local warp = Warps.get_details(warp_id) local position = warp.position event.player.zoom_to_world(position,1.5) end) @@ -276,16 +82,7 @@ Gui.new_button() end) :on_click(function(player,element) local warp_id = element.parent.caption - local warp = warp_details[warp_id] - local surface = warp.surface - local position = { - x=warp.position.x+0.5, - y=warp.position.y+0.5 - } - - local goto_position = surface.find_non_colliding_position('character',position,32,1) - if player.driving then player.driving = false end - player.teleport(goto_position,surface) + Warps.teleport_player(warp_id,player) if config.bypass_warp_limits_permision and not Roles.player_allowed(player,config.bypass_warp_limits_permision) then warp_timer:set_store(player.name,0) @@ -311,18 +108,17 @@ end) local posy = position.y local dist2 = config.minimum_distance^2 - local warps = Store.get_children(warp_name_store) - for _,warp_id in pairs(warps) do - local warp = warp_details[warp_id] + local warps = Warps.get_all_warps() + for warp_id,warp in pairs(warps) do local pos = warp.position if (posx-pos.x)^2+(posy-pos.y)^2 < dist2 then - local warp_name = Store.get(warp_name_store,warp_id) + local warp_name = Warps.get_warp_name(warp_id) player.print{'warp-list.too-close',warp_name} return end end - add_warp(player) + Warps.new_warp(player.force.name,player.surface,position,player.name) end) --- Confirms the edit to name or icon of the warp @@ -339,12 +135,8 @@ end) local warp_id = element.parent.name local warp_name = element.parent.warp.text local warp_icon = element.parent.parent['icon-'..warp_id].icon.elem_value - local warp = warp_details[warp_id] - warp.editing[player.name] = nil - warp.last_edit_player = player.name - warp.last_edit_time = game.tick - Store.set(warp_name_store,warp_id,warp_name) - Store.set(warp_icon_store,warp_id,warp_icon) + Warps.set_editing(warp_id,player.name) + Warps.update_warp(warp_id,warp_name,warp_icon,player.name) end) --- Cancels the editing changes of the selected warp name or icon @@ -360,8 +152,7 @@ Gui.new_button() end) :on_click(function(player,element) local warp_id = element.parent.name - local details = warp_details[warp_id] - details.editing[player.name] = nil + Warps.set_editing(warp_id,player.name) generate_warp(player,element.parent.parent,warp_id) end) @@ -377,7 +168,7 @@ Gui.new_button() end) :on_click(function(player,element) local warp_id = element.parent.name - remove_warp(warp_id) + Warps.remove_warp(warp_id) end) --- Opens edit mode for the warp @@ -392,8 +183,7 @@ Gui.new_button() end) :on_click(function(player,element) local warp_id = element.parent.name - local details = warp_details[warp_id] - details.editing[player.name] = true + Warps.set_editing(warp_id,player.name,true) generate_warp(player,element.parent.parent.parent,warp_id) end) @@ -411,11 +201,11 @@ end) >>> discard_warp ]] function generate_warp(player,element,warp_id) - local warp_name = Store.get(warp_name_store,warp_id) - local warp_icon = Store.get(warp_icon_store,warp_id) or config.default_icon - local warp = warp_details[warp_id] + local warp_name = Warps.get_warp_name(warp_id) + local warp_icon = Warps.get_warp_icon(warp_id) + local warp = Warps.get_details(warp_id) - local editing = warp.editing and warp.editing[player.name] + local editing = Warps.is_editing(warp_id,player.name) local last_edit_player = warp.last_edit_player local last_edit_time = warp.last_edit_time local position = warp.position @@ -608,22 +398,23 @@ Gui.new_left_frame('gui/warp-list') :set_direction('vertical') :on_creation(function(player,element) local data_table = generate_container(player,element) - local force_name = player.force.name + local warps = Warps.get_warps(player.force.name) - local warps = force_warps[force_name] or {} - for _,warp_id in pairs(warps) do - generate_warp(player,data_table,warp_id) + for key,warp_id in pairs(warps) do + if key ~= 'spawn' then + generate_warp(player,data_table,warp_id) + end end end) :on_update(function(player,element) local data_table = element.container.scroll.table - local force_name = player.force.name + local warps = Warps.get_warps(player.force.name) data_table.clear() - - local warps = force_warps[force_name] or {} - for _,warp_id in pairs(warps) do - generate_warp(player,data_table,warp_id) + for key,warp_id in pairs(warps) do + if key ~= 'spawn' then + generate_warp(player,data_table,warp_id) + end end end) :on_player_toggle(function(player,element,visible) @@ -631,47 +422,12 @@ end) end) --- When the name of a warp is updated this is triggered -Store.register(warp_name_store,function(value,warp_id) - local warp = warp_details[warp_id] - local force = game.forces[warp.force] - - local names = {} - local spawn_id - for _,_warp_id in pairs(force_warps[force.name]) do - local name = Store.get(warp_name_store,_warp_id) - if not warp_details[_warp_id].editing then - spawn_id = _warp_id - else - names[name.._warp_id] = _warp_id - end - end - - force_warps[force.name] = table_values(table_keysort(names)) - table.insert(force_warps[force.name],1,spawn_id) - +Warps.add_handler(function(force,warp_id) for _,player in pairs(force.players) do warp_list:update(player) end end) ---- When the icon is updated this is called -Store.register(warp_icon_store,function(value,warp_id) - local warp = warp_details[warp_id] - local force = game.forces[warp.force] - - for _,player in pairs(force.players) do - local frame = warp_list:get_frame(player) - local element = frame.container.scroll.table - generate_warp(player,element,warp_id) - end - - if value then - make_warp_tag(warp_id) - else - clear_warp_area(warp_id) - end -end) - --- When the player leaves or enters range of a warp this is triggered Store.register(warp_player_in_range_store,function(value,player_name) local player = game.players[player_name] @@ -689,17 +445,16 @@ Store.register(warp_player_in_range_store,function(value,player_name) return end - if force_warps[force.name] then - for _,warp_id in pairs(force_warps[force.name]) do - local element = table_area['icon-'..warp_id][goto_warp.name] - if element and element.valid then - element.enabled = state - if state then - local position = warp_details[warp_id].position - element.tooltip = {'warp-list.goto-tooltip',position.x,position.y} - else - element.tooltip = {'warp-list.goto-disabled'} - end + local warps = Warps.get_warps(force.name) + for _,warp_id in pairs(warps) do + local element = table_area['icon-'..warp_id][goto_warp.name] + if element and element.valid then + element.enabled = state + if state then + local position = Warps.get_details(warp_id).position + element.tooltip = {'warp-list.goto-tooltip',position.x,position.y} + else + element.tooltip = {'warp-list.goto-disabled'} end end end @@ -717,14 +472,14 @@ Event.on_nth_tick(math.floor(60/config.update_smothing),function() for _,player in pairs(game.connected_players) do local was_in_range = Store.get(warp_player_in_range_store,player.name) local force = player.force - local warps = force_warps[force.name] + local warps = Warps.get_warps(force.name) - if warps then + if #warps > 0 then local surface = player.surface.index local pos = player.position local px,py = pos.x,pos.y for _,warp_id in pairs(warps) do - local warp = warp_details[warp_id] + local warp = Warps.get_details(warp_id) local wpos = warp.position if warp.surface.index == surface then local dx,dy = px-wpos.x,py-wpos.y @@ -749,7 +504,6 @@ end) --- When a player is created it will set them being in range to false to stop warping on join Event.add(defines.events.on_player_created,function(event) local player = Game.get_player_by_index(event.player_index) - local force_name = player.force.name local allowed = config.bypass_warp_limits_permision and Roles.player_allowed(player,config.bypass_warp_limits_permision) or false Store.set(warp_player_in_range_store,player.name,allowed) @@ -757,24 +511,22 @@ Event.add(defines.events.on_player_created,function(event) warp_timer:set_store(player.name,1) end - if not force_warps[force_name] then - add_spawn(player) - end + local force = player.force + local spawn_position = force.get_spawn_position(player.surface) + Warps.new_warp(force.name,player.surface,spawn_position,nil,'Spawn',true,true) end) local function maintain_tag(event) local tag = event.tag local force = event.force - local warps = force_warps[force.name] - if warps then - for _,warp_id in pairs(warps) do - local warp = warp_details[warp_id] - if not warp.tag or not warp.tag.valid or warp.tag == tag then - if event.name == defines.events.on_chart_tag_removed then - warp.tag = nil - end - make_warp_tag(warp_id) + local warps = Warps.get_warps(force.name) + for _,warp_id in pairs(warps) do + local warp = Warps.get_warps(force.name) + if not warp.tag or not warp.tag.valid or warp.tag == tag then + if event.name == defines.events.on_chart_tag_removed then + warp.tag = nil end + Warps.make_chart_tag(warp_id) end end end