Advertisement
Guest User

wmo_light_adder.py

a guest
Aug 13th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Author: Garthog
  2. # You need to download gamh's pyWMO, then create a new file where you paste this code.
  3. # Don't forget to create a folder "output" where you run this file.
  4. # Also, you need Python 3.3
  5.  
  6. import sys
  7. from pywmo import Wmo
  8.  
  9. wmo_name = input('Enter WMO Filename : ');
  10. building = Wmo(wmo_name);
  11.  
  12. nLight = building.num_lights;
  13.  
  14. print("There are " + str(nLight) + " lights in this WMO.");
  15.  
  16. while(1):
  17.     command = input("What do you want to do ?\n\"a\" - Add a light\n\"i\" - Get informations about a light\n\"q\" - Exit\n")
  18.    
  19.     if(command == "q"):
  20.        
  21.         while(1):
  22.             save = input("Do you want to save (yes/no) ? ")
  23.            
  24.             if save.upper() == "YES":
  25.                 print("Saving file")
  26.                 building.write_file("./output/" + wmo_name)
  27.                 break;
  28.             elif save.upper() == "NO":
  29.                 print("Exiting without saving")
  30.                 break;
  31.             else:
  32.                 print("You have to write \"yes\" or \"no\"");
  33.                
  34.         print("See ya later");    
  35.         sys.exit();
  36.     elif(command == "a"):
  37.         print("Light definition")
  38.        
  39.         light = { }
  40.        
  41.         light["flag1"] = int(input("LightType : "))
  42.         light["flag2"] = int(input("type : "))
  43.         light["flag3"] = int(input("useAtten : "))
  44.         light["flag4"] = int(input("pad : "))
  45.        
  46.         light["color"] = (int(input("B : ")), int(input("G : ")), int(input("R : ")), int(input("A : ")))
  47.         light["position"] = (float(input("X : ")), float(input("Y : ")), float(input("Z : ")))
  48.        
  49.         light["intensity"] = float(input("intensity : "))
  50.        
  51.         light["attenuation_start"] = float(input("attenuation_start : "))
  52.         light["attenuation_stop"] = float(input("attenuation_stop : "))
  53.        
  54.         light["unknown1"] = float(input("Unknown 1 : "))
  55.         light["unknown2"] = float(input("Unknown 2 : "))
  56.         light["unknown3"] = float(input("Unknown 3 : "))
  57.         light["unknown4"] = float(input("Unknown 4 : "))
  58.        
  59.         building.num_lights += 1;
  60.         building.lights.append(light);
  61.            
  62.         print("There are " + str(len(building.groups)) + " groups")
  63.        
  64.         while(1):
  65.             group = input("In which group do you want to reference that light ( type \"m\" to return the main menu ) ? ")
  66.            
  67.             if(group == "s"):
  68.                 break;
  69.            
  70.             group = int(group)
  71.            
  72.             if(group >= 0 and group < len(building.groups)):
  73.            
  74.                 if not building.groups[group].flags & 0x200:
  75.                     building.groups[group].flags &= 0x200
  76.                     building.groups[group].light_refs = []
  77.                    
  78.                 building.groups[group].light_refs.append(building.num_lights - 1)
  79.                 print("Light ref added to group " + str(group))
  80.             else:
  81.                 print("Bad group.")
  82.        
  83.        
  84.         print("Light succefully added. There are now " + str(building.num_lights) + " lights.")
  85.        
  86.     elif(command == "i"):
  87.         while(1):
  88.             subcommand = input("Type \"l\" to list all lights, or just type a number to print info of that specific light\n( type \"m\" to return the main menu )\n")
  89.            
  90.             if(subcommand == "m"):
  91.                 break;
  92.             elif(subcommand == "l"):
  93.                 i = 0;
  94.                 while i < building.num_lights:
  95.                     print("Light " + str(i) + " X: " + str(building.lights[i]["position"][0]) + " Y: "
  96.                     + str(building.lights[i]["position"][1]) + " Z:" + str(building.lights[i]["position"][2]));
  97.                     i += 1
  98.             elif(subcommand.isdigit()):
  99.                 light_index = int(subcommand)
  100.                 if light_index >= 0 and light_index < building.num_lights:
  101.                     print("Informations of light " + subcommand)
  102.                     print("Flags " + str(building.lights[light_index]["flag1"]) + " " + str(building.lights[light_index]["flag2"])
  103.                     + "  " + str(building.lights[light_index]["flag3"]) + " " + str(building.lights[light_index]["flag4"]))
  104.                     print("Color ( BGRA ) " + str(building.lights[light_index]["color"][0]) + " "+ str(building.lights[light_index]["color"][1]) + " "
  105.                         + str(building.lights[light_index]["color"][2]) + " "+ str(building.lights[light_index]["color"][3]))
  106.                     print("Position X:" + str(building.lights[light_index]["position"][0]) + " Y: "
  107.                     + str(building.lights[light_index]["position"][1]) + " Z:" + str(building.lights[light_index]["position"][2]));
  108.                     print("Intensity " + str(building.lights[light_index]["intensity"]))
  109.                     print("Attenuation Start " + str(building.lights[light_index]["attenuation_start"]))
  110.                     print("Attenuation Stop " + str(building.lights[light_index]["attenuation_stop"]))
  111.                     print("Unknown floats " + str(building.lights[light_index]["unknown1"]) + " " + str(building.lights[light_index]["unknown2"]) + " "
  112.                     + str(building.lights[light_index]["unknown3"]) + " " + str(building.lights[light_index]["unknown4"]))
  113.                    
  114.                     for i in range(len(building.groups)):
  115.                         if building.groups[i].flags & 0x200:
  116.                             if light_index in building.groups[i].light_refs:
  117.                                 print("Referenced in group " + str(i))
  118.                                
  119.                 else:
  120.                     print("This light doesn't exist.")
  121.     else:
  122.         print("Unknown command")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement