PageRenderTime 66ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/new_engine/bin/levels/convert_map.lua

https://bitbucket.org/DerekMitnik/2chantra
Lua | 60 lines | 53 code | 6 blank | 1 comment | 7 complexity | 2545e69539debca0edc5421ddb898942 MD5 | raw file
  1. if not arg[1] or not arg[2] then
  2. print("usage: "..arg[0].." <old_map_name> <new_map_name>")
  3. return
  4. end
  5. map_file = io.open(arg[1], "r")
  6. new_map = io.open(arg[2], "w")
  7. line = map_file:read()
  8. new_map:write("CreateMap({\n")
  9. while line do
  10. if string.match(line, "group%s*=%s*") then
  11. proto, x1, y1 = string.match(line, "CreateSprite%(%s*(\"[^\"]+\"),%s*([-%d]+),%s*([-%d]+)%)")
  12. line = "NONE"
  13. elseif string.match(line, "GroupObjects") then
  14. x2, y2 = string.match(line, "CreateSprite%(%s*\"[^\"]+\",%s*([-%d]+),%s*([-%d]+)%)")
  15. line = string.format("\t{constants.ObjGroup, %s, %i, %i, %i, %i},", proto, x1, y1, x2, y2)
  16. end
  17. if string.match(line, "phys%-empty") then
  18. if string.match( line, "%-end" ) then
  19. x2, y2 = string.match( line, "\", (%S+), (%S+)" )
  20. y1 = string.gsub(y1, ",.*", "")
  21. y2 = string.gsub(y2, ",.*", "")
  22. line = string.format("\t{constants.ObjGroup, %s, %s, %s, %s, %s},", proto, x1, y1, x2, y2)
  23. else
  24. --print(line)
  25. proto, x1, y1 = string.match( line, "(\"[^\"]+\"), (%S+), (%S+)" )
  26. --print(proto, x1, y1)
  27. line = ""
  28. end
  29. end
  30. z = string.match(line, "nil, ([^)]+)")
  31. if z then
  32. z = string.gsub(z, "%,", "%.")
  33. else
  34. z = ""
  35. end
  36. line = line.gsub(line, ", nil, [^\)]+", "")
  37. line = string.gsub(line, "CreateEnemy%(\"warhead%-launcher\",%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjSpawner, \"technopoke-spawned\", %1, %2, 1, 1, constants.dirAny, 64},")
  38. line = string.gsub(line, "CreateEnemy%(\"penguin_omsk%-spawner%-right\",%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjSpawner, \"slowpoke-spawned\", %1, %2, 1, 1, constants.dirAny, 64},")
  39. line = string.gsub(line, "CreateEnemy%(\"el bitardo\",%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjSpawner, \"btard-spawned\", %1, %2, 1, 1, constants.dirAny, 64},")
  40. line = string.gsub(line, "CreateEnemy%(\"robot%-spawner%-right\",%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjSpawner, \"slowpoke-moonwalking\", %1, %2, 1, 1, constants.dirAny, 64},")
  41. line = string.gsub(line, "CreateEnemy%(\"spawner%-([^\"]+)\",%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjSpawner, \"%1\", %2, %3, 1, 1, constants.dirAny, 64},")
  42. for i=22,43 do
  43. line = string.gsub(line, "CreateSprite%(%s*\"er%-"..i.."f\",%s*(%S+),%s*(%S+)%);?", "")
  44. end
  45. line = string.gsub(line, "CreateSprite%(%s*\"er%-(%d+)f\",%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjTile, \"rock-tiles\", %2, %3, %1, "..z.."},")
  46. line = string.gsub(line, "CreateSprite%(%s*(\"[^\"]+\"),%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjSprite, %1, %2, %3},")
  47. line = string.gsub(line, "CreatePlayer%(%s*(\"[^\"]+\"),%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjPlayer, %1, %2, %3},")
  48. line = string.gsub(line, "CreateItem%(%s*(\"[^\"]+\"),%s*(%S+),%s*(%S+)%);?", "\t{constants.ObjItem, %1, %2, %3},")
  49. if line~="NONE" and line ~= "" then new_map:write(line.."\n") end
  50. line = map_file:read()
  51. end
  52. new_map:write("})\n")
  53. new_map:close()
  54. map_file:close()