From f44ab9b44f166034e19632f2632120bef86771d7 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 17 Oct 2019 23:23:51 +0100 Subject: [PATCH] Store bug fixes --- README.md | 12 ++++++++---- expcore/store.lua | 4 +++- modules/control/warps.lua | 10 +++++----- modules/gui/task-list.lua | 5 ++++- modules/gui/warp-list.lua | 18 ++++++++++++------ 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 8ff71f05..93092fb6 100644 --- a/README.md +++ b/README.md @@ -47,15 +47,17 @@ Explosive Gaming (often ExpGaming) is a server hosting community with a strong f All are welcome to make pull requests and issues for this scenario, if you are in any doubt please ask someone in our [discord]. If you do not know lua and don't feel like learning you can always make a [feature request]. All our docs can be found [here][docs]. Please keep in mind while making code changes: * New features should have the branch names: `feature/feature-name` -* New features are merged into `dev` after it has been completed. -* After a number of features have been added a release branch is made: `release/X.Y.0`; this branch should have no new features and only bug fixes or localization. -* A release is merged into `master` on the following friday in time for the the weekly reset. -* Patches may be named `patch/X.Y.Z` and fill be merged into `master` and `dev` when appropriate. +* New features are merged into `dev` after it has been completed, this can be done through a pull request. +* After a number of features have been added a release branch is made: `release/X.Y.0` +* Bug fixes and localization can be made to the release branch with a pull request rather than into dev. +* A release is merged into `master` on the following friday after it is considered stable. +* Patches may be named `patch/X.Y.Z` and will be merged into `dev` and then `master` when appropriate. ## Releases | Scenario Version* | Version Name | Factorio Version** | |---|---|---| +| [v5.10][s5.10] | Data Store Rewrite | [v0.17.71][f0.17.71] | | [v5.9][s5.9] | Control Modules and Documentation | [v0.17.63][f0.17.63] | | [v5.8][s5.8] | Home and Chat Bot | [v0.17.47][f0.17.49] | | [v5.7][s5.7] | Warp System | [v0.17.47][f0.17.47] | @@ -76,6 +78,7 @@ All are welcome to make pull requests and issues for this scenario, if you are i \*\* Factorio versions show the version they were made for, often the minimum requirement. +[s5.10]: https://github.com/explosivegaming/scenario/releases/tag/5.10.0 [s5.9]: https://github.com/explosivegaming/scenario/releases/tag/5.9.0 [s5.8]: https://github.com/explosivegaming/scenario/releases/tag/5.8.0 [s5.7]: https://github.com/explosivegaming/scenario/releases/tag/5.7.0 @@ -92,6 +95,7 @@ All are welcome to make pull requests and issues for this scenario, if you are i [s1.0]: https://github.com/explosivegaming/scenario/releases/tag/v1.0 [s0.1]: https://github.com/explosivegaming/scenario/releases/tag/v0.1 +[f0.17.71]: https://wiki.factorio.com/Version_history/0.17.0#0.17.71 [f0.17.63]: https://wiki.factorio.com/Version_history/0.17.0#0.17.63 [f0.17.49]: https://wiki.factorio.com/Version_history/0.17.0#0.17.49 [f0.17.47]: https://wiki.factorio.com/Version_history/0.17.0#0.17.47 diff --git a/expcore/store.lua b/expcore/store.lua index 96b521b8..f58e41b9 100644 --- a/expcore/store.lua +++ b/expcore/store.lua @@ -277,7 +277,9 @@ function Store.clear(store,key) -- Check if there is a key being used if key then - data_store[store][key] = nil + if type(data_store[store]) == 'table' then + data_store[store][key] = nil + end else data_store[store] = nil end diff --git a/modules/control/warps.lua b/modules/control/warps.lua index a9e3c5d7..ad503c3a 100644 --- a/modules/control/warps.lua +++ b/modules/control/warps.lua @@ -304,14 +304,14 @@ function Warps.add_warp(force_name,surface,position,player_name,warp_name) 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] + local warp_ids = force_warps[force_name] + if not warp_ids then + warp_ids = {} + force_warps[force_name] = warp_ids end -- Insert the warp id into the force warps - table.insert(warps,warp_id) + table.insert(warp_ids,warp_id) -- Create the editing table local editing = {} diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index 1704ebbd..d82a3a77 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -326,7 +326,7 @@ Tasks.on_update(function(task,task_id) local players if task then local force = game.forces[task.force_name] - players = force.players + players = force.connected_players else players = game.connected_players end @@ -338,6 +338,9 @@ Tasks.on_update(function(task,task_id) end end) +--- Update the tasks when the player joins +Event.add(defines.events.on_player_joined_game,task_list 'redraw') + --- Makes sure the right buttons are present when roles change Event.add(Roles.events.on_role_assigned,task_list 'redraw') Event.add(Roles.events.on_role_unassigned,task_list 'redraw') diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index c94c54fa..67c11571 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -94,7 +94,7 @@ end) 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 + if config.bypass_warp_limits_permission and not Roles.player_allowed(player,config.bypass_warp_limits_permission) then warp_timer:set_store(player.name,0) Store.trigger(player_in_range_store,player) end @@ -436,6 +436,11 @@ end) --- When the name of a warp is updated this is triggered Warps.on_update(warp_list 'update_all') +--- Update the warps when the player joins +Event.add(defines.events.on_player_joined_game,warp_list 'redraw') +Event.add(Roles.events.on_role_assigned,warp_list 'redraw') +Event.add(Roles.events.on_role_unassigned,warp_list 'redraw') + --- When the player leaves or enters range of a warp this is triggered Store.watch(player_in_range_store,function(value,player_name) local player = game.players[player_name] @@ -459,7 +464,7 @@ Store.watch(player_in_range_store,function(value,player_name) if element and element.valid then element.enabled = state if state then - local position = Warps.get_details(warp_id).position + local position = Warps.get_warp(warp_id).position element.tooltip = {'warp-list.goto-tooltip',position.x,position.y} else element.tooltip = {'warp-list.goto-disabled'} @@ -483,7 +488,7 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function() local was_in_range = Store.get(player_in_range_store,player) -- Get the ids of all the warps on the players force - local force_name = player.force + local force_name = player.force.name local warp_ids = force_warps[force_name] if not warp_ids then warp_ids = Warps.get_force_warp_ids(force_name) @@ -497,11 +502,11 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function() local px,py = pos.x,pos.y -- Loop over each warp - for _,warp_id in pairs(warp_ids) do + for _,warp_id in ipairs(warp_ids) do -- Check if warp id is chached local warp = warps[warp_id] if not warp then - warp = Warps.get(warp_id) + warp = Warps.get_warp(warp_id) warps[warp_id] = warp end @@ -509,11 +514,12 @@ Event.on_nth_tick(math.floor(60/config.update_smoothing),function() local warp_pos = warp.position 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 + if (warp_id == warp_ids.spawn and (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(player_in_range_store,player,true) end + was_in_range = false -- stops setting back to false below break end end