Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2024
23
0
251 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. from omg import WAD, MapEditor, thinginfo # omgifol
  5.  
  6.  
  7.  
  8. def thingToTuple(thing):
  9.     pos = thing.x, thing.y
  10.  
  11.     try:
  12.         if thing.type not in thinginfo.monsters:
  13.             return None # Not interested in non-monster things
  14.         name = thinginfo.all_num2desc[thing.type]
  15.  
  16.     except KeyError:
  17.         # Seems omg doesn't recognize some things, esp. decorations
  18.         # name = f"thing {thing.type}"
  19.         return None
  20.  
  21.     tup = [name, pos]
  22.  
  23.     flags = []
  24.     if thing.easy: flags.append('E')
  25.     if thing.medium: flags.append('M')
  26.     if thing.hard: flags.append('H')
  27.     # if thing.deaf: flags.append('D')
  28.     if thing.multiplayer: flags.append('U')
  29.     tup.append(''.join(flags))
  30.  
  31.     angle = thing.angle
  32.     # tup.append(angle)
  33.  
  34.     return tuple(tup)
  35.  
  36.  
  37.  
  38. # Get list of all things in a specific map in g_type2def
  39. def mapGetThings(wad_name, map_id):
  40.     print(f"Reading {wad_name}:{map_id}")
  41.     wad = WAD(wad_name)
  42.     edit = MapEditor(wad.maps[map_id])
  43.  
  44.     result = set()
  45.     count = 0
  46.  
  47.     for thing in edit.things:
  48.         thing = thingToTuple(thing)
  49.         if thing is None: continue
  50.  
  51.         if thing in result:
  52.             # We don't handle duplicate tihngs properly, so I'll at
  53.             # least report them.
  54.             print(f"Duplicate: {thing}")
  55.         result.add(thing)
  56.         count += 1
  57.  
  58.     if count != len(result):
  59.         print("Count mismatch") # Duplicates?
  60.     print(f"Found {count} things in {wad_name}:{map_id}")
  61.     print()
  62.     return result
  63.  
  64.  
  65. def main():
  66.     if len(sys.argv) != 5:
  67.         print("Usage: compare.py DOOM2.WAD MAP31 mymap.wad MAP01")
  68.         exit(-1)
  69.  
  70.     wad_src, map_src = sys.argv[1:3]
  71.     wad_new, map_new = sys.argv[3:5]
  72.  
  73.     things_src = mapGetThings(wad_src, map_src)
  74.     things_new = mapGetThings(wad_new, map_new)
  75.  
  76.     extra, missing = [], []
  77.     for thing in things_new:
  78.         if thing not in things_src:
  79.             extra.append(thing)
  80.     for thing in things_src:
  81.         if thing not in things_new:
  82.             missing.append(thing)
  83.  
  84.     if len(extra) + len(missing) == 0:
  85.         print("No mismatches found")
  86.     else:
  87.         print("Mismatches found")
  88.         if len(extra) != 0:
  89.             print(f"Extra things (in {wad_new}:{map_new} but " +
  90.                 f"missing from {wad_src}:{map_src}):")
  91.             for thing in extra:
  92.                 print(f"- {thing}")
  93.         if len(missing) != 0:
  94.             print(f"Missing things (in {wad_src}:{map_src} but " +
  95.                 f"missing from {wad_new}:{map_new}):")
  96.             for thing in missing:
  97.                 print(f"- {thing}")
  98.  
  99.  
  100. if __name__ == "__main__":
  101.     main()
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement