Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LovelySanta committed Aug 31, 2019
1 parent bab315f commit 9a9398b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---------------------------------------------------------------------------------------------------
Version: 2.3.1
Date: 31. 8. 2019
Bugfixes:
- Fixed crash related to faulty emitters
- Fixed crash related to old data not migrating
---------------------------------------------------------------------------------------------------
Version: 2.3.0
Date: 30. 8. 2019
Features:
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": "ForceFields2",
"version": "2.3.0",
"version": "2.3.1",
"factorio_version": "0.17",
"title": "Force Fields",
"author": "lovely_santa",
Expand Down
67 changes: 66 additions & 1 deletion src/config-changes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "__LSlib__/LSlib"

ConfigChanges = {}

ConfigChanges.currentVersion = 1.3
ConfigChanges.currentVersion = 1.4



Expand All @@ -23,6 +23,10 @@ function ConfigChanges:onConfigurationChanged()
log("Updating ForceFields from version 1.2 to version 1.3")
self:updateToVersion_1_3()
end
if global.forcefields.version == 1.3 then
log("Updating ForceFields from version 1.3 to version 1.4")
self:updateToVersion_1_4()
end
end
log("ForceFields are updated! Have a nice gaming session!")
end
Expand Down Expand Up @@ -154,4 +158,65 @@ function ConfigChanges:updateToVersion_1_3()

-- now we are up to date to this version
global.forcefields.version = 1.3
end



function ConfigChanges:updateToVersion_1_4()
-- close all gui's
if global.forcefields.emitterConfigGuis ~= nil then
for playerIndex, player in pairs(game.players) do
local guiCenter = player.gui.center
if global.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil then
guiCenter["emitterConfig"].destroy()
if guiCenter["fieldConfig"] then guiCenter["fieldConfig"].destroy() end
global.forcefields.emitterConfigGuis["I" .. playerIndex] = nil
if LSlib.utils.table.isEmpty(global.forcefields.emitterConfigGuis) then
global.forcefields.emitterConfigGuis = nil
break
end
end
end
end

-- add setup to all emitter tables (emitterConfig)
local getConfigName = function(oldConfig)
if not oldConfig then
return "forcefield-wall-"
elseif oldConfig == "-forcefield" then
return "forcefield-wall-"
elseif config == "-forcefield-gate" then
return "forcefield-gate-"
end
end
if global.forcefields.killedEmitters ~= nil then
local killedEmitters = global.forcefields.killedEmitters
for k,emitterTable in pairs(killedEmitters) do
for index, emitterConfig in pairs(emitterTable["config"] or {}) do
killedEmitters[k]["config"][index] = getConfigName(killedEmitters[k]["config"][index])
end
end
global.forcefields.killedEmitters = killedEmitters
end
if global.forcefields.emitters ~= nil then
local emitters = global.forcefields.emitters
for k,emitterTable in pairs(emitters) do
for index, emitterConfig in pairs(emitterTable["config"] or {}) do
emitters[k]["config"][index] = getConfigName(emitters[k]["config"][index])
end
end
global.forcefields.emitters = emitters
end
if global.forcefields.activeEmitters ~= nil then
local activeEmitters = global.forcefields.activeEmitters
for k,emitterTable in pairs(activeEmitters) do
for index, emitterConfig in pairs(emitterTable["config"] or {}) do
activeEmitters[k]["config"][index] = getConfigName(activeEmitters[k]["config"][index])
end
end
global.forcefields.activeEmitters = activeEmitters
end

-- now we are up to date to this version
global.forcefields.version = 1.4
end
19 changes: 8 additions & 11 deletions src/emitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,10 @@ end

function Emitter:onEmitterMined(emitter, playerIndex)
local emitterTable = self:findEmitter(emitter)
local player
if not emitterTable then return end
local player = playerIndex and game.players[playerIndex] or nil

if emitterTable ~= nil then
self:removeEmitterID(emitterTable["emitter-NEI"])
end
if playerIndex then
player = game.players[playerIndex]
end
self:removeEmitterID(emitterTable["emitter-NEI"])

if emitterTable["distance-upgrades"] ~= 0 then
if player then
Expand All @@ -95,16 +91,17 @@ function Emitter:onEmitterMined(emitter, playerIndex)
dropOnGround(emitterTable["entity"].surface, emitterTable["entity"].position, {name = "processing-unit", count = emitterTable["width-upgrades"]}, true, emitterTable["entity"].force)
end
end

end



function Emitter:onEmitterDied(emitter)
local emitterTable = self:findEmitter(emitter)
if emitterTable ~= nil then
self:removeEmitterID(emitterTable["emitter-NEI"])
self:storeKilledEmitter(emitterTable)
end
if emitterTable == nil then return end

self:removeEmitterID(emitterTable["emitter-NEI"])
self:storeKilledEmitter(emitterTable)
end


Expand Down

0 comments on commit 9a9398b

Please sign in to comment.