diff --git a/docs/addons/Advanced-Start.html b/docs/addons/Advanced-Start.html index 70565d43..92e9514b 100644 --- a/docs/addons/Advanced-Start.html +++ b/docs/addons/Advanced-Start.html @@ -348,7 +348,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Popups.html b/docs/addons/Chat-Popups.html index 87fa5946..9b87675a 100644 --- a/docs/addons/Chat-Popups.html +++ b/docs/addons/Chat-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Chat-Reply.html b/docs/addons/Chat-Reply.html index 7ad2d0fc..7a55158f 100644 --- a/docs/addons/Chat-Reply.html +++ b/docs/addons/Chat-Reply.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/addons/Compilatron.html b/docs/addons/Compilatron.html index e31e807c..9d466ac6 100644 --- a/docs/addons/Compilatron.html +++ b/docs/addons/Compilatron.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/addons/Damage-Popups.html b/docs/addons/Damage-Popups.html index 54851800..16d816fe 100644 --- a/docs/addons/Damage-Popups.html +++ b/docs/addons/Damage-Popups.html @@ -349,7 +349,7 @@ generated by LDoc diff --git a/docs/addons/Death-Logger.html b/docs/addons/Death-Logger.html index 4389b74f..6c190526 100644 --- a/docs/addons/Death-Logger.html +++ b/docs/addons/Death-Logger.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Discord-Alerts.html b/docs/addons/Discord-Alerts.html index 365640cb..a20be316 100644 --- a/docs/addons/Discord-Alerts.html +++ b/docs/addons/Discord-Alerts.html @@ -460,7 +460,7 @@ generated by LDoc diff --git a/docs/addons/Player-Colours.html b/docs/addons/Player-Colours.html index 5642fdfd..072aa277 100644 --- a/docs/addons/Player-Colours.html +++ b/docs/addons/Player-Colours.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Pollution-Grading.html b/docs/addons/Pollution-Grading.html index 07290700..6b312eca 100644 --- a/docs/addons/Pollution-Grading.html +++ b/docs/addons/Pollution-Grading.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/addons/Scorched-Earth.html b/docs/addons/Scorched-Earth.html index d4d38eb0..a75fc560 100644 --- a/docs/addons/Scorched-Earth.html +++ b/docs/addons/Scorched-Earth.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/addons/Spawn-Area.html b/docs/addons/Spawn-Area.html index e692dfc6..8a5abbc8 100644 --- a/docs/addons/Spawn-Area.html +++ b/docs/addons/Spawn-Area.html @@ -376,7 +376,7 @@ generated by LDoc diff --git a/docs/commands/Admin-Chat.html b/docs/commands/Admin-Chat.html index 9cd5d0f9..c50c6b68 100644 --- a/docs/commands/Admin-Chat.html +++ b/docs/commands/Admin-Chat.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Bonus.html b/docs/commands/Bonus.html index b68ae163..faf01081 100644 --- a/docs/commands/Bonus.html +++ b/docs/commands/Bonus.html @@ -500,7 +500,7 @@ generated by LDoc diff --git a/docs/commands/Cheat-Mode.html b/docs/commands/Cheat-Mode.html index c31e382f..356a9c94 100644 --- a/docs/commands/Cheat-Mode.html +++ b/docs/commands/Cheat-Mode.html @@ -361,7 +361,7 @@ generated by LDoc diff --git a/docs/commands/Clear-Inventory.html b/docs/commands/Clear-Inventory.html index 2e016c22..e6388451 100644 --- a/docs/commands/Clear-Inventory.html +++ b/docs/commands/Clear-Inventory.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Debug.html b/docs/commands/Debug.html index 42d1f028..4ee9fbb0 100644 --- a/docs/commands/Debug.html +++ b/docs/commands/Debug.html @@ -365,7 +365,7 @@ generated by LDoc diff --git a/docs/commands/Find.html b/docs/commands/Find.html index 3d763a33..f4592e11 100644 --- a/docs/commands/Find.html +++ b/docs/commands/Find.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Help.html b/docs/commands/Help.html index 5cc96005..251496a1 100644 --- a/docs/commands/Help.html +++ b/docs/commands/Help.html @@ -404,7 +404,7 @@ generated by LDoc diff --git a/docs/commands/Home.html b/docs/commands/Home.html index 9cbb73fd..76775f55 100644 --- a/docs/commands/Home.html +++ b/docs/commands/Home.html @@ -458,7 +458,7 @@ generated by LDoc diff --git a/docs/commands/Interface.html b/docs/commands/Interface.html index e91c0dbd..5d22452e 100644 --- a/docs/commands/Interface.html +++ b/docs/commands/Interface.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/commands/Jail.html b/docs/commands/Jail.html index a847fcef..555a57ea 100644 --- a/docs/commands/Jail.html +++ b/docs/commands/Jail.html @@ -611,7 +611,7 @@ generated by LDoc diff --git a/docs/commands/Kill.html b/docs/commands/Kill.html index 8da3f852..76b5659c 100644 --- a/docs/commands/Kill.html +++ b/docs/commands/Kill.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Me.html b/docs/commands/Me.html index 1fd9e72c..04d8d002 100644 --- a/docs/commands/Me.html +++ b/docs/commands/Me.html @@ -360,7 +360,7 @@ generated by LDoc diff --git a/docs/commands/Rainbow.html b/docs/commands/Rainbow.html index 70831137..c2addce1 100644 --- a/docs/commands/Rainbow.html +++ b/docs/commands/Rainbow.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/commands/Repair.html b/docs/commands/Repair.html index a23ec6d0..79684a5a 100644 --- a/docs/commands/Repair.html +++ b/docs/commands/Repair.html @@ -321,7 +321,7 @@ generated by LDoc diff --git a/docs/commands/Reports.html b/docs/commands/Reports.html index 04d813f0..3675fd4e 100644 --- a/docs/commands/Reports.html +++ b/docs/commands/Reports.html @@ -585,7 +585,7 @@ generated by LDoc diff --git a/docs/commands/Roles.html b/docs/commands/Roles.html index 1917696b..34b5a762 100644 --- a/docs/commands/Roles.html +++ b/docs/commands/Roles.html @@ -557,7 +557,7 @@ generated by LDoc diff --git a/docs/commands/Spawn.html b/docs/commands/Spawn.html index 1b228fe3..3cbff6d4 100644 --- a/docs/commands/Spawn.html +++ b/docs/commands/Spawn.html @@ -389,7 +389,7 @@ generated by LDoc diff --git a/docs/commands/Tag.html b/docs/commands/Tag.html index 9dc0449c..bb3b4d84 100644 --- a/docs/commands/Tag.html +++ b/docs/commands/Tag.html @@ -443,7 +443,7 @@ generated by LDoc diff --git a/docs/commands/Teleport.html b/docs/commands/Teleport.html index a6e936fc..37e00592 100644 --- a/docs/commands/Teleport.html +++ b/docs/commands/Teleport.html @@ -484,7 +484,7 @@ generated by LDoc diff --git a/docs/commands/Warnings.html b/docs/commands/Warnings.html index cf5694f0..e0f3efdb 100644 --- a/docs/commands/Warnings.html +++ b/docs/commands/Warnings.html @@ -569,7 +569,7 @@ generated by LDoc diff --git a/docs/configs/Advanced-Start.html b/docs/configs/Advanced-Start.html index b7b25fa0..bb81cea4 100644 --- a/docs/configs/Advanced-Start.html +++ b/docs/configs/Advanced-Start.html @@ -506,7 +506,7 @@ generated by LDoc diff --git a/docs/configs/Bonuses.html b/docs/configs/Bonuses.html index adc1cbe9..27e252db 100644 --- a/docs/configs/Bonuses.html +++ b/docs/configs/Bonuses.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/Chat-Reply.html b/docs/configs/Chat-Reply.html index 10e381fd..9e6519d5 100644 --- a/docs/configs/Chat-Reply.html +++ b/docs/configs/Chat-Reply.html @@ -485,7 +485,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Admin.html b/docs/configs/Commands-Auth-Admin.html index 6779709d..25e81ce6 100644 --- a/docs/configs/Commands-Auth-Admin.html +++ b/docs/configs/Commands-Auth-Admin.html @@ -294,7 +294,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Roles.html b/docs/configs/Commands-Auth-Roles.html index 8739e69c..d8f86e12 100644 --- a/docs/configs/Commands-Auth-Roles.html +++ b/docs/configs/Commands-Auth-Roles.html @@ -320,7 +320,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Auth-Runtime-Disable.html b/docs/configs/Commands-Auth-Runtime-Disable.html index fdbba9e6..eedbf824 100644 --- a/docs/configs/Commands-Auth-Runtime-Disable.html +++ b/docs/configs/Commands-Auth-Runtime-Disable.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse-Roles.html b/docs/configs/Commands-Parse-Roles.html index 331eea4a..ab26c6f2 100644 --- a/docs/configs/Commands-Parse-Roles.html +++ b/docs/configs/Commands-Parse-Roles.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Commands-Parse.html b/docs/configs/Commands-Parse.html index 25400a02..4ec6ed0a 100644 --- a/docs/configs/Commands-Parse.html +++ b/docs/configs/Commands-Parse.html @@ -338,7 +338,7 @@ see ./expcore/commands.lua for more details

