Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/control.lua b/control.lua
- index 7254d59..d4c0307 100644
- --- a/control.lua
- +++ b/control.lua
- @@ -15,7 +15,7 @@ end
- -- Returns the channel string corresponding with the current combinator state
- local function get_channel_string(radio, toggle, showlog)
- local cb = radio.get_control_behavior()
- -
- +
- -- Make sure there is always exactly one section
- if cb.sections_count == 0 then
- log("Adding logistic section for "..tostring(radio))
- @@ -26,35 +26,35 @@ local function get_channel_string(radio, toggle, showlog)
- cb.remove_section(2)
- end
- end
- -
- +
- -- If "toggle" is true, it means that the toggle-entity keybind is *about to* change the enable state of this combinator.
- -- It doesn't actually happen until after the linked custom input has executed, so we have to assume that it will toggle in the future.
- if (not cb.enabled and not toggle) or (cb.enabled and toggle) then
- return
- end
- -
- +
- -- Make sure that the first section was created correctly
- local section = cb.get_section(1)
- if not section then
- return
- end
- -
- +
- -- Make sure the first section always stays active. Disable the radio with the constant combinator enable switch.
- if not section.active then
- log("Setting logistic section active for "..tostring(radio))
- section.active = true
- end
- -
- +
- -- If the first section is named (in a group), use the group name as the channel instead of the icons
- - if section.group and section.group ~= "" then
- + if settings.global["shortwave-use-logistic-group-name"].value and section.group and section.group ~= "" then
- return "group."..section.group
- end
- -
- +
- -- Make sure that at least one signal entry is in the section
- if section.filters_count == 0 then
- return
- end
- -
- +
- -- Assemble the channel string using all specified signals and empty slots
- local channel_string = ""
- for i=1,section.filters_count do
- @@ -124,7 +124,7 @@ local function radio_port(radio)
- end
- port.operable = false
- -
- +
- return port
- end
- @@ -132,7 +132,7 @@ end
- local function get_existing_channel(link)
- local team = link.force.index
- if not storage.teams[team] then return end
- -
- +
- -- Find the central link this radio-link is connected to
- local target_relay
- local link_red = link.get_wire_connector(defines.wire_connector_id.circuit_red)
- @@ -142,7 +142,7 @@ local function get_existing_channel(link)
- break
- end
- end
- -
- +
- -- Find the channel this central link is associated with
- if not target_relay then return end
- for channel, relay in pairs(storage.teams[team]) do
- @@ -157,20 +157,20 @@ local function radio_tune(radio, toggle, showlog)
- local team = radio.force.index
- local link = radio_link(radio)
- local port = radio_port(radio)
- -
- +
- -- Check if the channel name changed and log if it did
- local old_channel = get_existing_channel(link)
- local channel = get_channel_string(radio, toggle)
- -
- +
- if (old_channel and channel and old_channel == channel) or (not old_channel and not channel) then
- -- New and old channel are identical, nothing to do here
- return false
- end
- -
- +
- if showlog then
- log("Retuning "..tostring(radio)..": \""..(old_channel and (game.forces[team] and game.forces[team].name or tostring(team)).."::"..old_channel or "<invalid>").."\" became \""..(channel and (game.forces[team] and game.forces[team].name or tostring(team)).."::"..channel or "<disabled>").."\"")
- end
- -
- +
- -- Channel changed, remove old wires if any
- local link_red = link.get_wire_connector(defines.wire_connector_id.circuit_red)
- local link_green = link.get_wire_connector(defines.wire_connector_id.circuit_green)
- @@ -180,7 +180,7 @@ local function radio_tune(radio, toggle, showlog)
- link_red.disconnect_from(connection.target, defines.wire_origin.script)
- end
- end
- -
- +
- for _, connection in pairs(link_green.connections) do
- if connection.target.owner.name == "shortwave-link" then
- link_green.disconnect_from(connection.target, defines.wire_origin.script)
- @@ -217,7 +217,7 @@ local function radio_tune(radio, toggle, showlog)
- local port_red = port.get_wire_connector(defines.wire_connector_id.combinator_input_red)
- local port_green = port.get_wire_connector(defines.wire_connector_id.combinator_input_green)
- -
- +
- link_red.connect_to(port_red, false, defines.wire_origin.script)
- link_green.connect_to(port_green, false, defines.wire_origin.script)
- @@ -227,13 +227,13 @@ end
- local function retune_all(showlog)
- local warning = false
- -
- +
- for _,surface in pairs(game.surfaces) do
- for _,entity in pairs(surface.find_entities_filtered{name="shortwave-radio"}) do
- warning = radio_tune(entity, false, showlog) or warning
- end
- end
- -
- +
- return warning
- end
- @@ -259,7 +259,7 @@ function check_channels(second_time)
- end
- end
- end
- -
- +
- -- If any link was deleted because it was invalid, retune all radios to recreate the link and check again.
- if retune then
- assert(not second_time, "Invalid shortwave radio link could not be corrected.")
- @@ -293,7 +293,7 @@ local function OnEntityCreated(event)
- entity.destroy()
- return
- end
- -
- +
- elseif entity.name == "shortwave-radio" then
- check_state(entity.force)
- radio_tune(entity)
- @@ -329,7 +329,7 @@ local function OnEntityRemoved(event)
- for _, connection in pairs(link_green.connections) do
- link_green.disconnect_from(connection.target, defines.wire_origin.script)
- end
- -
- +
- -- We removed it from the table so it won't show up as invalid in the consistency check. We still have to retune everything that was connected to it.
- retune_all(true)
- break
- @@ -367,6 +367,13 @@ local function OnEntitySettingChanged(event)
- end
- end
- +local function OnLogisticGroupChanged(event)
- +
- + if settings.global["shortwave-use-logistic-group-name"].value then
- + return
- + end
- +end
- +
- remote.add_interface('shortwave', {
- get_channel_merged_signals = function(force, channel)
- @@ -432,6 +439,9 @@ script.on_event(defines.events.on_gui_closed, OnEntitySettingChanged)
- script.on_event(defines.events.on_entity_settings_pasted, OnEntitySettingChanged)
- script.on_event("shortwave-toggle", OnEntitySettingChanged)
- +-- When logistic group changes
- +script.on_event(defines.events.on_entity_logistic_slot_changed, retune_all)
- +
- -- When player pipettes radio
- script.on_event(defines.events.on_player_pipette, function(event)
- local player = game.players[event.player_index]
- @@ -452,12 +462,12 @@ end)
- -- On configuration changed, need to recheck that all the channel signals still exist
- script.on_configuration_changed(function()
- local old_storage = serpent.block(storage)
- -
- +
- -- First retune all channels and make new central links if necessary. Remember to print a warning if any channels changed.
- local warning = retune_all(true)
- -- Then purge unused and invalid links. This might trigger another retune_all() and another check_channels() but nothing will have changed.
- check_channels()
- -
- +
- if warning then
- game.print{"shortwave-message.migration-changed"}
- log{"shortwave-message.migration-log",old_storage,serpent.block(storage)}
- diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg
- index 3d9b6a0..a176a89 100644
- --- a/locale/en/locale.cfg
- +++ b/locale/en/locale.cfg
- @@ -4,6 +4,12 @@ shortwave=Shortwave
- [mod-description]
- shortwave=Connect circuit networks wirelessly via shortwave radio channels.
- +[mod-setting-name]
- +shortwave-use-logistic-group-name=Use Logistic Group Name
- +
- +[mod-setting-description]
- +shortwave-use-logistic-group-name=Whether the Logistic Group Name overrides the signal-based channel or is ignored
- +
- [item-name]
- shortwave-radio=Shortwave Radio
- shortwave-port=Shortwave I/O
- diff --git a/settings.lua b/settings.lua
- new file mode 100644
- index 0000000..a8e5e01
- --- /dev/null
- +++ b/settings.lua
- @@ -0,0 +1,9 @@
- +data:extend{
- +-- Use labels - Map setting
- +{
- +type = "bool-setting",
- +setting_type = "runtime-global",
- +name = "shortwave-use-logistic-group-name",
- +default_value = true
- +},
- +}
Add Comment
Please, Sign In to add comment