mirror of
https://github.com/Xevion/project-cybersyn.git
synced 2025-12-09 14:08:15 -06:00
added active delivery icon
This commit is contained in:
@@ -84,13 +84,19 @@ end
|
||||
---@param comb LuaEntity
|
||||
---@param signals ConstantCombinatorParameters[]?
|
||||
function set_combinator_output(map_data, comb, signals)
|
||||
if comb.valid then
|
||||
local out = map_data.to_output[comb.unit_number]
|
||||
if out.valid then
|
||||
out.get_or_create_control_behavior().parameters = signals
|
||||
end
|
||||
local out = map_data.to_output[comb.unit_number]
|
||||
if out.valid then
|
||||
out.get_or_create_control_behavior().parameters = signals
|
||||
end
|
||||
end
|
||||
---@param comb LuaEntity
|
||||
---@param op string
|
||||
function set_combinator_operation(comb, op)
|
||||
local a = comb.get_or_create_control_behavior()--[[@as LuaArithmeticCombinatorControlBehavior]]
|
||||
local control = a.parameters
|
||||
control.operation = op
|
||||
a.parameters = control
|
||||
end
|
||||
|
||||
---@param map_data MapData
|
||||
---@param station Station
|
||||
@@ -333,6 +339,12 @@ local function send_train_between(map_data, r_station_id, p_station_id, depot, p
|
||||
train.entity.schedule = create_manifest_schedule(train.depot_name, p_station.entity_stop, r_station.entity_stop, manifest)
|
||||
set_comb2(map_data, p_station)
|
||||
set_comb2(map_data, r_station)
|
||||
if p_station.entity_comb1.valid then
|
||||
set_combinator_operation(p_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
|
||||
end
|
||||
if r_station.entity_comb1.valid then
|
||||
set_combinator_operation(r_station.entity_comb1, OPERATION_PRIMARY_IO_ACTIVE)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -32,13 +32,14 @@ function gui_opened(comb, player)
|
||||
local rootgui = player.gui.screen
|
||||
local selected_index = 0
|
||||
local control = comb.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
||||
if control.operation == OPERATION_PRIMARY_IO then
|
||||
local op = control.operation
|
||||
if op == OPERATION_PRIMARY_IO or op == OPERATION_PRIMARY_IO_ACTIVE then
|
||||
selected_index = 1
|
||||
elseif control.operation == OPERATION_SECONDARY_IO then
|
||||
elseif op == OPERATION_SECONDARY_IO then
|
||||
selected_index = 2
|
||||
elseif control.operation == OPERATION_DEPOT then
|
||||
elseif op == OPERATION_DEPOT then
|
||||
selected_index = 3
|
||||
elseif control.operation == OPERATION_WAGON_MANIFEST then
|
||||
elseif op == OPERATION_WAGON_MANIFEST then
|
||||
selected_index = 4
|
||||
end
|
||||
|
||||
@@ -142,28 +143,26 @@ function register_gui_actions()
|
||||
if not comb or not comb.valid then return end
|
||||
|
||||
local parent = element.parent.bottom
|
||||
local a = comb.get_or_create_control_behavior() --[[@as LuaArithmeticCombinatorControlBehavior]]
|
||||
local control = a.parameters
|
||||
if element.selected_index == 1 then
|
||||
control.operation = OPERATION_PRIMARY_IO
|
||||
set_combinator_operation(comb, OPERATION_PRIMARY_IO)
|
||||
element.parent["network_label"].visible = true
|
||||
parent["network"].visible = true
|
||||
parent["radiobutton"].visible = true
|
||||
parent["radiolabel"].visible = true
|
||||
elseif element.selected_index == 2 then
|
||||
control.operation = OPERATION_SECONDARY_IO
|
||||
set_combinator_operation(comb, OPERATION_SECONDARY_IO)
|
||||
element.parent["network_label"].visible = false
|
||||
parent["network"].visible = false
|
||||
parent["radiobutton"].visible = false
|
||||
parent["radiolabel"].visible = false
|
||||
elseif element.selected_index == 3 then
|
||||
control.operation = OPERATION_DEPOT
|
||||
set_combinator_operation(comb, OPERATION_DEPOT)
|
||||
element.parent["network_label"].visible = true
|
||||
parent["network"].visible = true
|
||||
parent["radiobutton"].visible = false
|
||||
parent["radiolabel"].visible = false
|
||||
elseif element.selected_index == 4 then
|
||||
control.operation = OPERATION_WAGON_MANIFEST
|
||||
set_combinator_operation(comb, OPERATION_WAGON_MANIFEST)
|
||||
element.parent["network_label"].visible = false
|
||||
parent["network"].visible = false
|
||||
parent["radiobutton"].visible = false
|
||||
@@ -172,7 +171,6 @@ function register_gui_actions()
|
||||
return
|
||||
end
|
||||
|
||||
a.parameters = control
|
||||
on_combinator_updated(global, comb)
|
||||
elseif msg[1] == "choose-elem-button" then
|
||||
local element = event.element
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
--By Mami
|
||||
local flib_event = require("__flib__.event")
|
||||
|
||||
|
||||
---@param map_data MapData
|
||||
---@param station Station
|
||||
---@param sign int?
|
||||
local function set_comb1(map_data, station, manifest, sign)
|
||||
local comb = station.entity_comb1
|
||||
if comb.valid then
|
||||
if manifest then
|
||||
local signals = {}
|
||||
for i, item in ipairs(manifest) do
|
||||
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = sign*item.count}
|
||||
end
|
||||
set_combinator_output(map_data, comb, signals)
|
||||
else
|
||||
if station.deliveries_total == 0 then
|
||||
set_combinator_operation(comb, OPERATION_PRIMARY_IO)
|
||||
end
|
||||
set_combinator_output(map_data, comb, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param map_data MapData
|
||||
---@param train Train
|
||||
local function on_failed_delivery(map_data, train)
|
||||
@@ -10,7 +32,7 @@ local function on_failed_delivery(map_data, train)
|
||||
local station = map_data.stations[train.p_station_id]
|
||||
remove_manifest(map_data, station, train.manifest, 1)
|
||||
if train.status == STATUS_P then
|
||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
||||
set_comb1(map_data, station, nil)
|
||||
unset_wagon_combs(map_data, station)
|
||||
end
|
||||
end
|
||||
@@ -19,7 +41,7 @@ local function on_failed_delivery(map_data, train)
|
||||
local station = map_data.stations[train.r_station_id]
|
||||
remove_manifest(map_data, station, train.manifest, -1)
|
||||
if train.status == STATUS_R then
|
||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
||||
set_comb1(map_data, station, nil)
|
||||
unset_wagon_combs(map_data, station)
|
||||
end
|
||||
end
|
||||
@@ -224,16 +246,22 @@ local function on_combinator_built(map_data, comb)
|
||||
|
||||
local a = comb.get_or_create_control_behavior()--[[@as LuaArithmeticCombinatorControlBehavior]]
|
||||
local control = a.parameters
|
||||
if control.operation == OPERATION_DEFAULT then
|
||||
control.operation = OPERATION_PRIMARY_IO
|
||||
local op = control.operation
|
||||
if op == OPERATION_DEFAULT then
|
||||
op = OPERATION_PRIMARY_IO
|
||||
control.operation = op
|
||||
control.first_signal = NETWORK_SIGNAL_DEFAULT
|
||||
a.parameters = control
|
||||
elseif op == OPERATION_PRIMARY_IO_ACTIVE then
|
||||
op = OPERATION_PRIMARY_IO
|
||||
control.operation = op
|
||||
a.parameters = control
|
||||
end
|
||||
if control.operation == OPERATION_WAGON_MANIFEST then
|
||||
if op == OPERATION_WAGON_MANIFEST then
|
||||
if rail then
|
||||
force_update_station_from_rail(map_data, rail, nil)
|
||||
end
|
||||
elseif control.operation == OPERATION_DEPOT then
|
||||
elseif op == OPERATION_DEPOT then
|
||||
if stop then
|
||||
local station = map_data.stations[stop.unit_number]
|
||||
---@type Depot
|
||||
@@ -244,7 +272,7 @@ local function on_combinator_built(map_data, comb)
|
||||
on_depot_built(map_data, stop, comb, control)
|
||||
end
|
||||
end
|
||||
elseif control.operation == OPERATION_SECONDARY_IO then
|
||||
elseif op == OPERATION_SECONDARY_IO then
|
||||
if stop then
|
||||
local station = map_data.stations[stop.unit_number]
|
||||
if station and not station.entity_comb2 then
|
||||
@@ -375,11 +403,12 @@ local function on_stop_built(map_data, stop)
|
||||
if entity.valid and entity.name == COMBINATOR_NAME and map_data.to_stop[entity.unit_number] == nil then
|
||||
map_data.to_stop[entity.unit_number] = stop
|
||||
local control = entity.get_or_create_control_behavior().parameters--[[@as ArithmeticCombinatorParameters]]
|
||||
if control.operation == OPERATION_PRIMARY_IO then
|
||||
local op = control.operation
|
||||
if op == OPERATION_PRIMARY_IO then
|
||||
comb1 = entity
|
||||
elseif control.operation == OPERATION_SECONDARY_IO then
|
||||
elseif op == OPERATION_SECONDARY_IO then
|
||||
comb2 = entity
|
||||
elseif control.operation == OPERATION_DEPOT then
|
||||
elseif op == OPERATION_DEPOT then
|
||||
depot_comb = entity
|
||||
end
|
||||
end
|
||||
@@ -525,25 +554,15 @@ local function on_train_arrives_buffer(map_data, stop, train)
|
||||
if train.status == STATUS_D_TO_P then
|
||||
if train.p_station_id == station_id then
|
||||
train.status = STATUS_P
|
||||
--change circuit outputs
|
||||
local station = map_data.stations[station_id]
|
||||
local signals = {}
|
||||
for i, item in ipairs(train.manifest) do
|
||||
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = item.count}
|
||||
end
|
||||
set_combinator_output(map_data, station.entity_comb1, signals)
|
||||
set_comb1(map_data, station, train.manifest, 1)
|
||||
set_p_wagon_combs(map_data, station, train)
|
||||
end
|
||||
elseif train.status == STATUS_P_TO_R then
|
||||
if train.r_station_id == station_id then
|
||||
train.status = STATUS_R
|
||||
--change circuit outputs
|
||||
local station = map_data.stations[station_id]
|
||||
local signals = {}
|
||||
for i, item in ipairs(train.manifest) do
|
||||
signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = -item.count}
|
||||
end
|
||||
set_combinator_output(map_data, station.entity_comb1, signals)
|
||||
set_comb1(map_data, station, train.manifest, -1)
|
||||
set_r_wagon_combs(map_data, station, train)
|
||||
end
|
||||
else
|
||||
@@ -562,6 +581,11 @@ end
|
||||
local function on_train_leaves_station(map_data, train)
|
||||
if train.manifest then
|
||||
if train.status == STATUS_P then
|
||||
train.status = STATUS_P_TO_R
|
||||
local station = map_data.stations[train.p_station_id]
|
||||
remove_manifest(map_data, station, train.manifest, 1)
|
||||
set_comb1(map_data, station, nil)
|
||||
unset_wagon_combs(map_data, station)
|
||||
if train.has_filtered_wagon then
|
||||
train.has_filtered_wagon = false
|
||||
for carriage_i, carriage in ipairs(train.entity.carriages) do
|
||||
@@ -576,16 +600,11 @@ local function on_train_leaves_station(map_data, train)
|
||||
end
|
||||
end
|
||||
end
|
||||
train.status = STATUS_P_TO_R
|
||||
local station = map_data.stations[train.p_station_id]
|
||||
remove_manifest(map_data, station, train.manifest, 1)
|
||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
||||
unset_wagon_combs(map_data, station)
|
||||
elseif train.status == STATUS_R then
|
||||
train.status = STATUS_R_TO_D
|
||||
local station = map_data.stations[train.r_station_id]
|
||||
remove_manifest(map_data, station, train.manifest, -1)
|
||||
set_combinator_output(map_data, station.entity_comb1, nil)
|
||||
set_comb1(map_data, station, nil)
|
||||
unset_wagon_combs(map_data, station)
|
||||
end
|
||||
elseif train.depot then
|
||||
|
||||
Reference in New Issue
Block a user