generated by LDoc diff --git a/docs/configs/Compilatron.html b/docs/configs/Compilatron.html index c1ec24c0..4d6d2620 100644 --- a/docs/configs/Compilatron.html +++ b/docs/configs/Compilatron.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Death-Logger.html b/docs/configs/Death-Logger.html index 6984e385..9602becc 100644 --- a/docs/configs/Death-Logger.html +++ b/docs/configs/Death-Logger.html @@ -416,7 +416,7 @@ generated by LDoc diff --git a/docs/configs/Discord-Alerts.html b/docs/configs/Discord-Alerts.html index 267441da..368bf27b 100644 --- a/docs/configs/Discord-Alerts.html +++ b/docs/configs/Discord-Alerts.html @@ -237,7 +237,7 @@ generated by LDoc diff --git a/docs/configs/File-Loader.html b/docs/configs/File-Loader.html index 85256018..fc1e5061 100644 --- a/docs/configs/File-Loader.html +++ b/docs/configs/File-Loader.html @@ -240,7 +240,7 @@ generated by LDoc diff --git a/docs/configs/Permission-Groups.html b/docs/configs/Permission-Groups.html index 2e8548bb..ff7cc7f2 100644 --- a/docs/configs/Permission-Groups.html +++ b/docs/configs/Permission-Groups.html @@ -295,7 +295,7 @@ generated by LDoc diff --git a/docs/configs/Player-List.html b/docs/configs/Player-List.html index 271f36bf..8054236d 100644 --- a/docs/configs/Player-List.html +++ b/docs/configs/Player-List.html @@ -812,7 +812,7 @@ generated by LDoc diff --git a/docs/configs/Pollution-Grading.html b/docs/configs/Pollution-Grading.html index 0a2d8790..8b2af2cc 100644 --- a/docs/configs/Pollution-Grading.html +++ b/docs/configs/Pollution-Grading.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Popup-Messages.html b/docs/configs/Popup-Messages.html index 5c7cde1e..6dac218a 100644 --- a/docs/configs/Popup-Messages.html +++ b/docs/configs/Popup-Messages.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Preset-Player-Colours.html b/docs/configs/Preset-Player-Colours.html index bce07929..feaf4071 100644 --- a/docs/configs/Preset-Player-Colours.html +++ b/docs/configs/Preset-Player-Colours.html @@ -324,7 +324,7 @@ generated by LDoc diff --git a/docs/configs/Repair.html b/docs/configs/Repair.html index 003d3780..2055d520 100644 --- a/docs/configs/Repair.html +++ b/docs/configs/Repair.html @@ -414,7 +414,7 @@ generated by LDoc diff --git a/docs/configs/Rockets.html b/docs/configs/Rockets.html index 48d37d33..10ec31d9 100644 --- a/docs/configs/Rockets.html +++ b/docs/configs/Rockets.html @@ -834,7 +834,7 @@ generated by LDoc diff --git a/docs/configs/Roles.html b/docs/configs/Roles.html index 9a8f17f1..242d61fb 100644 --- a/docs/configs/Roles.html +++ b/docs/configs/Roles.html @@ -292,7 +292,7 @@ generated by LDoc diff --git a/docs/configs/Science.html b/docs/configs/Science.html index 284f26bb..5a57edf3 100644 --- a/docs/configs/Science.html +++ b/docs/configs/Science.html @@ -354,7 +354,7 @@ generated by LDoc diff --git a/docs/configs/Scorched-Earth.html b/docs/configs/Scorched-Earth.html index 3593adba..d4e60cac 100644 --- a/docs/configs/Scorched-Earth.html +++ b/docs/configs/Scorched-Earth.html @@ -388,7 +388,7 @@ generated by LDoc diff --git a/docs/configs/Spawn-Area.html b/docs/configs/Spawn-Area.html index 0b71c658..3818e287 100644 --- a/docs/configs/Spawn-Area.html +++ b/docs/configs/Spawn-Area.html @@ -744,7 +744,7 @@ generated by LDoc diff --git a/docs/configs/Tasks.html b/docs/configs/Tasks.html index 7941273f..4fd21978 100644 --- a/docs/configs/Tasks.html +++ b/docs/configs/Tasks.html @@ -384,7 +384,7 @@ generated by LDoc diff --git a/docs/configs/Warnings.html b/docs/configs/Warnings.html index 25328292..f770e411 100644 --- a/docs/configs/Warnings.html +++ b/docs/configs/Warnings.html @@ -355,7 +355,7 @@ generated by LDoc diff --git a/docs/configs/Warps.html b/docs/configs/Warps.html index db44192d..aef51683 100644 --- a/docs/configs/Warps.html +++ b/docs/configs/Warps.html @@ -684,7 +684,7 @@ generated by LDoc diff --git a/docs/control/Jail.html b/docs/control/Jail.html index d22001c1..c31473b4 100644 --- a/docs/control/Jail.html +++ b/docs/control/Jail.html @@ -1208,7 +1208,7 @@ generated by LDoc diff --git a/docs/control/Production.html b/docs/control/Production.html index c275a1d0..8c5394a9 100644 --- a/docs/control/Production.html +++ b/docs/control/Production.html @@ -1329,7 +1329,7 @@ generated by LDoc diff --git a/docs/control/Reports.html b/docs/control/Reports.html index 1460c0d8..db328140 100644 --- a/docs/control/Reports.html +++ b/docs/control/Reports.html @@ -1110,7 +1110,7 @@ generated by LDoc diff --git a/docs/control/Rockets.html b/docs/control/Rockets.html index 91554fce..335b6534 100644 --- a/docs/control/Rockets.html +++ b/docs/control/Rockets.html @@ -984,7 +984,7 @@ generated by LDoc diff --git a/docs/control/Tasks.html b/docs/control/Tasks.html index 30ad0f82..c9321fe8 100644 --- a/docs/control/Tasks.html +++ b/docs/control/Tasks.html @@ -288,7 +288,7 @@ Tasks.update_task(task_id,'We need more iron!',game. - add_task(force_name[, task_number][, player_name]) + add_task(force_name[, task_number][, player_name][, task_message]) Add a new task for a force, the task can be placed into a certain position for that force @@ -597,7 +597,7 @@ Tasks.update_task(task_id,'We need more iron!',game.
# - add_task(force_name[, task_number][, player_name]) + add_task(force_name[, task_number][, player_name][, task_message])
@@ -662,6 +662,23 @@ Tasks.update_task(task_id,'We need more iron!',game. + + + +
  • + + task_message + + : + + (string) + + the message that is used for this task, if not given default is used + + (optional) +
  • + + @@ -981,7 +998,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 ebf70325..1ad8e0e1 100644 --- a/docs/control/Warnings.html +++ b/docs/control/Warnings.html @@ -1465,7 +1465,7 @@ generated by LDoc diff --git a/docs/control/Warps.html b/docs/control/Warps.html index 220cd035..49821ac4 100644 --- a/docs/control/Warps.html +++ b/docs/control/Warps.html @@ -44,7 +44,7 @@ - + @@ -207,7 +207,7 @@ - + @@ -228,7 +228,7 @@

    Warps control

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

    +- Stores warps for each force.

    @@ -237,25 +237,20 @@

    Usage

    -
    
    -    -- import the module from the control modules
    -    local Warps = require 'modules.control.warps' --- @dep 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})
    +    
    -- Making a new spawn warp
    +local player = game.player
    +local force = player.force
    +local spawn_id = Warps.add_warp(force.name,player.surface,player.position,player.name,'Spawn')
     
    -    -- You can then update the warp information, name and icon, with the update function
    -    Warps.update_warp(warp_id,'Best Warp','iron-plate')
    +Warps.set_spawn_warp(spawn_id, force)
    +Warps.make_warp_tag(spawn_id)
    +
    -- Making a new warp with a warp area
    +local player = game.player
    +local force = player.force
    +local warp_id = Warps.add_warp(force.name,player.surface,player.position,player.name)
     
    -    -- 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)
    +Warps.make_warp_area(warp_id) +Warps.make_warp_tag(warp_id)
    @@ -291,32 +286,20 @@ - get_warp_name(warp_id) - Gets the name of a warp + get_warp(warp_id) + Gets the warp information that is linked with this id - get_warp_icon(warp_id) - Gets the icon of a warp + get_force_warp_ids(force_name) + Gets all the warp ids that a force has - get_details(warp_id) - Gets the task details stored at this id + get_spawn_warp_id(force_name) + Get the id of the spawn warp - 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 + get_editing(warp_id, player_name) + Gets the editing state for a player @@ -327,36 +310,56 @@ - add_handler(callback) - Adds a new handler for when a warp is updated + add_warp(force_name, surface, position[, player_name][, warp_name]) + Add a new warp for a force, the warp must have a surface and a position - set_editing(warp_id, player_name[, state]) - Sets a player to be editing this warp, used with is_editing + remove_warp(warp_id) + Removes a warp and any data linked to it - update_warp(warp_id, name, icon[, player_name='server']) - Updates a warp to a differecnt name and icon, both must be given + update_warp(warp_id[, new_name][, new_icon][, player_name='server']) + Update the name and icon for a warp + + + set_editing(warp_id, player_name, state) + Set the editing state for a player, can be used as a warning or to display a text field + + + on_update(handler) + Adds an update handler for when a warp is added, removed, or updated -

    Generators

    +

    Map Intergration

    - - + + - - + + - - + + + + + + + + + + + + + +
    make_chart_tag(warp_id)Adds or updates the chart tag for a warpmake_warp_tag(warp_id)Add or update the chat tag for this warp
    new_warp(force_name, surface, position[, 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 arearemove_warp_tag(warp_id)Remove the chart tag for this warp
    remove_warp(warp_id)Removes a warp and clears the area where it was addedmake_warp_area(warp_id)Add a warp area for the warp, purely cosmetic
    remove_warp_area(warp_id)Remove the warp area for a warp
    set_spawn_warp(warp_id, force)Set a warp to be the spawn point for a force, force must own this warp
    teleport_player(warp_id, player)Teleport a player to a warp point
    @@ -498,128 +501,14 @@
    - # - get_warp_name(warp_id) + # + get_warp(warp_id)
    -

    Gets the name of a warp

    -

    - - - Parameters: - - - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - get_warp_icon(warp_id) -
    -
    -
    -
    - -

    Gets the icon of a warp

    -

    - - - Parameters: - - - - - - - Returns: - - - - - - - - - - -
    -
    -
    -
    - # - get_details(warp_id) -
    -
    -
    -
    - -

    Gets the task details stored at this id

    +

    Gets the warp information that is linked with this id

    @@ -653,7 +542,7 @@ @@ -663,20 +552,23 @@ + Usage: +
    -- Getting warp information outside of on_update
    +local warp = Warps.get_warp(warp_id)
    - # - get_warps(force_name) + # + get_force_warp_ids(force_name)
    -

    Gets all warps for a force

    +

    Gets all the warp ids that a force has

    @@ -696,7 +588,7 @@ (string) - the name of the force to get the warps for + the name of the force that you want the warp ids for @@ -710,7 +602,7 @@ @@ -720,31 +612,57 @@ + Usage: +
    -- Getting the warp ids for a force
    +local warp_ids = Warps.get_force_warp_ids(game.player.force.name)
    - # - get_all_warps() + # + get_spawn_warp_id(force_name)
    -

    Gets all warps from all forces

    +

    Get the id of the spawn warp

    + Parameters: + + + Returns: @@ -754,20 +672,23 @@ + Usage: +
    -- Getting the spawn warp id
    +local spawn_id = Warps.get_spawn_warp_id(game.player.force.name)
    - # - is_editing(warp_id, player_name) + # + get_editing(warp_id, player_name)
    -

    Gets if a player is currently editing this warp

    +

    Gets the editing state for a player

    @@ -827,6 +748,734 @@ + Usage: +
    -- Check if a player is editing a warp or not
    +local editing = Warps.get_editing(warp_id,game.player.name)
    + + +
    + +

    Setters

    +
    +
    +
    +
    + # + add_warp(force_name, surface, position[, player_name][, warp_name]) +
    +
    +
    +
    + +

    Add a new warp for a force, the warp must have a surface and a position

    +

    + + + Parameters: + +
      + + + + + +
    • + + force_name + + : + + (string) + + the name of the force to add the warp for + +
    • + + + + + +
    • + + surface + + : + + (LuaSurface) + + the surface that the warp will be on + +
    • + + + + + +
    • + + position + + : + + (Position) + + the position that the warp will be on + +
    • + + + + + +
    • + + player_name + + : + + (string) + + the name of the player that is adding the warp + + (optional) +
    • + + + + + +
    • + + warp_name + + : + + (string) + + the name of the warp that is being added, if omited default is used + + (optional) +
    • + + +
    + + + + + Returns: +
      +
    • + (string) + the uid of the warp which was created +
    • +
    + + + + + + + + Usage: +
    -- Adding a new warp for your force at your position
    +local player = game.player
    +local warp_id = Warps.add_warp(player.force.name,player.surface,player.position,player.name)
    + + +
    +
    +
    +
    + # + remove_warp(warp_id) +
    +
    +
    +
    + +

    Removes a warp and any data linked to it

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp that you want to remove + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Removing a warp
    +Warps.remove_warp(warp_id)
    + + +
    +
    +
    +
    + # + update_warp(warp_id[, new_name][, new_icon][, player_name='server']) +
    +
    +
    +
    + +

    Update the name and icon for a warp

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp that you want to update + +
    • + + + + + +
    • + + new_name + + : + + (string) + + the new name that you want the warp to have + + (optional) +
    • + + + + + +
    • + + new_icon + + : + + (string) + + the new icon that you want the warp to have + + (optional) +
    • + + + + + +
    • + + player_name + + : + + (string) + + the name of the player that made the edit + + (default: 'server') +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Changing the name and icon for a warp
    +Warps.update_warp(warp_id,'My Warp','iron-plate',game.player.name)
    + + +
    +
    +
    +
    + # + set_editing(warp_id, player_name, state) +
    +
    +
    +
    + +

    Set the editing state for a player, can be used as a warning or to display a text field

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp that you want to effect + +
    • + + + + + +
    • + + player_name + + : + + (string) + + the name of the player you want to set the state for + +
    • + + + + + +
    • + + state + + : + + (boolean) + + the new state to set editing to + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Setting your editing state to true
    +Warps.set_editing(warp_id,game.player.name,true)
    + + +
    +
    +
    +
    + # + on_update(handler) +
    +
    +
    +
    + +

    Adds an update handler for when a warp is added, removed, or updated

    +

    + + + Parameters: + +
      + + + + + +
    • + + handler + + : + + (function) + + the handler which is called when a warp is updated + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Add a game print when a warp is updated
    +Warps.on_update(function(warp)
    +    game.print(warp.force_name..' now has the warp: '..warp.name)
    +end)
    + + +
    +
    +

    Map Intergration

    +
    +
    +
    +
    + # + make_warp_tag(warp_id) +
    +
    +
    +
    + +

    Add or update the chat tag for this warp

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp you want the chart tag for + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if a new tag was made, false if it was updated +
    • +
    + + + + + + + + Usage: +
    -- Adding a chart tag for a new warp
    +local tag_added = Warps.make_warp_tag(warp_id)
    + + +
    +
    +
    +
    + # + remove_warp_tag(warp_id) +
    +
    +
    +
    + +

    Remove the chart tag for this warp

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid for the warp that you want to remove the chart tag from + +
    • + + +
    + + + + + Returns: +
      +
    • + (boolean) + true if the tag was valid and was removed, false if the tag was invalid +
    • +
    + + + + + + + + Usage: +
    -- Removing the chart tag from a warp
    +local removed = Warps.remove_warp_tag(warp_id)
    + + +
    +
    +
    +
    + # + make_warp_area(warp_id) +
    +
    +
    +
    + +

    Add a warp area for the warp, purely cosmetic

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp you want the area for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Adding a warp area for a warp
    +Warps.make_warp_area(warp_id)
    + + +
    +
    +
    +
    + # + remove_warp_area(warp_id) +
    +
    +
    +
    + +

    Remove the warp area for a warp

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp that you want to remove the area for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Remove the warp area for a warp
    +Warps.remove_warp_area(warp_id)
    + + +
    +
    +
    +
    + # + set_spawn_warp(warp_id, force) +
    +
    +
    +
    + +

    Set a warp to be the spawn point for a force, force must own this warp

    +

    + + + Parameters: + +
      + + + + + +
    • + + warp_id + + : + + (string) + + the uid of the warp that you want to be the spawn for the force + +
    • + + + + + +
    • + + force + + : + + (LuaForce) + + the force that you want to set the spawn for + +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Set your forces spawn to a warp
    +Warps.set_spawn_warp(warp_id,game.player.force)
    @@ -840,7 +1489,7 @@
    -

    Teleports a player to a warp point

    +

    Teleport a player to a warp point

    @@ -893,508 +1542,9 @@ - - -
    -
    -

    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, position[, 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 - -
    • - - - - - -
    • - - position - - : - - (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 - -
    • - - -
    - - - - - - - - - - - + Usage: +
    -- Teleport yourself to a warp point
    +Warps.teleport_player(warp_id,game.player)
    @@ -1413,7 +1563,7 @@ generated by LDoc diff --git a/docs/core/Commands.html b/docs/core/Commands.html index 3e51b1d4..f14de469 100644 --- a/docs/core/Commands.html +++ b/docs/core/Commands.html @@ -1972,7 +1972,7 @@ generated by LDoc diff --git a/docs/core/Common-Library.html b/docs/core/Common-Library.html index b68abc64..e9d35485 100644 --- a/docs/core/Common-Library.html +++ b/docs/core/Common-Library.html @@ -2746,7 +2746,7 @@ Common.table_insert(tbl,50,tbl2) generated by LDoc diff --git a/docs/core/Gui.html b/docs/core/Gui.html index 16ab505d..a50ba4ed 100644 --- a/docs/core/Gui.html +++ b/docs/core/Gui.html @@ -10987,7 +10987,7 @@ generated by LDoc diff --git a/docs/core/Permissions-Groups.html b/docs/core/Permissions-Groups.html index 70e41128..dd574a66 100644 --- a/docs/core/Permissions-Groups.html +++ b/docs/core/Permissions-Groups.html @@ -1432,7 +1432,7 @@ generated by LDoc diff --git a/docs/core/Roles.html b/docs/core/Roles.html index e5993370..ed416dcd 100644 --- a/docs/core/Roles.html +++ b/docs/core/Roles.html @@ -3152,7 +3152,7 @@ generated by LDoc diff --git a/docs/core/Store.html b/docs/core/Store.html index 4a247031..10806138 100644 --- a/docs/core/Store.html +++ b/docs/core/Store.html @@ -362,8 +362,12 @@ Store.set(player_scores,game.player,10) Used to update all values that are in a store, similar to Store.update but acts on all keys at once, will trigger watchers for every key present - trigger(store[, key][, value]) - Used to trigger any watchers that are on this store, the key and value are passed to the watcher functions + trigger(store[, key]) + Used to trigger watcher functions, this may be used to trigger them if you did not use Store.update or Store.set + + + raw_trigger(store[, key][, value]) + Used to trigger watcher functions, the value and key are passed directly to the watchers regardless if the value is correct @@ -1252,13 +1256,87 @@ Store.set(player_scores,game.player,10)
    # - trigger(store[, key][, value]) + trigger(store[, key])
    -

    Used to trigger any watchers that are on this store, the key and value are passed to the watcher functions

    +

    Used to trigger watcher functions, this may be used to trigger them if you did not use Store.update or Store.set

    +

    + + + Parameters: + +
      + + + + + +
    • + + store + + : + + (number) + + the uid of the store that you want to trigger + +
    • + + + + + +
    • + + key + + : + + (string or any) + + the key that you want to trigger, must be a string unless you have a serializer + + (optional) +
    • + + +
    + + + + + + + + + + + + Usage: +
    -- Faking the update to a store
    +-- The type of store we use does not really matter for this as long as you pass it what you watchers are expecting
    +local scenario_diffculty = Store.register()
    +
    +-- Trigger the watchers with a fake change of diffculty
    +Store.trigger(scenario_diffculty)
    + + +
    +
    +
    +
    + # + raw_trigger(store[, key][, value]) +
    +
    +
    +
    + +

    Used to trigger watcher functions, the value and key are passed directly to the watchers regardless if the value is correct

    @@ -1336,7 +1414,7 @@ Store.set(player_scores,game.player,10) -- Trigger the watchers with a fake change of diffculty -- This is mostly used internally but it can be useful in other cases -Store.trigger(scenario_diffculty,nil,'normal') +Store.raw_trigger(scenario_diffculty,nil,'normal')
    @@ -1355,7 +1433,7 @@ Store.set(player_scores,game.player,10) generated by LDoc diff --git a/docs/core/Sudo.html b/docs/core/Sudo.html index 3508e4ab..9a50edd8 100644 --- a/docs/core/Sudo.html +++ b/docs/core/Sudo.html @@ -544,7 +544,7 @@ generated by LDoc diff --git a/docs/guis/Player-List.html b/docs/guis/Player-List.html index 3f89ba2e..eee69c11 100644 --- a/docs/guis/Player-List.html +++ b/docs/guis/Player-List.html @@ -626,7 +626,7 @@ generated by LDoc diff --git a/docs/guis/Rocket-Info.html b/docs/guis/Rocket-Info.html index 6474bb2d..16e9cadf 100644 --- a/docs/guis/Rocket-Info.html +++ b/docs/guis/Rocket-Info.html @@ -629,7 +629,7 @@ generated by LDoc diff --git a/docs/guis/Science-Info.html b/docs/guis/Science-Info.html index 21b03a69..3119948b 100644 --- a/docs/guis/Science-Info.html +++ b/docs/guis/Science-Info.html @@ -449,7 +449,7 @@ generated by LDoc diff --git a/docs/guis/Task-List.html b/docs/guis/Task-List.html index 01acaa37..d5ed83fa 100644 --- a/docs/guis/Task-List.html +++ b/docs/guis/Task-List.html @@ -632,7 +632,7 @@ generated by LDoc diff --git a/docs/guis/Warps-List.html b/docs/guis/Warps-List.html index 896d6665..f9a3c9b9 100644 --- a/docs/guis/Warps-List.html +++ b/docs/guis/Warps-List.html @@ -837,7 +837,7 @@ generated by LDoc diff --git a/docs/index.html b/docs/index.html index d1adc427..07dcc66a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -118,7 +118,7 @@ Warps Control Module - Warps - - Stores warps for each force. +- Stores warps for each force.

    Addons

    @@ -514,7 +514,7 @@ see ./expcore/commands.lua for more details
    generated by LDoc diff --git a/docs/modules/control.html b/docs/modules/control.html index 2472c618..01c09b06 100644 --- a/docs/modules/control.html +++ b/docs/modules/control.html @@ -351,7 +351,7 @@ generated by LDoc diff --git a/docs/modules/utils.alien_evolution_progress.html b/docs/modules/utils.alien_evolution_progress.html index 62aac5db..e0bff02c 100644 --- a/docs/modules/utils.alien_evolution_progress.html +++ b/docs/modules/utils.alien_evolution_progress.html @@ -419,7 +419,7 @@ fraction will decide a chance to spawn. 1 alien for 2 spawner's will have 50% on generated by LDoc diff --git a/docs/modules/utils.core.html b/docs/modules/utils.core.html index c3dd9764..2d619cbc 100644 --- a/docs/modules/utils.core.html +++ b/docs/modules/utils.core.html @@ -1164,7 +1164,7 @@ generated by LDoc diff --git a/docs/modules/utils.debug.html b/docs/modules/utils.debug.html index 4ff4c9a8..89d1652c 100644 --- a/docs/modules/utils.debug.html +++ b/docs/modules/utils.debug.html @@ -654,7 +654,7 @@ generated by LDoc diff --git a/docs/modules/utils.dump_env.html b/docs/modules/utils.dump_env.html index dd8b00f9..f4b29047 100644 --- a/docs/modules/utils.dump_env.html +++ b/docs/modules/utils.dump_env.html @@ -323,7 +323,7 @@ generated by LDoc diff --git a/docs/modules/utils.event.html b/docs/modules/utils.event.html index f65f4892..7bc59dd3 100644 --- a/docs/modules/utils.event.html +++ b/docs/modules/utils.event.html @@ -1292,7 +1292,7 @@ generated by LDoc diff --git a/docs/modules/utils.event_core.html b/docs/modules/utils.event_core.html index f08daadc..f3da2188 100644 --- a/docs/modules/utils.event_core.html +++ b/docs/modules/utils.event_core.html @@ -434,7 +434,7 @@ generated by LDoc diff --git a/docs/modules/utils.math.html b/docs/modules/utils.math.html index 5902d9ed..317d2a54 100644 --- a/docs/modules/utils.math.html +++ b/docs/modules/utils.math.html @@ -353,7 +353,7 @@ generated by LDoc diff --git a/docs/modules/utils.recipe_locker.html b/docs/modules/utils.recipe_locker.html index 01abc7b2..fe5b79ca 100644 --- a/docs/modules/utils.recipe_locker.html +++ b/docs/modules/utils.recipe_locker.html @@ -441,7 +441,7 @@ generated by LDoc diff --git a/docs/modules/utils.state_machine.html b/docs/modules/utils.state_machine.html index d453b460..f3fb7488 100644 --- a/docs/modules/utils.state_machine.html +++ b/docs/modules/utils.state_machine.html @@ -752,7 +752,7 @@ generated by LDoc diff --git a/docs/modules/utils.table.html b/docs/modules/utils.table.html index 6e8b192b..5d70029e 100644 --- a/docs/modules/utils.table.html +++ b/docs/modules/utils.table.html @@ -1418,7 +1418,7 @@ generated by LDoc diff --git a/docs/modules/utils.task.html b/docs/modules/utils.task.html index 75f7ebc3..0d490e35 100644 --- a/docs/modules/utils.task.html +++ b/docs/modules/utils.task.html @@ -651,7 +651,7 @@ generated by LDoc diff --git a/docs/modules/utils.timestamp.html b/docs/modules/utils.timestamp.html index 65fd3fff..38a04573 100644 --- a/docs/modules/utils.timestamp.html +++ b/docs/modules/utils.timestamp.html @@ -442,7 +442,7 @@ generated by LDoc diff --git a/docs/topics/license.html b/docs/topics/license.html index 3199dbb6..5414825d 100644 --- a/docs/topics/license.html +++ b/docs/topics/license.html @@ -789,7 +789,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 8702e7af..b313179f 100644 --- a/docs/topics/readme.md.html +++ b/docs/topics/readme.md.html @@ -333,7 +333,7 @@ generated by LDoc diff --git a/expcore/gui/prototype.lua b/expcore/gui/prototype.lua index 20624583..a98dece7 100644 --- a/expcore/gui/prototype.lua +++ b/expcore/gui/prototype.lua @@ -98,11 +98,7 @@ function Constructor.store(sync,callback) if not sync then categorize = location - location = Store.uid_location() - end - - if Store.is_registered(location) then - return error('Location for store is already registered: '..location,2) + location = Store.register() end self.store = location @@ -110,7 +106,7 @@ function Constructor.store(sync,callback) Instances.register(self.name,self.categorize) - Store.register(self.store,sync,function(value,category) + Store.watch(self.store,function(value,category) self:raise_event('on_store_update',value,category) if Instances.is_registered(self.name) then diff --git a/expcore/gui/test.lua b/expcore/gui/test.lua index 2e25c61b..a7fe9952 100644 --- a/expcore/gui/test.lua +++ b/expcore/gui/test.lua @@ -650,8 +650,8 @@ end) Event.add(defines.events.on_tick,function() progressbar_one:increment() progressbar_three:decrement() - local categories = Store.get_children(progressbar_two.store) - for _,category in pairs(categories) do + local categories = Store.get(progressbar_two.store) or {} + for category,_ in pairs(categories) do progressbar_two:increment(1,category) end end) diff --git a/expcore/store.lua b/expcore/store.lua index c040e192..0b78ae7e 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -99,7 +99,7 @@ function Store.validate(store,key,error_stack) if not success then -- Serializer casued an error while serializing the key - error('Store watcher casued an error: '..key,error_stack+1) + error('Store watcher casued an error:\n\t'..key,error_stack+1) elseif type(key) ~= 'string' then -- Serializer was successful but failed to return a string value error('Store key serializer did not return a string; recived type '..type(key),error_stack+1) @@ -227,7 +227,12 @@ function Store.get(store,key) -- Get the data from the data store local data = data_store[store] if key then - return data[key] + if type(data) ~= 'table' then + data_store[store] = {_value = data_store[store]} + return nil + else + return data[key] + end end -- Return all data if there is no key @@ -269,7 +274,7 @@ function Store.clear(store,key) end -- Trigger any watch functions - Store.trigger(store,key,nil) + Store.raw_trigger(store,key,nil) end --[[-- Used to set the data in a store, will trigger any watchers, key is optional depending on if you are using them @@ -321,7 +326,7 @@ function Store.set(store,key,value) end -- Trigger any watchers - Store.trigger(store,key,value) + Store.raw_trigger(store,key,value) end --[[-- Used to update the data in a store, use this with tables, will trigger any watchers, key is optional depending on if you are using them @@ -396,7 +401,7 @@ function Store.update(store,key,updater) end -- Trigger any watchers - Store.trigger(store,key,value) + Store.raw_trigger(store,key,value) end --[[-- Used to update all values that are in a store, similar to Store.update but acts on all keys at once, will trigger watchers for every key present @@ -439,11 +444,34 @@ function Store.map(store,updater) if rtn then data[key] = rtn end - Store.trigger(store,key,data[key]) + Store.raw_trigger(store,key,data[key]) end end ---[[-- Used to trigger any watchers that are on this store, the key and value are passed to the watcher functions +--[[-- Used to trigger watcher functions, this may be used to trigger them if you did not use Store.update or Store.set +@tparam number store the uid of the store that you want to trigger +@tparam[opt] ?string|any key the key that you want to trigger, must be a string unless you have a serializer +@usage-- Faking the update to a store +-- The type of store we use does not really matter for this as long as you pass it what you watchers are expecting +local scenario_diffculty = Store.register() + +-- Trigger the watchers with a fake change of diffculty +Store.trigger(scenario_diffculty) + +]] +function Store.trigger(store,key) + key = Store.validate(store,key,2) + + -- Get the data from the data store + local data = data_store[store] + if key then + Store.raw_trigger(store,key,data[key]) + else + Store.raw_trigger(store,key,data) + end +end + +--[[-- Used to trigger watcher functions, the value and key are passed directly to the watchers regardless if the value is correct @tparam number store the uid of the store that you want to trigger @tparam[opt] ?string|any key the key that you want to trigger, must be a string unless you have a serializer @tparam[opt] any value the new value that is at this key or store, passed directly to the watcher @@ -454,18 +482,18 @@ local scenario_diffculty = Store.register() -- Trigger the watchers with a fake change of diffculty -- This is mostly used internally but it can be useful in other cases -Store.trigger(scenario_diffculty,nil,'normal') +Store.raw_trigger(scenario_diffculty,nil,'normal') ]] -function Store.trigger(store,key,value) +function Store.raw_trigger(store,key,value) key = Store.validate(store,key,2) -- Get the watchers and then loop over them - local watchers = Store.watchers[store] + local watchers = Store.watchers[store] or {} for _,watcher in pairs(watchers) do local success, err = pcall(watcher,value,key) if not success then - error('Store watcher casued an error: '..err) + error('Store watcher casued an error:\n\t'..err) end end end diff --git a/modules/control/tasks.lua b/modules/control/tasks.lua index 4223c91f..6b2d9630 100644 --- a/modules/control/tasks.lua +++ b/modules/control/tasks.lua @@ -34,15 +34,17 @@ Tasks.store = task_store @tparam string force_name the name of the force to add the task for @tparam[opt] number task_number the order place to add the task to, appends to end if omited @tparam[opt] string player_name the player who added this task, will cause them to be listed under editing +@tparam[opt] string task_message the message that is used for this task, if not given default is used @treturn string the uid of the task which was created @usage-- Adding a new task for your force local task_id = Tasks.add_task(game.player.force.name,nil,game.player.name) ]] -function Tasks.add_task(force_name,task_number,player_name) +function Tasks.add_task(force_name,task_number,player_name,task_message) -- Get a new task id local task_id = tostring(Token.uid()) + task_message = task_message or 'New Task' -- Get the existing tasks for this force local tasks = force_tasks[force_name] @@ -68,7 +70,7 @@ function Tasks.add_task(force_name,task_number,player_name) Store.set(task_store,task_id,{ task_id = task_id, force_name = force_name, - message = 'New Task', + message = task_message, last_edit_name = player_name or '', last_edit_time = game.tick, curently_editing = editing diff --git a/modules/control/warps.lua b/modules/control/warps.lua index 5a7d5445..a9e3c5d7 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -1,27 +1,23 @@ --[[-- Control Module - Warps - - Stores warps for each force. - @control Warps - @alias Warps +- Stores warps for each force. +@control Warps +@alias Warps - @usage - -- import the module from the control modules - local Warps = require 'modules.control.warps' --- @dep modules.control.warps +@usage-- Making a new spawn warp +local player = game.player +local force = player.force +local spawn_id = Warps.add_warp(force.name,player.surface,player.position,player.name,'Spawn') - -- 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}) +Warps.set_spawn_warp(spawn_id, force) +Warps.make_warp_tag(spawn_id) - -- You can then update the warp information, name and icon, with the update function - Warps.update_warp(warp_id,'Best Warp','iron-plate') +@usage-- Making a new warp with a warp area +local player = game.player +local force = player.force +local warp_id = Warps.add_warp(force.name,player.surface,player.position,player.name) - -- 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) +Warps.make_warp_area(warp_id) +Warps.make_warp_tag(warp_id) ]] @@ -31,153 +27,139 @@ local Token = require 'utils.token' --- @dep utils.token local config = require 'config.warps' --- @dep config.warps local table_values,table_keysort = ext_require('expcore.common','table_values','table_keysort') --- @dep expcore.common -local Warps = { - store = { - names = 'gui.left.warps.names', - icons = 'gui.left.warps.tags' - }, - details = {}, - forces = {}, - handlers = {} -} +local Warps = {} -local warp_details = Warps.details -local force_warps = Warps.forces -Global.register({ - warp_details=warp_details, - force_warps=force_warps -},function(tbl) - Warps.details = tbl.warp_details - Warps.forces = tbl.force_warps - warp_details = Warps.details - force_warps = Warps.forces +-- Global lookup table for force name to task ids +local force_warps = {} +Global.register(force_warps,function(tbl) + force_warps = tbl 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 +-- Warp store is keyed by warp id, value is a table +local warp_store = Store.register() +Warps.store = warp_store - 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 +-- When a warp is updated change its chat tag and resort the warp order +Store.watch(warp_store,function(warp,warp_id) + if warp then + -- Update the map chart tag if there is one + if warp.tag then + Warps.make_warp_tag(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 + -- Check that the name of the warp has been changed + if warp.name == warp.old_name then return end - for _,handler in pairs(Warps.handlers) do - handler(force,warp_id) + -- Get the names of all the warp points for this force + local force_name = warp.force_name + local warp_ids = force_warps[force_name] + local spawn_id = warp_ids.spawn + + local warp_names = {} + for _,next_warp_id in pairs(warp_ids) do + local next_warp = Store.get(warp_store,next_warp_id) + if next_warp_id ~= spawn_id then + warp_names[next_warp.name..next_warp_id] = next_warp_id + end + end + + -- Sort the warp names in alphabetical order + local new_warp_ids = table_values(table_keysort(warp_names)) + table.insert(new_warp_ids,1,spawn_id) + new_warp_ids.spawn = spawn_id + force_warps[force_name] = new_warp_ids 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. +--- Map Intergration. -- functions used to create and alter warps with in the map --- @section generators +-- @section mapIntergration ---- 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] +--[[-- Add or update the chat tag for this warp +@tparam string warp_id the uid of the warp you want the chart tag for +@treturn boolean true if a new tag was made, false if it was updated - local name = Store.get(warp_names,warp_id) - local icon = Store.get(warp_icons,warp_id) +@usage-- Adding a chart tag for a new warp +local tag_added = Warps.make_warp_tag(warp_id) - if warp.tag and warp.tag.valid then - warp.tag.text = 'Warp: '..name - warp.tag.icon = {type='item',name=icon} +]] +function Warps.make_warp_tag(warp_id) + local warp = Store.get(warp_store,warp_id) + local name = warp.name + local icon = warp.icon + + -- Edit the existing tag if it is present + local tag = warp.tag + if tag and tag.valid then + tag.text = 'Warp: '..name + tag.icon = {type='item',name=icon} return false end - local force = game.forces[warp.force] + -- Make a new tag if one did not exist + local force = game.forces[warp.force_name] 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} + tag = force.add_chart_tag(surface,{ + position = {position.x+0.5,position.y+0.5}, + text = 'Warp: '..name, + icon = {type='item',name=icon} }) + -- Add the tag to this warp, store.update not needed as we dont want it to trigger 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 position 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' +--[[-- Remove the chart tag for this warp +@tparam string warp_id the uid for the warp that you want to remove the chart tag from +@treturn boolean true if the tag was valid and was removed, false if the tag was invalid - if not force_warps[force_name] then - force_warps[force_name] = {} - end - table.insert(force_warps[force_name],warp_id) +@usage-- Removing the chart tag from a warp +local removed = Warps.remove_warp_tag(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={} - } +]] +function Warps.remove_warp_tag(warp_id) + local warp = Store.get(warp_store,warp_id) - local warp = warp_details[warp_id] - - if player_name then - warp.editing[player_name] = true + -- Check there is a tag to remove + local tag = warp.tag + if not tag or not tag.valid then + warp.tag = nil + return false end - if set_spawn then - force_warps[force_name].spawn = warp_id - game.forces[force_name].set_spawn_position(position,surface) - end + -- Remove the warp chart tag if it is valid + tag.destroy() + warp.tag = nil - Store.set(warp_names,warp_id,warp_name) - Store.set(warp_icons,warp_id,config.default_icon) + return true +end - if block_generation then return warp_id end +--[[-- Add a warp area for the warp, purely cosmetic +@tparam string warp_id the uid of the warp you want the area for +@usage-- Adding a warp area for a warp +Warps.make_warp_area(warp_id) + +]] +function Warps.make_warp_area(warp_id) + local warp = Store.get(warp_store,warp_id) + local surface = warp.surface + local position = warp.position local posx = position.x local posy = position.y local radius = config.activation_range local radius2 = radius^2 + -- Get the tile that is being replaced, store.update not needed as we dont want it to trigger local old_tile = surface.get_tile(position).name warp.old_tile = old_tile + -- Make a circle that acts as a base for the warp structure 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 @@ -189,14 +171,14 @@ function Warps.new_warp(force_name,surface,position,player_name,warp_name,block_ end surface.set_tiles(base_tiles) - -- this adds the tile pattern + -- Add a tile patern ontop of the base 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 + -- Add entities to the warp structure for _,entity in pairs(config.entities) do entity = surface.create_entity{ name=entity[1], @@ -208,29 +190,28 @@ function Warps.new_warp(force_name,surface,position,player_name,warp_name,block_ 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) +--[[-- Remove the warp area for a warp +@tparam string warp_id the uid of the warp that you want to remove the area for - local warp = warp_details[warp_id] +@usage-- Remove the warp area for a warp +Warps.remove_warp_area(warp_id) + +]] +function Warps.remove_warp_area(warp_id) + local warp = Store.get(warp_store,warp_id) local position = warp.position local surface = warp.surface local radius = config.activation_range local radius2 = radius^2 + -- Check that a warp area was created previously local base_tile = warp.old_tile + if not base_tile then return end + + -- Reset all the tiles that were replaced local tiles = {} - -- clears the area where the warp was for x = -radius, radius do local x2 = x^2 for y = -radius, radius do @@ -242,7 +223,7 @@ function Warps.remove_warp(warp_id) end surface.set_tiles(tiles) - -- removes all entites (in the area) on the neutral force + -- Remove all the entites that are in the area local entities = surface.find_entities_filtered{ force='neutral', area={ @@ -251,108 +232,230 @@ function Warps.remove_warp(warp_id) } } 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 +--[[-- Set a warp to be the spawn point for a force, force must own this warp +@tparam string warp_id the uid of the warp that you want to be the spawn for the force +@tparam LuaForce force the force that you want to set the spawn for ---- 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 +@usage-- Set your forces spawn to a warp +Warps.set_spawn_warp(warp_id,game.player.force) + +]] +function Warps.set_spawn_warp(warp_id,force) + -- Check the force owns this warp + local warp = Store.get(warp_store,warp_id) + if warp.force_name ~= force.name then return end + + -- Set this warp as the spawn + local warp_ids = force_warps[warp.force_name] + if not warp_ids then + warp_ids = {} + force_warps[warp.force_name] = warp_ids end - return false + warp_ids.spawn = warp_id + + -- Set the forces spawn to this warp + force.set_spawn_position(warp.position, warp.surface) 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 +--[[-- Teleport 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 ---- 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 +@usage-- Teleport yourself to a warp point +Warps.teleport_player(warp_id,game.player) ---- 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 warp = Store.get(warp_store,warp_id) local surface = warp.surface local position = { x=warp.position.x+0.5, y=warp.position.y+0.5 } + -- Teleport the player 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 +--- Setters. +-- functions used to created and alter warps +-- @section setters + +--[[-- Add a new warp for a force, the warp must have a surface and a position +@tparam string force_name the name of the force to add the warp for +@tparam LuaSurface surface the surface that the warp will be on +@tparam Concepts.Position position the position that the warp will be on +@tparam[opt] string player_name the name of the player that is adding the warp +@tparam[opt] string warp_name the name of the warp that is being added, if omited default is used +@treturn string the uid of the warp which was created + +@usage-- Adding a new warp for your force at your position +local player = game.player +local warp_id = Warps.add_warp(player.force.name,player.surface,player.position,player.name) + +]] +function Warps.add_warp(force_name,surface,position,player_name,warp_name) + -- Get new warp id + local warp_id = tostring(Token.uid()) + warp_name = warp_name or 'New warp' + + -- Get the existing warps for this force + local warps = force_warps[force_name] + if not warps then + force_warps[force_name] = {} + warps = force_warps[force_name] + end + + -- Insert the warp id into the force warps + table.insert(warps,warp_id) + + -- Create the editing table + local editing = {} + if player_name then + editing[player_name] = true + end + + -- Add the new warp to the store + Store.set(warp_store,warp_id,{ + warp_id = warp_id, + force_name = force_name, + name = warp_name, + icon = config.default_icon, + surface = surface, + position = { + x = math.floor(position.x), + y = math.floor(position.y) + }, + last_edit_name = player_name or '', + last_edit_time = game.tick, + currently_editing = editing + }) + + return warp_id +end + +--[[-- Removes a warp and any data linked to it +@tparam string warp_id the uid of the warp that you want to remove + +@usage-- Removing a warp +Warps.remove_warp(warp_id) + +]] +function Warps.remove_warp(warp_id) + local warp = Store.get(warp_store,warp_id) + local force_name = warp.force_name + Warps.remove_warp_tag(warp_id) + Warps.remove_warp_area(warp_id) + Store.clear(warp_store,warp_id) + table.remove_element(force_warps[force_name],warp_id) +end + +--[[-- Update the name and icon for a warp +@tparam string warp_id the uid of the warp that you want to update +@tparam[opt] string new_name the new name that you want the warp to have +@tparam[opt] string new_icon the new icon that you want the warp to have +@tparam[opt='server'] string player_name the name of the player that made the edit + +@usage-- Changing the name and icon for a warp +Warps.update_warp(warp_id,'My Warp','iron-plate',game.player.name) + +]] +function Warps.update_warp(warp_id,new_name,new_icon,player_name) + Store.update(warp_store,warp_id,function(warp) + warp.last_edit_name = player_name or '' + warp.last_edit_time = game.tick + warp.old_name = warp.name + warp.name = new_name or warp.name + warp.icon = new_icon or warp.icon + end) +end + +--[[-- Set the editing state for a player, can be used as a warning or to display a text field +@tparam string warp_id the uid of the warp that you want to effect +@tparam string player_name the name of the player you want to set the state for +@tparam boolean state the new state to set editing to + +@usage-- Setting your editing state to true +Warps.set_editing(warp_id,game.player.name,true) + +]] +function Warps.set_editing(warp_id,player_name,state) + Store.update(warp_store,warp_id,function(warp) + warp.currently_editing[player_name] = state + end) +end + +--[[-- Adds an update handler for when a warp is added, removed, or updated +@tparam function handler the handler which is called when a warp is updated + +@usage-- Add a game print when a warp is updated +Warps.on_update(function(warp) + game.print(warp.force_name..' now has the warp: '..warp.name) +end) + +]] +function Warps.on_update(handler) + Store.watch(warp_store,handler) +end + +--- Getters. +-- function used to get information about warps +-- @section getters + +--[[-- Gets the warp information that is linked with this id +@tparam string warp_id the uid of the warp you want to get +@treturn table the warp information + +@usage-- Getting warp information outside of on_update +local warp = Warps.get_warp(warp_id) + +]] +function Warps.get_warp(warp_id) + return Store.get(warp_store,warp_id) +end + +--[[-- Gets all the warp ids that a force has +@tparam string force_name the name of the force that you want the warp ids for +@treturn table an array of all the warp ids + +@usage-- Getting the warp ids for a force +local warp_ids = Warps.get_force_warp_ids(game.player.force.name) + +]] +function Warps.get_force_warp_ids(force_name) + return force_warps[force_name] or {} +end + +--[[-- Get the id of the spawn warp +@tparam string force_name the name of the force that you want to get the spawn warp for +@treturn ?string|nil the uid of the spawn warp for this force if there is one + +@usage-- Getting the spawn warp id +local spawn_id = Warps.get_spawn_warp_id(game.player.force.name) + +]] +function Warps.get_spawn_warp_id(force_name) + local warp_ids = force_warps[force_name] or {} + return warp_ids.spawn +end + +--[[-- Gets the editing state for a player +@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 + +@usage-- Check if a player is editing a warp or not +local editing = Warps.get_editing(warp_id,game.player.name) + +]] +function Warps.get_editing(warp_id,player_name) + local warp = Store.get(warp_store,warp_id) + return warp.currently_editing[player_name] +end + +-- Module return return Warps \ No newline at end of file diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index 9ea2305f..1704ebbd 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -14,7 +14,7 @@ local Tasks = require 'modules.control.tasks' --- @dep modules.control.tasks --- If a player is allowed to use the edit buttons local function player_allowed_edit(player,task) if task then - if config.user_can_edit_own_tasks and task.last_edit_player == player.name then + if config.user_can_edit_own_tasks and task.last_edit_name == player.name then return true end else diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index 9fb9e390..a1b50dc2 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -15,22 +15,25 @@ local config = require 'config.warps' --- @dep config.warps local format_time,table_keys = ext_require('expcore.common','format_time','table_keys') --- @dep expcore.common local Warps = require 'modules.control.warps' --- @dep modules.control.warps -local warp_player_in_range_store = 'gui.left.warps.in_range' +-- Stores a boolean value indexed by player name +local player_in_range_store = Store.register(function(player) + return player.name +end) -local keep_open = {} -Global.register(keep_open,function(tbl) - keep_open = tbl +-- Table that stores a boolean value of weather to keep the warp gui open +local keep_gui_open = {} +Global.register(keep_gui_open,function(tbl) + keep_gui_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 = Warps.get_details(warp_id) - local warps = Warps.get_warps(player.force.name) - if warps.spawn == warp_id then +local function player_allowed_edit(player,warp) + if warp then + local spawn_id = Warps.get_spawn_warp_id(player.force.name) + if spawn_id == warp.warp_id then return false end - if config.user_can_edit_own_warps and details.last_edit_player == player.name then + if config.user_can_edit_own_warps and warp.last_edit_name == player.name then return true end else @@ -55,7 +58,7 @@ end 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 = Warps.get_details(warp_id) + local warp = Warps.get_warp(warp_id) local position = warp.position event.player.zoom_to_world(position,1.5) end) @@ -73,9 +76,7 @@ Gui.new_progressbar() style.color = Colors.light_blue end) :on_store_complete(function(player_name,reset) - -- this is to force an update of the button - local in_range = Store.get(warp_player_in_range_store,player_name) - Store.set(warp_player_in_range_store,player_name,in_range) + Store.trigger(player_in_range_store,player_name) end) --- When the button is clicked it will teleport the player @@ -92,11 +93,10 @@ end) local warp_id = element.parent.caption Warps.teleport_player(warp_id,player) + -- Reset the warp cooldown if the player does not have unlimited warps 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) - -- this is to force an update of the buttons - local in_range = Store.get(warp_player_in_range_store,player.name) - Store.set(warp_player_in_range_store,player.name,in_range) + Store.trigger(player_in_range_store,player) end end) @@ -112,22 +112,28 @@ Gui.new_button() style.width = 20 end) :on_click(function(player,element) + local force_name = player.force.name + local surface = player.surface local position = player.position local px = position.x local py = position.y local dist2 = config.minimum_distance^2 - local warps = Warps.get_all_warps() - for warp_id,warp in pairs(warps) do + -- Check the distance to all existing warps + local warp_ids = Warps.get_force_warp_ids(force_name) + for _,warp_id in pairs(warp_ids) do + local warp = Warps.get_warp(warp_id) local pos = warp.position - if (px-pos.x)^2+(py-pos.y)^2 < dist2 then - local warp_name = Warps.get_warp_name(warp_id) - player.print{'warp-list.too-close',warp_name} + if surface == warp.surface and (px-pos.x)^2+(py-pos.y)^2 < dist2 then + player.print{'warp-list.too-close',warp.name} return end end - Warps.new_warp(player.force.name,player.surface,position,player.name) + -- Add the new warp + local warp_id = Warps.add_warp(force_name,surface,position,player.name) + Warps.make_warp_tag(warp_id) + Warps.make_warp_area(warp_id) end) --- Confirms the edit to name or icon of the warp @@ -151,7 +157,6 @@ end) --- Cancels the editing changes of the selected warp name or icon -- @element cancel_edit -local generate_warp local cancel_edit = Gui.new_button() :set_sprites('utility/close_black') @@ -164,7 +169,6 @@ end) :on_click(function(player,element) local warp_id = element.parent.name Warps.set_editing(warp_id,player.name) - generate_warp(player,element.parent.parent,warp_id) end) --- Removes a warp from the list, including the physical area and map tag @@ -197,7 +201,6 @@ end) :on_click(function(player,element) local warp_id = element.parent.name Warps.set_editing(warp_id,player.name,true) - generate_warp(player,element.parent.parent.parent,warp_id) end) --[[ Generates each warp, handles both view and edit mode @@ -213,23 +216,22 @@ end) >>> edit_warp >>> discard_warp ]] -function generate_warp(player,element,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 = 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 - - if not warp_name then +local function generate_warp(player,element,warp_id) + local warp = Warps.get_warp(warp_id) + if not warp then -- warp is nil so remove it from the list Gui.destroy_if_valid(element['icon-'..warp_id]) Gui.destroy_if_valid(element['edit-'..warp_id]) Gui.destroy_if_valid(element[warp_id]) else + local warp_name = warp.name + local warp_icon = warp.icon + local editing = warp.currently_editing[player.name] + local last_edit_name = warp.last_edit_name + local last_edit_time = warp.last_edit_time + local position = warp.position + -- if it is not already present then add it now local warp_area = element[warp_id] local icon_area = element['icon-'..warp_id] @@ -261,8 +263,8 @@ function generate_warp(player,element,warp_id) end local edit_area = element['edit-'..warp_id][warp_id] - local players = warp.editing and table_keys(warp.editing) or {} - local allowed = player_allowed_edit(player,warp_id) + local players = warp.currently_editing and table_keys(warp.currently_editing) or {} + local allowed = player_allowed_edit(player,warp) edit_area.visible = allowed @@ -278,7 +280,7 @@ function generate_warp(player,element,warp_id) if not editing and element_type == 'label' then -- update the label already present label_element.caption = warp_name - label_element.tooltip = {'warp-list.last-edit',last_edit_player,format_time(last_edit_time)} + label_element.tooltip = {'warp-list.last-edit',last_edit_name,format_time(last_edit_time)} icon_area[goto_warp.name].sprite = 'item/'..warp_icon elseif not editing then @@ -295,7 +297,7 @@ function generate_warp(player,element,warp_id) btn.tooltip = {'warp-list.goto-tooltip',position.x,position.y} local timer = warp_timer:get_store(player.name) - local enabled = not timer and Store.get(warp_player_in_range_store,player.name) + local enabled = not timer and Store.get(player_in_range_store,player) or Roles.player_allowed(player,config.bypass_warp_limits_permission) if not enabled then btn.enabled = false @@ -310,7 +312,7 @@ function generate_warp(player,element,warp_id) name=zoom_to_map_name, type='label', caption=warp_name, - tooltip={'warp-list.last-edit',last_edit_player,format_time(last_edit_time)} + tooltip={'warp-list.last-edit',last_edit_name,format_time(last_edit_time)} } label.style.single_line = false label.style.maximal_width = 150 @@ -412,38 +414,30 @@ Gui.new_left_frame('gui/warp-list') :set_direction('vertical') :on_creation(function(player,element) local data_table = generate_container(player,element) - local warps = Warps.get_warps(player.force.name) + local warp_ids = Warps.get_force_warp_ids(player.force.name) - for key,warp_id in pairs(warps) do - if key ~= 'spawn' then - generate_warp(player,data_table,warp_id) - end + for _,warp_id in ipairs(warp_ids) do + generate_warp(player,data_table,warp_id) end end) :on_update(function(player,element) local data_table = element.container.scroll.table - local warps = Warps.get_warps(player.force.name) + local warp_ids = Warps.get_force_warp_ids(player.force.name) data_table.clear() - for key,warp_id in pairs(warps) do - if key ~= 'spawn' then - generate_warp(player,data_table,warp_id) - end + for _,warp_id in ipairs(warp_ids) do + generate_warp(player,data_table,warp_id) end end) :on_player_toggle(function(player,element,visible) - keep_open[player.name] = visible + keep_gui_open[player.name] = visible end) --- When the name of a warp is updated this is triggered -Warps.add_handler(function(force,warp_id) - for _,player in pairs(force.players) do - warp_list:update(player) - end -end) +Warps.on_update(warp_list 'update_all') --- When the player leaves or enters range of a warp this is triggered -Store.register(warp_player_in_range_store,function(value,player_name) +Store.register(player_in_range_store,function(value,player_name) local player = game.players[player_name] local force = player.force local frame = warp_list:get_frame(player_name) @@ -451,7 +445,7 @@ Store.register(warp_player_in_range_store,function(value,player_name) local timer = warp_timer:get_store(player_name) local state = not timer and value - if not keep_open[player.name] then + if not keep_gui_open[player.name] then Gui.toggle_left_frame(warp_list.name,player,value) end @@ -459,8 +453,8 @@ Store.register(warp_player_in_range_store,function(value,player_name) return end - local warps = Warps.get_warps(force.name) - for _,warp_id in pairs(warps) do + local warp_ids = Warps.get_force_warp_ids(force.name) + for _,warp_id in pairs(warp_ids) do local element = table_area['icon-'..warp_id][goto_warp.name] if element and element.valid then element.enabled = state @@ -478,38 +472,59 @@ end) local r2 = config.activation_range^2 local rs2 = config.spawn_activation_range^2 Event.on_nth_tick(math.floor(60/config.update_smoothing),function() - local categories = Store.get_keys(warp_timer.store) - for _,category in pairs(categories) do + local categories = Store.get(warp_timer.store) or {} + for category,_ in pairs(categories) do warp_timer:increment(1,category) end + local force_warps = {} + local warps = {} 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 = Warps.get_warps(force.name) + local was_in_range = Store.get(player_in_range_store,player) - if #warps > 0 then - local surface = player.surface.index + -- Get the ids of all the warps on the players force + local force_name = player.force + local warp_ids = force_warps[force_name] + if not warp_ids then + warp_ids = Warps.get_force_warp_ids(force_name) + force_warps[force_name] = warp_ids + end + + -- Check if the force has any warps + if #warp_ids > 0 then + local surface = player.surface local pos = player.position local px,py = pos.x,pos.y - for _,warp_id in pairs(warps) do - local warp = Warps.get_details(warp_id) + + -- Loop over each warp + for _,warp_id in pairs(warp_ids) do + -- Check if warp id is chached + local warp = warps[warp_id] + if not warp then + warp = Warps.get(warp_id) + warps[warp_id] = warp + end + + -- Check if the player is within range local warp_pos = warp.position - if warp.surface.index == surface then - local dx,dy = px-warp_pos.x,py-warp_pos.y - if not warp.editing and (dx*dx)+(dy*dy) < rs2 or (dx*dx)+(dy*dy) < r2 then + if warp.surface == surface then + local dx, dy = px-warp_pos.x, py-warp_pos.y + if (dx*dx)+(dy*dy) < rs2 or (dx*dx)+(dy*dy) < r2 then + -- Set in range to true if the player was preiovusly out of range if not was_in_range then - Store.set(warp_player_in_range_store,player.name,true) + Store.set(player_in_range_store,player,true) end - return + break end end end - if was_in_range then - Store.set(warp_player_in_range_store,player.name,false) - end - end + -- Set in range to false if the player was preiovusly in range + if was_in_range then + Store.set(player_in_range_store,player,false) + end + + end end @@ -519,30 +534,38 @@ end) Event.add(defines.events.on_player_created,function(event) local player = Game.get_player_by_index(event.player_index) + -- Check if a player is allowed unlimited warps local allowed = config.bypass_warp_limits_permission and Roles.player_allowed(player,config.bypass_warp_limits_permission) or false - Store.set(warp_player_in_range_store,player.name,allowed) + Store.set(player_in_range_store,player,allowed) if allowed then warp_timer:set_store(player.name,1) end + -- If the force has no spawn then make a spawn warp local force = player.force - if not Warps.forces[force.name] then + local spawn_id = Warps.get_spawn_warp_id(force.name) + if not spawn_id then local spawn_position = force.get_spawn_position(player.surface) - Warps.new_warp(force.name,player.surface,spawn_position,nil,'Spawn',true,true) + spawn_id = Warps.add_warp(force.name,player.surface,spawn_position,nil,'Spawn') + Warps.set_spawn_warp(spawn_id,force) + Store.trigger(Warps.store,spawn_id) + Warps.make_warp_tag(spawn_id) end end) local function maintain_tag(event) + if not event.player_index then return end local tag = event.tag - local force = event.force - 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 + local force_name = event.force.name + local warp_ids = Warps.get_force_warp_ids(force_name) + for _,warp_id in pairs(warp_ids) do + local warp = Warps.get_warp(warp_id) + local wtag = warp.tag + if not wtag or not wtag.valid or wtag == tag then if event.name == defines.events.on_chart_tag_removed then warp.tag = nil end - Warps.make_chart_tag(warp_id) + Warps.make_warp_tag(warp_id) end end end