fixed failed delivery bug

This commit is contained in:
monica
2023-01-07 17:14:02 -05:00
committed by Monica Moniot
parent 1821dc1ccc
commit e7446e11c1
4 changed files with 24 additions and 18 deletions

View File

@@ -13,6 +13,15 @@ local trains_tab = require("scripts.gui.trains")
--local alerts_tab = require("scripts.gui.alerts") --local alerts_tab = require("scripts.gui.alerts")
--- @class PlayerData
--- @field refs {[string]: LuaGuiElement}?
--- @field search_query string?
--- @field network_name string
--- @field network_flag int
--- @field pinning boolean
function Index:dispatch(msg, e) function Index:dispatch(msg, e)
-- "Transform" the action based on criteria -- "Transform" the action based on criteria
if msg.transform == "handle_refresh_click" then if msg.transform == "handle_refresh_click" then
@@ -64,13 +73,13 @@ function manager.build(player, player_data)
type = "frame", type = "frame",
direction = "vertical", direction = "vertical",
visible = false, visible = false,
handler = manager_handle.close, handler = manager.handle.close,
children = { children = {
{ {
name = "manager_titlebar", name = "manager_titlebar",
type = "flow", type = "flow",
style = "flib_titlebar_flow", style = "flib_titlebar_flow",
handler = manager_handle.titlebar_click, handler = manager.handle.titlebar_click,
children = { children = {
{ type = "label", style = "frame_title", caption = { "mod-name.LtnManager" }, ignored_by_interaction = true }, { type = "label", style = "frame_title", caption = { "mod-name.LtnManager" }, ignored_by_interaction = true },
{ type = "empty-widget", style = "flib_titlebar_drag_handle", ignored_by_interaction = true }, { type = "empty-widget", style = "flib_titlebar_drag_handle", ignored_by_interaction = true },
@@ -83,9 +92,9 @@ function manager.build(player, player_data)
tooltip = { "gui.ltnm-dispatcher-disabled-description" }, tooltip = { "gui.ltnm-dispatcher-disabled-description" },
visible = not settings.global["cybersyn-enable-planner"].value, visible = not settings.global["cybersyn-enable-planner"].value,
}, },
templates.frame_action_button("manager_pin_button", "ltnm_pin", { "gui.ltnm-keep-open" }, manager_handle.pin),--on_gui_clicked templates.frame_action_button("manager_pin_button", "ltnm_pin", { "gui.ltnm-keep-open" }, manager.handle.pin),--on_gui_clicked
templates.frame_action_button("manager_refresh_button", "ltnm_refresh", { "gui.ltnm-refresh-tooltip" }, manager_handle.refresh_click),--on_gui_clicked templates.frame_action_button("manager_refresh_button", "ltnm_refresh", { "gui.ltnm-refresh-tooltip" }, manager.handle.refresh_click),--on_gui_clicked
templates.frame_action_button(nil, "utility/close", { "gui.close-instruction" }, manager_handle.close),--on_gui_clicked templates.frame_action_button(nil, "utility/close", { "gui.close-instruction" }, manager.handle.close),--on_gui_clicked
}, },
}, },
{ {
@@ -102,7 +111,7 @@ function manager.build(player, player_data)
name = "manager_text_search_field", name = "manager_text_search_field",
type = "textfield", type = "textfield",
clear_and_focus_on_right_click = true, clear_and_focus_on_right_click = true,
handler = manager_handle.update_text_search_query, --on_gui_text_changed handler = manager.handle.update_text_search_query, --on_gui_text_changed
}, },
{ type = "empty-widget", style = "flib_horizontal_pusher" }, { type = "empty-widget", style = "flib_horizontal_pusher" },
{ type = "label", style = "caption_label", caption = { "gui.ltnm-network-id-label" } }, { type = "label", style = "caption_label", caption = { "gui.ltnm-network-id-label" } },
@@ -114,13 +123,13 @@ function manager.build(player, player_data)
allow_negative = true, allow_negative = true,
clear_and_focus_on_right_click = true, clear_and_focus_on_right_click = true,
text = "-1", text = "-1",
handler = manager_handle.update_network_id_query, --on_gui_text_changed handler = manager.handle.update_network_id_query, --on_gui_text_changed
}, },
{ type = "label", style = "caption_label", caption = { "gui.ltnm-surface-label" } }, { type = "label", style = "caption_label", caption = { "gui.ltnm-surface-label" } },
{ {
name = "manager_surface_dropdown", name = "manager_surface_dropdown",
type = "drop-down", type = "drop-down",
handler = manager_handle.change_surface, --on_gui_selection_state_changed handler = manager.handle.change_surface, --on_gui_selection_state_changed
}, },
}, },
}, },
@@ -194,7 +203,7 @@ function manager.wrapper(e, handler)
local player = game.get_player(e.player_index) local player = game.get_player(e.player_index)
if not player then return end if not player then return end
local player_data = global.manager.players[e.player_index] local player_data = global.manager.players[e.player_index]
handler(player, player_data, refs) handler(player, player_data, player_data.refs)
end end
@@ -237,13 +246,14 @@ end
--- @param player LuaPlayer --- @param player LuaPlayer
--- @param player_data PlayerData --- @param player_data PlayerData
--- @param refs table<string, LuaGuiElement> --- @param refs table<string, LuaGuiElement>
function manager.handle.update_text_search_query(player, player_data, refs) --- @param e GuiEventData
function manager.handle.update_text_search_query(player, player_data, refs, e)
local query = e.text local query = e.text
-- Input sanitization -- Input sanitization
for pattern, replacement in pairs(constants.input_sanitizers) do for pattern, replacement in pairs(constants.input_sanitizers) do
query = string.gsub(query, pattern, replacement) query = string.gsub(query, pattern, replacement)
end end
Gui.state.search_query = query player_data.search_query = query
if Gui.state.search_job then if Gui.state.search_job then
on_tick_n.remove(Gui.state.search_job) on_tick_n.remove(Gui.state.search_job)

