import sys if len(sys.argv) <= 1: exit(0) fielddef = [ ("Amb", "RGB"), ("Amb_Obj", "RGB"), ("Amb_bl", "RGB"), ("Amb_Obj_bl", "RGB"), ("Dir", "RGB"), ("Sky top", "RGB"), ("Sky bot", "RGB"), ("SunCore", "RGB"), ("SunCorona", "RGB"), ("SunSz", "float"), ("SprSz", "float"), ("SprBght", "float"), ("Shdw", "int"), ("LightShd", "int"), ("PoleShd", "int"), ("FarClp", "float"), ("FogSt", "float"), ("radiosityIntensity", "int"), ("radiosityLimit", "int"), ("LightOnGround", "float"), ("LowCloudsRGB", "RGB"), ("TopCloudRGB", "RGB"), ("BottomCloudRGB", "RGB"), ("BlurRGB", "RGB"), ("WaterRGBA", "RGBA"), ("blurAlpha", "float"), ("blurOffset", "float"), ] fieldnames = [d[0] for d in fielddef] weathernames = ["SUNNY", "CLOUDY", "RAINY", "FOGGY", "EXTRASUNNY", "RAINY", "EXTRACOLOURS", "ULTRASUNNY"] NWEATHER = len(weathernames) timenames = ["Midnight", "1AM", "2AM", "3AM", "4AM", "5AM", "6AM", "7AM", "8AM", "9AM", "10AM", "11AM", "Midday", "1PM", "2PM", "3PM", "4PM", "5PM", "6PM", "7PM", "8PM", "9PM", "10PM", "11PM"] NHOUR = len(timenames) def toNumbers(f): def getval(i, t): if t == 'int': try: return (int(f[i]), i+1) except: return (-1000, i+i) elif t == 'float': try: return (float(f[i]), i+1) except: return (1.0, i+i) elif t == 'RGB': try: return ([int(f[i]), int(f[i+1]), int(f[i+2])], i+3) except: return ([-100, -100, -100], i+3) elif t == 'RGBA': try: return ([int(f[i]), int(f[i+1]), int(f[i+2]), int(f[i+3])], i+4) except: return ([-100, -100, -100, -100], i) i = 0 dict = {} for d in fielddef: (dict[d[0]], i) = getval(i, d[1]) return dict def toStrings(weather): s = [] for d in fielddef: if d[1] == 'RGB' or d[1] == 'RGBA': s += [str(x) for x in weather[d[0]]] else: s += [str(weather[d[0]])] return s def getFieldWidths(lines): widths = [] for i in range(len(lines[0])): width = 0 for l in lines: if len(l[i]) > width: width = len(l[i]) widths.append(width) return widths def alignLine(fields, widths): return " ".join([f.rjust(w) for f, w in zip(fields, widths)]) def alignLineR(fields, widths): return " ".join([f.ljust(w) for f, w in zip(fields, widths)]) def combineTuples(lines, widths): newlines = [] for line in lines: l = [f.rjust(w) for f, w in zip(line, widths)] x = [] i = 0 for d in fielddef: if d[1] == 'RGB': x.append(" ".join(l[i:i+3])) i += 3 elif d[1] == 'RGBA': x.append(" ".join(l[i:i+4])) i += 4 else: x.append(l[i]) i += 1 newlines.append(x) return newlines path = sys.argv[1]; f = open(path, 'r') lines = [toNumbers(l.strip('\n').split()) for l in f.readlines() if l[0:2] != '//'] f.close() ## print compact = False lines = [toStrings(l) for l in lines] widths = getFieldWidths(lines) lines = combineTuples(lines, widths) widths = getFieldWidths([fieldnames] + lines) i = 0 for l in lines: if i % NHOUR == 0: print("//") print("/////////////////////////////////////////// " + weathernames[i//NHOUR]) print("//") if NHOUR == 24 and i % 12 == 0 or \ i % NHOUR == 0: if not compact or i % NHOUR == 0: print("// " + alignLineR(fieldnames, widths)) # if not compact or i % 24 == 0 or i % 24 == 12: if not compact: print("// "+timenames[i%NHOUR]) print(" " + alignLineR(l, widths)) i += 1