--[[ Copyright (c) 2017 Optera
 * Part of Loader Redux
 *
 * See LICENSE.md in the project directory for license information.
--]]

function make_loader_entity(name, belt)
  local loader = data.raw["loader"][name] or optera_lib.copy_prototype(data.raw["loader"]["loader"], name)
  loader.flags = {"placeable-neutral", "placeable-player", "player-creation", "fast-replaceable-no-build-while-moving"}
  loader.icon = "__MoreLoaderRedux__/graphics/icon/"..name..".png"
  loader.icon_size = 32

  loader.structure.direction_in.sheet = {
    filename="__MoreLoaderRedux__/graphics/entity/"..name..".png",
    width = 128,
    height = 128,
    hr_version = {
      filename="__MoreLoaderRedux__/graphics/entity/hr-"..name..".png",
      width = 256,
      height = 256,
      scale = 0.5,
    }
  }
  loader.structure.direction_out.sheet ={
    filename="__MoreLoaderRedux__/graphics/entity/"..name..".png",
    width = 128,
    height = 128,
    y = 128,
    hr_version = {
      filename="__MoreLoaderRedux__/graphics/entity/hr-"..name..".png",
      width = 256,
      height = 256,
      y = 256,
      scale = 0.5,
    }
  }
  loader.speed = belt.speed

  -- 0.17 animations
  loader.belt_animation_set = belt.belt_animation_set
  loader.structure_render_layer = "transport-belt-circuit-connector"

  -- 0.16 legacy
  -- loader.belt_horizontal = belt.belt_horizontal or basic_belt_horizontal
  -- loader.belt_vertical   = belt.belt_vertical or basic_belt_vertical
  -- loader.ending_top      = belt.ending_top or basic_belt_ending_top
  -- loader.ending_bottom   = belt.ending_bottom or basic_belt_ending_bottom
  -- loader.ending_side     = belt.ending_side or basic_belt_ending_side
  -- loader.starting_top    = belt.starting_top or basic_belt_starting_top
  -- loader.starting_bottom = belt.starting_bottom or basic_belt_starting_bottom
  -- loader.starting_side   = belt.starting_side or basic_belt_starting_side

  return loader
end

data:extend({
  make_loader_entity("loader", data.raw["transport-belt"]["transport-belt"]),
  make_loader_entity("fast-loader", data.raw["transport-belt"]["fast-transport-belt"]),
  make_loader_entity("express-loader", data.raw["transport-belt"]["express-transport-belt"]),
})
data.raw["loader"]["loader"].next_upgrade = "fast-loader"
data.raw["loader"]["fast-loader"].next_upgrade = "express-loader"
data.raw["loader"]["express-loader"].next_upgrade = nil

if mods["UltimateBelts_Owoshima_And_Pankeko-Mod"] then
  data:extend({
    make_loader_entity("loader", data.raw["transport-belt"]["transport-belt"]),
    make_loader_entity("fast-loader", data.raw["transport-belt"]["fast-transport-belt"]),
    make_loader_entity("express-loader", data.raw["transport-belt"]["express-transport-belt"]),
    make_loader_entity("ultra-fast-loader", data.raw["transport-belt"]["ultra-fast-belt"]),
    make_loader_entity("extreme-fast-loader", data.raw["transport-belt"]["extreme-fast-belt"]),
    make_loader_entity("ultra-express-loader", data.raw["transport-belt"]["ultra-express-belt"]),
    make_loader_entity("extreme-express-loader", data.raw["transport-belt"]["extreme-express-belt"]),
    make_loader_entity("ultimate-loader", data.raw["transport-belt"]["ultimate-belt"]),
  })
  data.raw["loader"]["loader"].next_upgrade = "fast-loader"
  data.raw["loader"]["fast-loader"].next_upgrade = "express-loader"
  data.raw["loader"]["express-loader"].next_upgrade = "ultra-fast-loader"
  data.raw["loader"]["ultra-fast-loader"].next_upgrade = "extreme-fast-loader"
  data.raw["loader"]["extreme-fast-loader"].next_upgrade = "ultra-express-loader"
  data.raw["loader"]["ultra-express-loader"].next_upgrade = "extreme-express-loader"
  data.raw["loader"]["extreme-express-loader"].next_upgrade = "ultimate-loader"
  data.raw["loader"]["ultimate-loader"].next_upgrade = nil
end
