fixed display bug

This commit is contained in:
mamoniot
2022-12-23 17:06:52 -05:00
parent 8f993dd1ca
commit a4694742f8
5 changed files with 45 additions and 42 deletions

View File

@@ -24,8 +24,8 @@ function remove_manifest(map_data, station, manifest, sign)
end end
set_comb2(map_data, station) set_comb2(map_data, station)
station.deliveries_total = station.deliveries_total - 1 station.deliveries_total = station.deliveries_total - 1
if station.deliveries_total == 0 and band(station.display_state, 4) > 0 then if station.deliveries_total == 0 and band(station.display_state, 1) > 0 then
station.display_state = station.display_state - 4 station.display_state = station.display_state - 1
update_display(map_data, station) update_display(map_data, station)
end end
end end
@@ -100,14 +100,11 @@ function create_delivery(map_data, r_station_id, p_station_id, train_id, manifes
set_comb2(map_data, p_station) set_comb2(map_data, p_station)
set_comb2(map_data, r_station) set_comb2(map_data, r_station)
if band(p_station.display_state, 4) == 0 then p_station.display_state = 1
p_station.display_state = 4 update_display(map_data, p_station)
update_display(map_data, p_station) r_station.display_state = 1
end update_display(map_data, r_station)
if band(r_station.display_state, 4) == 0 then
r_station.display_state = 4
update_display(map_data, r_station)
end
interface_raise_train_status_changed(train_id, old_status, STATUS_TO_P) interface_raise_train_status_changed(train_id, old_status, STATUS_TO_P)
else else
interface_raise_train_dispatch_failed(train_id) interface_raise_train_dispatch_failed(train_id)
@@ -244,8 +241,8 @@ local function tick_dispatch(map_data, mod_settings)
else else
for i, id in ipairs(r_stations) do for i, id in ipairs(r_stations) do
local station = stations[id] local station = stations[id]
if station and band(station.display_state, 1) == 0 then if station and band(station.display_state, 2) == 0 then
station.display_state = station.display_state + 1 station.display_state = station.display_state + 2
update_display(map_data, station) update_display(map_data, station)
end end
end end
@@ -290,8 +287,8 @@ local function tick_dispatch(map_data, mod_settings)
if not r_station_i then if not r_station_i then
for _, id in ipairs(r_stations) do for _, id in ipairs(r_stations) do
local station = stations[id] local station = stations[id]
if station and band(station.display_state, 1) == 0 then if station and band(station.display_state, 2) == 0 then
station.display_state = station.display_state + 1 station.display_state = station.display_state + 2
update_display(map_data, station) update_display(map_data, station)
end end
end end
@@ -303,7 +300,6 @@ local function tick_dispatch(map_data, mod_settings)
---@type string ---@type string
local network_name local network_name
if r_station.network_name == NETWORK_EVERY then if r_station.network_name == NETWORK_EVERY then
--TODO: here
_, _, network_name = string.find(item_network_name, "(^.*):") _, _, network_name = string.find(item_network_name, "(^.*):")
else else
network_name = r_station.network_name network_name = r_station.network_name
@@ -420,23 +416,18 @@ local function tick_dispatch(map_data, mod_settings)
effective_count = p_station.item_p_counts[item_name] effective_count = p_station.item_p_counts[item_name]
override_threshold = p_station.item_thresholds and p_station.item_thresholds[item_name] override_threshold = p_station.item_thresholds and p_station.item_thresholds[item_name]
if override_threshold and p_station.is_stack and item_type == "item" then if override_threshold and p_station.is_stack and not is_fluid then
override_threshold = override_threshold*get_stack_size(map_data, item_name) override_threshold = override_threshold*get_stack_size(map_data, item_name)
end end
if effective_count < (override_threshold or r_threshold) then if effective_count < (override_threshold or r_threshold) then
--this p station should have serviced the current r station, lock it so it can't serve any others --this p station should have serviced the current r station, lock it so it can't serve any others
--this will lock stations even when the r station manages to find a p station, this not a problem because all stations will be unlocked before it could be an issue --this will lock stations even when the r station manages to find a p station, this not a problem because all stations will be unlocked before it could be an issue
table_remove(p_stations, j) table_remove(p_stations, j)
if band(p_station.display_state, 2) == 0 then if band(p_station.display_state, 4) == 0 then
p_station.display_state = p_station.display_state + 2 p_station.display_state = p_station.display_state + 4
update_display(map_data, p_station) update_display(map_data, p_station)
end end
goto p_continue_remove goto p_continue_remove
else
if band(p_station.display_state, 2) == 1 then
p_station.display_state = p_station.display_state - 2
update_display(map_data, p_station)
end
end end
p_prior = p_station.priority p_prior = p_station.priority
@@ -476,8 +467,8 @@ local function tick_dispatch(map_data, mod_settings)
elseif correctness == 4 then elseif correctness == 4 then
send_alert_no_train_matches_p_layout(r_station.entity_stop, closest_to_correct_p_station.entity_stop) send_alert_no_train_matches_p_layout(r_station.entity_stop, closest_to_correct_p_station.entity_stop)
end end
if band(r_station.display_state, 1) == 0 then if band(r_station.display_state, 2) == 0 then
r_station.display_state = r_station.display_state + 1 r_station.display_state = r_station.display_state + 2
update_display(map_data, r_station) update_display(map_data, r_station)
end end
end end
@@ -633,9 +624,21 @@ local function tick_poll_station(map_data, mod_settings)
end end
end end
end end
if is_requesting_nothing and band(station.display_state, 1) == 1 then if station.display_state > 1 then
station.display_state = station.display_state - 1 if is_requesting_nothing and band(station.display_state, 2) == 1 then
update_display(map_data, station) station.display_state = station.display_state - 2
update_display(map_data, station)
end
if band(station.display_state, 8) == 1 then
if band(station.display_state, 4) == 1 then
station.display_state = station.display_state - 4
else
station.display_state = station.display_state - 8
update_display(map_data, station)
end
elseif band(station.display_state, 4) == 1 then
station.display_state = station.display_state + 4
end
end end
end end
return false return false

View File

@@ -392,12 +392,12 @@ function update_display(map_data, station)
local params = control.parameters local params = control.parameters
--NOTE: the following check can cause a bug where the display desyncs if the player changes the operation of the combinator and then changes it back before the mod can notice, however removing it causes a bug where the user's change is overwritten and ignored. Everything's bad we need an event to catch copy-paste by blueprint. --NOTE: the following check can cause a bug where the display desyncs if the player changes the operation of the combinator and then changes it back before the mod can notice, however removing it causes a bug where the user's change is overwritten and ignored. Everything's bad we need an event to catch copy-paste by blueprint.
if params.operation == MODE_PRIMARY_IO or params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then if params.operation == MODE_PRIMARY_IO or params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then
if station.display_state >= 4 then if station.display_state == 0 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 params.operation = MODE_PRIMARY_IO
elseif station.display_state%2 == 1 then
params.operation = MODE_PRIMARY_IO_ACTIVE
else
params.operation = MODE_PRIMARY_IO_FAILED_REQUEST
end end
control.parameters = params control.parameters = params
end end

View File

@@ -65,7 +65,7 @@ function gui_opened(comb, player)
on_click = {"close", comb.unit_number} on_click = {"close", comb.unit_number}
}} }}
}}, }},
{type="frame", name="frame", style="inside_shallow_frame_with_padding", style_mods={padding=12}, children={ {type="frame", name="frame", style="inside_shallow_frame_with_padding", style_mods={padding=12, bottom_padding=10}, children={
{type="flow", name="vflow", direction="vertical", style_mods={horizontal_align="left"}, children={ {type="flow", name="vflow", direction="vertical", style_mods={horizontal_align="left"}, children={
--status --status
{type="flow", style="status_flow", direction="horizontal", style_mods={vertical_align="center", horizontally_stretchable=true, bottom_padding=4}, children={ {type="flow", style="status_flow", direction="horizontal", style_mods={vertical_align="center", horizontally_stretchable=true, bottom_padding=4}, children={
@@ -95,11 +95,11 @@ function gui_opened(comb, player)
---choose-elem-button ---choose-elem-button
{type="line", style_mods={top_padding=10}}, {type="line", style_mods={top_padding=10}},
{type="label", name="network_label", ref={"network_label"}, style="heading_3_label", caption={"cybersyn-gui.network"}, style_mods={top_padding=8}}, {type="label", name="network_label", ref={"network_label"}, style="heading_3_label", caption={"cybersyn-gui.network"}, style_mods={top_padding=8}},
{type="flow", name="bottom", direction="horizontal", style_mods={vertical_align="center", top_margin=0, top_padding=0}, children={ {type="flow", name="bottom", direction="horizontal", style_mods={vertical_align="center"}, children={
{type="choose-elem-button", name="network", style="slot_button_in_shallow_frame", ref={"network"}, elem_type="signal", tooltip={"cybersyn-gui.network-tooltip"}, signal=signal, style_mods={bottom_margin=1, right_margin=6}, actions={ {type="choose-elem-button", name="network", style="slot_button_in_shallow_frame", ref={"network"}, elem_type="signal", tooltip={"cybersyn-gui.network-tooltip"}, signal=signal, style_mods={bottom_margin=1, right_margin=6}, actions={
on_elem_changed={"choose-elem-button", comb.unit_number} on_elem_changed={"choose-elem-button", comb.unit_number}
}}, }},
{type="flow", name="right", direction="vertical", style_mods={horizontal_align="left", top_margin=0, top_padding=0}, children={ {type="flow", name="right", direction="vertical", style_mods={horizontal_align="left"}, children={
{type="flow", name="allow_list", direction="horizontal", style_mods={vertical_align="center"}, children={ {type="flow", name="allow_list", direction="horizontal", style_mods={vertical_align="center"}, children={
{type="checkbox", name="allow_list", ref={"allow_list"}, state=allow_list, tooltip={"cybersyn-gui.allow-list-tooltip"}, actions={ {type="checkbox", name="allow_list", ref={"allow_list"}, state=allow_list, tooltip={"cybersyn-gui.allow-list-tooltip"}, actions={
on_checked_state_changed={"allow_list", comb.unit_number} on_checked_state_changed={"allow_list", comb.unit_number}

View File

@@ -363,12 +363,12 @@ function combinator_update(map_data, comb, reset_display)
station = map_data.stations[id] station = map_data.stations[id]
if should_reset and station and station.entity_comb1 == comb then if should_reset and station and station.entity_comb1 == comb then
--make sure only MODE_PRIMARY_IO gets stored on map_data.to_comb_params --make sure only MODE_PRIMARY_IO gets stored on map_data.to_comb_params
if station.display_state >= 2 then if station.display_state == 0 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 params.operation = MODE_PRIMARY_IO
elseif station.display_state%2 == 1 then
params.operation = MODE_PRIMARY_IO_ACTIVE
else
params.operation = MODE_PRIMARY_IO_FAILED_REQUEST
end end
control.parameters = params control.parameters = params
should_reset = false should_reset = false

View File

@@ -135,7 +135,7 @@ local migrations_table = {
control.parameters = params control.parameters = params
end end
for id, station in pairs(map_data.stations) do for id, station in pairs(map_data.stations) do
station.display_state = (station.display_state >= 2 and 4) + station.display_state%2 station.display_state = (station.display_state >= 2 and 1) + (station.display_state%2)*2
end end
end, end,
} }