Module:AocUtils: Difference between revisions

From ZeldaMods (Breath of the Wild)
Jump to navigation Jump to search
imported>Leoetlino
No edit summary
imported>Leoetlino
(optimise)
 
(9 intermediate revisions by the same user not shown)
Line 2: Line 2:


aoc_resource_prefixes = {
aoc_resource_prefixes = {
   "^Terrain/A/AocField",
   "Terrain/A/AocField",
   "^UI/StaffRollDLC/",
   "UI/StaffRollDLC/",
   "^Map/MainField/",
   "Map/MainField/",
   "^Map/MainFieldDungeon/",
   "Map/MainFieldDungeon/",
   "^Map/AocField/",
   "Map/AocField/",
   "^Physics/StaticCompound/AocField/",
   "Physics/StaticCompound/AocField/",
   "^Physics/StaticCompound/MainFieldDungeon/",
   "Physics/StaticCompound/MainFieldDungeon/",
   "^Movie/Demo6",
   "Movie/Demo6",
   "^Game/AocField/",
   "Game/AocField/",
   "^NavMesh/AocField/",
   "NavMesh/AocField/",
   "^NavMesh/MainFieldDungeon/",
   "NavMesh/MainFieldDungeon/",
   "^Physics/TeraMeshRigidBody/AocField/",
   "Physics/TeraMeshRigidBody/AocField/",
   "^Voice/.*/Stream_Demo6.*/.*\.bfstm$",
   "System/AocVersion.txt",
  "^System/AocVersion\.txt$",
   "Pack/RemainsWind.pack",
   "^Pack/RemainsWind.pack$",
   "Pack/RemainsElectric.pack",
   "^Pack/RemainsElectric.pack$",
   "Pack/RemainsWater.pack",
   "^Pack/RemainsWater.pack$",
   "Pack/RemainsFire.pack",
   "^Pack/RemainsFire.pack$",
   "Pack/FinalTrial.pack",
   "^Pack/FinalTrial.pack$",
}
}
local function starts_with(str, start)
  return str:sub(1, #start) == start
end
local function ends_with(str, ending)
  return ending == "" or str:sub(-#ending) == ending
end


function has_aoc_dungeon_num(s)
function has_aoc_dungeon_num(s)
Line 34: Line 41:
function should_use_aoc_file_device(path)
function should_use_aoc_file_device(path)
   for i, p in ipairs(aoc_resource_prefixes) do
   for i, p in ipairs(aoc_resource_prefixes) do
     if string.find(path, p) then
     if starts_with(path, p) then
       return true
       return true
     end
     end
   end
   end
   if string.find(path, "^Pack/") and string.find(path, "\.pack$") and has_aoc_dungeon_num(path) then
   if string.find(path, "^Voice/.*/Stream_Demo6.*/.*\.bfstm$") then
  return true
  end
  if starts_with(path, "Pack/") and ends_with(path, ".pack") and has_aoc_dungeon_num(path) then
return true
return true
   end
   end
   if string.find(path, "^Map/CDungeon/") and has_aoc_dungeon_num(path) then
   if starts_with(path, "Map/CDungeon/") and has_aoc_dungeon_num(path) then
return true
return true
   end
   end
   if string.find(path, "^Physics/StaticCompound/") and has_aoc_dungeon_num(path) then
   if starts_with(path, "Physics/StaticCompound/") and has_aoc_dungeon_num(path) then
return true
return true
   end
   end
   if string.find(path, "^NavMesh/CDungeon/") and has_aoc_dungeon_num(path) then
   if starts_with(path, "NavMesh/CDungeon/") and has_aoc_dungeon_num(path) then
return true
return true
   end
   end
Line 54: Line 64:


function pack.get_aoc_canonical_path(frame)
function pack.get_aoc_canonical_path(frame)
   path = frame.args['path']
   local path = frame.args.path
  local aoc_only = frame.args.aoc_only == "true"
   if not path then
   if not path then
   return ""
   return "(unknown)"
   end
   end
   if should_use_aoc_file_device(path) then
   if aoc_only or should_use_aoc_file_device(path) then
   return "Aoc/0010/" + path
   return "Aoc/0010/" .. path
   end
   end
   return path
   return path

Latest revision as of 17:07, 21 September 2018

Documentation for this module may be created at Module:AocUtils/doc

local pack = {}

aoc_resource_prefixes = {
  "Terrain/A/AocField",
  "UI/StaffRollDLC/",
  "Map/MainField/",
  "Map/MainFieldDungeon/",
  "Map/AocField/",
  "Physics/StaticCompound/AocField/",
  "Physics/StaticCompound/MainFieldDungeon/",
  "Movie/Demo6",
  "Game/AocField/",
  "NavMesh/AocField/",
  "NavMesh/MainFieldDungeon/",
  "Physics/TeraMeshRigidBody/AocField/",
  "System/AocVersion.txt",
  "Pack/RemainsWind.pack",
  "Pack/RemainsElectric.pack",
  "Pack/RemainsWater.pack",
  "Pack/RemainsFire.pack",
  "Pack/FinalTrial.pack",
}

local function starts_with(str, start)
   return str:sub(1, #start) == start
end

local function ends_with(str, ending)
   return ending == "" or str:sub(-#ending) == ending
end

function has_aoc_dungeon_num(s)
  local dungeon_num_str = string.match(s, "Dungeon(%d%d%d)")
  if dungeon_num_str == nil then
  	return false
  end
  local dungeon_num = tonumber(dungeon_num_str)
  return dungeon_num > 119
end

function should_use_aoc_file_device(path)
  for i, p in ipairs(aoc_resource_prefixes) do
    if starts_with(path, p) then
      return true
    end
  end
  if string.find(path, "^Voice/.*/Stream_Demo6.*/.*\.bfstm$") then
  	return true
  end
  if starts_with(path, "Pack/") and ends_with(path, ".pack") and has_aoc_dungeon_num(path) then
	return true
  end
  if starts_with(path, "Map/CDungeon/") and has_aoc_dungeon_num(path) then
	return true
  end
  if starts_with(path, "Physics/StaticCompound/") and has_aoc_dungeon_num(path) then
	return true
  end
  if starts_with(path, "NavMesh/CDungeon/") and has_aoc_dungeon_num(path) then
	return true
  end
  return false
end

function pack.get_aoc_canonical_path(frame)
  local path = frame.args.path
  local aoc_only = frame.args.aoc_only == "true"
  if not path then
  	return "(unknown)"
  end
  if aoc_only or should_use_aoc_file_device(path) then
  	return "Aoc/0010/" .. path
  end
  return path
end

return pack