Skip to content

Commit

Permalink
Update to 2.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwerOxotnik committed Mar 13, 2022
1 parent 7370881 commit 866ed55
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---------------------------------------------------------------------------------------------------
Version: 2.13.2
Date: 2022-03-13
Bugfixes:
- Improved stability with some gui events
- Fixed interaction with checkboxes
- Buttons create in existing saves where there wasn't the mod before
---------------------------------------------------------------------------------------------------
Version: 2.13.1
Date: 2022-03-13
Bugfixes:
Expand Down
36 changes: 24 additions & 12 deletions diplomacy/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,32 @@ local function on_player_created(event)
end

local STATE_GUIS = {
["diplomacy_table"] = function(event)
select_diplomacy.diplomacy_check_press(event)
end,
["d_show_players_state"] = function(event, player, element)
["diplomacy_table"] = select_diplomacy.diplomacy_check_press,
["d_show_players_state"] = function(element, player, event)
global.diplomacy.players[event.player_index].show_players_state = element.state
DIPLOMACY_FRAME.update(player)
end,
}
local function on_gui_checked_state_changed(event)
local f = STATE_GUIS[event.element.parent.name]
if f then f(event.element, game.get_player(event.player_index), event) end
-- Validation of data
local element = event.element
if not (element and element.valid) then return end
local parent = element.parent
if not (parent and parent.valid) then return end

local f = STATE_GUIS[parent.name]
if f then f(element, game.get_player(event.player_index), event) end
end

local function on_gui_selection_state_changed(event)
if event.element.name == "d_filter_of_diplomacy_stance" then
local player = game.get_player(event.player_index)
global.diplomacy.players[event.player_index].filter_of_diplomacy_stance = event.element.selected_index
-- Validation of data
local element = event.element
if not (element and element.valid) then return end

if element.name == "d_filter_of_diplomacy_stance" then
local player_index = event.player_index
global.diplomacy.players[player_index].filter_of_diplomacy_stance = element.selected_index
local player = game.get_player(player_index)
DIPLOMACY_FRAME.update(player)
end
end
Expand Down Expand Up @@ -427,9 +436,12 @@ local function update_global_data()
if not game then return end

local players_data = diplomacy.players
for player_index in pairs(game.players) do
if players_data[player_index] == nil then
players_data[player_index] = {}
for player_index, player in pairs(game.players) do
if player.valid then
create_button(player)
if players_data[player_index] == nil then
players_data[player_index] = {}
end
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions diplomacy/gui/frames/diplomacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ diplomacy_frame.fill = function(player)
end

diplomacy_frame.update = function(player)
if player and player.valid and player.connected then
diplomacy_frame.fill(player)
if player and player.valid then
if player.connected then
diplomacy_frame.fill(player)
end
else
for _, _player in pairs(game.connected_players) do
diplomacy_frame.fill(_player)
Expand Down
33 changes: 16 additions & 17 deletions diplomacy/gui/select_diplomacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ end

local select_diplomacy = {}

select_diplomacy.diplomacy_check_press = function(event)
local gui = event.element
if not gui.valid then return end

if not (gui.name:find("_enemy")
or gui.name:find("_neutral")
or gui.name:find("_ally")) then
select_diplomacy.diplomacy_check_press = function(gui)
local gui_name = gui.name
if not (gui_name:find("_enemy")
or gui_name:find("_neutral")
or gui_name:find("_ally")) then
return
end

Expand All @@ -100,22 +98,23 @@ select_diplomacy.diplomacy_check_press = function(event)
end

local index = 1
for k, child in pairs(gui.parent.children) do
if child.name == gui.name then
local children = gui.parent.children
for k, child in pairs(children) do
if child.name == gui_name then
index = k
break
end
end

if gui.name:find("_neutral") then
gui.parent.children[index+1].state = false
gui.parent.children[index-1].state = false
elseif gui.name:find("_ally") then
gui.parent.children[index-2].state = false
gui.parent.children[index-1].state = false
if gui_name:find("_neutral") then
children[index+1].state = false
children[index-1].state = false
elseif gui_name:find("_ally") then
children[index-2].state = false
children[index-1].state = false
else
gui.parent.children[index+1].state = false
gui.parent.children[index+2].state = false
children[index+1].state = false
children[index+2].state = false
end
end

Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "diplomacy",
"version": "2.13.1",
"version": "2.13.2",
"factorio_version": "1.1",
"title": "Diplomacy",
"author": "ZwerOxotnik",
Expand Down

0 comments on commit 866ed55

Please sign in to comment.