diff --git a/bobclasses/control.lua b/bobclasses/control.lua index f75909249..805e892fb 100644 --- a/bobclasses/control.lua +++ b/bobclasses/control.lua @@ -95,21 +95,21 @@ remote.add_interface("bobclasses", { add_starting_inventory = function(data) for i, item in pairs(data) do - table.insert(global.starting_inventory, item) + table.insert(storage.starting_inventory, item) end end, add_respawn_inventory = function(data) for i, item in pairs(data) do - table.insert(global.respawn_inventory, item) + table.insert(storage.respawn_inventory, item) end end, -- Added by Pi-C (2021-10-28) get_classes = function() wlog("Entered remote function get_classes!") - wlog("next(global.classes): " .. tostring(global.classes and next(global.classes) and true or false)) - return global.classes + wlog("next(storage.classes): " .. tostring(storage.classes and next(storage.classes) and true or false)) + return storage.classes end, -- Jetpack expects this function on other mods' remote interfaces to inform them @@ -118,7 +118,7 @@ remote.add_interface("bobclasses", { -- new_character = luaEntity, old_character = luaEntity} on_character_swapped = function(event) wlog("Entered remote function get_classes!") - wlog("next(global.classes): " .. tostring(global.classes and next(global.classes) and true or false)) + wlog("next(storage.classes): " .. tostring(storage.classes and next(storage.classes) and true or false)) local new, old = event.new_character, event.old_character local player = (new and new.valid and new.player or new.associated_player) or (old and old.valid and old.player or old.associated_player) @@ -134,11 +134,11 @@ function add_class(name, class) -- "class" must be a table so we can add class_name --~ if name and class then if name and type(class) == "table" then - -- "name" won't be available when global.classes[name] is passed on to a + -- "name" won't be available when storage.classes[name] is passed on to a -- function. That is a problem when remote functions from other mods are -- called with just the class data, so better store the name with the data! class.class_name = name - global.classes[name] = class + storage.classes[name] = class end end @@ -262,30 +262,30 @@ end function init() wlog("Entered function init()") - if not global.players then - global.players = {} + if not storage.players then + storage.players = {} end - if not global.names then - global.names = {} + if not storage.names then + storage.names = {} end - if not global.sprite then - global.sprite = {} + if not storage.sprite then + storage.sprite = {} end - if not global.classes then - global.classes = {} + if not storage.classes then + storage.classes = {} end - if not global.starting_inventory then - global.starting_inventory = {} + if not storage.starting_inventory then + storage.starting_inventory = {} end - if not global.respawn_inventory then - global.respawn_inventory = {} + if not storage.respawn_inventory then + storage.respawn_inventory = {} end - global.classes["ballanced"] = nil - global.classes["balanced"] = nil - global.classes["miner"] = nil - global.classes["fighter"] = nil - global.classes["builder"] = nil + storage.classes["ballanced"] = nil + storage.classes["balanced"] = nil + storage.classes["miner"] = nil + storage.classes["fighter"] = nil + storage.classes["builder"] = nil add_class("balanced", { entity_name = "character", @@ -521,12 +521,12 @@ function init() for i, player in pairs(game.players) do create_button(i) - if not global.players[i] then - global.players[i] = { respawn = false, first_character = true } + if not storage.players[i] then + storage.players[i] = { respawn = false, first_character = true } end -- reset class bonuses - for _, class in pairs(global.classes) do + for _, class in pairs(storage.classes) do if player.character and player.character.name == class.entity_name then for i, bonus in pairs(class.bonuses) do player.character[i] = bonus @@ -535,7 +535,7 @@ function init() end local characters = player.get_associated_characters() for _, character in pairs(characters) do - for _, class in pairs(global.classes) do + for _, class in pairs(storage.classes) do if character.name == class.entity_name then for i, bonus in pairs(class.bonuses) do character[i] = bonus @@ -567,7 +567,7 @@ end) script.on_event(defines.events.on_player_created, function(event) wlog("Entered event handler on_player_created(" .. serpent.line(event) .. ")") create_button(event.player_index) - global.players[event.player_index] = { respawn = false, first_character = true } + storage.players[event.player_index] = { respawn = false, first_character = true } class_select(event.player_index) end) @@ -575,11 +575,11 @@ script.on_event(defines.events.on_player_respawned, function(event) wlog("Entered event handler on_player_respawned(" .. serpent.line(event) .. ")") --player_index :: uint --player_port :: LuaEntity (optional): The player port used to respawn if one was used. - if not global.players[event.player_index] then - global.players[event.player_index] = {} + if not storage.players[event.player_index] then + storage.players[event.player_index] = {} end - global.players[event.player_index].respawn = true - global.players[event.player_index].first_character = false + storage.players[event.player_index].respawn = true + storage.players[event.player_index].first_character = false class_select(event.player_index) end) @@ -591,7 +591,7 @@ script.on_event(defines.events.on_built_entity, function(event) -- event.created_entity.associated_player = game.players[event.player_index] -- an alternate that should do the same thing as above. refresh_avatar_gui(event.player_index) - for i, class in pairs(global.classes) do + for i, class in pairs(storage.classes) do if event.created_entity.name == class.entity_name then for i, bonus in pairs(class.bonuses) do event.created_entity[i] = bonus @@ -631,8 +631,8 @@ script.on_event(defines.events.on_entity_died, function(event) -- event.entity.associated_player = nil --alternate method refresh_avatar_gui(player.index) end - global.names[event.entity.unit_number] = nil --character name cleanup - global.sprite[event.entity.unit_number] = nil --character icon cleanup + storage.names[event.entity.unit_number] = nil --character name cleanup + storage.sprite[event.entity.unit_number] = nil --character icon cleanup end --~ end) end, { { filter = "type", type = "character" } }) @@ -678,10 +678,10 @@ script.on_event(defines.events.on_gui_click, function(event) wlog("Calling switch_character for player " .. event.player_index .. "!") -- Must call switch_character AFTER delete_minimap_gui! --~ switch_character(event.player_index, character) - --~ if character.unit_number == global.players[event.player_index].minimap_unit then + --~ if character.unit_number == storage.players[event.player_index].minimap_unit then --~ delete_minimap_gui(event.player_index) --~ end - if character.unit_number == global.players[event.player_index].minimap_unit then + if character.unit_number == storage.players[event.player_index].minimap_unit then delete_minimap_gui(event.player_index) end switch_character(event.player_index, character) @@ -734,18 +734,18 @@ script.on_event(defines.events.on_gui_click, function(event) draw_class_gui(event.player_index) end if event.element.valid and event.element.name == "bob_avatar_rename" then - global.players[event.player_index].rename_mode = not global.players[event.player_index].rename_mode + storage.players[event.player_index].rename_mode = not storage.players[event.player_index].rename_mode refresh_avatar_gui(event.player_index) refresh_buttons_row(event.player_index) end wlog("Checking class buttons") - for i, class in pairs(global.classes) do + for i, class in pairs(storage.classes) do if event.element.valid and event.element.name == class.button.name then wlog("Must create character of class " .. class.button.name .. "!") create_character(event.player_index, class) - global.players[event.player_index].respawn = false - global.players[event.player_index].first_character = false + storage.players[event.player_index].respawn = false + storage.players[event.player_index].first_character = false close_class_gui(event.player_index) end end @@ -755,8 +755,8 @@ script.on_event(defines.events.on_gui_click, function(event) end if event.element.valid and event.element.name == "bob_class_gui_close" then close_class_gui(event.player_index) - global.players[event.player_index].respawn = false - global.players[event.player_index].first_character = false + storage.players[event.player_index].respawn = false + storage.players[event.player_index].first_character = false end end) @@ -766,13 +766,13 @@ script.on_event(defines.events.on_gui_text_changed, function(event) local characters = game.players[event.player_index].get_associated_characters() local i = tonumber(string.match(event.element.name, "%d+")) local character = characters[i] - global.names[character.unit_number] = event.element.text + storage.names[character.unit_number] = event.element.text end if event.element.valid and event.element.name == "bob_avatar_current_character_textfield" then local player = game.players[event.player_index] if player.character then - global.names[player.character.unit_number] = event.element.text + storage.names[player.character.unit_number] = event.element.text end end end) @@ -781,7 +781,7 @@ function try_to_reopen_class_select(event) wlog("Entered function try_to_reopen_class_select(" .. serpent.line(event) .. ")") local player = game.players[event.player_index] if - global.players[event.player_index].first_character + storage.players[event.player_index].first_character and player.controller_type == defines.controllers.character and player.character and player.character.valid @@ -836,7 +836,7 @@ function add_class_gui_classes(gui, player_index) gui.table.add({ type = "table", name = "t3", column_count = 5 }) gui.table.add({ type = "table", name = "t3_advanced", column_count = 5 }) gui.add({ type = "table", name = "other", column_count = 5 }) - for i, class in pairs(global.classes) do + for i, class in pairs(storage.classes) do local add_it = true if class.prerequisites then for i, technology in pairs(class.prerequisites) do @@ -899,7 +899,7 @@ function close_avatar_gui(player_index) local player = game.players[player_index] if player.gui.left.bob_avatar_gui then player.gui.left.bob_avatar_gui.destroy() - local globtable = global.players[player_index] + local globtable = storage.players[player_index] globtable.rename_mode = nil globtable.minimap_unit = nil @@ -914,7 +914,7 @@ end function draw_avatar_gui(player_index) wlog("Entered function draw_avatar_gui(" .. player_index .. ")") close_avatar_gui(player_index) - local globtable = global.players[player_index] + local globtable = storage.players[player_index] local player = game.players[player_index] local gui = player.gui.left.add({ type = "frame", name = "bob_avatar_gui", direction = "vertical" }) --, caption = {"gui.bob-avatar-gui"} @@ -960,22 +960,22 @@ end function draw_current_character_info(player_index) wlog("Entered function draw_current_character_info(" .. player_index .. ")") local player = game.players[player_index] - local gui = global.players[player_index].current_character + local gui = storage.players[player_index].current_character if gui then gui.clear() if player.character then local entity = player.character - if not global.sprite[entity.unit_number] then + if not storage.sprite[entity.unit_number] then reset_character_icon(entity) end gui.add({ type = "label", name = "current", caption = { "gui.bob-current-character" } }) gui.add({ type = "sprite-button", name = "bob_avatar_current_character", - sprite = global.sprite[entity.unit_number], + sprite = storage.sprite[entity.unit_number], style = "transparent_slot", }) - if global.players[player_index].rename_mode then + if storage.players[player_index].rename_mode then gui.add({ type = "sprite-button", name = "bob_avatar_current_character_seticon", @@ -984,8 +984,8 @@ function draw_current_character_info(player_index) tooltip = { "gui.bob-avatar-seticon" }, }) gui.add({ type = "textfield", name = "bob_avatar_current_character_textfield" }) - if global.names[entity.unit_number] then - gui["bob_avatar_current_character_textfield"].text = global.names[entity.unit_number] + if storage.names[entity.unit_number] then + gui["bob_avatar_current_character_textfield"].text = storage.names[entity.unit_number] end else gui.add({ @@ -993,8 +993,8 @@ function draw_current_character_info(player_index) name = "bob_avatar_current_character_name", caption = entity.prototype.localised_name, }) - if global.names[entity.unit_number] then - gui["bob_avatar_current_character_name"].caption = global.names[entity.unit_number] + if storage.names[entity.unit_number] then + gui["bob_avatar_current_character_name"].caption = storage.names[entity.unit_number] end end elseif player.controller_type ~= defines.controllers.character then @@ -1011,7 +1011,7 @@ end function draw_buttons_row(player_index) wlog("Entered function draw_buttons_row(" .. player_index .. ")") local player = game.players[player_index] - local gui = global.players[player_index].buttons_row + local gui = storage.players[player_index].buttons_row if gui then gui.clear() @@ -1023,7 +1023,7 @@ function draw_buttons_row(player_index) }) gui.add({ type = "empty-widget", name = "filler", style = "bob_draggable_footer" }) gui.filler.style.height = 28 - if global.players[player_index].rename_mode then + if storage.players[player_index].rename_mode then gui.bob_avatar_rename.style = "selected_mod_gui_button_28" end @@ -1064,11 +1064,11 @@ end function draw_characters_list(player_index) wlog("Entered function draw_characters_list(" .. player_index .. ")") - if not global.players[player_index] then -- If this doesn't exist, something went wrong. - global.players[player_index] = { respawn = false, rename_mode = false } --so we'll attempt to fix it + if not storage.players[player_index] then -- If this doesn't exist, something went wrong. + storage.players[player_index] = { respawn = false, rename_mode = false } --so we'll attempt to fix it end - local gui = global.players[player_index].characters_list + local gui = storage.players[player_index].characters_list local characters = game.players[player_index].get_associated_characters() if gui then gui.clear() @@ -1078,7 +1078,7 @@ function draw_characters_list(player_index) return end - if global.players[player_index].rename_mode then + if storage.players[player_index].rename_mode then gui.add({ type = "table", column_count = 6, @@ -1099,17 +1099,17 @@ function draw_characters_list(player_index) end for i, entity in pairs(characters) do gui.table.add({ type = "label", name = "bob_avatar_list_number_" .. i, caption = string.format("#%d ", i) }) - if not global.sprite[entity.unit_number] then + if not storage.sprite[entity.unit_number] then reset_character_icon(entity) end gui.table.add({ type = "sprite-button", name = "bob_avatar_list_character_" .. i, - sprite = global.sprite[entity.unit_number], + sprite = storage.sprite[entity.unit_number], style = "mod_gui_item_button", tooltip = { "gui.bob-avatar-switch" }, }) - if global.players[player_index].rename_mode then + if storage.players[player_index].rename_mode then gui.table.add({ type = "sprite-button", name = "bob_avatar_list_seticon_" .. i, @@ -1119,13 +1119,13 @@ function draw_characters_list(player_index) }) gui.table.add({ type = "textfield", name = "bob_avatar_list_textfield_" .. i }) - if global.names[entity.unit_number] then - gui.table["bob_avatar_list_textfield_" .. i].text = global.names[entity.unit_number] + if storage.names[entity.unit_number] then + gui.table["bob_avatar_list_textfield_" .. i].text = storage.names[entity.unit_number] end else gui.table.add({ type = "label", name = "bob_avatar_list_name_" .. i, caption = entity.prototype.localised_name }) - if global.names[entity.unit_number] then - gui.table["bob_avatar_list_name_" .. i].caption = global.names[entity.unit_number] + if storage.names[entity.unit_number] then + gui.table["bob_avatar_list_name_" .. i].caption = storage.names[entity.unit_number] end end gui.table.add({ @@ -1142,7 +1142,7 @@ function draw_characters_list(player_index) style = "mod_gui_button_28", tooltip = { "gui.bob-avatar-minimap" }, }) - if entity.unit_number == global.players[player_index].minimap_unit then + if entity.unit_number == storage.players[player_index].minimap_unit then gui.table["bob_avatar_list_minimap_" .. i].style = "selected_mod_gui_button_28" end end @@ -1163,11 +1163,11 @@ end function refresh_minimap_buttons(player_index) wlog("Entered function refresh_minimap_buttons(" .. player_index .. ")") local characters = game.players[player_index].get_associated_characters() - local gui = global.players[player_index].characters_list + local gui = storage.players[player_index].characters_list if gui and gui.table then for i, entity in pairs(characters) do if gui.table["bob_avatar_list_minimap_" .. i] then - if characters[i].unit_number == global.players[player_index].minimap_unit then + if characters[i].unit_number == storage.players[player_index].minimap_unit then gui.table["bob_avatar_list_minimap_" .. i].style = "selected_mod_gui_button_28" else gui.table["bob_avatar_list_minimap_" .. i].style = "mod_gui_button_28" @@ -1181,19 +1181,19 @@ function draw_minimap_gui(player_index, entity) wlog("Entered function draw_minimap_gui(" .. player_index .. ")") local player = game.players[player_index] - local gui = global.players[player_index].minimap_gui + local gui = storage.players[player_index].minimap_gui - if global.players[player_index].minimap_unit == entity.unit_number then + if storage.players[player_index].minimap_unit == entity.unit_number then delete_minimap_gui(player_index) else - if not gui and global.players[player_index].gui and global.players[player_index].gui.main_flow then - gui = global.players[player_index].gui.main_flow.add({ type = "flow", name = "minimap_flow" }) + if not gui and storage.players[player_index].gui and storage.players[player_index].gui.main_flow then + gui = storage.players[player_index].gui.main_flow.add({ type = "flow", name = "minimap_flow" }) gui.style.padding = 4 - global.players[player_index].minimap_gui = gui + storage.players[player_index].minimap_gui = gui end if gui then gui.clear() - global.players[player_index].minimap_unit = entity.unit_number + storage.players[player_index].minimap_unit = entity.unit_number gui.add({ type = "minimap", name = "bob_avatar_minimap", @@ -1209,11 +1209,11 @@ end function delete_minimap_gui(player_index) wlog("Entered function delete_minimap_gui(" .. player_index .. ")") - local gui = global.players[player_index].minimap_gui + local gui = storage.players[player_index].minimap_gui if gui then gui.destroy() - global.players[player_index].minimap_unit = nil - global.players[player_index].minimap_gui = nil + storage.players[player_index].minimap_unit = nil + storage.players[player_index].minimap_gui = nil refresh_minimap_buttons(player_index) end end @@ -1234,7 +1234,7 @@ function set_character_icon(player_index, entity) hand_item = player.cursor_ghost.name end if hand_item then - global.sprite[entity.unit_number] = "item/" .. hand_item + storage.sprite[entity.unit_number] = "item/" .. hand_item else reset_character_icon(entity) end @@ -1243,12 +1243,12 @@ end function reset_character_icon(entity) wlog("Entered function reset_character_icon(" .. entity.name .. ")") local sprite = "entity/" .. entity.name - for i, class in pairs(global.classes) do + for i, class in pairs(storage.classes) do if entity.name == class.entity_name then sprite = class.button.sprite end end - global.sprite[entity.unit_number] = sprite + storage.sprite[entity.unit_number] = sprite end function create_character(player_index, class) @@ -1354,12 +1354,12 @@ function create_character(player_index, class) player.character[i] = bonus end - if not global.players[player_index] then -- If this doesn't exist, something went wrong. - global.players[player_index] = { respawn = false, first_character = true } --so we'll attempt to fix it + if not storage.players[player_index] then -- If this doesn't exist, something went wrong. + storage.players[player_index] = { respawn = false, first_character = true } --so we'll attempt to fix it end - if global.players[player_index].first_character then - for i, item in pairs(global.starting_inventory) do + if storage.players[player_index].first_character then + for i, item in pairs(storage.starting_inventory) do player.insert(item) end if class.starting_inventory then @@ -1373,9 +1373,9 @@ function create_character(player_index, class) end end end - global.players[player_index].first_character = false - elseif global.players[player_index].respawn then - for i, item in pairs(global.respawn_inventory) do + storage.players[player_index].first_character = false + elseif storage.players[player_index].respawn then + for i, item in pairs(storage.respawn_inventory) do player.insert(item) end if class.respawn_inventory.replace then @@ -1389,7 +1389,7 @@ function create_character(player_index, class) end end end - global.players[player_index].respawn = false + storage.players[player_index].respawn = false end refresh_avatar_gui(player_index) end @@ -1477,8 +1477,8 @@ function switch_character(player_index, new_character) end end - global.players[player_index].respawn = false - global.players[player_index].first_character = false + storage.players[player_index].respawn = false + storage.players[player_index].first_character = false refresh_avatar_gui(player_index) end diff --git a/bobinserters/control.lua b/bobinserters/control.lua index dd1633006..8e822a201 100644 --- a/bobinserters/control.lua +++ b/bobinserters/control.lua @@ -334,60 +334,57 @@ bobmods.logistics.inserters.offset_positions = { } function bobmods.inserters.create_global_table_basic() - if not global then - global = {} + if not storage.bobmods then + storage.bobmods = {} end - if not global.bobmods then - global.bobmods = {} + if not storage.bobmods.inserters then + storage.bobmods.inserters = {} end - if not global.bobmods.inserters then - global.bobmods.inserters = {} - end - if not global.bobmods.inserters.blacklist then - global.bobmods.inserters.blacklist = {} + if not storage.bobmods.inserters.blacklist then + storage.bobmods.inserters.blacklist = {} end end function bobmods.inserters.create_global_table(player_index) bobmods.inserters.create_global_table_basic() - if not global.bobmods.inserters[player_index] then - global.bobmods.inserters[player_index] = {} + if not storage.bobmods.inserters[player_index] then + storage.bobmods.inserters[player_index] = {} end - if not global.bobmods.logistics then - global.bobmods.logistics = {} + if not storage.bobmods.logistics then + storage.bobmods.logistics = {} end - if not global.bobmods.logistics[player_index] then - global.bobmods.logistics[player_index] = {} + if not storage.bobmods.logistics[player_index] then + storage.bobmods.logistics[player_index] = {} end - if not global.bobmods.logistics[player_index].enabled then - global.bobmods.logistics[player_index].enabled = false + if not storage.bobmods.logistics[player_index].enabled then + storage.bobmods.logistics[player_index].enabled = false end - if not global.bobmods.logistics[player_index].long_in then - global.bobmods.logistics[player_index].long_in = false + if not storage.bobmods.logistics[player_index].long_in then + storage.bobmods.logistics[player_index].long_in = false end - if not global.bobmods.logistics[player_index].long_out then - global.bobmods.logistics[player_index].long_out = false + if not storage.bobmods.logistics[player_index].long_out then + storage.bobmods.logistics[player_index].long_out = false end - if not global.bobmods.logistics[player_index].near then - global.bobmods.logistics[player_index].near = false + if not storage.bobmods.logistics[player_index].near then + storage.bobmods.logistics[player_index].near = false end - if not global.bobmods.logistics[player_index].show then - global.bobmods.logistics[player_index].show = false + if not storage.bobmods.logistics[player_index].show then + storage.bobmods.logistics[player_index].show = false end - if not global.bobmods.logistics[player_index].enabled2 then - global.bobmods.logistics[player_index].enabled2 = false + if not storage.bobmods.logistics[player_index].enabled2 then + storage.bobmods.logistics[player_index].enabled2 = false end - if not global.bobmods.logistics[player_index].pickup then - global.bobmods.logistics[player_index].pickup = 18 + if not storage.bobmods.logistics[player_index].pickup then + storage.bobmods.logistics[player_index].pickup = 18 end - if not global.bobmods.logistics[player_index].drop then - global.bobmods.logistics[player_index].drop = 8 + if not storage.bobmods.logistics[player_index].drop then + storage.bobmods.logistics[player_index].drop = 8 end - if not global.bobmods.logistics[player_index].offset then - global.bobmods.logistics[player_index].offset = 2 + if not storage.bobmods.logistics[player_index].offset then + storage.bobmods.logistics[player_index].offset = 2 end end @@ -398,7 +395,7 @@ script.on_event("bob-inserter-pickup-rotate", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then bobmods.inserters.rotate_pickup(entity, player) end @@ -411,7 +408,7 @@ script.on_event("bob-inserter-drop-rotate", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then bobmods.inserters.rotate_drop(entity, player) end @@ -424,7 +421,7 @@ script.on_event("bob-inserter-pickup-range", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then bobmods.inserters.pickup_range(entity, player) end @@ -437,7 +434,7 @@ script.on_event("bob-inserter-drop-range", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then bobmods.inserters.drop_range(entity, player) end @@ -450,7 +447,7 @@ script.on_event("bob-inserter-long", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then bobmods.inserters.long_range(entity, player) end @@ -463,7 +460,7 @@ script.on_event("bob-inserter-near", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then bobmods.inserters.near_range(entity, player) end @@ -476,9 +473,9 @@ script.on_event("bob-inserter-open-gui", function(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.inserters.blacklist[entity.name] + and not storage.bobmods.inserters.blacklist[entity.name] then - global.bobmods.inserters[event.player_index].position = "center" + storage.bobmods.inserters[event.player_index].position = "center" bobmods.inserters.open_gui(entity, player) else bobmods.inserters.delete_gui(event.player_index) @@ -490,10 +487,10 @@ script.on_event(defines.events.on_gui_opened, function(event) if event.gui_type == defines.gui_type.entity and event.entity and event.entity.type == "inserter" then if event.entity.prototype.allow_custom_vectors - and not global.bobmods.inserters.blacklist[event.entity.name] + and not storage.bobmods.inserters.blacklist[event.entity.name] and settings.get_player_settings(player)["bobmods-inserters-gui-position"].value ~= "off" then - global.bobmods.inserters[event.player_index].position = "left" + storage.bobmods.inserters[event.player_index].position = "left" bobmods.inserters.open_gui(event.entity, player) else bobmods.inserters.delete_gui(event.player_index) @@ -504,7 +501,7 @@ end) script.on_event(defines.events.on_gui_closed, function(event) -- this is checking for what GUI was just told to close. as we want to delete only when closing my GUI, or when closing the inserters GUI IF not opening mine. if - global.bobmods.inserters[event.player_index].position == "center" + storage.bobmods.inserters[event.player_index].position == "center" and event.gui_type == defines.gui_type.custom and event.element and event.element.valid --the GUI actually exists. @@ -516,25 +513,25 @@ end) script.on_event(defines.events.on_gui_checked_state_changed, function(event) local player = game.players[event.player_index] - local entity = global.bobmods.inserters[event.player_index].entity + local entity = storage.bobmods.inserters[event.player_index].entity if event.element.valid then if event.element.name == "bob_logistics_inserter_enabled" then - global.bobmods.logistics[event.player_index].enabled = event.element.state + storage.bobmods.logistics[event.player_index].enabled = event.element.state if event.element.state then - global.bobmods.logistics[event.player_index].enabled2 = false + storage.bobmods.logistics[event.player_index].enabled2 = false end bobmods.logistics.create_gui(event.player_index) elseif event.element.name == "bob_logistics_inserter_long_in" then - global.bobmods.logistics[event.player_index].long_in = event.element.state + storage.bobmods.logistics[event.player_index].long_in = event.element.state elseif event.element.name == "bob_logistics_inserter_long_out" then - global.bobmods.logistics[event.player_index].long_out = event.element.state + storage.bobmods.logistics[event.player_index].long_out = event.element.state elseif event.element.name == "bob_logistics_inserter_near" then - global.bobmods.logistics[event.player_index].near = event.element.state + storage.bobmods.logistics[event.player_index].near = event.element.state elseif event.element.name == "bob_logistics_inserter_enabled2" then - global.bobmods.logistics[event.player_index].enabled2 = event.element.state + storage.bobmods.logistics[event.player_index].enabled2 = event.element.state if event.element.state then - global.bobmods.logistics[event.player_index].enabled = false + storage.bobmods.logistics[event.player_index].enabled = false end bobmods.logistics.create_gui(event.player_index) elseif string.sub(event.element.name, 1, 6) == "button" then @@ -542,13 +539,13 @@ script.on_event(defines.events.on_gui_checked_state_changed, function(event) if event.element.parent.name == "bob_logistics_pickup" then remote.call("bobinserters", "draw_button_position_check", { gui = event.element.parent, position = i }) - global.bobmods.logistics[event.player_index].pickup = i + storage.bobmods.logistics[event.player_index].pickup = i elseif event.element.parent.name == "bob_logistics_drop" then remote.call("bobinserters", "draw_button_position_check", { gui = event.element.parent, position = i }) - global.bobmods.logistics[event.player_index].drop = i + storage.bobmods.logistics[event.player_index].drop = i elseif event.element.parent.name == "bob_logistics_offset" then remote.call("bobinserters", "draw_button_offset_check", { gui = event.element.parent, position = i }) - global.bobmods.logistics[event.player_index].offset = i + storage.bobmods.logistics[event.player_index].offset = i elseif entity and entity.valid and player.can_reach_entity(entity) then if event.element.parent.name == "bob_inserter_gui_pickup" then bobmods.inserters.gui_pickup_click(entity, event.element) @@ -566,7 +563,7 @@ end) script.on_event(defines.events.on_gui_click, function(event) local player = game.players[event.player_index] - local entity = global.bobmods.inserters[event.player_index].entity + local entity = storage.bobmods.inserters[event.player_index].entity if event.element.valid then if entity and entity.valid and player.can_reach_entity(entity) then if event.element.name == "bob_inserter_gui_close" then @@ -578,10 +575,10 @@ script.on_event(defines.events.on_gui_click, function(event) end if event.element.valid and event.element.name == "bob_logistics_inserter_button" then - if global.bobmods.logistics[event.player_index].show then - global.bobmods.logistics[event.player_index].show = false + if storage.bobmods.logistics[event.player_index].show then + storage.bobmods.logistics[event.player_index].show = false else - global.bobmods.logistics[event.player_index].show = true + storage.bobmods.logistics[event.player_index].show = true end bobmods.logistics.show_gui_options(event.player_index) end @@ -589,9 +586,9 @@ end) script.on_event(defines.events.on_player_rotated_entity, function(event) local player = game.players[event.player_index] - local entity = global.bobmods.inserters[event.player_index].entity + local entity = storage.bobmods.inserters[event.player_index].entity if entity == event.entity and player.can_reach_entity(entity) then - if global.bobmods.inserters[player.index].gui and global.bobmods.inserters[player.index].gui.valid then + if storage.bobmods.inserters[player.index].gui and storage.bobmods.inserters[player.index].gui.valid then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -599,10 +596,10 @@ end) script.on_event(defines.events.on_tick, function(event) if game.tick % 20 == 0 then - if global and global.bobmods and global.bobmods.inserters then + if storage and storage.bobmods and storage.bobmods.inserters then for i, player in pairs(game.connected_players) do - if global.bobmods.inserters[player.index] then - local entity = global.bobmods.inserters[player.index].entity + if storage.bobmods.inserters[player.index] then + local entity = storage.bobmods.inserters[player.index].entity if entity and (not entity.valid or not player.can_reach_entity(entity)) then bobmods.inserters.delete_gui(player.index) end @@ -656,7 +653,7 @@ script.on_event(defines.events.on_research_finished, function(event) or event.research.name == bobmods.inserters.more2_technology then for i, player in pairs(event.research.force.players) do - local entity = global.bobmods.inserters[player.index].entity + local entity = storage.bobmods.inserters[player.index].entity if entity and entity.valid and player.can_reach_entity(entity) then bobmods.inserters.open_gui(entity, player) end @@ -680,7 +677,7 @@ script.on_event(defines.events.on_built_entity, function(event) and event.item.place_result.type == "inserter" and (entity.type == "inserter" or (entity.type == "entity-ghost" and entity.ghost_type == "inserter")) and event.item.place_result.name == entity_name --probably don't even need this line anymore. - and not global.bobmods.inserters.blacklist[entity_name] + and not storage.bobmods.inserters.blacklist[entity_name] then bobmods.logistics.set_positions(entity, event.player_index) end @@ -918,7 +915,7 @@ function calculate_new_drop_offset(drop_position, drop_offset, new_position) end function bobmods.logistics.set_positions(entity, player_index) - if global.bobmods.logistics[player_index].enabled then + if storage.bobmods.logistics[player_index].enabled then local force = game.players[player_index].force local direction = (entity.direction / 2) + 1 @@ -926,9 +923,9 @@ function bobmods.logistics.set_positions(entity, player_index) local more_unlocked = tech_unlocked(force, bobmods.inserters.more_technology) local near_unlocked = tech_unlocked(force, bobmods.inserters.near_technology) - local long_in = global.bobmods.logistics[player_index].long_in - local long_out = global.bobmods.logistics[player_index].long_out - local near = global.bobmods.logistics[player_index].near + local long_in = storage.bobmods.logistics[player_index].long_in + local long_out = storage.bobmods.logistics[player_index].long_out + local near = storage.bobmods.logistics[player_index].near local pickup_position = get_pickup_position(entity) local drop_position, drop_offset = get_split_drop_position(entity) @@ -967,13 +964,13 @@ function bobmods.logistics.set_positions(entity, player_index) set_both_positions(entity, pickup_position, full_drop_position) end - if global.bobmods.logistics[player_index].enabled2 and remote.interfaces.bobinserters then + if storage.bobmods.logistics[player_index].enabled2 and remote.interfaces.bobinserters then local pickup_position = - remote.call("bobinserters", "get_position", { position = global.bobmods.logistics[player_index].pickup }) + remote.call("bobinserters", "get_position", { position = storage.bobmods.logistics[player_index].pickup }) local drop_position = - remote.call("bobinserters", "get_position", { position = global.bobmods.logistics[player_index].drop }) + remote.call("bobinserters", "get_position", { position = storage.bobmods.logistics[player_index].drop }) local drop_offset = - remote.call("bobinserters", "get_offset", { position = global.bobmods.logistics[player_index].offset }) + remote.call("bobinserters", "get_offset", { position = storage.bobmods.logistics[player_index].offset }) local direction = (entity.direction / 2) if direction == 2 then -- 2 is up, because inserters are backwards. @@ -1081,7 +1078,7 @@ function bobmods.inserters.rotate_pickup(entity, player) local pickup_position = get_pickup_position(entity) pickup_position = bobmods.inserters.rotate_position(player.force, pickup_position) set_pickup_position(entity, pickup_position) - if entity == global.bobmods.inserters[player.index].entity then + if entity == storage.bobmods.inserters[player.index].entity then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -1091,7 +1088,7 @@ function bobmods.inserters.rotate_drop(entity, player) local new_position = bobmods.inserters.rotate_position(player.force, drop_position) local new_offset = calculate_new_drop_offset(drop_position, drop_offset, new_position) set_split_drop_position(entity, new_position, new_offset) - if entity == global.bobmods.inserters[player.index].entity then + if entity == storage.bobmods.inserters[player.index].entity then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -1122,7 +1119,7 @@ function bobmods.inserters.pickup_range(entity, player) pickup_position = bobmods.logistics.set_range(pickup_position, 2) end set_pickup_position(entity, pickup_position) - if entity == global.bobmods.inserters[player.index].entity then + if entity == storage.bobmods.inserters[player.index].entity then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -1156,7 +1153,7 @@ function bobmods.inserters.drop_range(entity, player) end set_split_drop_position(entity, drop_position, drop_offset) - if entity == global.bobmods.inserters[player.index].entity then + if entity == storage.bobmods.inserters[player.index].entity then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -1198,7 +1195,7 @@ function bobmods.inserters.long_range(entity, player) local full_drop_position = combine_drop_position(drop_position, drop_offset) set_both_positions(entity, pickup_position, full_drop_position) - if entity == global.bobmods.inserters[player.index].entity then + if entity == storage.bobmods.inserters[player.index].entity then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -1242,7 +1239,7 @@ function bobmods.inserters.near_range(entity, player) end set_split_drop_position(entity, drop_position, drop_offset) - if entity == global.bobmods.inserters[player.index].entity then + if entity == storage.bobmods.inserters[player.index].entity then bobmods.inserters.refresh_position_checkboxes(entity, player) end end @@ -1302,7 +1299,7 @@ function bobmods.logistics.show_gui_options(player_index) player.gui.left.bob_logistics_inserter_gui.destroy() end - if global.bobmods.logistics[player_index].show then + if storage.bobmods.logistics[player_index].show then bobmods.logistics.create_gui(player_index) end end @@ -1332,30 +1329,30 @@ function bobmods.logistics.create_gui(player_index) gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_enabled", - state = global.bobmods.logistics[player_index].enabled, + state = storage.bobmods.logistics[player_index].enabled, caption = { "gui.bob-logistics-enabled" }, }) end - if global.bobmods.logistics[player_index].enabled then + if storage.bobmods.logistics[player_index].enabled then if long_unlocked then if more_unlocked then gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_long_in", - state = global.bobmods.logistics[player_index].long_in, + state = storage.bobmods.logistics[player_index].long_in, caption = { "gui.bob-logistics-pickup" }, }) gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_long_out", - state = global.bobmods.logistics[player_index].long_out, + state = storage.bobmods.logistics[player_index].long_out, caption = { "gui.bob-logistics-drop" }, }) else gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_long_in", - state = global.bobmods.logistics[player_index].long_in, + state = storage.bobmods.logistics[player_index].long_in, caption = { "gui.bob-logistics-long" }, }) end @@ -1364,7 +1361,7 @@ function bobmods.logistics.create_gui(player_index) gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_near", - state = global.bobmods.logistics[player_index].near, + state = storage.bobmods.logistics[player_index].near, caption = { "gui.bob-logistics-near" }, }) end @@ -1374,24 +1371,24 @@ function bobmods.logistics.create_gui(player_index) gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_enabled2", - state = global.bobmods.logistics[player_index].enabled2, + state = storage.bobmods.logistics[player_index].enabled2, caption = { "gui.bob-logistics-enabled2" }, }) - if global.bobmods.logistics[player_index].enabled2 then + if storage.bobmods.logistics[player_index].enabled2 then remote.call("bobinserters", "draw_gui", { player_index = player_index, gui = gui, name = "bob_logistics", - pickup = global.bobmods.logistics[player_index].pickup, - drop = global.bobmods.logistics[player_index].drop, - offset = global.bobmods.logistics[player_index].offset, + pickup = storage.bobmods.logistics[player_index].pickup, + drop = storage.bobmods.logistics[player_index].drop, + offset = storage.bobmods.logistics[player_index].offset, }) end end end function bobmods.inserters.delete_gui(player_index) - local globtable = global.bobmods.inserters[player_index] + local globtable = storage.bobmods.inserters[player_index] if globtable then if globtable.gui and globtable.gui.valid then globtable.gui.destroy() @@ -1407,7 +1404,7 @@ end function bobmods.inserters.open_gui(entity, player) bobmods.inserters.delete_gui(player.index) - local globtable = global.bobmods.inserters[player.index] + local globtable = storage.bobmods.inserters[player.index] globtable.entity = entity local long_unlocked = tech_unlocked(player.force, bobmods.inserters.long_technology) @@ -1947,14 +1944,14 @@ function bobmods.inserters.refresh_position_checkboxes(entity, player) local pickup_position = get_pickup_position(entity) local drop_position, drop_offset = get_split_drop_position(entity) - if global.bobmods.inserters[player.index].pickup then - bobmods.inserters.draw_button_position_check(global.bobmods.inserters[player.index].pickup, pickup_position) + if storage.bobmods.inserters[player.index].pickup then + bobmods.inserters.draw_button_position_check(storage.bobmods.inserters[player.index].pickup, pickup_position) end - if global.bobmods.inserters[player.index].drop then - bobmods.inserters.draw_button_position_check(global.bobmods.inserters[player.index].drop, drop_position) + if storage.bobmods.inserters[player.index].drop then + bobmods.inserters.draw_button_position_check(storage.bobmods.inserters[player.index].drop, drop_position) end - if global.bobmods.inserters[player.index].offset then - bobmods.inserters.draw_button_offset_check(global.bobmods.inserters[player.index].offset, drop_offset) + if storage.bobmods.inserters[player.index].offset then + bobmods.inserters.draw_button_offset_check(storage.bobmods.inserters[player.index].offset, drop_offset) end end @@ -2031,7 +2028,7 @@ EG: remote.call("bobinserters", "blacklist_inserter", "burner-inserter") will bl -- blacklist_inserter = function(data) bobmods.inserters.create_global_table_basic() - global.bobmods.inserters.blacklist[data] = true + storage.bobmods.inserters.blacklist[data] = true end, --[[ Pass this function a table of names of inserters, and they will be ignored. @@ -2041,7 +2038,7 @@ EG: remote.call("bobinserters", "blacklist_inserters", {"burner-inserter"}) will blacklist_inserters = function(data) bobmods.inserters.create_global_table_basic() for i, inserter in pairs(data) do - global.bobmods.inserters.blacklist[inserter] = true + storage.bobmods.inserters.blacklist[inserter] = true end end, --[[ diff --git a/boblogistics/control.lua b/boblogistics/control.lua index 39e73e160..5659eca8e 100644 --- a/boblogistics/control.lua +++ b/boblogistics/control.lua @@ -147,34 +147,31 @@ function bobmods.logistics.set_range(position_in, range) end function bobmods.logistics.create_global_table_basic() - if not global then - global = {} + if not storage.bobmods then + storage.bobmods = {} end - if not global.bobmods then - global.bobmods = {} + if not storage.bobmods.logistics then + storage.bobmods.logistics = {} end - if not global.bobmods.logistics then - global.bobmods.logistics = {} - end - if not global.bobmods.logistics.blacklist then - global.bobmods.logistics.blacklist = {} + if not storage.bobmods.logistics.blacklist then + storage.bobmods.logistics.blacklist = {} end end function bobmods.logistics.create_global_table(player_index) bobmods.logistics.create_global_table_basic() - if not global.bobmods.logistics[player_index] then - global.bobmods.logistics[player_index] = {} + if not storage.bobmods.logistics[player_index] then + storage.bobmods.logistics[player_index] = {} end - if not global.bobmods.logistics[player_index].enabled then - global.bobmods.logistics[player_index].enabled = false + if not storage.bobmods.logistics[player_index].enabled then + storage.bobmods.logistics[player_index].enabled = false end - if not global.bobmods.logistics[player_index].long_in then - global.bobmods.logistics[player_index].long_in = false + if not storage.bobmods.logistics[player_index].long_in then + storage.bobmods.logistics[player_index].long_in = false end - if not global.bobmods.logistics[player_index].show then - global.bobmods.logistics[player_index].show = false + if not storage.bobmods.logistics[player_index].show then + storage.bobmods.logistics[player_index].show = false end end @@ -239,16 +236,16 @@ function bobmods.logistics.create_gui(player_index) gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_enabled", - state = global.bobmods.logistics[player_index].enabled, + state = storage.bobmods.logistics[player_index].enabled, caption = { "gui.bob-logistics-enabled" }, }) end - if global.bobmods.logistics[player_index].enabled then + if storage.bobmods.logistics[player_index].enabled then if long_unlocked then gui.table.add({ type = "checkbox", name = "bob_logistics_inserter_long_in", - state = global.bobmods.logistics[player_index].long_in, + state = storage.bobmods.logistics[player_index].long_in, caption = { "gui.bob-logistics-long" }, }) end @@ -258,7 +255,7 @@ end function bobmods.logistics.show_gui_options(player_index) local player = game.players[player_index] - if not global.bobmods then + if not storage.bobmods then bobmods.logistics.player_setup(player_index) end @@ -266,20 +263,20 @@ function bobmods.logistics.show_gui_options(player_index) player.gui.left.bob_logistics_inserter_gui.destroy() end - if global.bobmods.logistics[player_index].show then + if storage.bobmods.logistics[player_index].show then bobmods.logistics.create_gui(player_index) end end function bobmods.logistics.set_positions(entity, player_index) - local enabled = global.bobmods.logistics[player_index].enabled + local enabled = storage.bobmods.logistics[player_index].enabled if enabled then local force = game.players[player_index].force local direction = (entity.direction / 2) + 1 local long_unlocked = tech_unlocked(force, bobmods.logistics.long_technology) - local long_in = global.bobmods.logistics[player_index].long_in + local long_in = storage.bobmods.logistics[player_index].long_in local pickup_position = { x = entity.pickup_position.x - entity.position.x, y = entity.pickup_position.y - entity.position.y } @@ -364,7 +361,7 @@ function bobmods.logistics.check_range(event) entity and entity.type == "inserter" and player.can_reach_entity(entity) - and not global.bobmods.logistics.blacklist[entity.name] + and not storage.bobmods.logistics.blacklist[entity.name] then bobmods.logistics.long_range(entity, player) end @@ -410,10 +407,10 @@ end) script.on_event(defines.events.on_gui_checked_state_changed, function(event) if not game.active_mods["bobinserters"] then if event.element.name == "bob_logistics_inserter_enabled" then - global.bobmods.logistics[event.player_index].enabled = event.element.state + storage.bobmods.logistics[event.player_index].enabled = event.element.state bobmods.logistics.create_gui(event.player_index) elseif event.element.name == "bob_logistics_inserter_long_in" then - global.bobmods.logistics[event.player_index].long_in = event.element.state + storage.bobmods.logistics[event.player_index].long_in = event.element.state end end end) @@ -421,10 +418,10 @@ end) script.on_event(defines.events.on_gui_click, function(event) if not game.active_mods["bobinserters"] then if event.element.valid and event.element.name == "bob_logistics_inserter_button" then - if global.bobmods.logistics[event.player_index].show then - global.bobmods.logistics[event.player_index].show = false + if storage.bobmods.logistics[event.player_index].show then + storage.bobmods.logistics[event.player_index].show = false else - global.bobmods.logistics[event.player_index].show = true + storage.bobmods.logistics[event.player_index].show = true end bobmods.logistics.show_gui_options(event.player_index) end @@ -456,7 +453,7 @@ script.on_event(defines.events.on_built_entity, function(event) and event.item.place_result.type == "inserter" and (entity.type == "inserter" or (entity.type == "entity-ghost" and entity.ghost_type == "inserter")) and event.item.place_result.name == entity_name --probably don't even need this line anymore. - and not global.bobmods.logistics.blacklist[entity_name] + and not storage.bobmods.logistics.blacklist[entity_name] then bobmods.logistics.set_positions(entity, event.player_index) end @@ -503,7 +500,7 @@ EG: remote.call("boblogistics", "blacklist_inserter", "burner-inserter") will bl -- blacklist_inserter = function(data) bobmods.logistics.create_global_table_basic() - global.bobmods.logistics.blacklist[data] = true + storage.bobmods.logistics.blacklist[data] = true end, --[[ Pass this function a table of names of inserters, and they will be ignored. @@ -513,7 +510,7 @@ EG: remote.call("boblogistics", "blacklist_inserters", {"burner-inserter"}) will blacklist_inserters = function(data) bobmods.logistics.create_global_table_basic() for i, inserter in pairs(data) do - global.bobmods.logistics.blacklist[inserter] = true + storage.bobmods.logistics.blacklist[inserter] = true end end, --[[