Skip to content

Commit

Permalink
Bugfixes for signs in MP - Ref: jpanther#71
Browse files Browse the repository at this point in the history
  • Loading branch information
jpanther committed May 28, 2018
1 parent 45e433f commit 030aa47
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
9 changes: 9 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---------------------------------------------------------------------------------------------------
Version: 0.8.9
Date: 28. 05. 2018
Added:
- Enabled support for multiple players to place signs concurrently in multiplayer games
- Added console command to allow admins to remove any orphaned signs that are unminable
Bugfixes:
- Fixed an issue where placing a sign could sometimes cause a desync in multiplayer games
- Fixed an issue where an orphaned indestructible sign could be left behind when a player leaves a multiplayer game
---------------------------------------------------------------------------------------------------
Version: 0.8.8
Date: 15. 05. 2018
Added:
Expand Down
56 changes: 46 additions & 10 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ local function init_global()
global.icons = nil
global.signs = global.signs or {}
global.sign_last_built = global.sign_last_built or {}
global.sign_gui = global.sign_gui or {}

if global.icons == nil then
local prototypes = {
Expand Down Expand Up @@ -196,10 +197,10 @@ local function create_sign_gui(player)
if player.gui.center["dect-gui-sign"] then
player.gui.center["dect-gui-sign"].destroy()
end
sign_gui = player.gui.center.add({type="frame", name="dect-gui-sign", caption={"dect-gui.sign-title"}, direction="vertical"})
local gui_scroll = sign_gui.add({type="scroll-pane", name="dect-gui-scroll", vertical_scroll_policy="auto", horizontal_scroll_policy="auto", style="dect-scroll"})
global.sign_gui[player.index] = player.gui.center.add({type="frame", name="dect-gui-sign", caption={"dect-gui.sign-title"}, direction="vertical"})
local gui_scroll = global.sign_gui[player.index].add({type="scroll-pane", name="dect-gui-scroll", vertical_scroll_policy="auto", horizontal_scroll_policy="auto", style="dect-scroll"})
local gui_table = gui_scroll.add({type="table", name="dect-icons-table", column_count=20, style="dect-icon-table"})
local gui_cancel = sign_gui.add({type="button", name="dect-gui-button-cancel", caption={"dect-gui.sign-cancel"}})
local gui_cancel = global.sign_gui[player.index].add({type="button", name="dect-gui-button-cancel", caption={"dect-gui.sign-cancel"}})
for _, icon in pairs(global.icons) do
local match = false
for _, child in pairs(gui_table.children_names) do
Expand All @@ -214,11 +215,11 @@ local function create_sign_gui(player)
end

-- Destroy the sign GUI
local function destroy_sign_gui()
if sign_gui ~= nil then
sign_gui.destroy()
local function destroy_sign_gui(player)
if global.sign_gui[player.index] ~= nil then
global.sign_gui[player.index].destroy()
end
sign_gui = nil
global.sign_gui[player.index] = nil
end

-- Place a sign on game surface
Expand All @@ -233,7 +234,7 @@ end
local function on_built_entity(event)
local player = game.players[event.player_index]
if event.created_entity.name == "dect-sign-wood" or event.created_entity.name == "dect-sign-steel" then
if sign_gui ~= nil then
if global.sign_gui[event.player_index] ~= nil then
player.insert({name=event.created_entity.name, count=1})
event.created_entity.destroy()
else
Expand Down Expand Up @@ -269,27 +270,62 @@ local function on_gui_click(event)
game.players[event.player_index].insert({name = global.sign_last_built[event.player_index].name, count = 1})
global.sign_last_built[event.player_index].destroy()
end
destroy_sign_gui()
destroy_sign_gui(game.players[event.player_index])
end
elseif event.element.parent.name == "dect-icons-table" then
for _, icon in pairs(global.icons) do
if event.element.name == "dect-icon-"..icon.name then
create_sign(game.players[event.player_index], "dect-icon-"..icon.name, global.sign_last_built[event.player_index].position, global.sign_last_built[event.player_index])
global.sign_last_built[event.player_index].destructible = true
global.sign_last_built[event.player_index].minable = true
destroy_sign_gui()
destroy_sign_gui(game.players[event.player_index])
break
end
end
end
end
end

-- Kill off any ophaned signs when a player leaves the game while still selecting an icon
local function on_player_state_changed(event)
local player = game.players[event.player_index]
if global.sign_gui[player.index] ~= nil then
destroy_sign_gui(player)
global.sign_last_built[player.index].destroy()
end
end

local function on_load(data)
-- Command to remove any unminable signs from the player's current surface
commands.add_command("dect-destroy-orphaned-signs", {"dect-cmd.destroy-orphaned-signs"}, function()
local surface = game.player.surface
local signs = surface.find_entities_filtered{name={"dect-sign-wood", "dect-sign-steel"}}
local match = false

for _, sign in pairs(signs) do
if sign.minable == false then
local pos = sign.position
match = true
sign.destroy()
notification({"dect-notify.cmd-removed-orphaned-sign", {"dect-notify.dectorio"}, pos})
end
end

if not match then
notification({"dect-notify.cmd-no-orphaned-signs", {"dect-notify.dectorio"}})
end
end)
end

-- Fire events!
script.on_load(on_load)
script.on_init(on_init)
script.on_configuration_changed(on_configuration_changed)
script.on_event(defines.events.on_built_entity, on_built_entity)
script.on_event(defines.events.on_pre_player_mined_item, on_mined_entity)
script.on_event(defines.events.on_robot_pre_mined, on_mined_entity)
script.on_event(defines.events.on_entity_died, on_mined_entity)
script.on_event(defines.events.on_gui_click, on_gui_click)
script.on_event(defines.events.on_pre_player_left_game, on_player_state_changed)
script.on_event(defines.events.on_pre_player_died, on_player_state_changed)
script.on_event(defines.events.on_player_joined_game, on_player_state_changed)
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dectorio",
"version": "0.8.8",
"version": "0.8.9",
"title": "Dectorio",
"author": "PantherX",
"contact": "",
Expand Down
5 changes: 5 additions & 0 deletions locale/en/dectorio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ dectorio-flooring-stack-size=The number of flooring items that can be stacked in
dectorio-landscaping-stack-size=The number of landscaping items that can be stacked in one inventory slot (default = 500)
dectorio-walls-stack-size=The number of walls that can be stacked in one inventory slot (default = 200)

[dect-cmd]
destroy-orphaned-signs=Removes any orphaned signs from the player's current surface.
[dect-gui]
sign-title=Select an icon
sign-cancel=Cancel
Expand All @@ -58,6 +61,8 @@ recommended-setting=[__1__] You can resolve this conflict by changing the '__2__
mod-portal=[__1__] Refer to the mod portal for further details.
supported-mod-added=[__1__] Added support for __2__ mod.
supported-mod-removed=[__1__] Removed support for __2__ mod.
cmd-removed-orphaned-sign=[__1__] Orphaned sign successfully removed at __2__.
cmd-no-orphaned-signs=[__1__] There were no orphaned signs to remove.
[dect-signal]
arrow-down=Down
Expand Down

0 comments on commit 030aa47

Please sign in to comment.