mirror of
https://github.com/0ptera/Logistic-Train-Network.git
synced 2025-09-06 20:34:47 +00:00
1.10.4 (#160)
* added valid checks to global.LogisticTrainStops loops * migrate to optera lib
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 1.10.4
|
||||
Date: 2019-03-19
|
||||
Changes:
|
||||
- moved functionality to Opteras Library
|
||||
Bugfixes:
|
||||
- renaming stops in editor can cause errors
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 1.10.3
|
||||
Date: 14.3.2019
|
||||
Date: 2019-03-14
|
||||
Features:
|
||||
- added on_delivery_pickup_complete
|
||||
Changes:
|
||||
@@ -9,7 +16,7 @@ Date: 14.3.2019
|
||||
- fixed potential upgrade path errors
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 1.10.2
|
||||
Date: 7.3.2019
|
||||
Date: 2019-03-07
|
||||
Features:
|
||||
- added Stack Thresholds, only for items of course
|
||||
Changes:
|
||||
@@ -19,7 +26,7 @@ Date: 7.3.2019
|
||||
- fixed potential nil reference #157
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 1.10.1
|
||||
Date: 3.3.2019
|
||||
Date: 2019-03-03
|
||||
Features:
|
||||
- recipes are more affordable with Bob Electronics
|
||||
- added circuit network as dependency for technology
|
||||
@@ -28,7 +35,7 @@ Date: 3.3.2019
|
||||
- switched dependency for creative-mode to the 0.17 re-release
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 1.10.0
|
||||
Date: 27.2.2019
|
||||
Date: 2019-02-27
|
||||
Features:
|
||||
- updated to Factorio 0.17
|
||||
- new thumbnail
|
||||
|
@@ -4,29 +4,9 @@
|
||||
* See LICENSE.md in the project directory for license information.
|
||||
--]]
|
||||
|
||||
local function createIcons(entity)
|
||||
if entity.icons then
|
||||
local icons = {}
|
||||
for k,v in pairs(entity.icons) do
|
||||
-- assume every other mod is written lazy lacking full prototype definitions
|
||||
icons[#icons+1] = { icon = v.icon, icon_size = v.icon_size or entity.icon_size or 32, tint = v.tint }
|
||||
end
|
||||
icons[#icons+1] = { icon = "__LogisticTrainNetwork__/graphics/icons/encoded-position.png", icon_size = 32, tint = {r=1, g=1, b=1, a=1} }
|
||||
-- log(serpent.block(icons))
|
||||
return icons
|
||||
elseif entity.icon then
|
||||
local icons = {
|
||||
{ icon = entity.icon, icon_size = entity.icon_size or 32, tint = {r=1, g=1, b=1, a=1} },
|
||||
{ icon = "__LogisticTrainNetwork__/graphics/icons/encoded-position.png", icon_size = 32, tint = {r=1, g=1, b=1, a=1} }
|
||||
}
|
||||
-- log(serpent.block(icons))
|
||||
return icons
|
||||
else
|
||||
local icons = { icon = "__LogisticTrainNetwork__/graphics/icons/encoded-position.png", icon_size = 32, tint = {r=1, g=1, b=1, a=1} }
|
||||
-- log(serpent.block(icons))
|
||||
return icons
|
||||
end
|
||||
end
|
||||
optera_lib = optera_lib or {}
|
||||
|
||||
local icon_encoded_position = { { icon = "__LogisticTrainNetwork__/graphics/icons/encoded-position.png", icon_size = 32, tint = {r=1, g=1, b=1, a=1} } }
|
||||
|
||||
local lococount = 0
|
||||
for _, loco in pairs(data.raw["locomotive"]) do
|
||||
@@ -34,7 +14,7 @@ for _, loco in pairs(data.raw["locomotive"]) do
|
||||
local signal = {
|
||||
type = "virtual-signal",
|
||||
name = "LTN-"..loco.name,
|
||||
icons = createIcons(loco),
|
||||
icons = optera_lib.create_icons(loco, icon_encoded_position) or icon_encoded_position,
|
||||
icon_size = nil,
|
||||
subgroup = "LTN-signal",
|
||||
order = "z[LTN-signal]-u"..string.format("%02d", lococount),
|
||||
@@ -49,7 +29,7 @@ for _, wagon in pairs(data.raw["cargo-wagon"]) do
|
||||
local signal = {
|
||||
type = "virtual-signal",
|
||||
name = "LTN-"..wagon.name,
|
||||
icons = createIcons(wagon),
|
||||
icons = optera_lib.create_icons(wagon, icon_encoded_position) or icon_encoded_position,
|
||||
icon_size = nil,
|
||||
subgroup = "LTN-signal",
|
||||
order = "z[LTN-signal]-v"..string.format("%02d", wagoncount),
|
||||
@@ -62,7 +42,7 @@ for _, wagon in pairs(data.raw["fluid-wagon"]) do
|
||||
local signal = {
|
||||
type = "virtual-signal",
|
||||
name = "LTN-"..wagon.name,
|
||||
icons = createIcons(wagon),
|
||||
icons = optera_lib.create_icons(wagon, icon_encoded_position) or icon_encoded_position,
|
||||
icon_size = nil,
|
||||
subgroup = "LTN-signal",
|
||||
order = "z[LTN-signal]-v"..string.format("%02d", wagoncount),
|
||||
@@ -75,7 +55,7 @@ for _, wagon in pairs(data.raw["artillery-wagon"]) do
|
||||
local signal = {
|
||||
type = "virtual-signal",
|
||||
name = "LTN-"..wagon.name,
|
||||
icons = createIcons(wagon),
|
||||
icons = optera_lib.create_icons(wagon, icon_encoded_position) or icon_encoded_position,
|
||||
icon_size = nil,
|
||||
subgroup = "LTN-signal",
|
||||
order = "z[LTN-signal]-v"..string.format("%02d", wagoncount),
|
||||
|
3
data.lua
3
data.lua
@@ -4,7 +4,8 @@
|
||||
* See LICENSE.md in the project directory for license information.
|
||||
--]]
|
||||
|
||||
require ("util.copyPrototype")
|
||||
optera_lib = optera_lib or {}
|
||||
|
||||
require ("prototypes.technology")
|
||||
require ("prototypes.recipes")
|
||||
require ("prototypes.items")
|
||||
|
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "LogisticTrainNetwork",
|
||||
"version": "1.10.3",
|
||||
"version": "1.10.4",
|
||||
"title": "LTN - Logistic Train Network",
|
||||
"author": "Optera",
|
||||
"contact": "https://forums.factorio.com/memberlist.php?mode=viewprofile&u=21729",
|
||||
"homepage": "https://forums.factorio.com/viewforum.php?f=214",
|
||||
"description": "Adds new train stops forming a highly configurable, fully automated logistic network.",
|
||||
"factorio_version": "0.17",
|
||||
"dependencies": ["base >= 0.17.11", "?cargo-ships >= 0.0.27", "?creative-mod >= 1.0.4"]
|
||||
"dependencies": ["base >= 0.17.15", "OpteraLib >= 0.1.0", "?cargo-ships >= 0.0.27", "?creative-mod >= 1.0.4"]
|
||||
}
|
||||
|
@@ -4,14 +4,14 @@
|
||||
* See LICENSE.md in the project directory for license information.
|
||||
--]]
|
||||
|
||||
local ltn_stop = copyPrototype("train-stop", "train-stop", "logistic-train-stop")
|
||||
local ltn_stop = optera_lib.copy_prototype(data.raw["train-stop"]["train-stop"], "logistic-train-stop")
|
||||
ltn_stop.icon = "__LogisticTrainNetwork__/graphics/icons/train-stop.png"
|
||||
ltn_stop.icon_size = 32
|
||||
ltn_stop.next_upgrade = nil
|
||||
ltn_stop.selection_box = {{-0.6, -0.6}, {0.6, 0.6}}
|
||||
ltn_stop.collision_box = {{-0.5, -0.1}, {0.5, 0.4}}
|
||||
|
||||
local ltn_stop_in = copyPrototype("lamp", "small-lamp","logistic-train-stop-input")
|
||||
local ltn_stop_in = optera_lib.copy_prototype(data.raw["lamp"]["small-lamp"],"logistic-train-stop-input")
|
||||
ltn_stop_in.icon = "__LogisticTrainNetwork__/graphics/icons/train-stop.png"
|
||||
ltn_stop_in.icon_size = 32
|
||||
ltn_stop_in.next_upgrade = nil
|
||||
@@ -22,7 +22,7 @@ ltn_stop_in.energy_usage_per_tick = "10W"
|
||||
ltn_stop_in.light = { intensity = 1, size = 6 }
|
||||
ltn_stop_in.energy_source = {type="void"}
|
||||
|
||||
local ltn_stop_out = copyPrototype("constant-combinator","constant-combinator","logistic-train-stop-output")
|
||||
local ltn_stop_out = optera_lib.copy_prototype(data.raw["constant-combinator"]["constant-combinator"],"logistic-train-stop-output")
|
||||
ltn_stop_out.icon = "__LogisticTrainNetwork__/graphics/icons/output.png"
|
||||
ltn_stop_out.icon_size = 32
|
||||
ltn_stop_out.next_upgrade = nil
|
||||
@@ -75,7 +75,7 @@ local control_connection_points = {
|
||||
green = util.by_pixel(-1, 0)
|
||||
}
|
||||
|
||||
local ltn_lamp_control = copyPrototype("constant-combinator","constant-combinator","logistic-train-stop-lamp-control")
|
||||
local ltn_lamp_control = optera_lib.copy_prototype(data.raw["constant-combinator"]["constant-combinator"],"logistic-train-stop-lamp-control")
|
||||
ltn_lamp_control.icon = "__LogisticTrainNetwork__/graphics/icons/empty.png"
|
||||
ltn_lamp_control.icon_size = 32
|
||||
ltn_lamp_control.next_upgrade = nil
|
||||
@@ -198,7 +198,7 @@ data:extend({
|
||||
|
||||
-- support for cargo ship ports
|
||||
if mods["cargo-ships"] then
|
||||
ltn_port = copyPrototype("train-stop", "port", "ltn-port")
|
||||
ltn_port = optera_lib.copy_prototype(data.raw["train-stop"]["port"], "ltn-port")
|
||||
ltn_port.selection_box = {{-0.01, -0.6}, {1.9, 0.6}}
|
||||
ltn_port.collision_box = {{-0.01, -0.1}, {1.9, 0.4}}
|
||||
data:extend({
|
||||
|
@@ -4,20 +4,20 @@
|
||||
* See LICENSE.md in the project directory for license information.
|
||||
--]]
|
||||
|
||||
local ltn_stop = copyPrototype("item", "train-stop", "logistic-train-stop")
|
||||
local ltn_stop = optera_lib.copy_prototype(data.raw["item"]["train-stop"], "logistic-train-stop")
|
||||
ltn_stop.icon = "__LogisticTrainNetwork__/graphics/icons/train-stop.png"
|
||||
ltn_stop.icon_size = 32
|
||||
ltn_stop.order = ltn_stop.order.."-c"
|
||||
|
||||
local ltn_stop_in = copyPrototype("item", "small-lamp", "logistic-train-stop-input")
|
||||
local ltn_stop_in = optera_lib.copy_prototype(data.raw["item"]["small-lamp"], "logistic-train-stop-input")
|
||||
ltn_stop_in.flags = {"hidden"}
|
||||
|
||||
local ltn_stop_out = copyPrototype("item", "constant-combinator","logistic-train-stop-output")
|
||||
local ltn_stop_out = optera_lib.copy_prototype(data.raw["item"]["constant-combinator"],"logistic-train-stop-output")
|
||||
ltn_stop_out.flags = {"hidden"}
|
||||
ltn_stop_out.icon = "__LogisticTrainNetwork__/graphics/icons/output.png"
|
||||
ltn_stop_out.icon_size = 32
|
||||
|
||||
local ltn_lamp_control = copyPrototype("item", "constant-combinator","logistic-train-stop-lamp-control")
|
||||
local ltn_lamp_control = optera_lib.copy_prototype(data.raw["item"]["constant-combinator"],"logistic-train-stop-lamp-control")
|
||||
ltn_lamp_control.flags = {"hidden"}
|
||||
ltn_lamp_control.icon = "__LogisticTrainNetwork__/graphics/icons/empty.png"
|
||||
ltn_stop_out.icon_size = 32
|
||||
@@ -31,9 +31,9 @@ data:extend({
|
||||
|
||||
-- support for cargo ship ports
|
||||
if mods["cargo-ships"] then
|
||||
ltn_port = copyPrototype("item", "port", "ltn-port")
|
||||
ltn_port =optera_lib.copy_prototype(data.raw["item"]["port"], "ltn-port")
|
||||
ltn_port.order = ltn_port.order.."-c"
|
||||
|
||||
|
||||
data:extend({
|
||||
ltn_port
|
||||
})
|
||||
|
@@ -4,7 +4,7 @@
|
||||
* See LICENSE.md in the project directory for license information.
|
||||
--]]
|
||||
|
||||
local ltn_stop = copyPrototype("recipe", "train-stop", "logistic-train-stop")
|
||||
local ltn_stop = optera_lib.copy_prototype(data.raw["recipe"]["train-stop"], "logistic-train-stop")
|
||||
ltn_stop.ingredients = {
|
||||
{"train-stop", 1},
|
||||
{"constant-combinator", 1},
|
||||
@@ -20,7 +20,7 @@ data:extend({
|
||||
|
||||
-- support for cargo ship ports
|
||||
if mods["cargo-ships"] then
|
||||
ltn_port = copyPrototype("recipe", "port", "ltn-port")
|
||||
ltn_port =optera_lib.copy_prototype(data.raw["recipe"]["port"], "ltn-port")
|
||||
ltn_port.ingredients = {
|
||||
{"port", 1},
|
||||
{"constant-combinator", 1},
|
||||
|
@@ -163,13 +163,17 @@ end
|
||||
-- ensures removal of trainID from global.Dispatcher.Deliveries and stop.activeDeliveries
|
||||
function RemoveDelivery(trainID)
|
||||
for stopID, stop in pairs(global.LogisticTrainStops) do
|
||||
for i=#stop.activeDeliveries, 1, -1 do --trainID should be unique => checking matching stop name not required
|
||||
if stop.activeDeliveries[i] == trainID then
|
||||
table.remove(stop.activeDeliveries, i)
|
||||
if #stop.activeDeliveries > 0 then
|
||||
setLamp(stop, "yellow", #stop.activeDeliveries)
|
||||
else
|
||||
setLamp(stop, "green", 1)
|
||||
if not stop.entity.valid or not stop.input.valid or not stop.output.valid or not stop.lampControl.valid then
|
||||
RemoveStop(stopID)
|
||||
else
|
||||
for i=#stop.activeDeliveries, 1, -1 do --trainID should be unique => checking matching stop name not required
|
||||
if stop.activeDeliveries[i] == trainID then
|
||||
table.remove(stop.activeDeliveries, i)
|
||||
if #stop.activeDeliveries > 0 then
|
||||
setLamp(stop, "yellow", #stop.activeDeliveries)
|
||||
else
|
||||
setLamp(stop, "green", 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -302,7 +302,9 @@ local function renamedStop(targetID, old_name, new_name)
|
||||
local duplicateName = false
|
||||
local renameDeliveries = true
|
||||
for stopID, stop in pairs(global.LogisticTrainStops) do
|
||||
if stop.entity.backer_name == old_name then
|
||||
if not stop.entity.valid or not stop.input.valid or not stop.output.valid or not stop.lampControl.valid then
|
||||
RemoveStop(stopID)
|
||||
elseif stop.entity.backer_name == old_name then
|
||||
renameDeliveries = false
|
||||
end
|
||||
end
|
||||
|
@@ -199,16 +199,20 @@ local function update_delivery(old_train_id, new_train)
|
||||
|
||||
-- expanded RemoveDelivery(old_train_id) to also update
|
||||
for stopID, stop in pairs(global.LogisticTrainStops) do
|
||||
for i=#stop.activeDeliveries, 1, -1 do --trainID should be unique => checking matching stop name not required
|
||||
if stop.activeDeliveries[i] == old_train_id then
|
||||
if delivery then
|
||||
stop.activeDeliveries[i] = new_train.id -- update train id if delivery exists
|
||||
else
|
||||
table.remove(stop.activeDeliveries, i) -- otherwise remove entry
|
||||
if #stop.activeDeliveries > 0 then
|
||||
setLamp(stop, "yellow", #stop.activeDeliveries)
|
||||
if not stop.entity.valid or not stop.input.valid or not stop.output.valid or not stop.lampControl.valid then
|
||||
RemoveStop(stopID)
|
||||
else
|
||||
for i=#stop.activeDeliveries, 1, -1 do --trainID should be unique => checking matching stop name not required
|
||||
if stop.activeDeliveries[i] == old_train_id then
|
||||
if delivery then
|
||||
stop.activeDeliveries[i] = new_train.id -- update train id if delivery exists
|
||||
else
|
||||
setLamp(stop, "green", 1)
|
||||
table.remove(stop.activeDeliveries, i) -- otherwise remove entry
|
||||
if #stop.activeDeliveries > 0 then
|
||||
setLamp(stop, "yellow", #stop.activeDeliveries)
|
||||
else
|
||||
setLamp(stop, "green", 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,30 +0,0 @@
|
||||
--[[ Copyright (c) 2017 Optera
|
||||
* Part of Logistics Train Network
|
||||
*
|
||||
* See LICENSE.md in the project directory for license information.
|
||||
--]]
|
||||
|
||||
function copyPrototype(type, name, newName)
|
||||
if not data.raw[type][name] then error("type "..type.." "..name.." doesn't exist") end
|
||||
local p = table.deepcopy(data.raw[type][name])
|
||||
p.name = newName
|
||||
if p.minable and p.minable.result then
|
||||
p.minable.result = newName
|
||||
end
|
||||
if p.place_result then
|
||||
p.place_result = newName
|
||||
end
|
||||
if p.result then
|
||||
p.result = newName
|
||||
end
|
||||
if p.results then
|
||||
for _,result in pairs(p.results) do
|
||||
if result.name == name then
|
||||
result.name = newName
|
||||
end
|
||||
end
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
return copyPrototype
|
Reference in New Issue
Block a user