annotate orpg/tools/InterParse.py @ 207:40316be08270 alpha

Traipse Alpha 'OpenRPG' {100428-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 (Patch-2) Getting Ready for Beta! New Features: New Namespace method with two new syntaxes New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode New to Update Manager, checks Repo for updates on software start Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup Fix to Backgrounds not loading through remote loader Fix to Node name errors Fix to rolling dice in chat Whispers Fix to Splitters Sizing issues Fix to URL2Link plugin, modified regex compilation should remove memory leak Fix to mapy.py, a roll back due to zoomed grid issues Fix to whiteboard_handler, Circles work by you clicking the center of the circle Fix to Servers parse_incoming_dom which was outdated and did not respect XML Fix to a broken link in the server welcome message Fix to InterParse and logger requiring traceback Fix to Update Manager Status Bar Fix to failed image and erroneous pop up
author sirebral
date Wed, 28 Apr 2010 01:27:11 -0500
parents a088a1b4aa9b
children 9ac90179e8d8
rev   line source
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
1 #!/usr/bin/env python
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
2 # Copyright (C) 2000-2010 The OpenRPG Project
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
3 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
4 # openrpg-dev@lists.sourceforge.net
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
5 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
6 # This program is free software; you can redistribute it and/or modify
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
7 # it under the terms of the GNU General Public License as published by
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
9 # (at your option) any later version.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
10 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
14 # GNU General Public License for more details.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
15 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
17 # along with this program; if not, write to the Free Software
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
19 # --
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
20 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
21 # File: InterParse.py
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
22 # Author:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
23 # Maintainer: Tyler Starke (Traipse)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
24 # Version:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
25 # $Id: InterParse.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
26 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
27 # Description: InterParse = Interpretor Parser. This class parses all of the node referencing.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
28 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
29
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
30 from orpg.orpgCore import component
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
31 import re
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
32 from orpg.tools.orpg_log import logger
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
33 from wx import TextEntryDialog, ID_OK
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
34 from xml.etree.ElementTree import iselement
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
35
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
36 class InterParse():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
37
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
38 def __init__(self):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
39 pass
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
40
199
0ccfb8836b81 Traipse Alpha 'OpenRPG' {100427-00}
sirebral
parents: 198
diff changeset
41 def Post(self, s, tab=False, send=False, myself=False):
0ccfb8836b81 Traipse Alpha 'OpenRPG' {100427-00}
sirebral
parents: 198
diff changeset
42 if not tab: tab = component.get('chat')
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
43 s = self.Normalize(s, tab)
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
44 tab.set_colors()
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
45 tab.Post(s, send, myself)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
46
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
47 def ParseLogic(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
48 'Nodes now parse through ParsLogic. Easily add new parse rules right here!!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
49 s = self.NameSpaceE(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
50 s = self.NameSpaceI(s, node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
51 s = self.NodeMap(s, node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
52 s = self.NodeParent(s, node.get('map'))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
53 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
54
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
55 def Normalize(self, s, tab):
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
56 for plugin_fname in tab.activeplugins.keys():
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
57 plugin = tab.activeplugins[plugin_fname]
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
58 try: s = plugin.pre_parse(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
59 except Exception, e:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
60 if str(e) != "'module' object has no attribute 'post_msg'":
203
a088a1b4aa9b Traipse Alpha 'OpenRPG' {100427-04}
sirebral
parents: 199
diff changeset
61 #logger.general(traceback.format_exc())
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
62 logger.general("EXCEPTION: " + str(e))
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
63 if tab.parsed == 0:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
64 s = self.NameSpaceE(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
65 s = self.Node(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
66 s = self.Dice(s)
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
67 s = self.Filter(s, tab)
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
68 tab.parsed = 1
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
69 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
70
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
71 def Filter(self, s, tab):
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
72 s = tab.GetFilteredText(s)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
73 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
74
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
75 def Node(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
76 """Parses player input for embedded nodes rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
77 cur_loc = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
78 #[a-zA-Z0-9 _\-\.]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
79 reg = re.compile("(!@(.*?)@!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
80 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
81 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
82 newstr = self.Node(self.resolve_nodes(matches[i][1]))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
83 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
84 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
85
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
86 def Dice(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
87 """Parses player input for embedded dice rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
88 reg = re.compile("\[([^]]*?)\]")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
89 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
90 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
91 newstr = self.Unknown(matches[i])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
92 qmode = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
93 newstr1 = newstr
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
94 if newstr[0].lower() == 'q':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
95 newstr = newstr[1:]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
96 qmode = 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
97 if newstr[0].lower() == '#':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
98 newstr = newstr[1:]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
99 qmode = 2
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
100 try: newstr = component.get('DiceManager').proccessRoll(newstr)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
101 except: pass
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
102 if qmode == 1:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
103 s = s.replace("[" + matches[i] + "]",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
104 "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
105 elif qmode == 2:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
106 s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
107 else: s = s.replace("[" + matches[i] + "]",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
108 "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
109 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
110
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
111 def Unknown(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
112 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
113 newstr = "0"
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
114 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
115 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
116 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
117 lb = "Replace '?' with: "
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
118 if len(matches[i][0]):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
119 lb = matches[i][1] + "?: "
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
120 dlg = TextEntryDialog(component.get('chat'), lb, "Missing Value?")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
121 dlg.SetValue('')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
122 if matches[i][0] != '':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
123 dlg.SetTitle("Enter Value for " + matches[i][1])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
124 if dlg.ShowModal() == ID_OK: newstr = dlg.GetValue()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
125 if newstr == '': newstr = '0'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
126 s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
127 dlg.Destroy()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
128 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
129
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
130 def LocationCheck(self, x, roots, root_list, tree_map):
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
131 roots.append(tree_map[x])
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
132 root_list.append(self.get_node(roots))
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
133 node = root_list[x]
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
134 return node, roots, root_list
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
135
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
136 def FutureCheck(self, node, next):
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
137 future = node.getiterator('nodehandler')
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
138 for advance in future:
207
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
139 print next, advance.get('name')
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
140 if next == advance.get('name'): print True; return True
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
141 return False
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
142
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
143 def NameSpaceI(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
144 reg = re.compile("(!=(.*?)=!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
145 matches = reg.findall(s)
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
146 newstr = False
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
147 nodeable = ['rpg_grid_handler', 'container_handler',
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
148 'group_handler', 'tabber_handler',
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
149 'splitter_handler', 'form_handler', 'textctrl_handler']
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
150 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
151 tree_map = node.get('map').split('::')
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
152 roots = []; root_list = []
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
153 find = matches[i][1].split('::')
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
154 node = self.get_node([tree_map[0]])
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
155 for x in xrange(0, len(tree_map)):
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
156 (node, roots, root_list) = self.LocationCheck(x, roots, root_list, tree_map)
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
157 for x in xrange(0, len(find)):
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
158 namespace = node.getiterator('nodehandler')
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
159 for node in namespace:
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
160 if find[x] == node.get('name'):
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
161 if node.get('class') not in nodeable: continue
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
162 if node.get('class') == 'rpg_grid_handler':
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
163 newstr = self.NameSpaceGrid(find[x+1], node); break
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
164 try:
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
165 if self.FutureCheck(node, find[x+1]): break
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
166 else: continue
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
167 except:
207
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
168 if x == len(find)-1:
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
169 if node.find('text') != None: newstr = str(node.find('text').text)
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
170 else: newstr = 'Invalid Reference!'
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
171 break
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
172 if not newstr: newstr = 'Invalid Reference!'; break
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
173 s = s.replace(matches[i][0], newstr, 1)
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
174 s = self.ParseLogic(s, node)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
175 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
176
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
177 def NameSpaceE(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
178 reg = re.compile("(!&(.*?)&!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
179 matches = reg.findall(s)
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
180 newstr = False
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
181 nodeable = ['rpg_grid_handler', 'container_handler',
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
182 'group_handler', 'tabber_handler',
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
183 'splitter_handler', 'form_handler', 'textctrl_handler']
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
184 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
185 find = matches[i][1].split('::')
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
186 node = component.get('tree').xml_root
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
187 if not iselement(node):
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
188 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
189 s = self.NameSpaceE(s)
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
190 return s
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
191 for x in xrange(0, len(find)):
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
192 namespace = node.getiterator('nodehandler')
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
193 for node in namespace:
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
194 if find[x] == node.get('name'):
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
195 if node.get('class') not in nodeable: continue
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
196 if node.get('class') == 'rpg_grid_handler':
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
197 newstr = self.NameSpaceGrid(find[x+1], node); break
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
198 try:
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
199 if self.FutureCheck(node, find[x+1]): break
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
200 else: continue
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
201 except:
207
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
202 if x == len(find)-1:
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
203 if node.find('text') != None: newstr = str(node.find('text').text)
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
204 else: newstr = 'Invalid Reference!'
40316be08270 Traipse Alpha 'OpenRPG' {100428-00}
sirebral
parents: 203
diff changeset
205 break
197
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
206 else: break
fcd6aafbe232 Traipse Alpha 'OpenRPG' {100426-00}
sirebral
parents: 196
diff changeset
207 if not newstr: newstr = 'Invalid Reference!'
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
208 s = s.replace(matches[i][0], newstr, 1)
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
209 s = self.ParseLogic(s, node)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
210 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
211
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
212 def NameSpaceGrid(self, s, node):
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
213 cell = tuple(s.strip('(').strip(')').split(','))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
214 grid = node.find('grid')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
215 rows = grid.findall('row')
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
216 try:
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
217 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
218 s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
219 except: s = 'Invalid Grid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
220 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
221
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
222 def NodeMap(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
223 """Parses player input for embedded nodes rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
224 cur_loc = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
225 reg = re.compile("(!!(.*?)!!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
226 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
227 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
228 tree_map = node.get('map')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
229 tree_map = tree_map + '::' + matches[i][1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
230 newstr = '!@'+ tree_map +'@!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
231 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
232 s = self.Node(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
233 s = self.NodeParent(s, tree_map)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
234 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
235
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
236 def NodeParent(self, s, tree_map):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
237 """Parses player input for embedded nodes rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
238 cur_loc = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
239 reg = re.compile("(!#(.*?)#!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
240 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
241 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
242 ## Build the new tree_map
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
243 new_map = tree_map.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
244 del new_map[len(new_map)-1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
245 parent_map = matches[i][1].split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
246 ## Backwards Reference the Parent Children
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
247 child_node = self.get_node(new_map)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
248 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
249 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
250 s = self.Node(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
251 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
252
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
253 def get_root(self, child_node, tree_map, new_map, parent_map):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
254 if child_node == 'Invalid Reference!': return child_node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
255 roots = child_node.getchildren(); tr = tree_map.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
256 newstr = ''
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
257 for root in roots:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
258 try: t = new_map.index(root.get('name'))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
259 except: t = 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
260 if parent_map[0] == root.get('name'):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
261 newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
262 if newstr != '': return newstr
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
263 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
264 del new_map[len(new_map)-1]
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
265 child_node = self.get_node(new_map)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
266 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
267 return newstr
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
268
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 195
diff changeset
269 def get_node(self, path):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
270 return_node = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
271 value = ""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
272 depth = len(path)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
273 try: node = component.get('tree').tree_map[path[0]]['node']
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
274 except Exception, e: return return_node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
275 return_node = self.resolve_get_loop(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
276 return return_node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
277
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
278 def resolve_get_loop(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
279 if step == depth: return node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
280 else:
198
e221cd12b820 Traipse Alpha 'OpenRPG' {100426-01}
sirebral
parents: 197
diff changeset
281 child_list = node.getchildren()
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
282 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
283 if step == depth: break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
284 if child.get('name') == path[step]:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
285 node = self.resolve_get_loop(child, path, step+1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
286 return node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
287
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
288 def resolve_nodes(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
289 self.passed = False
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
290 string = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
291 value = ""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
292 path = s.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
293 depth = len(path)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
294 try: node = component.get('tree').tree_map[path[0]]['node']
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
295 except Exception, e: return string
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
296 if node.get('class') in ('dnd35char_handler',
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
297 "SWd20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
298 "d20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
299 "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
300 elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
301 else: string = self.resolve_loop(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
302 return string
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
303
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
304 def resolve_loop(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
305 if step == depth: return self.resolution(node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
306 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
307 child_list = node.findall('nodehandler')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
308 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
309 if step == depth: break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
310 if child.get('name') == path[step]:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
311 node = child
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
312 step += 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
313 if node.get('class') in ('dnd35char_handler',
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
314 "SWd20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
315 "d20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
316 "dnd3echar_handler"):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
317 string = self.resolve_cust_loop(node, path, step, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
318 elif node.get('class') == 'rpg_grid_handler':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
319 string = self.resolve_grid(node, path, step, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
320 else: string = self.resolve_loop(node, path, step, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
321 return string
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
322
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
323 def resolution(self, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
324 if self.passed == False:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
325 self.passed = True
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
326 if node.get('class') == 'textctrl_handler':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
327 s = str(node.find('text').text)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
328 else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
329 else: s = ''
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
330 s = self.ParseLogic(s, node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
331 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
332
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
333 def resolve_grid(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
334 if step == depth:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
335 return 'Invalid Grid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
336 cell = tuple(path[step].strip('(').strip(')').split(','))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
337 grid = node.find('grid')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
338 rows = grid.findall('row')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
339 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
340 try: s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
341 except: s = 'Invalid Grid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
342 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
343
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
344 def resolve_cust_loop(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
345 s = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
346 node_class = node.get('class')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
347 ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ##
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
348 if step == depth: self.resolution(node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
349 ##Build Abilities dictionary##
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
350 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
351 else: ab = node.find('abilities')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
352 ab_list = ab.findall('stat'); pc_stats = {}
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
353
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
354 for ability in ab_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
355 pc_stats[ability.get('name')] = (
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
356 str(ability.get('base')),
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
357 str((int(ability.get('base'))-10)/2) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
358 pc_stats[ability.get('abbr')] = (
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
359 str(ability.get('base')),
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
360 str((int(ability.get('base'))-10)/2) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
361
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
362 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
363 else: ab = node.find('saves')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
364 ab_list = ab.findall('save')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
365 for save in ab_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
366 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]) ) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
367 if save.get('name') == 'Fortitude': abbr = 'Fort'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
368 if save.get('name') == 'Reflex': abbr = 'Ref'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
369 if save.get('name') == 'Will': abbr = 'Will'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
370 pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
371
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
372 if path[step].lower() == 'skill':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
373 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
374 node = node.find('skills')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
375 child_list = node.findall('skill')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
376 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
377 if path[step+1].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
378 if step+2 == depth: s = child.get('rank')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
379 elif path[step+2].lower() == 'check':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
380 s = '<b>Skill Check:</b> ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
381 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
382
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
383 if path[step].lower() == 'feat':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
384 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
385 node = node.find('feats')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
386 child_list = node.findall('feat')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
387 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
388 if path[step+1].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
389 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
390 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
391 if path[step].lower() == 'cast':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
392 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
393 node = node.find('spells')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
394 child_list = node.findall('spell')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
395 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
396 if path[step+1].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
397 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
398 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
399 if path[step].lower() == 'attack':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
400 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
401 if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
402 bonus_text = '(Melee)'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
403 bonus = node.find('attacks')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
404 bonus = bonus.find('melee')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
405 bonus = bonus.attrib; d = int(pc_stats['Str'][1])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
406 elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
407 bonus_text = '(Ranged)'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
408 bonus = node.find('attacks')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
409 bonus = bonus.find('ranged')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
410 bonus = bonus.attrib; d = int(pc_stats['Dex'][1])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
411 for b in bonus:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
412 d += int(bonus[b])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
413 bonus = str(d)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
414 if path[step+2] == None: s= bonus
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
415 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
416 weapons = node.find('attacks')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
417 weapons = weapons.findall('weapon')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
418 for child in weapons:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
419 if path[step+2].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
420 s = '<b>Attack: '+bonus_text+'</b> '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
421 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
422 elif pc_stats.has_key(path[step].title()):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
423 if step+1 == depth: s = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
424 elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
425 elif path[step+1].title() == 'Check': s = '<b>'+path[step].title()+' Check:</b> [1d20+'+str(pc_stats[path[step].title()][1])+']'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
426 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
427 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
428
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
429 Parse = InterParse()