From bbb68c16b809f7a06f645383f4571d77998978db Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Sun, 11 Dec 2022 12:46:31 -0500 Subject: [PATCH] fixed minro display bugs --- cybersyn/scripts/gui.lua | 2 + cybersyn/scripts/main.lua | 64 ++++++++++++++++++------------- cybersyn/scripts/train-events.lua | 2 - 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/cybersyn/scripts/gui.lua b/cybersyn/scripts/gui.lua index 65d8219..3b1e27c 100644 --- a/cybersyn/scripts/gui.lua +++ b/cybersyn/scripts/gui.lua @@ -29,6 +29,8 @@ STATUS_NAMES_DEFAULT = "entity-status.disabled" ---@param comb LuaEntity ---@param player LuaPlayer function gui_opened(comb, player) + combinator_update(global, comb) + local rootgui = player.gui.screen local selected_index, signal, check, switch_state = get_comb_gui_settings(comb) diff --git a/cybersyn/scripts/main.lua b/cybersyn/scripts/main.lua index 6bd3fdc..cbe980d 100644 --- a/cybersyn/scripts/main.lua +++ b/cybersyn/scripts/main.lua @@ -398,18 +398,33 @@ function combinator_update(map_data, comb) local old_params = map_data.to_comb_params[unit_number] local has_changed = false - if params.operation ~= old_params.operation then - if (old_params.operation == MODE_PRIMARY_IO) and (params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST) then + local stop = map_data.to_stop[comb.unit_number] + if stop then + id = stop.unit_number + station = map_data.stations[id] + if station then --make sure only MODE_PRIMARY_IO gets stored on map_data.to_comb_params - params.operation = MODE_PRIMARY_IO - else - --NOTE: This is rather dangerous, we may need to actually implement operation changing - on_combinator_broken(map_data, comb) - on_combinator_built(map_data, comb) - interface_raise_combinator_changed(comb, old_params) - return + if station.display_state >= 2 then + params.operation = MODE_PRIMARY_IO_ACTIVE + elseif station.display_state == 1 then + params.operation = MODE_PRIMARY_IO_FAILED_REQUEST + else + params.operation = MODE_PRIMARY_IO + end + control.parameters = params end end + + if params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then + params.operation = MODE_PRIMARY_IO + end + if params.operation ~= old_params.operation then + --NOTE: This is rather dangerous, we may need to actually implement operation changing + on_combinator_broken(map_data, comb) + on_combinator_built(map_data, comb) + interface_raise_combinator_changed(comb, old_params) + return + end local new_signal = params.first_signal local old_signal = old_params.first_signal local new_network = new_signal and new_signal.name or nil @@ -420,24 +435,19 @@ function combinator_update(map_data, comb) end if params.second_constant ~= old_params.second_constant then has_changed = true - local stop = map_data.to_stop[comb.unit_number] - if stop then - local id = stop.unit_number - local station = map_data.stations[id] - if station then - local pre = station.allows_all_trains - set_station_from_comb_state(station) - if station.allows_all_trains ~= pre then - update_stop_if_auto(map_data, station, true) - end - else - local refueler = map_data.refuelers[id] - if refueler then - local pre = refueler.allows_all_trains - set_refueler_from_comb(mod_settings, refueler) - if refueler.allows_all_trains ~= pre then - update_stop_if_auto(map_data, refueler, false) - end + if station then + local pre = station.allows_all_trains + set_station_from_comb_state(station) + if station.allows_all_trains ~= pre then + update_stop_if_auto(map_data, station, true) + end + else + local refueler = map_data.refuelers[id] + if refueler then + local pre = refueler.allows_all_trains + set_refueler_from_comb(mod_settings, refueler) + if refueler.allows_all_trains ~= pre then + update_stop_if_auto(map_data, refueler, false) end end end diff --git a/cybersyn/scripts/train-events.lua b/cybersyn/scripts/train-events.lua index 818e8d5..76ceb42 100644 --- a/cybersyn/scripts/train-events.lua +++ b/cybersyn/scripts/train-events.lua @@ -374,9 +374,7 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train) interface_raise_train_status_changed(train_id, STATUS_F, train.status) elseif train.status == STATUS_D then --The train is leaving the depot without a manifest, the player likely intervened - local depot = map_data.depots[train.parked_at_depot_id--[[@as uint]]] remove_train(map_data, train_id, train) - send_lost_train_alert(train.entity, depot.entity_stop.backer_name) end end