diff --git a/.vscode/settings.json b/.vscode/settings.json index e938c28..13e719a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,7 +23,7 @@ "settings", "rcon", "rendering", - "global", + "storage", "log", "defines", "serpent", diff --git a/control.lua b/control.lua index e3fa6f4..7902162 100644 --- a/control.lua +++ b/control.lua @@ -21,26 +21,26 @@ remote.add_interface("loader-redux", { -- add loader name if it doesn't already exist add_loader = function(name) if name then - global.supported_loaders = global.supported_loaders or {} -- allows on_init of API subscribers be called before on_configuration_changed resets everything - global.supported_loaders[name] = true - global.supported_loader_names = {} - for k, v in pairs(global.supported_loaders) do - table.insert(global.supported_loader_names, k) + storage.supported_loaders = storage.supported_loaders or {} -- allows on_init of API subscribers be called before on_configuration_changed resets everything + storage.supported_loaders[name] = true + storage.supported_loader_names = {} + for k, v in pairs(storage.supported_loaders) do + table.insert(storage.supported_loader_names, k) end - log("global.supported_loaders: "..serpent.block(global.supported_loaders) ) + log("storage.supported_loaders: "..serpent.block(storage.supported_loaders) ) end end, -- remove loader name remove_loader = function(name) if name then - global.supported_loaders = global.supported_loaders or {} -- allows on_init of API subscribers be called before on_configuration_changed resets everything - global.supported_loaders[name] = nil - global.supported_loader_names = {} - for k, v in pairs(global.supported_loaders) do - table.insert(global.supported_loader_names, k) + storage.supported_loaders = storage.supported_loaders or {} -- allows on_init of API subscribers be called before on_configuration_changed resets everything + storage.supported_loaders[name] = nil + storage.supported_loader_names = {} + for k, v in pairs(storage.supported_loaders) do + table.insert(storage.supported_loader_names, k) end - log("global.supported_loaders: "..serpent.block(global.supported_loaders) ) + log("storage.supported_loaders: "..serpent.block(storage.supported_loaders) ) end end }) @@ -54,8 +54,8 @@ end) --Snap loaders on built or correct existing loaders when building next to them. script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event) - local entity = event.created_entity - if entity.type == "loader" and global.supported_loaders[entity.name] then + local entity = event.entity + if entity.type == "loader" and storage.supported_loaders[entity.name] then if use_snapping then snapping.snap_loader(entity, event) end @@ -76,7 +76,7 @@ end) ---- Bootstrap ---- function init_supported_loaders() - global.supported_loaders = {} -- clean old prototype names, API subscribers should be called afterwards + storage.supported_loaders = {} -- clean old prototype names, API subscribers should be called afterwards remote.call("loader-redux", "add_loader", "loader") remote.call("loader-redux", "add_loader", "fast-loader") remote.call("loader-redux", "add_loader", "express-loader") @@ -91,6 +91,6 @@ end) script.on_configuration_changed(function(data) init_supported_loaders() -- wipe unused globals - global.wagons = nil - global.loader_wagon_map = nil + storage.wagons = nil + storage.loader_wagon_map = nil end) diff --git a/graphics/entity/hr-loader-base.png b/graphics/entity/hr-loader-base.png deleted file mode 100644 index 0dca423..0000000 Binary files a/graphics/entity/hr-loader-base.png and /dev/null differ diff --git a/graphics/entity/hr-loader-front-patch.png b/graphics/entity/hr-loader-front-patch.png deleted file mode 100644 index 7258287..0000000 Binary files a/graphics/entity/hr-loader-front-patch.png and /dev/null differ diff --git a/graphics/entity/hr-loader-lights.png b/graphics/entity/hr-loader-lights.png deleted file mode 100644 index 756fd07..0000000 Binary files a/graphics/entity/hr-loader-lights.png and /dev/null differ diff --git a/graphics/entity/hr-loader-mask.png b/graphics/entity/hr-loader-mask.png deleted file mode 100644 index 9495fda..0000000 Binary files a/graphics/entity/hr-loader-mask.png and /dev/null differ diff --git a/graphics/entity/hr-loader-shadow.png b/graphics/entity/hr-loader-shadow.png deleted file mode 100644 index 466457f..0000000 Binary files a/graphics/entity/hr-loader-shadow.png and /dev/null differ diff --git a/graphics/entity/loader-base.png b/graphics/entity/loader-base.png index 7524323..0dca423 100644 Binary files a/graphics/entity/loader-base.png and b/graphics/entity/loader-base.png differ diff --git a/graphics/entity/loader-front-patch.png b/graphics/entity/loader-front-patch.png index 876967c..7258287 100644 Binary files a/graphics/entity/loader-front-patch.png and b/graphics/entity/loader-front-patch.png differ diff --git a/graphics/entity/loader-lights.png b/graphics/entity/loader-lights.png index 5a302b5..756fd07 100644 Binary files a/graphics/entity/loader-lights.png and b/graphics/entity/loader-lights.png differ diff --git a/graphics/entity/loader-mask.png b/graphics/entity/loader-mask.png index 2ca48e7..9495fda 100644 Binary files a/graphics/entity/loader-mask.png and b/graphics/entity/loader-mask.png differ diff --git a/graphics/entity/loader-shadow.png b/graphics/entity/loader-shadow.png index e5959db..466457f 100644 Binary files a/graphics/entity/loader-shadow.png and b/graphics/entity/loader-shadow.png differ diff --git a/info.json b/info.json index 4626ac8..33ff11d 100644 --- a/info.json +++ b/info.json @@ -1,11 +1,11 @@ { "name": "LoaderRedux", - "version": "1.9.1", + "version": "2.0.0", "title": "Loader Redux", "author": "Optera", "contact": "https://forums.factorio.com/memberlist.php?mode=viewprofile&u=21729", "homepage": "https://forums.factorio.com/viewtopic.php?f=97&t=48412", "description": "Adds Loaders capable of snapping to belts. Graphics from Arch666Angel and Kirazy.", - "factorio_version": "1.1", - "dependencies": ["base >= 1.1.75", "flib >= 0.6.0"] + "factorio_version": "2.0", + "dependencies": ["base >= 2.0.0", "flib >= 0.6.0"] } \ No newline at end of file diff --git a/make_loader.lua b/make_loader.lua index e182e51..3880968 100644 --- a/make_loader.lua +++ b/make_loader.lua @@ -1,248 +1,181 @@ ---[[ Copyright (c) 2017 Optera - * Part of Loader Redux - * - * See LICENSE.md in the project directory for license information. ---]] - -local flib = require('__flib__.data-util') -local lr_make_loader = {} - ---- create loader item --- @tparam String name --- @tparam String subgroup --- @tparam String order --- @tparam Types.Color[] tint -function lr_make_loader.make_loader_item(name, subgroup, order, tint) - return{ - type = "item", - name = name, - icons = { - -- Base - { - icon = "__LoaderRedux__/graphics/icon/icon-loader-base.png", - icon_size = 64, - icon_mipmaps = 4, - }, - -- Mask - { - icon = "__LoaderRedux__/graphics/icon/icon-loader-mask.png", - icon_size = 64, - icon_mipmaps = 4, - tint = tint, - }, - }, - subgroup = subgroup, - order = order, - place_result = name, - stack_size = 50 - } -end - ---- create loader entity --- @tparam String name --- @tparam Prototype.TransportBelt[] belt --- @tparam Types.Color[] tint --- @tparam String|nil next_upgrade -function lr_make_loader.make_loader_entity(name, belt, tint, next_upgrade) - local loader = data.raw["loader"][name] or flib.copy_prototype(data.raw["loader"]["loader"], name) - loader.flags = {"placeable-neutral", "placeable-player", "player-creation", "fast-replaceable-no-build-while-moving"} - loader.collision_mask = {"floor-layer", "object-layer", "transport-belt-layer", "water-tile"} -- match belt collision layers - loader.icons = { - -- Base - { - icon = "__LoaderRedux__/graphics/icon/icon-loader-base.png", - icon_size = 64, - icon_mipmaps = 4, - }, - -- Mask - { - icon = "__LoaderRedux__/graphics/icon/icon-loader-mask.png", - icon_size = 64, - icon_mipmaps = 4, - tint = tint, - }, - } - - loader.structure.front_patch = { - sheet = { - filename= "__LoaderRedux__/graphics/entity/loader-front-patch.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-front-patch.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - scale = 0.5, - } - } - - } - loader.structure.direction_in = { - sheets = { - -- Base - { - filename= "__LoaderRedux__/graphics/entity/loader-base.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-base.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - scale = 0.5, - } - }, - -- Mask - { - filename= "__LoaderRedux__/graphics/entity/loader-mask.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - tint = tint, - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-mask.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - tint = tint, - scale = 0.5, - } - }, - -- Shadow - { - filename= "__LoaderRedux__/graphics/entity/loader-shadow.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - draw_as_shadow = true, - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-shadow.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - draw_as_shadow = true, - scale = 0.5, - } - }, - -- Lights - { - filename= "__LoaderRedux__/graphics/entity/loader-lights.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - draw_as_light = true, - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-lights.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - draw_as_light = true, - scale = 0.5, - } - }, - } - } - loader.structure.direction_out = { - sheets = { - -- Base - { - filename= "__LoaderRedux__/graphics/entity/loader-base.png", - priority = "extra-high", - y = 79, - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-base.png", - priority = "extra-high", - y = 155, - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - scale = 0.5, - } - }, - -- Mask - { - filename= "__LoaderRedux__/graphics/entity/loader-mask.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - tint = tint, - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-mask.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - tint = tint, - scale = 0.5, - } - }, - -- Shadow - { - filename= "__LoaderRedux__/graphics/entity/loader-shadow.png", - priority = "extra-high", - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - draw_as_shadow = true, - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-shadow.png", - priority = "extra-high", - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - draw_as_shadow = true, - scale = 0.5, - } - }, - -- Lights - { - filename= "__LoaderRedux__/graphics/entity/loader-lights.png", - priority = "extra-high", - y = 79, - width = 94, - height = 79, - shift = util.by_pixel(10, 2), - draw_as_light = true, - hr_version = { - filename= "__LoaderRedux__/graphics/entity/hr-loader-lights.png", - priority = "extra-high", - y = 155, - width = 186, - height = 155, - shift = util.by_pixel(9.5, 1.5), - draw_as_light = true, - scale = 0.5, - } - }, - } - } - - loader.speed = belt.speed - loader.next_upgrade = next_upgrade - loader.allow_rail_interaction = settings.startup["loader-rail-interaction"].value - loader.structure_render_layer = "object" - - -- -- 0.17 animations - -- loader.belt_animation_set = belt.belt_animation_set - - return loader -end - +--[[ Copyright (c) 2017 Optera + * Part of Loader Redux + * + * See LICENSE.md in the project directory for license information. +--]] + +local flib = require('__flib__.data-util') +local lr_make_loader = {} + +--- create loader item +-- @tparam String name +-- @tparam String subgroup +-- @tparam String order +-- @tparam Types.Color[] tint +function lr_make_loader.make_loader_item(name, subgroup, order, tint) + return{ + type = "item", + name = name, + icons = { + -- Base + { + icon = "__LoaderRedux__/graphics/icon/icon-loader-base.png", + icon_size = 64, + }, + -- Mask + { + icon = "__LoaderRedux__/graphics/icon/icon-loader-mask.png", + icon_size = 64, + tint = tint, + }, + }, + subgroup = subgroup, + order = order, + place_result = name, + stack_size = 50 + } +end + +--- create loader entity +-- @tparam String name +-- @tparam Prototype.TransportBelt[] belt +-- @tparam Types.Color[] tint +-- @tparam String|nil next_upgrade +function lr_make_loader.make_loader_entity(name, belt, tint, next_upgrade) + local loader = data.raw["loader"][name] or flib.copy_prototype(data.raw["loader"]["loader"], name) + loader.flags = {"placeable-neutral", "placeable-player", "player-creation"} + loader.fast_replaceable_group = "loader" + loader.collision_mask = { + layers = { + floor = true, + object = true, + transport_belt = true, + water_tile = true + } + } + loader.icons = { + -- Base + { + icon = "__LoaderRedux__/graphics/icon/icon-loader-base.png", + icon_size = 64, + }, + -- Mask + { + icon = "__LoaderRedux__/graphics/icon/icon-loader-mask.png", + icon_size = 64, + tint = tint, + }, + } + loader.icon = nil -- not needed anymore, if .icons exists + + loader.structure.front_patch = { + sheet = { + filename= "__LoaderRedux__/graphics/entity/loader-front-patch.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + scale = 0.5, + } + } + loader.structure.direction_in = { + sheets = { + -- Base + { + filename= "__LoaderRedux__/graphics/entity/loader-base.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + scale = 0.5, + }, + -- Mask + { + filename= "__LoaderRedux__/graphics/entity/loader-mask.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + tint = tint, + scale = 0.5, + }, + -- Shadow + { + filename= "__LoaderRedux__/graphics/entity/loader-shadow.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + draw_as_shadow = true, + scale = 0.5, + }, + -- Lights + { + filename= "__LoaderRedux__/graphics/entity/loader-lights.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + draw_as_light = true, + scale = 0.5, + } + } + } + loader.structure.direction_out = { + sheets = { + -- Base + { + filename= "__LoaderRedux__/graphics/entity/loader-base.png", + priority = "extra-high", + y = 155, + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + scale = 0.5, + }, + -- Mask + { + filename= "__LoaderRedux__/graphics/entity/loader-mask.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + tint = tint, + scale = 0.5, + }, + -- Shadow + { + filename= "__LoaderRedux__/graphics/entity/loader-shadow.png", + priority = "extra-high", + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + draw_as_shadow = true, + scale = 0.5, + }, + -- Lights + { + filename= "__LoaderRedux__/graphics/entity/loader-lights.png", + priority = "extra-high", + y = 155, + width = 186, + height = 155, + shift = util.by_pixel(9.5, 1.5), + draw_as_light = true, + scale = 0.5, + }, + } + } + + loader.speed = belt.speed + loader.next_upgrade = next_upgrade + loader.allow_rail_interaction = settings.startup["loader-rail-interaction"].value + loader.structure_render_layer = "object" + + -- -- 0.17 animations + -- loader.belt_animation_set = belt.belt_animation_set + + return loader +end + return lr_make_loader \ No newline at end of file diff --git a/prototypes/recipe.lua b/prototypes/recipe.lua index 1468dc9..b819814 100644 --- a/prototypes/recipe.lua +++ b/prototypes/recipe.lua @@ -12,12 +12,14 @@ data:extend({ hidden = false, energy_required = 5, ingredients = { - {"iron-plate", 10}, - {"electronic-circuit", 10}, - {"inserter", 5}, - {"transport-belt", 5}, + {type = "item", name = "iron-plate", amount = 10}, + {type = "item", name = "electronic-circuit", amount = 10}, + {type = "item", name = "inserter", amount = 5}, + {type = "item", name = "transport-belt", amount = 5}, }, - result = "loader" + results = { + {type = "item", name = "loader", amount = 1} + } }, { type = "recipe", @@ -26,12 +28,14 @@ data:extend({ hidden = false, energy_required = 5, ingredients = { - {"iron-gear-wheel", 20}, - {"electronic-circuit", 20}, - {"advanced-circuit", 1}, - {"loader", 1}, + {type = "item", name = "iron-gear-wheel", amount = 20}, + {type = "item", name = "electronic-circuit", amount = 20}, + {type = "item", name = "advanced-circuit", amount = 1}, + {type = "item", name = "loader", amount = 1}, }, - result = "fast-loader" + results = { + {type = "item", name = "fast-loader", amount = 1} + } }, { type = "recipe", @@ -41,11 +45,13 @@ data:extend({ hidden = false, energy_required = 5, ingredients = { - {"iron-gear-wheel", 20}, - {"advanced-circuit", 20}, - {"fast-loader", 1}, - {type="fluid", name="lubricant", amount=80}, + {type = "item", name = "iron-gear-wheel", amount = 20}, + {type = "item", name = "advanced-circuit", amount = 20}, + {type = "item", name = "fast-loader", amount = 1}, + {type = "fluid", name = "lubricant", amount = 80}, }, - result = "express-loader" + results = { + {type= "item", name = "express-loader", amount = 1} + } }, }) diff --git a/script/snapping.lua b/script/snapping.lua index 1d4e0ca..77d8324 100644 --- a/script/snapping.lua +++ b/script/snapping.lua @@ -26,48 +26,42 @@ local function snap_loader_to_target(loader, entity, event) return end - -- loader facing - -- north 0: Loader 0 output or 4 input - -- east 2: Loader 2 output or 6 input - -- south 4: Loader 4 output or 0 input - -- west 6: Loader 6 output or 2 input - local direction = loader.direction local loader_type = loader.loader_type - if loader.direction == 0 or loader.direction == 4 then -- loader and entity are aligned vertically + if loader.direction == defines.direction.north or loader.direction == defines.direction.south then -- loader and entity are aligned vertically if loader.position.y > entity.position.y then - if entity.direction == 4 then - direction = 4 + if entity.direction == defines.direction.south then + direction = defines.direction.south loader_type = "input" else - direction = 0 + direction = defines.direction.north loader_type = "output" end elseif loader.position.y < entity.position.y then - if entity.direction == 0 then - direction = 0 + if entity.direction == defines.direction.north then + direction = defines.direction.north loader_type = "input" else - direction = 4 + direction = defines.direction.south loader_type = "output" end end else -- loader and entity are aligned horizontally if loader.position.x > entity.position.x then - if entity.direction == 2 then - direction = 2 + if entity.direction == defines.direction.east then + direction = defines.direction.east loader_type = "input" else - direction = 6 + direction = defines.direction.west loader_type = "output" end elseif loader.position.x < entity.position.x then - if entity.direction == 6 then - direction = 6 + if entity.direction == defines.direction.west then + direction = defines.direction.west loader_type = "input" else - direction = 2 + direction = defines.direction.east loader_type = "output" end end @@ -89,7 +83,7 @@ local function find_loader_by_entity(entity) {position.x + box.left_top.x-1, position.y + box.left_top.y-1}, {position.x + box.right_bottom.x + 1, position.y + box.right_bottom.y + 1} } - return entity.surface.find_entities_filtered{type="loader", name=global.supported_loader_names, area=area, force=entity.force} + return entity.surface.find_entities_filtered{type="loader", name=storage.supported_loader_names, area=area, force=entity.force} end -- returns entities in front and behind a given loader @@ -112,7 +106,7 @@ end -- called when entity was rotated or non loader was built function snapping.check_for_loaders(event) - local entity = event.created_entity or event.entity + local entity = event.entity if snapTypes[entity.type] then local loaders = find_loader_by_entity(entity) for _, loader in pairs(loaders) do