View File

@@ -55,6 +55,9 @@ end
---@param train_id uint ---@param train_id uint
---@param train Train ---@param train Train
function remove_train(map_data, train_id, train) function remove_train(map_data, train_id, train)
if train.manifest then
on_failed_delivery(map_data, train_id, train)
end
remove_available_train(map_data, train_id, train) remove_available_train(map_data, train_id, train)
local layout_id = train.layout_id local layout_id = train.layout_id

View File

@@ -162,7 +162,6 @@ local function on_station_broken(map_data, station_id, station)
local is_r_in_progress = is_p_in_progress or train.status == STATUS_TO_R or train.status == STATUS_R local is_r_in_progress = is_p_in_progress or train.status == STATUS_TO_R or train.status == STATUS_R
if (is_p and is_p_in_progress) or (is_r and is_r_in_progress) then if (is_p and is_p_in_progress) or (is_r and is_r_in_progress) then
--train is attempting delivery to a stop that was destroyed, stop it --train is attempting delivery to a stop that was destroyed, stop it
on_failed_delivery(map_data, train_id, train)
if not train.se_is_being_teleported then if not train.se_is_being_teleported then
remove_train(map_data, train_id, train) remove_train(map_data, train_id, train)
lock_train(train.entity) lock_train(train.entity)

View File

@@ -379,9 +379,6 @@ end
function on_train_broken(map_data, train_id, train) function on_train_broken(map_data, train_id, train)
--NOTE: train.entity is only absent if the train is climbing a space elevator as of 0.5.0 --NOTE: train.entity is only absent if the train is climbing a space elevator as of 0.5.0
if not train.se_is_being_teleported then if not train.se_is_being_teleported then
if train.manifest then
on_failed_delivery(map_data, train_id, train)
end
remove_train(map_data, train_id, train) remove_train(map_data, train_id, train)
end end
end end
@@ -391,9 +388,6 @@ local function on_train_modified(map_data, pre_train_id)
local train = map_data.trains[pre_train_id] local train = map_data.trains[pre_train_id]
--NOTE: train.entity is only absent if the train is climbing a space elevator as of 0.5.0 --NOTE: train.entity is only absent if the train is climbing a space elevator as of 0.5.0
if train and not train.se_is_being_teleported then if train and not train.se_is_being_teleported then
if train.manifest then
on_failed_delivery(map_data, pre_train_id, train)
end
remove_train(map_data, pre_train_id, train) remove_train(map_data, pre_train_id, train)
end end
end end