from pynwn.creature import Creature def check_vars(obj): for var, val in obj.vars.string.list(): try: x = int(val) print (" %s: Variable %s (%s) is convertable to int!" % (obj.resref, var, val)) continue # continue since if it's convertible to int it will also convert to float. except: pass try: x = float(val) print(" %s: Variable %s (%s) is convertable to float!" % (obj.resref, var, val)) except: pass if __name__ == '__main__': mod = Module('test.mod') print("Checking blueprints...") for obj in chain(mod.glob('*.ut[cdeimptw]'), mod.areas): check_vars(obj) print("\nChecking instances...") for area in mod.areas: for obj in chain(area.creatures, area.doors, area.placeables, area.triggers, area.stores, area.encounters, area.waypoints, area.items): check_vars(obj)
res = res + '\n' return res.rjust(justify + len(res)) def node_to_str(node, level): result = fmt(node.get_text(0), level) for ptr in node.pointers: node = ptr.get_node(ptr.index) # Make sure the dialog pointer isn't a link or else # there would be an infinite loop. if not ptr.is_link: level += 1 result += node_to_str(node, level) level -= 1 else: # Add extra indent for links... result += fmt(node.get_text(0), level + 1, True) return result result = '' for start in [s.index for s in dlg.starts]: result += node_to_str(dlg.entries[start], 0) return result if __name__ == '__main__': mod = Module('test.mod') for dlg in mod.glob('*.dlg'): print(dlg.resref) print(dialog_to_str(dlg), '\n\n')
for var, val in obj.vars.string.list(): try: x = int(val) print(" %s: Variable %s (%s) is convertable to int!" % (obj.resref, var, val)) continue # continue since if it's convertible to int it will also convert to float. except: pass try: x = float(val) print(" %s: Variable %s (%s) is convertable to float!" % (obj.resref, var, val)) except: pass if __name__ == '__main__': mod = Module('test.mod') print("Checking blueprints...") for obj in chain(mod.glob('*.ut[cdeimptw]'), mod.areas): check_vars(obj) print("\nChecking instances...") for area in mod.areas: for obj in chain(area.creatures, area.doors, area.placeables, area.triggers, area.stores, area.encounters, area.waypoints, area.items): check_vars(obj)
import enchant import enchant.checker from enchant.checker.CmdLineChecker import CmdLineChecker from pynwn.module import Module if __name__ == '__main__': # Using US english dictionary. chkr = enchant.checker.SpellChecker('en_US') cmdln = CmdLineChecker() cmdln.set_checker(chkr) mod = Module('test.mod') for dlg in mod.glob('*.dlg'): print(dlg.resref) for n in dlg.entries: if n.get_text(0) is None or len(n.get_text(0)) == 0: continue print n.get_text(0) chkr.set_text(n.get_text(0)) cmdln.run() n.set_text(0, chkr.get_text()) for n in dlg.replies: if n.get_text(0) is None or len(n.get_text(0)) == 0: continue print(n.get_text(0))