Advertisement
Guest User

Hyper Light Drifter LVL Parser

a guest
Apr 6th, 2016
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. import re, os
  2.  
  3. def populateResults(regex, line, results):
  4. result = regex.findall(line)
  5. if len(result) > 0:
  6. for element in result:
  7. return results.append(element)
  8.  
  9. def printResults(results, itemName, noItemMessage):
  10. if len(results) > 0:
  11. for element in results:
  12. location = locationRegex.search(element)
  13. exits = exitsRegex.search(element)
  14. if location:
  15. resultString = itemName + ": X: " + location.group(1) + ", Y: " + location.group(2)
  16. if exits:
  17. resultString += ", TO: " + exits.group(1)
  18. print resultString
  19.  
  20. else:
  21. print noItemMessage
  22.  
  23. hldPath = "/Users/me/Library/Application Support/Steam/steamapps/common/HyperLightDrifter/HyperLightDrifter.app/Contents/Resources/"
  24.  
  25. drifterBonesRegex = re.compile("obj,DrifterBones_Outfit.*")
  26. gearbitCrateRegex = re.compile("obj,Spawner.*GearbitCrate.*")
  27. doorRegex = re.compile("obj,door.*")
  28. teleporterRegex = re.compile("obj,Teleporter.*")
  29. elevatorRegex = re.compile("obj,Televator.*")
  30.  
  31. locationRegex = re.compile("\w*,\w*,\d*,(?P<x>-?\d+),(?P<y>-?\d+),.*")
  32. exitsRegex = re.compile(".*r[m?]=(.*),dr=.*")
  33.  
  34. for dirs, subdirs, files in os.walk(hldPath):
  35. for name in files:
  36. relDir = os.path.relpath(dirs, hldPath)
  37. relFile = os.path.join(relDir, name)
  38. if name.endswith(".lvl"):
  39. lvlFile = open(os.path.join(dirs, name), "r")
  40. print "===================="
  41. print relFile
  42. print "===================="
  43.  
  44. drifterBonesResults = []
  45. gearbitCrateResults = []
  46. doorResults = []
  47. teleporterResults = []
  48. elevatorResults = []
  49.  
  50. for line in lvlFile:
  51. populateResults(drifterBonesRegex, line, drifterBonesResults)
  52. populateResults(gearbitCrateRegex, line, gearbitCrateResults)
  53. populateResults(doorRegex, line, doorResults)
  54. populateResults(teleporterRegex, line, teleporterResults)
  55. populateResults(elevatorRegex, line, elevatorResults)
  56.  
  57. print "Items"
  58. print "--------------------"
  59. printResults(drifterBonesResults, "DRIFTER BONES", "NO DRIFTER BONES")
  60. printResults(gearbitCrateResults, "GEARBIT CRATE", "NO GEARBIT CRATES")
  61. print
  62. print "Exits"
  63. print "--------------------"
  64. printResults(doorResults, "DOOR", "NO DOORS")
  65. printResults(teleporterResults, "TELEPORTER", "NO TELEPORTERS")
  66. printResults(elevatorResults, "ELEVATOR", "NO ELEVATORS")
  67.  
  68. print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement