From ff4fad6e9f06a3211600a7bdab3435a78e43f465 Mon Sep 17 00:00:00 2001 From: m5df5a <33238764+m5df5a@users.noreply.github.com> Date: Wed, 15 Oct 2025 19:45:23 +0200 Subject: [PATCH] ported to 2.0 --- changelog.txt | 5 + control.lua | 8 +- info.json | 8 +- prototypes/entity/forcefield-builder.lua | 4 +- prototypes/gui/styles.lua | 11 +- prototypes/item/forcefield-builder.lua | 12 +- prototypes/recipe/emitter.lua | 16 +-- prototypes/recipe/forcefield-builder.lua | 24 ++-- prototypes/settings.lua | 16 +-- remote.lua | 14 +-- src/config-changes.lua | 138 +++++++++++------------ src/emitter.lua | 92 +++++++-------- src/forcefield.lua | 98 ++++++++-------- src/gui.lua | 96 ++++++++-------- src/settings.lua | 2 +- 15 files changed, 274 insertions(+), 270 deletions(-) diff --git a/changelog.txt b/changelog.txt index ba55d4d..8f8c271 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 2.4.0 +Date: 15. 10. 2025 + Features: + - Updated to 2.0.69 +--------------------------------------------------------------------------------------------------- Version: 2.3.8 Date: 14. 05. 2021 Bugfixes: diff --git a/control.lua b/control.lua index 84dd679..0443785 100644 --- a/control.lua +++ b/control.lua @@ -12,10 +12,10 @@ require 'remote' -- on load game for first time or when settings change function init() - if not global.forcefields then - global.forcefields = {} + if not storage.forcefields then + storage.forcefields = {} end - global.forcefields.version = ConfigChanges.currentVersion + storage.forcefields.version = ConfigChanges.currentVersion end script.on_init(function(_) @@ -35,7 +35,7 @@ end) -- on loading the map script.on_event(defines.events.on_tick, nil) script.on_load(function(event) - if global.forcefields and global.forcefields.ticking then + if storage.forcefields and storage.forcefields.ticking then script.on_event(defines.events.on_tick, function(_) Emitter:onTick() end) end end) diff --git a/info.json b/info.json index 4978639..0dcc40f 100644 --- a/info.json +++ b/info.json @@ -1,13 +1,13 @@ { "name": "ForceFields2", - "version": "2.3.8", - "factorio_version": "1.1", + "version": "2.4.0", + "factorio_version": "2.0", "title": "Force Fields", "author": "lovely_santa", "homepage": "https://mods.factorio.com/mod/ForceFields2", "description": "Adds multiple types of electric powered, self healing walls to keep the biters out.", "dependencies": [ - "base >= 1.1.1", - "LSlib >= 2020.11.26" + "base >= 2.0.69", + "LSlib >= 2025.10.15" ] } diff --git a/prototypes/entity/forcefield-builder.lua b/prototypes/entity/forcefield-builder.lua index 1fe3c62..052249c 100644 --- a/prototypes/entity/forcefield-builder.lua +++ b/prototypes/entity/forcefield-builder.lua @@ -20,7 +20,7 @@ function forcefieldWallEntity(color) table.insert(forcefieldWall.flags, "not-repairable") table.insert(forcefieldWall.flags, "not-blueprintable") table.insert(forcefieldWall.flags, "not-deconstructable") - table.insert(forcefieldWall.flags, "hidden") + forcefieldWall.hidden = true table.insert(forcefieldWall.flags, "not-upgradable") table.insert(forcefieldWall.flags, "no-copy-paste") @@ -98,7 +98,7 @@ function forcefieldGateEntity(color) table.insert(forcefieldGate.flags, "not-repairable") table.insert(forcefieldGate.flags, "not-blueprintable") table.insert(forcefieldGate.flags, "not-deconstructable") - table.insert(forcefieldGate.flags, "hidden") + forcefieldGate.hidden = true table.insert(forcefieldGate.flags, "not-upgradable") table.insert(forcefieldGate.flags, "no-copy-paste") diff --git a/prototypes/gui/styles.lua b/prototypes/gui/styles.lua index f0854e2..90b29dc 100644 --- a/prototypes/gui/styles.lua +++ b/prototypes/gui/styles.lua @@ -13,8 +13,15 @@ LSlib.styles.addFlowStyle{ name = guiSettings["guiTableRowHeaderFlowStyle"], parent = "flow", - margin = 0, - padding = 0, + top_margin = 0, + bottom_margin = 0, + left_margin = 0, + right_margin = 0, + + top_padding = 0, + bottom_padding = 0, + left_padding = 0, + right_padding = 0, horizontaly_strechable = true, } diff --git a/prototypes/item/forcefield-builder.lua b/prototypes/item/forcefield-builder.lua index 5438ada..4948663 100644 --- a/prototypes/item/forcefield-builder.lua +++ b/prototypes/item/forcefield-builder.lua @@ -21,11 +21,7 @@ function forcefieldWallItem(color) forcefieldWall.icon = nil forcefieldWall.icons = LSlib.item.getIcons("item", "stone-wall", nil, nil, colorTint) - if forcefieldWall.flags then - table.insert(forcefieldWall.flags, "hidden") - else - forcefieldWall.flags = { "hidden" } - end + forcefieldWall.hidden = true forcefieldWall.order = string.format("f[forcefields]-b[field]-%s[%s]-a[wall]", settings.order, color) forcefieldWall.subgroup = "forcefield" @@ -59,11 +55,7 @@ function forcefieldGateItem(color) forcefieldGate.icon = nil forcefieldGate.icons = LSlib.item.getIcons("item", "gate", nil, nil, colorTint) - if forcefieldGate.flags then - table.insert(forcefieldGate.flags, "hidden") - else - forcefieldGate.flags = { "hidden" } - end + forcefieldGate.hidden = true forcefieldGate.order = string.format("f[forcefields]-b[field]-%s[%s]-b[gate]", settings.order, color) forcefieldGate.subgroup = "forcefield" diff --git a/prototypes/recipe/emitter.lua b/prototypes/recipe/emitter.lua index 00928b7..b91303a 100644 --- a/prototypes/recipe/emitter.lua +++ b/prototypes/recipe/emitter.lua @@ -7,14 +7,14 @@ data:extend{ name = emitterSettings.emitterName, energy_required = 5, ingredients = { - {"steel-plate", 50}, - {"battery", 200}, - {"advanced-circuit", 20}, - {"small-lamp", 4}, + {type = "item", name = "steel-plate", amount = 50}, + {type = "item", name = "battery", amount = 200}, + {type = "item", name = "advanced-circuit", amount = 20}, + {type = "item", name = "small-lamp", amount = 4}, }, - result = emitterSettings.emitterName, - enabled = "false", - always_show_made_in = "true", - allow_decomposition = "false", + results = {{type = "item", name = emitterSettings.emitterName, amount = 1}}, + enabled = false, + always_show_made_in = true, + allow_decomposition = false, } } diff --git a/prototypes/recipe/forcefield-builder.lua b/prototypes/recipe/forcefield-builder.lua index c8a426f..1a4f54c 100644 --- a/prototypes/recipe/forcefield-builder.lua +++ b/prototypes/recipe/forcefield-builder.lua @@ -7,7 +7,7 @@ function forcefieldWallRecipe(color) data:extend{{ type = "recipe", name = string.format(settings.name, "wall", color), - enabled = "false", + enabled = false, localised_name = {"entity-name."..string.format(settings.name, "wall", color)}, localised_description = (not settings.manualPlaceable) and {"", @@ -25,15 +25,15 @@ function forcefieldWallRecipe(color) ingredients = {}, energy_required = math.floor(settings.properties.respawnRate * emitter.tickRate / 60 * 100)/100, - allow_decomposition = "false", - allow_as_intermediate = "false", - hide_from_stats = "true", + allow_decomposition = false, + allow_as_intermediate = false, + hide_from_stats = true, results = {}, - always_show_products = "false", + always_show_products = false, category = emitter["crafting-category"], - always_show_made_in = "true", + always_show_made_in = true, }} end @@ -49,7 +49,7 @@ function forcefieldGateRecipe(color) data:extend{{ type = "recipe", name = string.format(settings.name, "gate", color), - enabled = "false", + enabled = false, localised_name = {"entity-name."..string.format(settings.name, "gate", color)}, localised_description = (not settings.manualPlaceable) and {"", @@ -67,15 +67,15 @@ function forcefieldGateRecipe(color) ingredients = {}, energy_required = math.floor(settings.properties.respawnRate * emitter.tickRate / 60 * 100)/100, - allow_decomposition = "false", - allow_as_intermediate = "false", - hide_from_stats = "true", + allow_decomposition = false, + allow_as_intermediate = false, + hide_from_stats = true, results = {}, - always_show_made_in = "true", + always_show_made_in = true, category = emitter["crafting-category"], - always_show_made_in = "true", + always_show_made_in = true, }} end diff --git a/prototypes/settings.lua b/prototypes/settings.lua index 12138cd..d800e1d 100644 --- a/prototypes/settings.lua +++ b/prototypes/settings.lua @@ -82,19 +82,19 @@ prototypeSettings["blue"] = ["manualPlaceable"] = false, ["wallTechnology"] = prototyping and { ["additionalPrerequisites"] = { - "optics", + "lamp", "stone-wall", "military-2", - "advanced-electronics", + "advanced-circuit", "battery", }, ["additionalEffects"] = { {type = "unlock-recipe", recipe = prototypeSettings["emitter"].emitterName} }, ["technologyRecipe"] = { - ["count"] = math.floor( 0.5 + 2.5 * data.raw["technology"]["advanced-electronics"].unit.count), - ["ingredients"] = util.table.deepcopy(data.raw["technology"]["advanced-electronics"].unit.ingredients), - ["time"] = 2 * data.raw["technology"]["advanced-electronics"].unit.time, + ["count"] = math.floor( 0.5 + 2.5 * data.raw["technology"]["advanced-circuit"].unit.count), + ["ingredients"] = util.table.deepcopy(data.raw["technology"]["advanced-circuit"].unit.ingredients), + ["time"] = 2 * data.raw["technology"]["advanced-circuit"].unit.time, }, }, ["gateTechnology"] = prototyping and { @@ -105,9 +105,9 @@ prototypeSettings["blue"] = }, ["technologyRecipe"] = { - ["count"] = math.floor( 0.5 + 0.5 * (2.5 * data.raw["technology"]["advanced-electronics"].unit.count)), - ["ingredients"] = util.table.deepcopy(data.raw["technology"]["advanced-electronics"].unit.ingredients), - ["time"] = 2 * data.raw["technology"]["advanced-electronics"].unit.time, + ["count"] = math.floor( 0.5 + 0.5 * (2.5 * data.raw["technology"]["advanced-circuit"].unit.count)), + ["ingredients"] = util.table.deepcopy(data.raw["technology"]["advanced-circuit"].unit.ingredients), + ["time"] = 2 * data.raw["technology"]["advanced-circuit"].unit.time, }, }, } diff --git a/remote.lua b/remote.lua index 7ee9999..f007b56 100644 --- a/remote.lua +++ b/remote.lua @@ -17,13 +17,13 @@ remote.add_interface("forcefields", { -- reset removes all entities from the surface and re-init reset = function() - global.forcefields.emitters = nil - global.forcefields.fields = nil - global.forcefields.searchDamagedPos = nil - global.forcefields.activeEmitters = nil - global.forcefields.degradingFields = nil - global.forcefields.ticking = nil - global.forcefields.emitterConfigGUIs = nil + storage.forcefields.emitters = nil + storage.forcefields.fields = nil + storage.forcefields.searchDamagedPos = nil + storage.forcefields.activeEmitters = nil + storage.forcefields.degradingFields = nil + storage.forcefields.ticking = nil + storage.forcefields.emitterConfigGUIs = nil script.on_event(defines.events.on_tick, nil) for k,surface in pairs(game.surfaces) do diff --git a/src/config-changes.lua b/src/config-changes.lua index 21beaeb..d81ad15 100644 --- a/src/config-changes.lua +++ b/src/config-changes.lua @@ -10,24 +10,24 @@ ConfigChanges.currentVersion = 1.5 function ConfigChanges:onConfigurationChanged() log("Updating ForceFields to the new version, thanks for using this mod.") - if global.forcefields and global.forcefields.version then - if global.forcefields.version == 1.0 then + if storage.forcefields and storage.forcefields.version then + if storage.forcefields.version == 1.0 then log("Updating ForceFields from version 1.0 to version 1.1") self:updateToVersion_1_1() end - if global.forcefields.version == 1.1 then + if storage.forcefields.version == 1.1 then log("Updating ForceFields from version 1.1 to version 1.2") self:updateToVersion_1_2() end - if global.forcefields.version == 1.2 then + if storage.forcefields.version == 1.2 then log("Updating ForceFields from version 1.2 to version 1.3") self:updateToVersion_1_3() end - if global.forcefields.version == 1.3 then + if storage.forcefields.version == 1.3 then log("Updating ForceFields from version 1.3 to version 1.4") self:updateToVersion_1_4() end - if global.forcefields.version == 1.4 then + if storage.forcefields.version == 1.4 then log("Updating ForceFields from version 1.4 to version 1.5") self:updateToVersion_1_5() end @@ -39,21 +39,21 @@ end function ConfigChanges:updateToVersion_1_1() -- this is just for a test - global.forcefields.version = 1.1 + storage.forcefields.version = 1.1 end function ConfigChanges:updateToVersion_1_2() -- close all gui's - if global.forcefields.emitterConfigGuis ~= nil then + if storage.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 + if storage.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil then guiCenter["emitterConfig"].destroy() - global.forcefields.emitterConfigGuis["I" .. playerIndex] = nil - if LSlib.utils.table.isEmpty(global.forcefields.emitterConfigGuis) then - global.forcefields.emitterConfigGuis = nil + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil break end end @@ -76,34 +76,34 @@ function ConfigChanges:updateToVersion_1_2() ["red-forcefield"] = "red", ["red"] = "red", } - if global.forcefields.killedEmitters ~= nil then - local killedEmitters = global.forcefields.killedEmitters + if storage.forcefields.killedEmitters ~= nil then + local killedEmitters = storage.forcefields.killedEmitters for k,_ in pairs(killedEmitters) do killedEmitters[k]["config"] = util.table.deepcopy(emitterConfig) killedEmitters[k]["type"] = updateEmitterType[killedEmitters[k]["type"]] end - global.forcefields.killedEmitters = killedEmitters + storage.forcefields.killedEmitters = killedEmitters end - if global.forcefields.emitters ~= nil then - local emitters = global.forcefields.emitters + if storage.forcefields.emitters ~= nil then + local emitters = storage.forcefields.emitters for k,_ in pairs(emitters) do emitters[k]["config"] = util.table.deepcopy(emitterConfig) emitters[k]["type"] = updateEmitterType[emitters[k]["type"]] end - global.forcefields.emitters = emitters + storage.forcefields.emitters = emitters end - if global.forcefields.activeEmitters ~= nil then - local activeEmitters = global.forcefields.activeEmitters + if storage.forcefields.activeEmitters ~= nil then + local activeEmitters = storage.forcefields.activeEmitters for k,_ in pairs(activeEmitters) do activeEmitters[k]["config"] = util.table.deepcopy(emitterConfig) activeEmitters[k]["type"] = updateEmitterType[activeEmitters[k]["type"]] end - global.forcefields.activeEmitters = activeEmitters + storage.forcefields.activeEmitters = activeEmitters end -- change forcefield entity to emitter - if global.forcefields.degradingFields ~= nil then - local degradingFields = global.forcefields.degradingFields + if storage.forcefields.degradingFields ~= nil then + local degradingFields = storage.forcefields.degradingFields for k,v in pairs(degradingFields) do if v["entity"] ~= nil then if v["fieldEntity"] == nil then @@ -115,22 +115,22 @@ function ConfigChanges:updateToVersion_1_2() end -- now we are up to date to this version - global.forcefields.version = 1.2 + storage.forcefields.version = 1.2 end function ConfigChanges:updateToVersion_1_3() -- close all gui's - if global.forcefields.emitterConfigGuis ~= nil then + if storage.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 + if storage.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 + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil break end end @@ -138,45 +138,45 @@ function ConfigChanges:updateToVersion_1_3() end -- add setup to all emitter tables (emitterConfig) - if global.forcefields.killedEmitters ~= nil then - local killedEmitters = global.forcefields.killedEmitters + if storage.forcefields.killedEmitters ~= nil then + local killedEmitters = storage.forcefields.killedEmitters for k,_ in pairs(killedEmitters) do killedEmitters[k]["setup"] = "straight" end - global.forcefields.killedEmitters = killedEmitters + storage.forcefields.killedEmitters = killedEmitters end - if global.forcefields.emitters ~= nil then - local emitters = global.forcefields.emitters + if storage.forcefields.emitters ~= nil then + local emitters = storage.forcefields.emitters for k,_ in pairs(emitters) do emitters[k]["setup"] = "straight" end - global.forcefields.emitters = emitters + storage.forcefields.emitters = emitters end - if global.forcefields.activeEmitters ~= nil then - local activeEmitters = global.forcefields.activeEmitters + if storage.forcefields.activeEmitters ~= nil then + local activeEmitters = storage.forcefields.activeEmitters for k,_ in pairs(activeEmitters) do activeEmitters[k]["setup"] = "straight" end - global.forcefields.activeEmitters = activeEmitters + storage.forcefields.activeEmitters = activeEmitters end -- now we are up to date to this version - global.forcefields.version = 1.3 + storage.forcefields.version = 1.3 end function ConfigChanges:updateToVersion_1_4() -- close all gui's - if global.forcefields.emitterConfigGuis ~= nil then + if storage.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 + if storage.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 + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil break end end @@ -193,51 +193,51 @@ function ConfigChanges:updateToVersion_1_4() return "forcefield-gate-" end end - if global.forcefields.killedEmitters ~= nil then - local killedEmitters = global.forcefields.killedEmitters + if storage.forcefields.killedEmitters ~= nil then + local killedEmitters = storage.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 + storage.forcefields.killedEmitters = killedEmitters end - if global.forcefields.emitters ~= nil then - local emitters = global.forcefields.emitters + if storage.forcefields.emitters ~= nil then + local emitters = storage.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 + storage.forcefields.emitters = emitters end - if global.forcefields.activeEmitters ~= nil then - local activeEmitters = global.forcefields.activeEmitters + if storage.forcefields.activeEmitters ~= nil then + local activeEmitters = storage.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 + storage.forcefields.activeEmitters = activeEmitters end -- now we are up to date to this version - global.forcefields.version = 1.4 + storage.forcefields.version = 1.4 end function ConfigChanges:updateToVersion_1_5() -- close all gui's - if global.forcefields.emitterConfigGuis ~= nil then + if storage.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 + if storage.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 + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil break end end @@ -245,28 +245,28 @@ function ConfigChanges:updateToVersion_1_5() end -- add setup to fix errors in emitter table - if global.forcefields.killedEmitters ~= nil then - local killedEmitters = global.forcefields.killedEmitters + if storage.forcefields.killedEmitters ~= nil then + local killedEmitters = storage.forcefields.killedEmitters for k,_ in pairs(killedEmitters) do killedEmitters[k]["setup"] = killedEmitters[k]["setup"] or "straight" end - global.forcefields.killedEmitters = killedEmitters + storage.forcefields.killedEmitters = killedEmitters end - if global.forcefields.emitters ~= nil then - local emitters = global.forcefields.emitters + if storage.forcefields.emitters ~= nil then + local emitters = storage.forcefields.emitters for k,_ in pairs(emitters) do emitters[k]["setup"] = emitters[k]["setup"] or "straight" end - global.forcefields.emitters = emitters + storage.forcefields.emitters = emitters end - if global.forcefields.activeEmitters ~= nil then - local activeEmitters = global.forcefields.activeEmitters + if storage.forcefields.activeEmitters ~= nil then + local activeEmitters = storage.forcefields.activeEmitters for k,_ in pairs(activeEmitters) do activeEmitters[k]["setup"] = activeEmitters[k]["setup"] or "straight" end - global.forcefields.activeEmitters = activeEmitters + storage.forcefields.activeEmitters = activeEmitters end -- now we are up to date to this version - global.forcefields.version = 1.5 + storage.forcefields.version = 1.5 end diff --git a/src/emitter.lua b/src/emitter.lua index 375720c..ecf3cc0 100644 --- a/src/emitter.lua +++ b/src/emitter.lua @@ -11,19 +11,19 @@ Emitter = {} function Emitter:onEmitterBuilt(createdEntity) local newEmitter = {} local surface = createdEntity.surface - if not global.forcefields then - global.forcefields = {} + if not storage.forcefields then + storage.forcefields = {} end - if global.forcefields.emitters == nil then - global.forcefields.emitters = {} - global.forcefields.emitterNEI = 1 -- NextEmitterIndex + if storage.forcefields.emitters == nil then + storage.forcefields.emitters = {} + storage.forcefields.emitterNEI = 1 -- NextEmitterIndex end local maxWidth = settings.emitterMaxWidth local widthOffset = (maxWidth + 1)/2 local defaultType = settings.defaultFieldSuffix -- emitter data - newEmitter["emitter-NEI"] = "I" .. global.forcefields.emitterNEI + newEmitter["emitter-NEI"] = "I" .. storage.forcefields.emitterNEI newEmitter["entity"] = createdEntity -- emitter settings newEmitter["type"] = settings.defaultFieldType @@ -46,8 +46,8 @@ function Emitter:onEmitterBuilt(createdEntity) newEmitter["damaged-fields"] = nil -- Simulates reviving killed emitters => it copies old settings - if global.forcefields.killedEmitters ~= nil then - for k,killedEmitter in pairs(global.forcefields.killedEmitters) do + if storage.forcefields.killedEmitters ~= nil then + for k,killedEmitter in pairs(storage.forcefields.killedEmitters) do if killedEmitter["surface"] == surface and killedEmitter["position"].x == createdEntity.position.x and killedEmitter["position"].y == createdEntity.position.y then newEmitter["disabled"] = killedEmitter["disabled"] newEmitter["type"] = killedEmitter["type"] @@ -62,8 +62,8 @@ function Emitter:onEmitterBuilt(createdEntity) end end - global.forcefields.emitters["I" .. global.forcefields.emitterNEI] = util.table.deepcopy(newEmitter) - global.forcefields.emitterNEI = global.forcefields.emitterNEI + 1 + storage.forcefields.emitters["I" .. storage.forcefields.emitterNEI] = util.table.deepcopy(newEmitter) + storage.forcefields.emitterNEI = storage.forcefields.emitterNEI + 1 self:setActive(newEmitter, true, true) end @@ -197,8 +197,8 @@ end function Emitter:findEmitter(emitter) - if global.forcefields.emitters ~= nil then - for k,v in pairs(global.forcefields.emitters) do + if storage.forcefields.emitters ~= nil then + for k,v in pairs(storage.forcefields.emitters) do if v["entity"] == emitter then return v end @@ -222,10 +222,10 @@ function Emitter:setActive(emitterTable, enableCheckBuildingFields, skipResetTim if not emitterTable["active"] then emitterTable["active"] = true - if global.forcefields.activeEmitters == nil then - global.forcefields.activeEmitters = {} + if storage.forcefields.activeEmitters == nil then + storage.forcefields.activeEmitters = {} end - table.insert(global.forcefields.activeEmitters, emitterTable) + table.insert(storage.forcefields.activeEmitters, emitterTable) self:activateTicker() end end @@ -233,8 +233,8 @@ end function Emitter:activateTicker() - if not global.forcefields.ticking then - global.forcefields.ticking = settings.tickRate + if not storage.forcefields.ticking then + storage.forcefields.ticking = settings.tickRate script.on_event(defines.events.on_tick, function(_) Emitter:onTick() end) end end @@ -242,11 +242,11 @@ end function Emitter:onTick() - if global.forcefields.ticking == 0 then - global.forcefields.ticking = settings.tickRate - 1 + if storage.forcefields.ticking == 0 then + storage.forcefields.ticking = settings.tickRate - 1 self:updateTick() else - global.forcefields.ticking = global.forcefields.ticking - 1 + storage.forcefields.ticking = storage.forcefields.ticking - 1 end end @@ -255,13 +255,13 @@ end function Emitter:updateTick() local shouldKeepTicking -- Active emitters tick - if global.forcefields.activeEmitters ~= nil then + if storage.forcefields.activeEmitters ~= nil then local shouldRemainActive local emitterTable shouldKeepTicking = true -- For each active emitter check if they have fields to repair or fields to build - for k,emitterTable in pairs(global.forcefields.activeEmitters) do + for k,emitterTable in pairs(storage.forcefields.activeEmitters) do if emitterTable["entity"].valid then -- By default let us not keep it active, if its needed we re-activate it shouldRemainActive = false @@ -309,9 +309,9 @@ function Emitter:updateTick() end -- Degrading force fields tick - happens when a emitter dies or is mined. - if global.forcefields.degradingFields ~= nil then + if storage.forcefields.degradingFields ~= nil then shouldKeepTicking = true - for k,v in pairs(global.forcefields.degradingFields) do + for k,v in pairs(storage.forcefields.degradingFields) do -- TODO change v[entity] in config change + add position and surface --if not v["fieldEntity"] and v["entity"] then -- v["fieldEntity"] = v["entity"] @@ -332,8 +332,8 @@ function Emitter:updateTick() end end - if global.forcefields.searchDamagedPos ~= nil then - local searchDamagedPos = global.forcefields.searchDamagedPos + if storage.forcefields.searchDamagedPos ~= nil then + local searchDamagedPos = storage.forcefields.searchDamagedPos shouldKeepTicking = true -- for each damages position for index,xs in pairs (searchDamagedPos) do @@ -358,11 +358,11 @@ function Emitter:updateTick() searchDamagedPos = nil end - global.forcefields.searchDamagedPos = searchDamagedPos + storage.forcefields.searchDamagedPos = searchDamagedPos end if not shouldKeepTicking then - global.forcefields.ticking = nil + storage.forcefields.ticking = nil script.on_event(defines.events.on_tick, nil) end end @@ -370,13 +370,13 @@ end function Emitter:removeEmitterID(emitterID) - if global.forcefields.emitters ~= nil then - if global.forcefields.emitters[emitterID] ~= nil then - Forcefield:degradeLinkedFields(global.forcefields.emitters[emitterID]) - global.forcefields.emitters[emitterID] = nil - if LSlib.utils.table.isEmpty(global.forcefields.emitters) then - global.forcefields.emitters = nil - global.forcefields.emitterNEI = nil + if storage.forcefields.emitters ~= nil then + if storage.forcefields.emitters[emitterID] ~= nil then + Forcefield:degradeLinkedFields(storage.forcefields.emitters[emitterID]) + storage.forcefields.emitters[emitterID] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitters) then + storage.forcefields.emitters = nil + storage.forcefields.emitterNEI = nil else return true end @@ -387,11 +387,11 @@ end function Emitter:removeActiveEmitterID(activeEmitterID) - -- Returns true if the global.forcefields.activeEmitters table isn't empty - if global.forcefields.activeEmitters ~= nil and global.forcefields.activeEmitters[activeEmitterID] ~= nil then - table.remove(global.forcefields.activeEmitters, activeEmitterID) - if #global.forcefields.activeEmitters == 0 then - global.forcefields.activeEmitters = nil + -- Returns true if the storage.forcefields.activeEmitters table isn't empty + if storage.forcefields.activeEmitters ~= nil and storage.forcefields.activeEmitters[activeEmitterID] ~= nil then + table.remove(storage.forcefields.activeEmitters, activeEmitterID) + if #storage.forcefields.activeEmitters == 0 then + storage.forcefields.activeEmitters = nil else return true end @@ -401,9 +401,9 @@ end function Emitter:removeKilledEmitter(killedEmittersIndex) - table.remove(global.forcefields.killedEmitters, killedEmittersIndex) - if #global.forcefields.killedEmitters == 0 then - global.forcefields.killedEmitters = nil + table.remove(storage.forcefields.killedEmitters, killedEmittersIndex) + if #storage.forcefields.killedEmitters == 0 then + storage.forcefields.killedEmitters = nil end end @@ -411,8 +411,8 @@ end function Emitter:storeKilledEmitter(emitterTable) local newKilledEmitter = {} - if global.forcefields.killedEmitters == nil then - global.forcefields.killedEmitters = {} + if storage.forcefields.killedEmitters == nil then + storage.forcefields.killedEmitters = {} end newKilledEmitter["disabled"] = emitterTable["disabled"] newKilledEmitter["surface"] = emitterTable["entity"].surface @@ -423,5 +423,5 @@ function Emitter:storeKilledEmitter(emitterTable) newKilledEmitter["type"] = emitterTable["type"] newKilledEmitter["config"] = emitterTable["config"] newKilledEmitter["direction"] = emitterTable["direction"] - table.insert(global.forcefields.killedEmitters, newKilledEmitter) + table.insert(storage.forcefields.killedEmitters, newKilledEmitter) end diff --git a/src/forcefield.lua b/src/forcefield.lua index 8d391f6..9c8632e 100644 --- a/src/forcefield.lua +++ b/src/forcefield.lua @@ -12,16 +12,16 @@ function Forcefield:onForcefieldDamaged(damagedEntity) pos.x = math.floor(pos.x) pos.y = math.floor(pos.y) - if global.forcefields.searchDamagedPos == nil then - global.forcefields.searchDamagedPos = {} + if storage.forcefields.searchDamagedPos == nil then + storage.forcefields.searchDamagedPos = {} end - if global.forcefields.searchDamagedPos[index] == nil then - global.forcefields.searchDamagedPos[index] = {} + if storage.forcefields.searchDamagedPos[index] == nil then + storage.forcefields.searchDamagedPos[index] = {} end - if global.forcefields.searchDamagedPos[index][pos.x] == nil then - global.forcefields.searchDamagedPos[index][pos.x] = {} + if storage.forcefields.searchDamagedPos[index][pos.x] == nil then + storage.forcefields.searchDamagedPos[index][pos.x] = {} end - global.forcefields.searchDamagedPos[index][pos.x][pos.y] = 1 + storage.forcefields.searchDamagedPos[index][pos.x][pos.y] = 1 Emitter:activateTicker() end @@ -32,11 +32,11 @@ function Forcefield:onForcefieldDied(field) local surface = field.surface local index = surface.index - if global.forcefields.fields ~= nil and global.forcefields.fields[index] ~= nil and global.forcefields.fields[index][pos.x] ~= nil and global.forcefields.fields[index][pos.x][pos.y] ~= nil then - local emitterID = global.forcefields.fields[index][pos.x][pos.y] + if storage.forcefields.fields ~= nil and storage.forcefields.fields[index] ~= nil and storage.forcefields.fields[index][pos.x] ~= nil and storage.forcefields.fields[index][pos.x][pos.y] ~= nil then + local emitterID = storage.forcefields.fields[index][pos.x][pos.y] self:removeForceFieldID(index, pos.x, pos.y) - if global.forcefields.emitters ~= nil and global.forcefields.emitters[emitterID] ~= nil then - Emitter:setActive(global.forcefields.emitters[emitterID], true) + if storage.forcefields.emitters ~= nil and storage.forcefields.emitters[emitterID] ~= nil then + Emitter:setActive(storage.forcefields.emitters[emitterID], true) end if settings.forcefieldTypes[field.name]["deathEntity"] ~= nil then surface.create_entity({name = settings.forcefieldTypes[field.name]["deathEntity"], position = pos, force = field.force}) @@ -57,11 +57,11 @@ function Forcefield:onForcefieldMined(field, playerIndex) end end - if global.forcefields.fields ~= nil then + if storage.forcefields.fields ~= nil then local pos = field.position local index = field.surface.index - if global.forcefields.fields[index] ~= nil and global.forcefields.fields[index][pos.x] ~= nil and global.forcefields.fields[index][pos.x][pos.y] ~= nil then - local emitterTable = global.forcefields.emitters[global.forcefields.fields[index][pos.x][pos.y]] + if storage.forcefields.fields[index] ~= nil and storage.forcefields.fields[index][pos.x] ~= nil and storage.forcefields.fields[index][pos.x][pos.y] ~= nil then + local emitterTable = storage.forcefields.emitters[storage.forcefields.fields[index][pos.x][pos.y]] if emitterTable then Emitter:setActive(emitterTable, true) end @@ -96,7 +96,7 @@ function Forcefield:scanAndBuildFields(emitterTable) end -- Check if table for that surface exist, if not, make it - local fields = global.forcefields.fields + local fields = storage.forcefields.fields if fields == nil then fields = {} end @@ -139,10 +139,10 @@ function Forcefield:scanAndBuildFields(emitterTable) else -- If we can't place the field local blockingField = self:findForcefieldsRadius(surface, pos, 0.4, true) if blockingField ~= nil then - if global.forcefields.degradingFields ~= nil then + if storage.forcefields.degradingFields ~= nil then -- Prevents the emitter from going into extended sleep from "can't build" due to degrading fields (happens most when switching field types) local fpos = blockingField[1].position - for _,field in pairs(global.forcefields.degradingFields) do + for _,field in pairs(storage.forcefields.degradingFields) do if field["fieldEntity"].valid and field["fieldEntity"].position.x == pos.x and field["fieldEntity"].position.y == pos.y then builtField = true break @@ -173,7 +173,7 @@ function Forcefield:scanAndBuildFields(emitterTable) fields = nil end end - global.forcefields.fields = fields + storage.forcefields.fields = fields -- check if the whole field is blocked if blockingFields == incTimes then @@ -285,8 +285,8 @@ end function Forcefield:handleDamagedFields(forceFields) - local emitters = global.forcefields.emitters - local fields = global.forcefields.fields + local emitters = storage.forcefields.emitters + local fields = storage.forcefields.fields local pos local surface local index @@ -330,7 +330,7 @@ function Forcefield:handleDamagedFields(forceFields) end end - global.forcefields.emitters = emitters + storage.forcefields.emitters = emitters end @@ -445,7 +445,7 @@ end function Forcefield:degradeLinkedFields(emitterTable) - if global.forcefields.fields ~= nil and emitterTable["entity"].valid then + if storage.forcefields.fields ~= nil and emitterTable["entity"].valid then local fields local surface = emitterTable["entity"].surface local pos1, xInc, yInc, incTimes = self:getFieldsArea(emitterTable) @@ -476,26 +476,26 @@ function Forcefield:degradeLinkedFields(emitterTable) --we need to degrade all found fields if fields then - if global.forcefields.degradingFields == nil then - global.forcefields.degradingFields = {} + if storage.forcefields.degradingFields == nil then + storage.forcefields.degradingFields = {} end local index = surface.index for k,field in pairs(fields) do pos = field.position -- make sure the field is controlled by this emitter, if not, we don't need to degrade it - if global.forcefields.fields[index] ~= nil and global.forcefields.fields[index][pos.x] ~= nil and global.forcefields.fields[index][pos.x][pos.y] == emitterTable["emitter-NEI"] then + if storage.forcefields.fields[index] ~= nil and storage.forcefields.fields[index][pos.x] ~= nil and storage.forcefields.fields[index][pos.x][pos.y] == emitterTable["emitter-NEI"] then -- adds the forcefield entity to the degrading list - table.insert(global.forcefields.degradingFields, {["fieldEntity"] = field, ["emitter-NEI"] = emitterTable["emitter-NEI"], ["position"] = field.position, ["surface"] = field.surface}) + table.insert(storage.forcefields.degradingFields, {["fieldEntity"] = field, ["emitter-NEI"] = emitterTable["emitter-NEI"], ["position"] = field.position, ["surface"] = field.surface}) self:removeForceField(field) - if global.forcefields.fields == nil then + if storage.forcefields.fields == nil then break end end end - if #global.forcefields.degradingFields == 0 then - global.forcefields.degradingFields = nil + if #storage.forcefields.degradingFields == 0 then + storage.forcefields.degradingFields = nil else Emitter:activateTicker() end @@ -506,21 +506,21 @@ end function Forcefield:removeDegradingFieldID(fieldID) - -- Returns true if the global.forcefields.degradingFields table isn't empty - if global.forcefields.degradingFields ~= nil then + -- Returns true if the storage.forcefields.degradingFields table isn't empty + if storage.forcefields.degradingFields ~= nil then local emitterTable - if global.forcefields.emitters then - local emitterIndex = global.forcefields.degradingFields[fieldID]["emitter-NEI"] - local emitterTable = global.forcefields.emitters[emitterIndex] + if storage.forcefields.emitters then + local emitterIndex = storage.forcefields.degradingFields[fieldID]["emitter-NEI"] + local emitterTable = storage.forcefields.emitters[emitterIndex] end if emitterTable ~= nil then - table.remove(global.forcefields.degradingFields, fieldID) + table.remove(storage.forcefields.degradingFields, fieldID) Emitter:setActive(emitterTable, true) else - local pos = global.forcefields.degradingFields[fieldID].position - local surface = global.forcefields.degradingFields[fieldID].surface - table.remove(global.forcefields.degradingFields, fieldID) + local pos = storage.forcefields.degradingFields[fieldID].position + local surface = storage.forcefields.degradingFields[fieldID].surface + table.remove(storage.forcefields.degradingFields, fieldID) -- check if this field could be part of any emitter if surface and surface.valid then @@ -534,8 +534,8 @@ function Forcefield:removeDegradingFieldID(fieldID) end end - if #global.forcefields.degradingFields == 0 then - global.forcefields.degradingFields = nil + if #storage.forcefields.degradingFields == 0 then + storage.forcefields.degradingFields = nil else return true end @@ -546,10 +546,10 @@ end function Forcefield:removeForceField(field) -- removes a forcefield from the active fields list (glovel.forcefields.fields) - if global.forcefields.fields ~= nil then + if storage.forcefields.fields ~= nil then local pos = field.position local index = field.surface.index - if global.forcefields.fields[index] ~= nil and global.forcefields.fields[index][pos.x] ~= nil and global.forcefields.fields[index][pos.x][pos.y] ~= nil then + if storage.forcefields.fields[index] ~= nil and storage.forcefields.fields[index][pos.x] ~= nil and storage.forcefields.fields[index][pos.x][pos.y] ~= nil then self:removeForceFieldID(index, pos.x, pos.y) end end @@ -559,14 +559,14 @@ end function Forcefield:removeForceFieldID(index, x, y) -- Does no checking, make sure its a valid table index - global.forcefields.fields[index][x][y] = nil - if LSlib.utils.table.isEmpty(global.forcefields.fields[index][x]) then - global.forcefields.fields[index][x] = nil - if LSlib.utils.table.isEmpty(global.forcefields.fields[index]) then - global.forcefields.fields[index] = nil + storage.forcefields.fields[index][x][y] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.fields[index][x]) then + storage.forcefields.fields[index][x] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.fields[index]) then + storage.forcefields.fields[index] = nil end - if LSlib.utils.table.isEmpty(global.forcefields.fields) then - global.forcefields.fields = nil + if LSlib.utils.table.isEmpty(storage.forcefields.fields) then + storage.forcefields.fields = nil end end end diff --git a/src/gui.lua b/src/gui.lua index c1234fc..3339910 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -51,10 +51,10 @@ end function Gui:onCloseGui(guiElement, playerIndex) if guiElement and guiElement.valid and guiElement.name == self.guiElementNames.guiFrame then - if global.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil then + if storage.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil then -- Check the upgrade items - if global.forcefields.emitterConfigGuis["I" .. playerIndex][1]["entity"].valid then - local emitterTable = global.forcefields.emitterConfigGuis["I" .. playerIndex][1] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][1]["entity"].valid then + local emitterTable = storage.forcefields.emitterConfigGuis["I" .. playerIndex][1] --local upgrades = guiElement[self.guiElementNames.configTable][self.guiElementNames.upgradesTable] local upgrades = LSlib.gui.getElement(playerIndex, self.guiElementPaths.upgradesTable) @@ -82,10 +82,10 @@ function Gui:onCloseGui(guiElement, playerIndex) end -- Delete the gui data now... - global.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil end - if LSlib.utils.table.isEmpty(global.forcefields.emitterConfigGuis) then - global.forcefields.emitterConfigGuis = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil end if game.players[playerIndex].gui.center[self.guiElementNames.configFrame] then game.players[playerIndex].gui.center[self.guiElementNames.configFrame].destroy() @@ -101,10 +101,10 @@ function Gui:showEmitterGui(emitterTable, playerIndex) local canOpenGui = true -- Check if someone else has this gui open at this moment - if global.forcefields.emitterConfigGuis ~= nil then + if storage.forcefields.emitterConfigGuis ~= nil then for index,player in pairs(game.players) do --if index ~= playerIndex then - if global.forcefields.emitterConfigGuis["I" .. index] ~= nil and global.forcefields.emitterConfigGuis["I" .. index][1] == emitterTable then + if storage.forcefields.emitterConfigGuis["I" .. index] ~= nil and storage.forcefields.emitterConfigGuis["I" .. index][1] == emitterTable then if index ~= playerIndex then game.players[playerIndex].print(player.name .. " (player " .. index .. ") has the GUI for this emitter open right now.") end @@ -174,11 +174,11 @@ function Gui:showEmitterGui(emitterTable, playerIndex) LSlib.gui.getElement(playerIndex, self.guiElementPaths.upgradesWidth).number = emitterTable["width-upgrades"] -- Save gui - if global.forcefields.emitterConfigGuis == nil then - global.forcefields.emitterConfigGuis = {} + if storage.forcefields.emitterConfigGuis == nil then + storage.forcefields.emitterConfigGuis = {} end - global.forcefields.emitterConfigGuis["I" .. playerIndex] = {} - global.forcefields.emitterConfigGuis["I" .. playerIndex][1] = emitterTable + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = {} + storage.forcefields.emitterConfigGuis["I" .. playerIndex][1] = emitterTable return createdGui else @@ -190,7 +190,7 @@ end function Gui:createForcefieldGui(playerIndex, fieldWidth) local player = game.players[playerIndex] - local emitterTable = global.forcefields.emitterConfigGuis["I" .. playerIndex][1] + local emitterTable = storage.forcefields.emitterConfigGuis["I" .. playerIndex][1] local guiCenter = player.gui.center if guiCenter and guiCenter[self.guiElementNames.guiFrame] then if not guiCenter[self.guiElementNames.configFrame] then @@ -280,7 +280,7 @@ function Gui:handleGuiDirectionButtons(event) local directions = LSlib.gui.getElement(playerIndex, self.guiElementPaths.directionTable) -- Save the newly selected direction - global.forcefields.emitterConfigGuis["I" .. playerIndex][2] = nameToDirection[event.element.name] + storage.forcefields.emitterConfigGuis["I" .. playerIndex][2] = nameToDirection[event.element.name] -- Set the buttons accordingly to pressed selection directions[self.guiElementNames.directionOptionN].style = settings.guiSelectButtonStyle @@ -322,7 +322,7 @@ function Gui:handleGuiFieldTypeButtons(event) if shouldSwitch then -- Save the newly selected direction - global.forcefields.emitterConfigGuis["I" .. playerIndex][3] = nameToFieldType[selectedButtonName] + storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] = nameToFieldType[selectedButtonName] -- Set the buttons accordingly to pressed selection fields[self.guiElementNames.fieldTypeOptionB].style = settings.guiSelectButtonStyle @@ -361,7 +361,7 @@ function Gui:handleGuiFieldSetupButtons(event) if shouldSwitch then -- Save the newly selected setup - global.forcefields.emitterConfigGuis["I" .. playerIndex][5] = nameToFieldSetup[selectedButtonName] + storage.forcefields.emitterConfigGuis["I" .. playerIndex][5] = nameToFieldSetup[selectedButtonName] -- Set the buttons accordingly to pressed selection setups[self.guiElementNames.fieldSetupOptionS].style = settings.guiSelectButtonStyle @@ -522,9 +522,9 @@ function Gui:handleGuiMenuButtons(event) if event.element.name == self.guiElementNames.buttonApplySettings then if self:verifyAndSetFromGui(playerIndex) then -- Close the gui in the data - global.forcefields.emitterConfigGuis["I" .. playerIndex] = nil - if LSlib.utils.table.isEmpty(global.forcefields.emitterConfigGuis) then - global.forcefields.emitterConfigGuis = nil + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil end -- Close the gui visualy if guiCenter[self.guiElementNames.configFrame] then @@ -559,10 +559,10 @@ function Gui:handleGuiConfigWallChange(event) local player = game.players[playerIndex] local force = player.force local fieldType - if global.forcefields.emitterConfigGuis["I" .. playerIndex][3] ~= nil then - fieldType = global.forcefields.emitterConfigGuis["I" .. playerIndex][3] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] ~= nil then + fieldType = storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] else - fieldType = global.forcefields.emitterConfigGuis["I" .. playerIndex][1]["type"] + fieldType = storage.forcefields.emitterConfigGuis["I" .. playerIndex][1]["type"] end if not force.technologies[settings.fieldSuffix..fieldType].researched then @@ -597,10 +597,10 @@ function Gui:handleGuiConfigWallRowChange(event) local player = game.players[playerIndex] local force = player.force local fieldType - if global.forcefields.emitterConfigGuis["I" .. playerIndex][3] ~= nil then - fieldType = global.forcefields.emitterConfigGuis["I" .. playerIndex][3] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] ~= nil then + fieldType = storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] else - fieldType = global.forcefields.emitterConfigGuis["I" .. playerIndex][1]["type"] + fieldType = storage.forcefields.emitterConfigGuis["I" .. playerIndex][1]["type"] end if not force.technologies[settings.fieldSuffix..fieldType].researched then @@ -641,12 +641,12 @@ function Gui:handleGuiConfigWallClose(event) local configTableData = LSlib.gui.getElement(playerIndex, self.guiElementPaths.configTableSlider)[self.guiElementNames.configTableData] local configTable -- Undo all the changes that has been done - if not global.forcefields.emitterConfigGuis["I" .. playerIndex][4] then + if not storage.forcefields.emitterConfigGuis["I" .. playerIndex][4] then -- No previous settings, still using the settings from the emitterTable - configTable = util.table.deepcopy(global.forcefields.emitterConfigGuis["I" .. playerIndex][1]["config"]) + configTable = util.table.deepcopy(storage.forcefields.emitterConfigGuis["I" .. playerIndex][1]["config"]) else -- There where settings when opened, lets use these - configTable = global.forcefields.emitterConfigGuis["I" .. playerIndex][4] + configTable = storage.forcefields.emitterConfigGuis["I" .. playerIndex][4] end -- First we need to save the data @@ -680,7 +680,7 @@ function Gui:handleGuiConfigWallClose(event) configTable[fieldIndex-fieldOffset] = settings.fieldEmptySuffix end end - global.forcefields.emitterConfigGuis["I" .. playerIndex][4] = configTable + storage.forcefields.emitterConfigGuis["I" .. playerIndex][4] = configTable end -- Now we need to change the guis back @@ -760,16 +760,16 @@ function Gui:verifyAndSetFromGui(playerIndex) --local emitterConfigTable = frame[self.guiElementNames.configTable] --local upgrades = emitterConfigTable[self.guiElementNames.upgradesTable] - if global.forcefields.emitterConfigGuis ~= nil - and global.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil - and global.forcefields.emitterConfigGuis["I" .. playerIndex][1]["entity"].valid then + if storage.forcefields.emitterConfigGuis ~= nil + and storage.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil + and storage.forcefields.emitterConfigGuis["I" .. playerIndex][1]["entity"].valid then -- Check if settings have changed - local emitterTable = global.forcefields.emitterConfigGuis["I" .. playerIndex][1] + local emitterTable = storage.forcefields.emitterConfigGuis["I" .. playerIndex][1] -- Direction of the forcefield - if global.forcefields.emitterConfigGuis["I" .. playerIndex][2] ~= nil then - newDirection = global.forcefields.emitterConfigGuis["I" .. playerIndex][2] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][2] ~= nil then + newDirection = storage.forcefields.emitterConfigGuis["I" .. playerIndex][2] elseif emitterTable["direction"] == nil then player.print("No wall direction selected.") settingsAreGood = false @@ -778,8 +778,8 @@ function Gui:verifyAndSetFromGui(playerIndex) end -- Type of forcefield - if global.forcefields.emitterConfigGuis["I" .. playerIndex][3] ~= nil then - newFieldType = global.forcefields.emitterConfigGuis["I" .. playerIndex][3] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] ~= nil then + newFieldType = storage.forcefields.emitterConfigGuis["I" .. playerIndex][3] elseif emitterTable["type"] == nil then player.print("No wall type selected.") settingsAreGood = false @@ -788,8 +788,8 @@ function Gui:verifyAndSetFromGui(playerIndex) end -- Setting of forcefield - if global.forcefields.emitterConfigGuis["I" .. playerIndex][5] ~= nil then - newFieldSetup = global.forcefields.emitterConfigGuis["I" .. playerIndex][5] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][5] ~= nil then + newFieldSetup = storage.forcefields.emitterConfigGuis["I" .. playerIndex][5] elseif emitterTable["setup"] == nil then player.print("No wall setup selected.") settingsAreGood = false @@ -854,8 +854,8 @@ function Gui:verifyAndSetFromGui(playerIndex) newFieldConfig[i-widthOffset] = settings.defaultFieldSuffix end else - if global.forcefields.emitterConfigGuis["I" .. playerIndex][4] ~= nil then - newFieldConfig = global.forcefields.emitterConfigGuis["I" .. playerIndex][4] + if storage.forcefields.emitterConfigGuis["I" .. playerIndex][4] ~= nil then + newFieldConfig = storage.forcefields.emitterConfigGuis["I" .. playerIndex][4] else newFieldConfig = util.table.deepcopy(emitterTable["config"]) end @@ -909,9 +909,9 @@ function Gui:removeAllUpgrades(playerIndex) local frame = game.players[playerIndex].gui.center[self.guiElementNames.guiFrame] if frame then -- This shouldn't ever be required but won't hurt to check - if global.forcefields.emitterConfigGuis ~= nil - and global.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil - and global.forcefields.emitterConfigGuis["I" .. playerIndex][1]["entity"].valid then + if storage.forcefields.emitterConfigGuis ~= nil + and storage.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil + and storage.forcefields.emitterConfigGuis["I" .. playerIndex][1]["entity"].valid then local upgrades = frame[self.guiElementNames.configTable][self.guiElementNames.upgradesTable] local count --local buttonName @@ -927,10 +927,10 @@ function Gui:removeAllUpgrades(playerIndex) end end else -- invalid emitter entity (for example when someone destroys the emitter while another person is viewing the gui) - if global.forcefields.emitterConfigGuis ~= nil and global.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil then - global.forcefields.emitterConfigGuis["I" .. playerIndex] = nil - if LSlib.utils.table.isEmpty(global.forcefields.emitterConfigGuis) then - global.forcefields.emitterConfigGuis = nil + if storage.forcefields.emitterConfigGuis ~= nil and storage.forcefields.emitterConfigGuis["I" .. playerIndex] ~= nil then + storage.forcefields.emitterConfigGuis["I" .. playerIndex] = nil + if LSlib.utils.table.isEmpty(storage.forcefields.emitterConfigGuis) then + storage.forcefields.emitterConfigGuis = nil end end -- close the gui diff --git a/src/settings.lua b/src/settings.lua index cfb34cf..adb55db 100644 --- a/src/settings.lua +++ b/src/settings.lua @@ -134,7 +134,7 @@ settings.forcefieldCircleData = createFieldCircleData() function settings:verifyRemoteSettings() local modName = string.sub(settings.modName, 3, -3) - if game.active_mods["warptorio2"] then + if script.active_mods["warptorio2"] then LSlib.utils.log.log("Verify remote settings for warptorio2") local interfaceName = "warptorio2"