From 8a5d65f6c4882aa1c4a3457198bc2199ecd5b10b Mon Sep 17 00:00:00 2001 From: limelou <119715684+limelou@users.noreply.github.com> Date: Mon, 25 Aug 2025 22:32:41 -0700 Subject: [PATCH 1/2] implement the thing --- changelog.txt | 1 + scripts/biofluid/biofluid-gui.lua | 239 ++++++++++++++++++++++-------- scripts/biofluid/biofluid.lua | 162 +++++++++++--------- 3 files changed, 263 insertions(+), 139 deletions(-) diff --git a/changelog.txt b/changelog.txt index 218cd9ccc..b647ca762 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ Date: ? - When selecting view on map with an outpost selected, the map view now centers on the outpost rather than the caravan. Resolves https://github.com/pyanodon/pybugreports/issues/1170 - Reduce actual vatbrain radius by one tile match visible vatbrain radius. See https://github.com/pyanodon/pybugreports/issues/1062 - Fix actual vatbrain radius being offset by one tile to the east and south. See https://github.com/pyanodon/pybugreports/issues/1062 + - Biofluid networks now support provider priority - Caravans: when selecting view on map with an outpost selected, the map view now centers on the outpost rather than the caravan. Resolves https://github.com/pyanodon/pybugreports/issues/1170 - Caravans: fixed that ESC/E wouldn't close a caravan menu when opened from a caravan outpost. - Caravans: fixed scroll pane overlapping buttons in outpost's caravan view diff --git a/scripts/biofluid/biofluid-gui.lua b/scripts/biofluid/biofluid-gui.lua index 2d8062238..c02d05a02 100644 --- a/scripts/biofluid/biofluid-gui.lua +++ b/scripts/biofluid/biofluid-gui.lua @@ -9,7 +9,7 @@ py.on_event(defines.events.on_gui_opened, function(event) elseif connection_type == Biofluid.REQUESTER then Biofluid.build_requester_gui(entity, player) elseif connection_type == Biofluid.PROVIDER then - player.opened = nil + Biofluid.build_provider_gui(entity, player) end end) @@ -32,7 +32,7 @@ function Biofluid.update_bioport_gui(player, gui) local status = Biofluid.why_isnt_my_bioport_working(bioport_data) local img = Biofluid.failure_reasons[status] local content_flow = gui.content_frame.content_flow - content_flow.status_flow.status_text.caption = {status} + content_flow.status_flow.status_text.caption = { status } content_flow.status_flow.status_sprite.sprite = img local fuel_flow = content_flow.fuel_flow @@ -101,7 +101,7 @@ end function Biofluid.build_bioport_gui(entity, player) if player.gui.relative.bioport_gui then player.gui.relative.bioport_gui.destroy() end local main_frame = player.gui.relative.add { - type = "frame", name = "bioport_gui", caption = entity.prototype.localised_name, direction = "vertical", tags = {unit_number = entity.unit_number}, + type = "frame", name = "bioport_gui", caption = entity.prototype.localised_name, direction = "vertical", tags = { unit_number = entity.unit_number }, anchor = { gui = defines.relative_gui_type.assembling_machine_gui, position = defines.relative_gui_position.right @@ -111,46 +111,46 @@ function Biofluid.build_bioport_gui(entity, player) main_frame.style.vertically_stretchable = false main_frame.style.vertically_squashable = true - local content_frame = main_frame.add {type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding"} + local content_frame = main_frame.add { type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding" } content_frame.style.vertically_stretchable = true - local content_flow = content_frame.add {type = "flow", name = "content_flow", direction = "vertical"} + local content_flow = content_frame.add { type = "flow", name = "content_flow", direction = "vertical" } content_flow.style.vertical_spacing = 8 - content_flow.style.margin = {-4, 0, -4, 0} + content_flow.style.margin = { -4, 0, -4, 0 } content_flow.style.vertical_align = "center" - local status_flow = content_flow.add {type = "flow", name = "status_flow", direction = "horizontal"} + local status_flow = content_flow.add { type = "flow", name = "status_flow", direction = "horizontal" } status_flow.style.vertical_align = "center" - local status_sprite = status_flow.add {type = "sprite", name = "status_sprite"} + local status_sprite = status_flow.add { type = "sprite", name = "status_sprite" } status_sprite.resize_to_sprite = false - status_sprite.style.size = {16, 16} - status_flow.add {type = "label", name = "status_text"} - status_flow.add {type = "empty-widget", style = "py_empty_widget"} + status_sprite.style.size = { 16, 16 } + status_flow.add { type = "label", name = "status_text" } + status_flow.add { type = "empty-widget", style = "py_empty_widget" } - local camera_frame = content_flow.add {type = "frame", name = "camera_frame", style = "py_nice_frame"} - local camera = camera_frame.add {type = "camera", name = "camera", position = {entity.position.x, entity.position.y - 1}, style = "py_caravan_camera", surface_index = entity.surface.index} + local camera_frame = content_flow.add { type = "frame", name = "camera_frame", style = "py_nice_frame" } + local camera = camera_frame.add { type = "camera", name = "camera", position = { entity.position.x, entity.position.y - 1 }, style = "py_caravan_camera", surface_index = entity.surface.index } camera.visible = true camera.style.height = 155 - local fuel_flow = content_flow.add {type = "flow", name = "fuel_flow", direction = "horizontal"} + local fuel_flow = content_flow.add { type = "flow", name = "fuel_flow", direction = "horizontal" } fuel_flow.style.vertical_align = "center" local favorite_food_tooltip = py.generate_favorite_food_tooltip(Biofluid.favorite_foods, "biofluid-gui") for i = 1, Biofluid.fuel_size do - local fuel_slot = fuel_flow.add {type = "sprite-button", name = "py_biofluid_food_" .. i, style = "inventory_slot", tags = {unit_number = entity.unit_number, i = i}} + local fuel_slot = fuel_flow.add { type = "sprite-button", name = "py_biofluid_food_" .. i, style = "inventory_slot", tags = { unit_number = entity.unit_number, i = i } } fuel_slot.sprite = "slot_icon_fuel" fuel_slot.tooltip = favorite_food_tooltip end - local bar_flow = fuel_flow.add {type = "flow", name = "bar_flow", direction = "vertical"} - bar_flow.add {type = "progressbar", name = "fuel_bar", style = "burning_progressbar"}.style.horizontally_stretchable = true - bar_flow.add {type = "progressbar", name = "guano_bar", style = "bonus_progressbar"}.style.horizontally_stretchable = true - fuel_flow.add {type = "sprite-button", name = "py_guano_output", style = "inventory_slot", tags = {unit_number = entity.unit_number, slot_index = 1}, sprite = "item/guano"} + local bar_flow = fuel_flow.add { type = "flow", name = "bar_flow", direction = "vertical" } + bar_flow.add { type = "progressbar", name = "fuel_bar", style = "burning_progressbar" }.style.horizontally_stretchable = true + bar_flow.add { type = "progressbar", name = "guano_bar", style = "bonus_progressbar" }.style.horizontally_stretchable = true + fuel_flow.add { type = "sprite-button", name = "py_guano_output", style = "inventory_slot", tags = { unit_number = entity.unit_number, slot_index = 1 }, sprite = "item/guano" } - content_flow.add {type = "line"} + content_flow.add { type = "line" } - local module_flow = content_flow.add {type = "flow", name = "module_flow", direction = "horizontal"} + local module_flow = content_flow.add { type = "flow", name = "module_flow", direction = "horizontal" } module_flow.style.vertical_align = "center" local allowed_module_tooltip = py.generate_allowed_module_tooltip(Biofluid.biorobots) for i = 1, Biofluid.module_size do - local module_slot = module_flow.add {type = "sprite-button", name = "py_biofluid_module_" .. i, style = "inventory_slot", tags = {unit_number = entity.unit_number, i = i}} + local module_slot = module_flow.add { type = "sprite-button", name = "py_biofluid_module_" .. i, style = "inventory_slot", tags = { unit_number = entity.unit_number, i = i } } module_slot.sprite = "utility/empty_module_slot" module_slot.tooltip = allowed_module_tooltip end @@ -177,7 +177,7 @@ function Biofluid.update_requester_gui(player, gui) if not next(network.biofluid_bioports) then status = "entity-status.no-biofluid-network" end local img = Biofluid.failure_reasons[status] local content_flow = gui.content_frame.content_flow - content_flow.status_flow.status_text.caption = {status} + content_flow.status_flow.status_text.caption = { status } content_flow.status_flow.status_sprite.sprite = img local config_flow = content_flow.config_flow @@ -197,57 +197,57 @@ end function Biofluid.build_requester_gui(entity, player) if player.gui.screen.biofluid_requester_gui then player.gui.screen.biofluid_requester_gui.destroy() end local unit_number = entity.unit_number - local main_frame = player.gui.screen.add {type = "frame", name = "biofluid_requester_gui", caption = entity.prototype.localised_name, direction = "vertical"} + local main_frame = player.gui.screen.add { type = "frame", name = "biofluid_requester_gui", caption = entity.prototype.localised_name, direction = "vertical" } main_frame.auto_center = true player.opened = main_frame main_frame.style.width = 436 - local tags = {unit_number = unit_number} + local tags = { unit_number = unit_number } main_frame.tags = tags - local content_frame = main_frame.add {type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding"} + local content_frame = main_frame.add { type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding" } content_frame.style.vertically_stretchable = true - local content_flow = content_frame.add {type = "flow", name = "content_flow", direction = "vertical"} + local content_flow = content_frame.add { type = "flow", name = "content_flow", direction = "vertical" } content_flow.style.vertical_spacing = 8 - content_flow.style.margin = {-4, 0, -4, 0} + content_flow.style.margin = { -4, 0, -4, 0 } content_flow.style.vertical_align = "center" - local status_flow = content_flow.add {type = "flow", name = "status_flow", direction = "horizontal"} + local status_flow = content_flow.add { type = "flow", name = "status_flow", direction = "horizontal" } status_flow.style.vertical_align = "center" - local status_sprite = status_flow.add {type = "sprite", name = "status_sprite"} + local status_sprite = status_flow.add { type = "sprite", name = "status_sprite" } status_sprite.resize_to_sprite = false - status_sprite.style.size = {16, 16} - status_flow.add {type = "label", name = "status_text"} - status_flow.add {type = "empty-widget", style = "py_empty_widget"} + status_sprite.style.size = { 16, 16 } + status_flow.add { type = "label", name = "status_text" } + status_flow.add { type = "empty-widget", style = "py_empty_widget" } - local camera_frame = content_flow.add {type = "frame", name = "camera_frame", style = "py_nice_frame"} - local camera = camera_frame.add {type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index} + local camera_frame = content_flow.add { type = "frame", name = "camera_frame", style = "py_nice_frame" } + local camera = camera_frame.add { type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index } camera.visible = true camera.style.height = 155 camera.zoom = 2 - local label_flow = content_flow.add {type = "flow", direction = "horizontal"} - label_flow.add {type = "label", caption = {"gui-logistic.title-requests"}}.style.font = "default-semibold" - label_flow.add {type = "empty-widget", style = "py_empty_widget"} - label_flow.add {type = "label", caption = {"gui.priority"}}.style.font = "default-semibold" + local label_flow = content_flow.add { type = "flow", direction = "horizontal" } + label_flow.add { type = "label", caption = { "gui-logistic.title-requests" } }.style.font = "default-semibold" + label_flow.add { type = "empty-widget", style = "py_empty_widget" } + label_flow.add { type = "label", caption = { "gui.priority" } }.style.font = "default-semibold" - local config_flow = content_flow.add {type = "flow", direction = "horizontal", name = "config_flow"} + local config_flow = content_flow.add { type = "flow", direction = "horizontal", name = "config_flow" } config_flow.style.vertical_align = "center" - config_flow.add {type = "choose-elem-button", name = "py_request_type", elem_type = "fluid", tags = tags} - config_flow.add {type = "label", caption = "×"}.style.font = "heading-2" - local request_amount = config_flow.add {type = "textfield", name = "py_request_amount", tags = tags} + config_flow.add { type = "choose-elem-button", name = "py_request_type", elem_type = "fluid", tags = tags } + config_flow.add { type = "label", caption = "×" }.style.font = "heading-2" + local request_amount = config_flow.add { type = "textfield", name = "py_request_amount", tags = tags } request_amount.numeric = true request_amount.allow_decimal = false request_amount.allow_negative = false request_amount.style.width = 55 - config_flow.add {type = "empty-widget", style = "py_empty_widget"} + config_flow.add { type = "empty-widget", style = "py_empty_widget" } config_flow.add { type = "sprite-button", name = "py_change_priority_1", style = "py_schedule_move_button", - tags = {unit_number = unit_number, up = false}, + tags = { unit_number = unit_number, up = false }, sprite = "down-white", hovered_sprite = "down-black", clicked_sprite = "down-black" }.style.height = 35 - local priority = config_flow.add {type = "textfield", name = "py_requester_priority_input", tags = tags} + local priority = config_flow.add { type = "textfield", name = "py_requester_priority_input", tags = tags } priority.numeric = true priority.allow_decimal = false priority.allow_negative = false @@ -255,25 +255,25 @@ function Biofluid.build_requester_gui(entity, player) priority.style.height = 35 config_flow.add { type = "sprite-button", name = "py_change_priority_2", style = "py_schedule_move_button", - tags = {unit_number = unit_number, up = true}, + tags = { unit_number = unit_number, up = true }, sprite = "up-white", hovered_sprite = "up-black", clicked_sprite = "up-black" }.style.height = 35 - content_flow.add {type = "line"} - content_flow.add {type = "label", caption = {"gui.temperature-filter"}}.style.font = "default-semibold" + content_flow.add { type = "line" } + content_flow.add { type = "label", caption = { "gui.temperature-filter" } }.style.font = "default-semibold" - local temperature_flow = content_flow.add {type = "flow", direction = "horizontal", name = "temperature_flow"} + local temperature_flow = content_flow.add { type = "flow", direction = "horizontal", name = "temperature_flow" } temperature_flow.style.vertical_align = "center" - temperature_flow.add {type = "switch", allow_none_state = false, left_label_caption = {"gui-constant.off"}, right_label_caption = {"gui-constant.on"}, name = "py_biofluid_temperature_switch", tags = tags} + temperature_flow.add { type = "switch", allow_none_state = false, left_label_caption = { "gui-constant.off" }, right_label_caption = { "gui-constant.on" }, name = "py_biofluid_temperature_switch", tags = tags } - temperature_flow.add {type = "empty-widget", style = "py_empty_widget"} + temperature_flow.add { type = "empty-widget", style = "py_empty_widget" } - temperature_flow.add {type = "label", caption = "°C"}.style.font = "heading-2" + temperature_flow.add { type = "label", caption = "°C" }.style.font = "heading-2" - local equality_operator = temperature_flow.add {type = "drop-down", name = "py_biofluid_temperature_equality_operator", items = Biofluid.equality_operators, tags = tags, style = "circuit_condition_comparator_dropdown"} + local equality_operator = temperature_flow.add { type = "drop-down", name = "py_biofluid_temperature_equality_operator", items = Biofluid.equality_operators, tags = tags, style = "circuit_condition_comparator_dropdown" } equality_operator.style.left_margin = 10 - local temperature = temperature_flow.add {type = "textfield", name = "py_biofluid_temperature", tags = tags} + local temperature = temperature_flow.add { type = "textfield", name = "py_biofluid_temperature", tags = tags } temperature.numeric = true temperature.style.width = 55 temperature.enabled = false @@ -283,14 +283,99 @@ function Biofluid.build_requester_gui(entity, player) Biofluid.update_requester_gui(player, main_frame) end -py.on_event({defines.events.on_gui_closed, defines.events.on_player_changed_surface}, function(event) +function Biofluid.build_provider_gui(entity, player) + if player.gui.screen.biofluid_provider_gui then player.gui.screen.biofluid_provider_gui.destroy() end + local unit_number = entity.unit_number + + local main_frame = player.gui.screen.add { type = "frame", name = "biofluid_provider_gui", caption = entity.prototype.localised_name, direction = "vertical" } + main_frame.auto_center = true + player.opened = main_frame + main_frame.style.width = 436 + local tags = { unit_number = unit_number } + main_frame.tags = tags + + local content_frame = main_frame.add { type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding" } + content_frame.style.vertically_stretchable = true + local content_flow = content_frame.add { type = "flow", name = "content_flow", direction = "vertical" } + content_flow.style.vertical_spacing = 8 + content_flow.style.margin = { -4, 0, -4, 0 } + content_flow.style.vertical_align = "center" + + local status_flow = content_flow.add { type = "flow", name = "status_flow", direction = "horizontal" } + status_flow.style.vertical_align = "center" + local status_sprite = status_flow.add { type = "sprite", name = "status_sprite" } + status_sprite.resize_to_sprite = false + status_sprite.style.size = { 16, 16 } + status_flow.add { type = "label", name = "status_text" } + status_flow.add { type = "empty-widget", style = "py_empty_widget" } + + local camera_frame = content_flow.add { type = "frame", name = "camera_frame", style = "py_nice_frame" } + local camera = camera_frame.add { type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index } + camera.visible = true + camera.style.height = 155 + camera.zoom = 2 + + local label_flow = content_flow.add { type = "flow", direction = "horizontal" } + label_flow.add { type = "label", caption = { "gui.priority" } }.style.font = "default-semibold" + + local config_flow = content_flow.add { type = "flow", direction = "horizontal", name = "config_flow" } + config_flow.add { + type = "sprite-button", name = "py_change_priority_1", style = "py_schedule_move_button", + tags = { unit_number = unit_number, up = false }, + sprite = "down-white", hovered_sprite = "down-black", clicked_sprite = "down-black" + }.style.height = 35 + local priority = config_flow.add { type = "textfield", name = "py_provider_priority_input", tags = tags } + priority.numeric = true + priority.allow_decimal = false + priority.allow_negative = false + priority.style.width = 55 + priority.style.height = 35 + config_flow.add { + type = "sprite-button", name = "py_change_priority_2", style = "py_schedule_move_button", + tags = { unit_number = unit_number, up = true }, + sprite = "up-white", hovered_sprite = "up-black", clicked_sprite = "up-black" + }.style.height = 35 + + Biofluid.update_provider_gui(player, main_frame) +end + +function Biofluid.update_provider_gui(player, gui) + local unit_number = gui.tags.unit_number + local provider_data = storage.biofluid_providers[unit_number] + if not provider_data then + player.opened = nil; return + end + local entity = provider_data.entity + if not entity or not entity.valid then + player.opened = nil; return + end + local network = storage.biofluid_networks[provider_data.network_id] + if not network then + player.opened = nil; return + end + + local status = "entity-status.working" + if not next(network.biofluid_bioports) then status = "entity-status.no-biofluid-network" end + local img = Biofluid.failure_reasons[status] + local content_flow = gui.content_frame.content_flow + content_flow.status_flow.status_text.caption = { status } + content_flow.status_flow.status_sprite.sprite = img + + local config_flow = content_flow.config_flow + config_flow.py_provider_priority_input.text = tostring(provider_data.priority) +end + +py.on_event({ defines.events.on_gui_closed, defines.events.on_player_changed_surface }, function(event) local player = game.get_player(event.player_index) if event.gui_type == defines.gui_type.entity then local gui = player.gui.relative.bioport_gui if gui then gui.destroy() end elseif event.gui_type == defines.gui_type.custom then - local gui = player.gui.screen.biofluid_requester_gui - if gui then gui.destroy() end + local requester_gui = player.gui.screen.biofluid_requester_gui + if requester_gui then requester_gui.destroy() end + + local provider_gui = player.gui.screen.biofluid_provider_gui + if provider_gui then provider_gui.destroy() end end end) @@ -320,9 +405,18 @@ local function gui_click(event, inventory_index) Biofluid.update_bioport_gui(player, player.gui.relative.bioport_gui) end -gui_events[defines.events.on_gui_click]["py_biofluid_food_."] = function(event) gui_click(event, defines.inventory.assembling_machine_input) end -gui_events[defines.events.on_gui_click]["py_biofluid_module_."] = function(event) gui_click(event, defines.inventory.assembling_machine_input) end -gui_events[defines.events.on_gui_click]["py_guano_output"] = function(event) gui_click(event, defines.inventory.assembling_machine_output) end +gui_events[defines.events.on_gui_click]["py_biofluid_food_."] = function(event) + gui_click(event, + defines.inventory.assembling_machine_input) +end +gui_events[defines.events.on_gui_click]["py_biofluid_module_."] = function(event) + gui_click(event, + defines.inventory.assembling_machine_input) +end +gui_events[defines.events.on_gui_click]["py_guano_output"] = function(event) + gui_click(event, + defines.inventory.assembling_machine_output) +end gui_events[defines.events.on_gui_elem_changed]["py_request_type"] = function(event) local element = event.element @@ -348,11 +442,18 @@ end gui_events[defines.events.on_gui_click]["py_change_priority_."] = function(event) local element = event.element local unit_number = element.tags.unit_number + local requester_data = storage.biofluid_requesters[unit_number] - if not requester_data then return end - local change = element.tags.up and 1 or -1 - requester_data.priority = requester_data.priority + change - element.parent.py_requester_priority_input.text = tostring(requester_data.priority) + local provider_data = storage.biofluid_providers[unit_number] + if requester_data then + local change = element.tags.up and 1 or -1 + requester_data.priority = requester_data.priority + change + element.parent.py_requester_priority_input.text = tostring(requester_data.priority) + elseif provider_data then + local change = element.tags.up and 1 or -1 + provider_data.priority = provider_data.priority + change + element.parent.py_provider_priority_input.text = tostring(provider_data.priority) + end end gui_events[defines.events.on_gui_text_changed]["py_requester_priority_input"] = function(event) @@ -363,6 +464,14 @@ gui_events[defines.events.on_gui_text_changed]["py_requester_priority_input"] = requester_data.priority = tonumber(element.text) or 0 end +gui_events[defines.events.on_gui_text_changed]["py_provider_priority_input"] = function(event) + local element = event.element + local unit_number = element.tags.unit_number + local provider_data = storage.biofluid_providers[unit_number] + if not provider_data then return end + provider_data.priority = tonumber(element.text) or 0 +end + gui_events[defines.events.on_gui_switch_state_changed]["py_biofluid_temperature_switch"] = function(event) local element = event.element local unit_number = element.tags.unit_number diff --git a/scripts/biofluid/biofluid.lua b/scripts/biofluid/biofluid.lua index 1102cc878..3db33e395 100644 --- a/scripts/biofluid/biofluid.lua +++ b/scripts/biofluid/biofluid.lua @@ -45,7 +45,7 @@ local function migrate_network_data(fluids) local MAX_MESSAGE_SIZE = 30 if not fluids then return end - for _, biofluid_entity_type in pairs{"biofluid_robots", "biofluid_requesters"} do + for _, biofluid_entity_type in pairs { "biofluid_robots", "biofluid_requesters" } do for k, entry in pairs(storage[biofluid_entity_type]) do if fluids[entry.name] == "" then -- This fluid has been deleted from factorio. @@ -58,7 +58,7 @@ local function migrate_network_data(fluids) entity.surface.spill_item_stack { position = entity.position, force = entity.force_index, - stack = {name = entity.name, count = 1}, + stack = { name = entity.name, count = 1 }, marked_for_deconstruction = true } storage.biofluid_robots[k] = nil @@ -78,14 +78,17 @@ local function migrate_network_data(fluids) end if num_migrated ~= 0 then - local fluids_deleted = serpent.block(fluids_deleted):gsub("\"] = \"", " used to be => \""):gsub("%[\"", "biofluid robot at ") - local fluids_deleted_full = serpent.block(fluids_deleted_full):gsub("\"] = \"", " used to be => \""):gsub("%[\"", "biofluid robot at ") + local fluids_deleted = serpent.block(fluids_deleted):gsub("\"] = \"", " used to be => \""):gsub("%[\"", + "biofluid robot at ") + local fluids_deleted_full = serpent.block(fluids_deleted_full):gsub("\"] = \"", " used to be => \""):gsub("%[\"", + "biofluid robot at ") - game.print {"messages.warning-biofluid-migration", num_migrated, fluids_deleted} + game.print { "messages.warning-biofluid-migration", num_migrated, fluids_deleted } if num_migrated > MAX_MESSAGE_SIZE then - game.print("\t... " .. (num_migrated - MAX_MESSAGE_SIZE) .. " more not shown. Check factorio-current.log for full list.") + game.print("\t... " .. + (num_migrated - MAX_MESSAGE_SIZE) .. " more not shown. Check factorio-current.log for full list.") log "FULL LIST: " - log {"messages.warning-biofluid-migration", num_migrated, fluids_deleted_full} + log { "messages.warning-biofluid-migration", num_migrated, fluids_deleted_full } end end end @@ -111,7 +114,7 @@ py.on_event(py.events.on_built(), function(event) entity.active = false entity.custom_status = { diode = defines.entity_status_diode.green, - label = {"entity-status.working"}, + label = { "entity-status.working" }, } local unit_number = entity.unit_number if connection_type == Biofluid.REQUESTER then @@ -133,17 +136,21 @@ py.on_event(py.events.on_built(), function(event) active = false, guano = 0, animation = { - gobachov = {stage = 0, id = nil}, - chorkok = {stage = 0, id = nil} + gobachov = { stage = 0, id = nil }, + chorkok = { stage = 0, id = nil } } } - elseif entity.type == "pipe-to-ground" then + elseif entity.type == "pipe-to-ground" then entity.operable = false elseif connection_type == Biofluid.PROVIDER then - storage.biofluid_providers[unit_number] = {entity = entity} + local tags = event.tags or {} + storage.biofluid_providers[unit_number] = { + entity = entity, + priority = tags.priority or 0 + } end - - ::continue:: + + ::continue:: Biofluid.built_pipe() end) @@ -172,14 +179,15 @@ function Biofluid.built_pipe() for _, network in pairs(storage.biofluid_networks) do for provider_unit_number, amount in pairs(network.allocated_fluids_from_providers or {}) do - allocated_fluids_from_providers[provider_unit_number] = amount + (allocated_fluids_from_providers[provider_unit_number] or 0) + allocated_fluids_from_providers[provider_unit_number] = amount + + (allocated_fluids_from_providers[provider_unit_number] or 0) end end local networks = {} storage.biofluid_networks = networks - for _, biofluid_connectable_name in pairs {"biofluid_bioports", "biofluid_requesters", "biofluid_providers"} do + for _, biofluid_connectable_name in pairs { "biofluid_bioports", "biofluid_requesters", "biofluid_providers" } do local biofluid_connectables = storage[biofluid_connectable_name] local new_biofluid_connectables = {} @@ -260,12 +268,22 @@ end local allocated_fluids_from_providers local function provider_sort_function(entity_a, entity_b) local a = entity_a.fluidbox[1] + local priority_a = storage.biofluid_providers[entity_a.unit_number].priority if not a then a = 0 else a = a.amount end a = a - (allocated_fluids_from_providers[entity_a.unit_number] or 0) + local b = entity_b.fluidbox[1] + local priority_b = storage.biofluid_providers[entity_b.unit_number].priority if not b then b = 0 else b = b.amount end b = b - (allocated_fluids_from_providers[entity_b.unit_number] or 0) - return a > b + + if (priority_a > priority_b) then + return true + elseif (priority_a < priority_b) then + return false + else + return a > b + end end @@ -277,36 +295,32 @@ function order_by_distance(base_entity, unit_numbers) table.insert(order, unit_number) end table.sort(order, function(a, b) + local dataA = storage.biofluid_bioports[a] + if dataA == nil then return false end + + local entityA = dataA.entity + if entityA == nil then return false end + + local entityA_pos = entityA.position + if entityA_pos == nil then return false end + + local dataB = storage.biofluid_bioports[b] + if dataB == nil then return false end + + local entityB = dataB.entity + if entityB == nil then return false end + + local entityB_pos = entityB.position + if entityB_pos == nil then return false end + + local distA = (entityA_pos.x - base_entity.position.x) ^ 2 + (entityA_pos.y - base_entity.position.y) ^ 2 + local distB = (entityB_pos.x - base_entity.position.x) ^ 2 + (entityB_pos.y - base_entity.position.y) ^ 2 - local dataA = storage.biofluid_bioports[a] - if dataA == nil then return false end - - local entityA = dataA.entity - if entityA == nil then return false end - - local entityA_pos = entityA.position - if entityA_pos == nil then return false end - - local dataB = storage.biofluid_bioports[b] - if dataB == nil then return false end - - local entityB = dataB.entity - if entityB == nil then return false end - - local entityB_pos = entityB.position - if entityB_pos == nil then return false end - - local distA = (entityA_pos.x - base_entity.position.x)^2 + (entityA_pos.y - base_entity.position.y)^2 - local distB = (entityB_pos.x - base_entity.position.x)^2 + (entityB_pos.y - base_entity.position.y)^2 - return distA < distB end) return ipairs(order) end - - - local function random_order(l) local order = {} local i = 1 @@ -331,6 +345,7 @@ local function build_providers_by_contents(network_data, relavant_fluids) if not provider_data then goto continue end local provider = provider_data.entity if not provider.valid then goto continue end + local provider_priority = provider_data.priority local contents = provider.fluidbox[1] if not contents then goto continue end @@ -338,15 +353,15 @@ local function build_providers_by_contents(network_data, relavant_fluids) if not relavant_fluids[name] then goto continue end local already_allocated = network_data.allocated_fluids_from_providers[provider.unit_number] or 0 local can_give = contents.amount - already_allocated - - if (contents.amount >= Biofluid.tank_size) then - -- if the provider tank is full, allow as many bots as possible to use it - -- this allows a well-supplied provider to service many more requesters per unit time without impacting providers with smaller supply - -- the downside is that sudden demand spikes will waste biofluid bot time by over-allocating them, but that should be rare. - can_give = contents.amount - end - - if can_give < min_fluid_reserve then goto continue end + + if (contents.amount >= Biofluid.tank_size) then + -- if the provider tank is full, allow as many bots as possible to use it + -- this allows a well-supplied provider to service many more requesters per unit time without impacting providers with smaller supply + -- the downside is that sudden demand spikes will waste biofluid bot time by over-allocating them, but that should be rare. + can_give = contents.amount + end + + if can_give < min_fluid_reserve then goto continue end local list = providers_by_contents[name] or {} providers_by_contents[name] = list @@ -397,13 +412,13 @@ local function process_unfulfilled_requests(unfulfilled_request, relavant_fluids end end local can_give = contents.amount - (allocated_fluids_from_providers[p.unit_number] or 0) - - if (contents.amount >= Biofluid.tank_size) then - -- again, if the provider tank is full assume it is also well-supplied and can provide much more than we can currently see - -- ignore existing allocations and assume it will be full when we get there - can_give = contents.amount - end - + + if (contents.amount >= Biofluid.tank_size) then + -- again, if the provider tank is full assume it is also well-supplied and can provide much more than we can currently see + -- ignore existing allocations and assume it will be full when we get there + can_give = contents.amount + end + provider = p unfulfilled_request.amount = min(amount, can_give) break @@ -411,20 +426,19 @@ local function process_unfulfilled_requests(unfulfilled_request, relavant_fluids end if not provider then return end - + local requester_data = storage.biofluid_requesters[unfulfilled_request.entity.unit_number] - - for _, unit_number in order_by_distance(requester_data.entity, network_data.biofluid_bioports) do + for _, unit_number in order_by_distance(requester_data.entity, network_data.biofluid_bioports) do local bioport_data = storage.biofluid_bioports[unit_number] if not bioport_data or not bioport_data.active or not bioport_data.entity.valid then goto continue end - if (unfulfilled_request.amount <= 0) then - break - end + if (unfulfilled_request.amount <= 0) then + break + end local delivery_amount = Biofluid.start_journey(unfulfilled_request, provider, bioport_data) - + if delivery_amount ~= 0 then local allocated = network_data.allocated_fluids_from_providers allocated[provider.unit_number] = (allocated[provider.unit_number] or 0) + delivery_amount @@ -473,7 +487,7 @@ function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) local bioport_input_inventory = bioport.get_inventory(INPUT_INVENTORY) local robot_name for robot, delivery_size in pairs(Biofluid.delivery_sizes) do - local removed = bioport_input_inventory.remove {name = robot, count = 1} + local removed = bioport_input_inventory.remove { name = robot, count = 1 } if removed ~= 0 then robot_name = robot delivery_amount = min(delivery_amount, delivery_size) @@ -483,7 +497,7 @@ function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) if not robot_name then return 0 end Biofluid.poop(bioport_data, robot_name) local bioport_position = bioport.position - local position = {bioport_position.x, bioport_position.y - 2.5} + local position = { bioport_position.x, bioport_position.y - 2.5 } local provider_position = provider.position local robot = bioport.surface.create_entity { name = robot_name, @@ -514,7 +528,7 @@ function Biofluid.eat(bioport_data) if bioport_data.fuel_remaning <= 0 then local bioport_input_inventory = bioport.get_inventory(INPUT_INVENTORY) for food, calories in pairs(Biofluid.favorite_foods) do - local removed = bioport_input_inventory.remove {name = food, count = 1} + local removed = bioport_input_inventory.remove { name = food, count = 1 } if removed ~= 0 then bioport_data.fuel_remaning = calories bioport_data.last_eaten_fuel_value = calories @@ -534,7 +548,7 @@ function Biofluid.eat(bioport_data) end local batch_size = 3 -local special_delivery = {name = "guano", count = batch_size} +local special_delivery = { name = "guano", count = batch_size } function Biofluid.poop(bioport_data, robot_name) local poop_amount = Biofluid.taco_bell[robot_name] bioport_data.guano = bioport_data.guano + poop_amount @@ -609,7 +623,7 @@ local function find_new_home(biorobot_data, network_data) make_homeless(biorobot_data); return end local position = home.position - set_target(biorobot_data, {position.x, position.y - 2.5}) + set_target(biorobot_data, { position.x, position.y - 2.5 }) end local function go_home(biorobot_data) @@ -633,7 +647,7 @@ local function go_home(biorobot_data) return end local position = bioport_data.entity.position - set_target(biorobot_data, {position.x, position.y - 2.5}) + set_target(biorobot_data, { position.x, position.y - 2.5 }) end local function combine_tempatures(first_count, first_tempature, second_count, second_tempature) @@ -665,7 +679,7 @@ local function pickup(biorobot_data) if new_amount == 0 then provider.fluidbox[1] = nil else - provider.fluidbox[1] = {name = name, amount = new_amount, temperature = contents.temperature} + provider.fluidbox[1] = { name = name, amount = new_amount, temperature = contents.temperature } end set_target(biorobot_data, requester_data.entity.position) reset_provider_allocations(biorobot_data) @@ -710,7 +724,7 @@ local function dropoff(biorobot_data) temperature = combine_tempatures(contents.amount, contents.temperature, amount, temperature) } elseif amount > 0 then - requester.fluidbox[2] = {name = name, amount = amount, temperature = temperature} + requester.fluidbox[2] = { name = name, amount = amount, temperature = temperature } end go_home(biorobot_data) if biorobot_data.alt_mode_sprite then @@ -734,7 +748,7 @@ local function returning(biorobot_data) end local biorobot = biorobot_data.entity local inventory = bioport.get_inventory(INPUT_INVENTORY) - if inventory.insert {name = biorobot.name, count = 1} == 1 then + if inventory.insert { name = biorobot.name, count = 1 } == 1 then storage.biofluid_robots[biorobot.unit_number] = nil biorobot.destroy() Biofluid.update_bioport_animation(bioport_data) @@ -965,7 +979,7 @@ py.on_event(defines.events.on_selected_entity_changed, function(event) if entity_status then entity.custom_status = { diode = Biofluid.diode_colors[Biofluid.failure_reasons[entity_status]], - label = {entity_status}, + label = { entity_status }, } end end) From a54b03a4e9ed2b3e1a405a1b053db34da82b4abe Mon Sep 17 00:00:00 2001 From: limelou <119715684+limelou@users.noreply.github.com> Date: Mon, 25 Aug 2025 22:43:15 -0700 Subject: [PATCH 2/2] try to unformat --- scripts/biofluid/biofluid-gui.lua | 160 +++++++++++++++--------------- scripts/biofluid/biofluid.lua | 76 +++++++------- 2 files changed, 118 insertions(+), 118 deletions(-) diff --git a/scripts/biofluid/biofluid-gui.lua b/scripts/biofluid/biofluid-gui.lua index c02d05a02..96805f8a1 100644 --- a/scripts/biofluid/biofluid-gui.lua +++ b/scripts/biofluid/biofluid-gui.lua @@ -32,7 +32,7 @@ function Biofluid.update_bioport_gui(player, gui) local status = Biofluid.why_isnt_my_bioport_working(bioport_data) local img = Biofluid.failure_reasons[status] local content_flow = gui.content_frame.content_flow - content_flow.status_flow.status_text.caption = { status } + content_flow.status_flow.status_text.caption = {status} content_flow.status_flow.status_sprite.sprite = img local fuel_flow = content_flow.fuel_flow @@ -101,56 +101,56 @@ end function Biofluid.build_bioport_gui(entity, player) if player.gui.relative.bioport_gui then player.gui.relative.bioport_gui.destroy() end local main_frame = player.gui.relative.add { - type = "frame", name = "bioport_gui", caption = entity.prototype.localised_name, direction = "vertical", tags = { unit_number = entity.unit_number }, + type = "frame", name = "bioport_gui", caption = entity.prototype.localised_name, direction = "vertical", tags = {unit_number = entity.unit_number}, anchor = { gui = defines.relative_gui_type.assembling_machine_gui, position = defines.relative_gui_position.right - } - } + } + } main_frame.style.width = 448 main_frame.style.vertically_stretchable = false main_frame.style.vertically_squashable = true - local content_frame = main_frame.add { type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding" } + local content_frame = main_frame.add {type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding"} content_frame.style.vertically_stretchable = true - local content_flow = content_frame.add { type = "flow", name = "content_flow", direction = "vertical" } + local content_flow = content_frame.add {type = "flow", name = "content_flow", direction = "vertical"} content_flow.style.vertical_spacing = 8 - content_flow.style.margin = { -4, 0, -4, 0 } + content_flow.style.margin = {-4, 0, -4, 0} content_flow.style.vertical_align = "center" - local status_flow = content_flow.add { type = "flow", name = "status_flow", direction = "horizontal" } + local status_flow = content_flow.add {type = "flow", name = "status_flow", direction = "horizontal"} status_flow.style.vertical_align = "center" - local status_sprite = status_flow.add { type = "sprite", name = "status_sprite" } + local status_sprite = status_flow.add {type = "sprite", name = "status_sprite"} status_sprite.resize_to_sprite = false - status_sprite.style.size = { 16, 16 } - status_flow.add { type = "label", name = "status_text" } - status_flow.add { type = "empty-widget", style = "py_empty_widget" } + status_sprite.style.size = {16, 16} + status_flow.add {type = "label", name = "status_text"} + status_flow.add {type = "empty-widget", style = "py_empty_widget"} - local camera_frame = content_flow.add { type = "frame", name = "camera_frame", style = "py_nice_frame" } - local camera = camera_frame.add { type = "camera", name = "camera", position = { entity.position.x, entity.position.y - 1 }, style = "py_caravan_camera", surface_index = entity.surface.index } + local camera_frame = content_flow.add {type = "frame", name = "camera_frame", style = "py_nice_frame"} + local camera = camera_frame.add {type = "camera", name = "camera", position = {entity.position.x, entity.position.y - 1}, style = "py_caravan_camera", surface_index = entity.surface.index} camera.visible = true camera.style.height = 155 - local fuel_flow = content_flow.add { type = "flow", name = "fuel_flow", direction = "horizontal" } + local fuel_flow = content_flow.add {type = "flow", name = "fuel_flow", direction = "horizontal"} fuel_flow.style.vertical_align = "center" local favorite_food_tooltip = py.generate_favorite_food_tooltip(Biofluid.favorite_foods, "biofluid-gui") for i = 1, Biofluid.fuel_size do - local fuel_slot = fuel_flow.add { type = "sprite-button", name = "py_biofluid_food_" .. i, style = "inventory_slot", tags = { unit_number = entity.unit_number, i = i } } + local fuel_slot = fuel_flow.add {type = "sprite-button", name = "py_biofluid_food_" .. i, style = "inventory_slot", tags = {unit_number = entity.unit_number, i = i}} fuel_slot.sprite = "slot_icon_fuel" fuel_slot.tooltip = favorite_food_tooltip end - local bar_flow = fuel_flow.add { type = "flow", name = "bar_flow", direction = "vertical" } - bar_flow.add { type = "progressbar", name = "fuel_bar", style = "burning_progressbar" }.style.horizontally_stretchable = true - bar_flow.add { type = "progressbar", name = "guano_bar", style = "bonus_progressbar" }.style.horizontally_stretchable = true - fuel_flow.add { type = "sprite-button", name = "py_guano_output", style = "inventory_slot", tags = { unit_number = entity.unit_number, slot_index = 1 }, sprite = "item/guano" } + local bar_flow = fuel_flow.add {type = "flow", name = "bar_flow", direction = "vertical"} + bar_flow.add {type = "progressbar", name = "fuel_bar", style = "burning_progressbar"}.style.horizontally_stretchable = true + bar_flow.add {type = "progressbar", name = "guano_bar", style = "bonus_progressbar"}.style.horizontally_stretchable = true + fuel_flow.add {type = "sprite-button", name = "py_guano_output", style = "inventory_slot", tags = {unit_number = entity.unit_number, slot_index = 1}, sprite = "item/guano"} - content_flow.add { type = "line" } + content_flow.add {type = "line"} - local module_flow = content_flow.add { type = "flow", name = "module_flow", direction = "horizontal" } + local module_flow = content_flow.add {type = "flow", name = "module_flow", direction = "horizontal"} module_flow.style.vertical_align = "center" local allowed_module_tooltip = py.generate_allowed_module_tooltip(Biofluid.biorobots) for i = 1, Biofluid.module_size do - local module_slot = module_flow.add { type = "sprite-button", name = "py_biofluid_module_" .. i, style = "inventory_slot", tags = { unit_number = entity.unit_number, i = i } } + local module_slot = module_flow.add {type = "sprite-button", name = "py_biofluid_module_" .. i, style = "inventory_slot", tags = {unit_number = entity.unit_number, i = i}} module_slot.sprite = "utility/empty_module_slot" module_slot.tooltip = allowed_module_tooltip end @@ -177,7 +177,7 @@ function Biofluid.update_requester_gui(player, gui) if not next(network.biofluid_bioports) then status = "entity-status.no-biofluid-network" end local img = Biofluid.failure_reasons[status] local content_flow = gui.content_frame.content_flow - content_flow.status_flow.status_text.caption = { status } + content_flow.status_flow.status_text.caption = {status} content_flow.status_flow.status_sprite.sprite = img local config_flow = content_flow.config_flow @@ -197,57 +197,57 @@ end function Biofluid.build_requester_gui(entity, player) if player.gui.screen.biofluid_requester_gui then player.gui.screen.biofluid_requester_gui.destroy() end local unit_number = entity.unit_number - local main_frame = player.gui.screen.add { type = "frame", name = "biofluid_requester_gui", caption = entity.prototype.localised_name, direction = "vertical" } + local main_frame = player.gui.screen.add {type = "frame", name = "biofluid_requester_gui", caption = entity.prototype.localised_name, direction = "vertical"} main_frame.auto_center = true player.opened = main_frame main_frame.style.width = 436 - local tags = { unit_number = unit_number } + local tags = {unit_number = unit_number} main_frame.tags = tags - local content_frame = main_frame.add { type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding" } + local content_frame = main_frame.add {type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding"} content_frame.style.vertically_stretchable = true - local content_flow = content_frame.add { type = "flow", name = "content_flow", direction = "vertical" } + local content_flow = content_frame.add {type = "flow", name = "content_flow", direction = "vertical"} content_flow.style.vertical_spacing = 8 - content_flow.style.margin = { -4, 0, -4, 0 } + content_flow.style.margin = {-4, 0, -4, 0} content_flow.style.vertical_align = "center" - local status_flow = content_flow.add { type = "flow", name = "status_flow", direction = "horizontal" } + local status_flow = content_flow.add {type = "flow", name = "status_flow", direction = "horizontal"} status_flow.style.vertical_align = "center" - local status_sprite = status_flow.add { type = "sprite", name = "status_sprite" } + local status_sprite = status_flow.add {type = "sprite", name = "status_sprite"} status_sprite.resize_to_sprite = false - status_sprite.style.size = { 16, 16 } - status_flow.add { type = "label", name = "status_text" } - status_flow.add { type = "empty-widget", style = "py_empty_widget" } + status_sprite.style.size = {16, 16} + status_flow.add {type = "label", name = "status_text"} + status_flow.add {type = "empty-widget", style = "py_empty_widget"} - local camera_frame = content_flow.add { type = "frame", name = "camera_frame", style = "py_nice_frame" } - local camera = camera_frame.add { type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index } + local camera_frame = content_flow.add {type = "frame", name = "camera_frame", style = "py_nice_frame"} + local camera = camera_frame.add {type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index} camera.visible = true camera.style.height = 155 camera.zoom = 2 - local label_flow = content_flow.add { type = "flow", direction = "horizontal" } - label_flow.add { type = "label", caption = { "gui-logistic.title-requests" } }.style.font = "default-semibold" - label_flow.add { type = "empty-widget", style = "py_empty_widget" } - label_flow.add { type = "label", caption = { "gui.priority" } }.style.font = "default-semibold" + local label_flow = content_flow.add {type = "flow", direction = "horizontal"} + label_flow.add {type = "label", caption = {"gui-logistic.title-requests"}}.style.font = "default-semibold" + label_flow.add {type = "empty-widget", style = "py_empty_widget"} + label_flow.add {type = "label", caption = {"gui.priority"}}.style.font = "default-semibold" - local config_flow = content_flow.add { type = "flow", direction = "horizontal", name = "config_flow" } + local config_flow = content_flow.add {type = "flow", direction = "horizontal", name = "config_flow"} config_flow.style.vertical_align = "center" - config_flow.add { type = "choose-elem-button", name = "py_request_type", elem_type = "fluid", tags = tags } - config_flow.add { type = "label", caption = "×" }.style.font = "heading-2" - local request_amount = config_flow.add { type = "textfield", name = "py_request_amount", tags = tags } + config_flow.add {type = "choose-elem-button", name = "py_request_type", elem_type = "fluid", tags = tags} + config_flow.add {type = "label", caption = "×"}.style.font = "heading-2" + local request_amount = config_flow.add {type = "textfield", name = "py_request_amount", tags = tags} request_amount.numeric = true request_amount.allow_decimal = false request_amount.allow_negative = false request_amount.style.width = 55 - config_flow.add { type = "empty-widget", style = "py_empty_widget" } + config_flow.add {type = "empty-widget", style = "py_empty_widget"} config_flow.add { type = "sprite-button", name = "py_change_priority_1", style = "py_schedule_move_button", - tags = { unit_number = unit_number, up = false }, + tags = {unit_number = unit_number, up = false}, sprite = "down-white", hovered_sprite = "down-black", clicked_sprite = "down-black" - }.style.height = 35 - local priority = config_flow.add { type = "textfield", name = "py_requester_priority_input", tags = tags } + }.style.height = 35 + local priority = config_flow.add {type = "textfield", name = "py_requester_priority_input", tags = tags} priority.numeric = true priority.allow_decimal = false priority.allow_negative = false @@ -255,25 +255,25 @@ function Biofluid.build_requester_gui(entity, player) priority.style.height = 35 config_flow.add { type = "sprite-button", name = "py_change_priority_2", style = "py_schedule_move_button", - tags = { unit_number = unit_number, up = true }, + tags = {unit_number = unit_number, up = true}, sprite = "up-white", hovered_sprite = "up-black", clicked_sprite = "up-black" - }.style.height = 35 + }.style.height = 35 - content_flow.add { type = "line" } - content_flow.add { type = "label", caption = { "gui.temperature-filter" } }.style.font = "default-semibold" + content_flow.add {type = "line"} + content_flow.add {type = "label", caption = {"gui.temperature-filter"}}.style.font = "default-semibold" - local temperature_flow = content_flow.add { type = "flow", direction = "horizontal", name = "temperature_flow" } + local temperature_flow = content_flow.add {type = "flow", direction = "horizontal", name = "temperature_flow"} temperature_flow.style.vertical_align = "center" - temperature_flow.add { type = "switch", allow_none_state = false, left_label_caption = { "gui-constant.off" }, right_label_caption = { "gui-constant.on" }, name = "py_biofluid_temperature_switch", tags = tags } + temperature_flow.add {type = "switch", allow_none_state = false, left_label_caption = {"gui-constant.off"}, right_label_caption = {"gui-constant.on"}, name = "py_biofluid_temperature_switch", tags = tags} - temperature_flow.add { type = "empty-widget", style = "py_empty_widget" } + temperature_flow.add {type = "empty-widget", style = "py_empty_widget"} - temperature_flow.add { type = "label", caption = "°C" }.style.font = "heading-2" + temperature_flow.add {type = "label", caption = "°C"}.style.font = "heading-2" - local equality_operator = temperature_flow.add { type = "drop-down", name = "py_biofluid_temperature_equality_operator", items = Biofluid.equality_operators, tags = tags, style = "circuit_condition_comparator_dropdown" } + local equality_operator = temperature_flow.add {type = "drop-down", name = "py_biofluid_temperature_equality_operator", items = Biofluid.equality_operators, tags = tags, style = "circuit_condition_comparator_dropdown"} equality_operator.style.left_margin = 10 - local temperature = temperature_flow.add { type = "textfield", name = "py_biofluid_temperature", tags = tags } + local temperature = temperature_flow.add {type = "textfield", name = "py_biofluid_temperature", tags = tags} temperature.numeric = true temperature.style.width = 55 temperature.enabled = false @@ -287,44 +287,44 @@ function Biofluid.build_provider_gui(entity, player) if player.gui.screen.biofluid_provider_gui then player.gui.screen.biofluid_provider_gui.destroy() end local unit_number = entity.unit_number - local main_frame = player.gui.screen.add { type = "frame", name = "biofluid_provider_gui", caption = entity.prototype.localised_name, direction = "vertical" } + local main_frame = player.gui.screen.add {type = "frame", name = "biofluid_provider_gui", caption = entity.prototype.localised_name, direction = "vertical"} main_frame.auto_center = true player.opened = main_frame main_frame.style.width = 436 - local tags = { unit_number = unit_number } + local tags = {unit_number = unit_number} main_frame.tags = tags - local content_frame = main_frame.add { type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding" } + local content_frame = main_frame.add {type = "frame", name = "content_frame", direction = "vertical", style = "inside_shallow_frame_with_padding"} content_frame.style.vertically_stretchable = true - local content_flow = content_frame.add { type = "flow", name = "content_flow", direction = "vertical" } + local content_flow = content_frame.add {type = "flow", name = "content_flow", direction = "vertical"} content_flow.style.vertical_spacing = 8 - content_flow.style.margin = { -4, 0, -4, 0 } + content_flow.style.margin = {-4, 0, -4, 0} content_flow.style.vertical_align = "center" - local status_flow = content_flow.add { type = "flow", name = "status_flow", direction = "horizontal" } + local status_flow = content_flow.add {type = "flow", name = "status_flow", direction = "horizontal"} status_flow.style.vertical_align = "center" - local status_sprite = status_flow.add { type = "sprite", name = "status_sprite" } + local status_sprite = status_flow.add {type = "sprite", name = "status_sprite"} status_sprite.resize_to_sprite = false - status_sprite.style.size = { 16, 16 } - status_flow.add { type = "label", name = "status_text" } - status_flow.add { type = "empty-widget", style = "py_empty_widget" } + status_sprite.style.size = {16, 16} + status_flow.add {type = "label", name = "status_text"} + status_flow.add {type = "empty-widget", style = "py_empty_widget"} - local camera_frame = content_flow.add { type = "frame", name = "camera_frame", style = "py_nice_frame" } - local camera = camera_frame.add { type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index } + local camera_frame = content_flow.add {type = "frame", name = "camera_frame", style = "py_nice_frame"} + local camera = camera_frame.add {type = "camera", name = "camera", position = entity.position, style = "py_caravan_camera", surface_index = entity.surface.index} camera.visible = true camera.style.height = 155 camera.zoom = 2 - local label_flow = content_flow.add { type = "flow", direction = "horizontal" } - label_flow.add { type = "label", caption = { "gui.priority" } }.style.font = "default-semibold" + local label_flow = content_flow.add {type = "flow", direction = "horizontal"} + label_flow.add {type = "label", caption = {"gui.priority"}}.style.font = "default-semibold" - local config_flow = content_flow.add { type = "flow", direction = "horizontal", name = "config_flow" } + local config_flow = content_flow.add {type = "flow", direction = "horizontal", name = "config_flow"} config_flow.add { type = "sprite-button", name = "py_change_priority_1", style = "py_schedule_move_button", - tags = { unit_number = unit_number, up = false }, + tags = {unit_number = unit_number, up = false}, sprite = "down-white", hovered_sprite = "down-black", clicked_sprite = "down-black" - }.style.height = 35 - local priority = config_flow.add { type = "textfield", name = "py_provider_priority_input", tags = tags } + }.style.height = 35 + local priority = config_flow.add {type = "textfield", name = "py_provider_priority_input", tags = tags} priority.numeric = true priority.allow_decimal = false priority.allow_negative = false @@ -332,9 +332,9 @@ function Biofluid.build_provider_gui(entity, player) priority.style.height = 35 config_flow.add { type = "sprite-button", name = "py_change_priority_2", style = "py_schedule_move_button", - tags = { unit_number = unit_number, up = true }, + tags = {unit_number = unit_number, up = true}, sprite = "up-white", hovered_sprite = "up-black", clicked_sprite = "up-black" - }.style.height = 35 + }.style.height = 35 Biofluid.update_provider_gui(player, main_frame) end @@ -358,14 +358,14 @@ function Biofluid.update_provider_gui(player, gui) if not next(network.biofluid_bioports) then status = "entity-status.no-biofluid-network" end local img = Biofluid.failure_reasons[status] local content_flow = gui.content_frame.content_flow - content_flow.status_flow.status_text.caption = { status } + content_flow.status_flow.status_text.caption = {status} content_flow.status_flow.status_sprite.sprite = img local config_flow = content_flow.config_flow config_flow.py_provider_priority_input.text = tostring(provider_data.priority) end -py.on_event({ defines.events.on_gui_closed, defines.events.on_player_changed_surface }, function(event) +py.on_event({defines.events.on_gui_closed, defines.events.on_player_changed_surface}, function(event) local player = game.get_player(event.player_index) if event.gui_type == defines.gui_type.entity then local gui = player.gui.relative.bioport_gui diff --git a/scripts/biofluid/biofluid.lua b/scripts/biofluid/biofluid.lua index 3db33e395..edc1f6569 100644 --- a/scripts/biofluid/biofluid.lua +++ b/scripts/biofluid/biofluid.lua @@ -45,7 +45,7 @@ local function migrate_network_data(fluids) local MAX_MESSAGE_SIZE = 30 if not fluids then return end - for _, biofluid_entity_type in pairs { "biofluid_robots", "biofluid_requesters" } do + for _, biofluid_entity_type in pairs {"biofluid_robots", "biofluid_requesters"} do for k, entry in pairs(storage[biofluid_entity_type]) do if fluids[entry.name] == "" then -- This fluid has been deleted from factorio. @@ -58,9 +58,9 @@ local function migrate_network_data(fluids) entity.surface.spill_item_stack { position = entity.position, force = entity.force_index, - stack = { name = entity.name, count = 1 }, + stack = {name = entity.name, count = 1}, marked_for_deconstruction = true - } + } storage.biofluid_robots[k] = nil num_migrated = num_migrated + 1 @@ -83,12 +83,12 @@ local function migrate_network_data(fluids) local fluids_deleted_full = serpent.block(fluids_deleted_full):gsub("\"] = \"", " used to be => \""):gsub("%[\"", "biofluid robot at ") - game.print { "messages.warning-biofluid-migration", num_migrated, fluids_deleted } + game.print {"messages.warning-biofluid-migration", num_migrated, fluids_deleted} if num_migrated > MAX_MESSAGE_SIZE then game.print("\t... " .. (num_migrated - MAX_MESSAGE_SIZE) .. " more not shown. Check factorio-current.log for full list.") log "FULL LIST: " - log { "messages.warning-biofluid-migration", num_migrated, fluids_deleted_full } + log {"messages.warning-biofluid-migration", num_migrated, fluids_deleted_full} end end end @@ -114,8 +114,8 @@ py.on_event(py.events.on_built(), function(event) entity.active = false entity.custom_status = { diode = defines.entity_status_diode.green, - label = { "entity-status.working" }, - } + label = {"entity-status.working"}, + } local unit_number = entity.unit_number if connection_type == Biofluid.REQUESTER then local tags = event.tags or {} @@ -128,7 +128,7 @@ py.on_event(py.events.on_built(), function(event) target_temperature = tags.target_temperature or 15, temperature_operator = tags.temperature_operator or 1, priority = tags.priority or 0 - } + } elseif connection_type == Biofluid.ROBOPORT then storage.biofluid_bioports[unit_number] = { entity = entity, @@ -136,18 +136,18 @@ py.on_event(py.events.on_built(), function(event) active = false, guano = 0, animation = { - gobachov = { stage = 0, id = nil }, - chorkok = { stage = 0, id = nil } - } - } + gobachov = {stage = 0, id = nil}, + chorkok = {stage = 0, id = nil} + } + } elseif entity.type == "pipe-to-ground" then entity.operable = false elseif connection_type == Biofluid.PROVIDER then local tags = event.tags or {} - storage.biofluid_providers[unit_number] = { + storage.biofluid_providers[unit_number] = { entity = entity, priority = tags.priority or 0 - } + } end ::continue:: @@ -187,7 +187,7 @@ function Biofluid.built_pipe() local networks = {} storage.biofluid_networks = networks - for _, biofluid_connectable_name in pairs { "biofluid_bioports", "biofluid_requesters", "biofluid_providers" } do + for _, biofluid_connectable_name in pairs {"biofluid_bioports", "biofluid_requesters", "biofluid_providers"} do local biofluid_connectables = storage[biofluid_connectable_name] local new_biofluid_connectables = {} @@ -202,7 +202,7 @@ function Biofluid.built_pipe() biofluid_requesters = {}, biofluid_providers = {}, allocated_fluids_from_providers = {}, - } + } networks[network_id] = network network[biofluid_connectable_name][unit_number] = true if allocated_fluids_from_providers[unit_number] then @@ -239,7 +239,7 @@ function Biofluid.update_bioport_animation(bioport_data) target = entity, surface = entity.surface, animation_speed = creature_name == "chorkok" and 0.25 or 0.5 - }.id + }.id end end end @@ -474,9 +474,9 @@ local function set_target(biorobot_data, target) low_priority = true, allow_paths_through_own_entities = true, allow_destroy_friendly_entities = true, - }, + }, distraction = defines.distraction.none - } + } end function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) @@ -487,7 +487,7 @@ function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) local bioport_input_inventory = bioport.get_inventory(INPUT_INVENTORY) local robot_name for robot, delivery_size in pairs(Biofluid.delivery_sizes) do - local removed = bioport_input_inventory.remove { name = robot, count = 1 } + local removed = bioport_input_inventory.remove {name = robot, count = 1} if removed ~= 0 then robot_name = robot delivery_amount = min(delivery_amount, delivery_size) @@ -497,7 +497,7 @@ function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) if not robot_name then return 0 end Biofluid.poop(bioport_data, robot_name) local bioport_position = bioport.position - local position = { bioport_position.x, bioport_position.y - 2.5 } + local position = {bioport_position.x, bioport_position.y - 2.5} local provider_position = provider.position local robot = bioport.surface.create_entity { name = robot_name, @@ -505,7 +505,7 @@ function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) position = position, create_build_effect_smoke = false, direction = floor((atan2(position[2] - provider_position.y, position[1] - provider_position.x) / pi - 0.5) / 2 % 1 * 8) - } + } local biorobot_data = { entity = robot, status = PICKING_UP, @@ -516,7 +516,7 @@ function Biofluid.start_journey(unfulfilled_request, provider, bioport_data) delivery_amount = delivery_amount, name = unfulfilled_request.name, network_id = bioport_data.network_id - } + } set_target(biorobot_data, provider.position) storage.biofluid_robots[robot.unit_number] = biorobot_data Biofluid.update_bioport_animation(bioport_data) @@ -528,7 +528,7 @@ function Biofluid.eat(bioport_data) if bioport_data.fuel_remaning <= 0 then local bioport_input_inventory = bioport.get_inventory(INPUT_INVENTORY) for food, calories in pairs(Biofluid.favorite_foods) do - local removed = bioport_input_inventory.remove { name = food, count = 1 } + local removed = bioport_input_inventory.remove {name = food, count = 1} if removed ~= 0 then bioport_data.fuel_remaning = calories bioport_data.last_eaten_fuel_value = calories @@ -548,7 +548,7 @@ function Biofluid.eat(bioport_data) end local batch_size = 3 -local special_delivery = { name = "guano", count = batch_size } +local special_delivery = {name = "guano", count = batch_size} function Biofluid.poop(bioport_data, robot_name) local poop_amount = Biofluid.taco_bell[robot_name] bioport_data.guano = bioport_data.guano + poop_amount @@ -588,7 +588,7 @@ local function make_homeless(biorobot_data) surface = biorobot_data.entity.surface, x_scale = 0.4, y_scale = 0.4 - } + } end local function find_new_home(biorobot_data, network_data) @@ -623,7 +623,7 @@ local function find_new_home(biorobot_data, network_data) make_homeless(biorobot_data); return end local position = home.position - set_target(biorobot_data, { position.x, position.y - 2.5 }) + set_target(biorobot_data, {position.x, position.y - 2.5}) end local function go_home(biorobot_data) @@ -647,7 +647,7 @@ local function go_home(biorobot_data) return end local position = bioport_data.entity.position - set_target(biorobot_data, { position.x, position.y - 2.5 }) + set_target(biorobot_data, {position.x, position.y - 2.5}) end local function combine_tempatures(first_count, first_tempature, second_count, second_tempature) @@ -679,7 +679,7 @@ local function pickup(biorobot_data) if new_amount == 0 then provider.fluidbox[1] = nil else - provider.fluidbox[1] = { name = name, amount = new_amount, temperature = contents.temperature } + provider.fluidbox[1] = {name = name, amount = new_amount, temperature = contents.temperature} end set_target(biorobot_data, requester_data.entity.position) reset_provider_allocations(biorobot_data) @@ -695,7 +695,7 @@ local function pickup(biorobot_data) only_in_alt_mode = true, x_scale = 0.5, y_scale = 0.5, - }.id + }.id biorobot_data.alt_mode_sprite = rendering.draw_sprite { sprite = "fluid/" .. name, target = entity, @@ -703,7 +703,7 @@ local function pickup(biorobot_data) only_in_alt_mode = true, x_scale = 0.8, y_scale = 0.8, - }.id + }.id end local function dropoff(biorobot_data) @@ -722,9 +722,9 @@ local function dropoff(biorobot_data) name = name, amount = contents.amount + amount, temperature = combine_tempatures(contents.amount, contents.temperature, amount, temperature) - } + } elseif amount > 0 then - requester.fluidbox[2] = { name = name, amount = amount, temperature = temperature } + requester.fluidbox[2] = {name = name, amount = amount, temperature = temperature} end go_home(biorobot_data) if biorobot_data.alt_mode_sprite then @@ -748,7 +748,7 @@ local function returning(biorobot_data) end local biorobot = biorobot_data.entity local inventory = bioport.get_inventory(INPUT_INVENTORY) - if inventory.insert { name = biorobot.name, count = 1 } == 1 then + if inventory.insert {name = biorobot.name, count = 1} == 1 then storage.biofluid_robots[biorobot.unit_number] = nil biorobot.destroy() Biofluid.update_bioport_animation(bioport_data) @@ -817,7 +817,7 @@ function Biofluid.get_unfulfilled_requests() entity = requester, priority = requester_data.priority, network_id = network_id - } + } if requester_data.care_about_temperature then result[#result].target_temperature = requester_data.target_temperature result[#result].temperature_operator = requester_data.temperature_operator @@ -907,7 +907,7 @@ py.on_event(defines.events.on_player_setup_blueprint, function(event) target_temperature = requester_data.target_temperature, temperature_operator = requester_data.temperature_operator, priority = requester_data.priority - }) + }) end end end) @@ -979,8 +979,8 @@ py.on_event(defines.events.on_selected_entity_changed, function(event) if entity_status then entity.custom_status = { diode = Biofluid.diode_colors[Biofluid.failure_reasons[entity_status]], - label = { entity_status }, - } + label = {entity_status}, + } end end)