annotate orpg/tools/InterParse.py @ 191:a3d7e05085da beta

Traipse Beta 'OpenRPG' {100201-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Mon, 01 Feb 2010 09:57:07 -0600
parents
children fb08f5731b5e
rev   line source
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
1 from orpg.orpgCore import component
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
2 import re
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
3 from orpg.tools.orpg_log import logger
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
4
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
5 class InterParse():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
6
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
7 def __init__(self):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
8 pass
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
9
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
10 def Post(self, s, send=False, myself=False):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
11 s = self.Normalize(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
12 component.get('chat').set_colors()
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
13 component.get('chat').Post(s,send,myself)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
14
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
15 def Normalize(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
16 for plugin_fname in component.get('chat').activeplugins.keys():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
17 plugin = component.get('chat').activeplugins[plugin_fname]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
18 try: s = plugin.pre_parse(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
19 except Exception, e:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
20 if str(e) != "'module' object has no attribute 'post_msg'":
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
21 logger.general(traceback.format_exc())
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
22 logger.general("EXCEPTION: " + str(e))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
23 if component.get('chat').parsed == 0:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
24 s = self.Node(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
25 s = self.Dice(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
26 s = self.Filter(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
27 component.get('chat').parsed = 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
28 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
29
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
30 def Filter(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
31 s = component.get('chat').GetFilteredText(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
32 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
33
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
34 def Node(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
35 """Parses player input for embedded nodes rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
36 cur_loc = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
37 #[a-zA-Z0-9 _\-\.]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
38 reg = re.compile("(!@(.*?)@!)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
39 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
40 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
41 newstr = self.Node(self.resolve_nodes(matches[i][1]))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
42 s = s.replace(matches[i][0], newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
43 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
44
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
45 def Dice(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
46 """Parses player input for embedded dice rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
47 reg = re.compile("\[([^]]*?)\]")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
48 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
49 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
50 newstr = self.Unknown(matches[i])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
51 qmode = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
52 newstr1 = newstr
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
53 if newstr[0].lower() == 'q':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
54 newstr = newstr[1:]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
55 qmode = 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
56 if newstr[0].lower() == '#':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
57 newstr = newstr[1:]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
58 qmode = 2
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
59 try: newstr = component.get('DiceManager').proccessRoll(newstr)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
60 except: pass
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
61 if qmode == 1:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
62 s = s.replace("[" + matches[i] + "]",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
63 "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
64 elif qmode == 2:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
65 s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
66 else: s = s.replace("[" + matches[i] + "]",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
67 "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
68 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
69
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
70 def Unknown(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
71 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
72 newstr = "0"
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
73 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
74 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
75 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
76 lb = "Replace '?' with: "
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
77 if len(matches[i][0]):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
78 lb = matches[i][1] + "?: "
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
79 dlg = wx.TextEntryDialog(self, lb, "Missing Value?")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
80 dlg.SetValue('')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
81 if matches[i][0] != '':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
82 dlg.SetTitle("Enter Value for " + matches[i][1])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
83 if dlg.ShowModal() == wx.ID_OK: newstr = dlg.GetValue()
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
84 if newstr == '': newstr = '0'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
85 s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
86 dlg.Destroy()
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
87 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
88
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
89 def NodeMap(self, s, node):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
90 """Parses player input for embedded nodes rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
91 cur_loc = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
92 reg = re.compile("(!!(.*?)!!)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
93 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
94 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
95 tree_map = node.get('map')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
96 tree_map = tree_map + '::' + matches[i][1]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
97 newstr = '!@'+ tree_map +'@!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
98 s = s.replace(matches[i][0], newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
99 s = self.Node(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
100 s = self.NodeParent(s, tree_map)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
101 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
102
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
103 def NodeParent(self, s, tree_map):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
104 """Parses player input for embedded nodes rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
105 cur_loc = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
106 reg = re.compile("(!#(.*?)#!)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
107 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
108 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
109 ## Build the new tree_map
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
110 new_map = tree_map.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
111 del new_map[len(new_map)-1]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
112 parent_map = matches[i][1].split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
113 ## Backwards Reference the Parent Children
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
114 child_node = self.get_node('::'.join(new_map))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
115 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
116 s = s.replace(matches[i][0], newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
117 s = self.Node(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
118 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
119
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
120 def get_root(self, child_node, tree_map, new_map, parent_map):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
121 if child_node == 'Invalid Reference!': return child_node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
122 roots = child_node.getchildren(); tr = tree_map.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
123 newstr = ''
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
124 for root in roots:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
125 try: t = new_map.index(root.get('name'))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
126 except: t = 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
127 if parent_map[0] == root.get('name'):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
128 newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
129 if newstr != '': return newstr
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
130 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
131 del new_map[len(new_map)-1]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
132 child_node = self.get_node('::'.join(new_map))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
133 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
134 return newstr
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
135
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
136 def get_node(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
137 return_node = 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
138 value = ""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
139 path = s.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
140 depth = len(path)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
141 try: node = component.get('tree').tree_map[path[0]]['node']
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
142 except Exception, e: return return_node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
143 return_node = self.resolve_get_loop(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
144 return return_node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
145
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
146 def resolve_get_loop(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
147 if step == depth: return node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
148 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
149 child_list = node.findall('nodehandler')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
150 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
151 if step == depth: break
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
152 if child.get('name') == path[step]:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
153 node = self.resolve_get_loop(child, path, step+1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
154 return node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
155
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
156 def resolve_nodes(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
157 self.passed = False
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
158 string = 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
159 value = ""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
160 path = s.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
161 depth = len(path)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
162 try: node = component.get('tree').tree_map[path[0]]['node']
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
163 except Exception, e: return string
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
164 if node.get('class') in ('dnd35char_handler',
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
165 "SWd20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
166 "d20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
167 "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
168 elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
169 else: string = self.resolve_loop(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
170 return string
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
171
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
172 def resolve_loop(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
173 if step == depth: return self.resolution(node)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
174 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
175 child_list = node.findall('nodehandler')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
176 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
177 if step == depth: break
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
178 if child.get('name') == path[step]:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
179 node = child
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
180 step += 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
181 if node.get('class') in ('dnd35char_handler',
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
182 "SWd20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
183 "d20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
184 "dnd3echar_handler"):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
185 string = self.resolve_cust_loop(node, path, step, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
186 elif node.get('class') == 'rpg_grid_handler':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
187 string = self.resolve_grid(node, path, step, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
188 else: string = self.resolve_loop(node, path, step, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
189 return string
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
190
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
191 def resolution(self, node):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
192 if self.passed == False:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
193 self.passed = True
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
194 if node.get('class') == 'textctrl_handler':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
195 s = str(node.find('text').text)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
196 else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
197 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
198 s = ''
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
199 s = self.NodeMap(s, node)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
200 s = self.NodeParent(s, node.get('map'))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
201 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
202
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
203 def resolve_grid(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
204 if step == depth:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
205 return 'Invalid Grid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
206 cell = tuple(path[step].strip('(').strip(')').split(','))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
207 grid = node.find('grid')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
208 rows = grid.findall('row')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
209 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
210 try: s = self.NodeMap(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
211 except: s = 'Invalid Grid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
212 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
213
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
214 def resolve_cust_loop(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
215 s = 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
216 node_class = node.get('class')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
217 ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ##
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
218 if step == depth: self.resolution(node)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
219 ##Build Abilities dictionary##
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
220 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
221 else: ab = node.find('abilities')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
222 ab_list = ab.findall('stat'); pc_stats = {}
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
223
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
224 for ability in ab_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
225 pc_stats[ability.get('name')] = (
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
226 str(ability.get('base')),
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
227 str((int(ability.get('base'))-10)/2) )
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
228 pc_stats[ability.get('abbr')] = (
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
229 str(ability.get('base')),
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
230 str((int(ability.get('base'))-10)/2) )
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
231
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
232 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
233 else: ab = node.find('saves')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
234 ab_list = ab.findall('save')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
235 for save in ab_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
236 pc_stats[save.get('name')] = (str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
237 if save.get('name') == 'Fortitude': abbr = 'Fort'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
238 if save.get('name') == 'Reflex': abbr = 'Ref'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
239 if save.get('name') == 'Will': abbr = 'Will'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
240 pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
241
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
242 if path[step].lower() == 'skill':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
243 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
244 node = node.find('skills')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
245 child_list = node.findall('skill')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
246 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
247 if path[step+1].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
248 if step+2 == depth: s = child.get('rank')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
249 elif path[step+2].lower() == 'check':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
250 s = '<b>Skill Check:</b> ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
251 print s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
252 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
253
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
254 if path[step].lower() == 'feat':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
255 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
256 node = node.find('feats')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
257 child_list = node.findall('feat')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
258 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
259 if path[step+1].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
260 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
261 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
262 if path[step].lower() == 'cast':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
263 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
264 node = node.find('spells')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
265 child_list = node.findall('spell')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
266 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
267 if path[step+1].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
268 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
269 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
270 if path[step].lower() == 'attack':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
271 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
272 if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
273 bonus_text = '(Melee)'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
274 bonus = node.find('attacks')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
275 bonus = bonus.find('melee')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
276 bonus = bonus.attrib; d = int(pc_stats['Str'][1])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
277 elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
278 bonus_text = '(Ranged)'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
279 bonus = node.find('attacks')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
280 bonus = bonus.find('ranged')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
281 bonus = bonus.attrib; d = int(pc_stats['Dex'][1])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
282 for b in bonus:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
283 d += int(bonus[b])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
284 bonus = str(d)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
285 if path[step+2] == None: s= bonus
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
286 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
287 weapons = node.find('attacks')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
288 weapons = weapons.findall('weapon')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
289 for child in weapons:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
290 if path[step+2].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
291 s = '<b>Attack: '+bonus_text+'</b> '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
292 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
293 elif pc_stats.has_key(path[step].title()):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
294 if step+1 == depth: s = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
295 elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
296 elif path[step+1].title() == 'Check': s = '<b>'+path[step].title()+' Check:</b> [1d20+'+str(pc_stats[path[step].title()][1])+']'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
297 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
298 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
299
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
300 Parse = InterParse()