package.path = package.path .. ";./assets/scripts/?.lua"
require "luascape.io"
require "settings"

assets = {}

-- assets directory structure
assets.dirs = {
  character = {
    "tiny",
    "big",
    "utils"
  },
  "levels/tree",
  "levels/baked",
  "levels",
  "navigation",
  "scripts/renderer",
  "scripts/particles",
  "scripts/materials",
  shaders = {
    "hatch"
  },
  sounds = {
    "splitsounds",
    "laser"
  },
  textures = {
    "placeholders/PNG_FINAL_NEU",
    "placeholders",
    "dialogs",
    "dust",
    "fonts",
    "hatch",
    "laser",
    "level",
    "menu",
    "postfx",
    "skybox",
  },
  "typo",
}



local assetManager = AssetManager.instance()

--assetManager:registerProvider(ArchiveProvider("tinyandbig.sca"))

local textureProvider = AssetProviderComposite()
textureProvider.uniqueNameCheckEnabled = false
if settings.textureCompression then
  print("Using compressed textures")
  textureProvider.providers:add(DirectoryProvider("assets/textures/dds"))
  local ap = AliasProvider()
  ap.aliases["png"] = "dds" 
  ap.aliases["jpg"] = "dds" 
  ap.aliases["tga"] = "dds" 
  textureProvider.providers:add(ap)
end
local ap = AliasProvider()
ap.aliases["grossestor_alle.jpg"] = "grossestor_alle.png" 
textureProvider.providers:add(ap)
assetManager:registerProvider(textureProvider)

function assets.registerDir(root, dir)
  if type(dir) == "string" then
    dir = root.."/"..dir
    if root == "assets/textures" or dir == "assets/character/tiny" or dir == "assets/typo" then
      textureProvider.providers:add(DirectoryProvider(dir))
    else
      assetManager:registerDirectory(dir)
    end
  elseif type(dir) == "table" then
    assets.registerDir(root, "")
    for i,j in pairs(dir) do
      local r = root
      if type(i) == "string" then r = root.."/"..i end
      assets.registerDir(r, j)
    end
  end
end

assets.registerDir("assets", assets.dirs)
