annotate orpg/tools/InterParse.py @ 245:682032381be8 beta

Traipse Beta 'OpenRPG' {101130-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 (Closing/Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log New Earthdawn Dieroller New IronClaw roller, sheet, and image Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner Update to Dieroller. Cleaner, more effecient expression system Update to Hidden Die plugin, allows for non standard dice rolls Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug Fix to Gametree for XSLT Sheets Fix to Gametree for locating gametree files Fix to Send to Chat from Gametree Fix to Gametree, renaming and remapping operates correctly Fix to aliaslib, prevents error caused when SafeHTML is sent None
author sirebral
date Tue, 30 Nov 2010 02:34:58 -0600
parents 3bbfd84619c0
children
rev   line source
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
1 #!/usr/bin/env python
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
2 # Copyright (C) 2000-2010 The OpenRPG Project
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
3 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
4 # openrpg-dev@lists.sourceforge.net
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
5 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
6 # This program is free software; you can redistribute it and/or modify
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
7 # it under the terms of the GNU General Public License as published by
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
9 # (at your option) any later version.
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
10 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
11 # This program is distributed in the hope that it will be useful,
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
14 # GNU General Public License for more details.
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
15 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
16 # You should have received a copy of the GNU General Public License
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
17 # along with this program; if not, write to the Free Software
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
19 # --
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
20 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
21 # File: InterParse.py
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
22 # Author:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
23 # Maintainer: Tyler Starke (Traipse)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
24 # Version:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
25 # $Id: InterParse.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
26 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
27 # Description: InterParse = Interpretor Parser. This class parses all of the node referencing.
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
28 #
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
29
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
30 from orpg.orpgCore import component
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
31 import re
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
32 from orpg.tools.orpg_log import logger
194
44ef45e77880 Traipse Beta 'OpenRPG' {100201-03}
sirebral
parents: 192
diff changeset
33 from wx import TextEntryDialog, ID_OK
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
34 from xml.etree.ElementTree import iselement
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
35
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
36 class InterParse():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
37
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
38 def __init__(self):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
39 pass
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
40
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
41 def Post(self, s, tab=False, send=False, myself=False):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
42 if not tab: tab = component.get('chat')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
43 s = self.Normalize(s, tab)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
44 tab.set_colors()
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
45 tab.Post(s, send, myself)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
46
245
682032381be8 Traipse Beta 'OpenRPG' {101130-00}
sirebral
parents: 243
diff changeset
47 def ParseLogic(self, s, node=None):
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
48 'Nodes now parse through ParsLogic. Easily add new parse rules right here!!'
245
682032381be8 Traipse Beta 'OpenRPG' {101130-00}
sirebral
parents: 243
diff changeset
49 if not node: s = self.NameSpaceE(s)
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
50 s = self.NameSpaceI(s, node)
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
51 #s = self.NodeMap(s, node)
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
52 #s = self.NodeParent(s, node)
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
53 return s
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
54
242
72e0cce81a47 Traipse Beta 'OpenRPG' {100817-00}
sirebral
parents: 238
diff changeset
55 def Normalize(self, s, tab=False):
72e0cce81a47 Traipse Beta 'OpenRPG' {100817-00}
sirebral
parents: 238
diff changeset
56 if not tab: tab = component.get('chat')
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
57 for plugin_fname in tab.activeplugins.keys():
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
58 plugin = tab.activeplugins[plugin_fname]
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
59 try: s = plugin.pre_parse(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
60 except Exception, e:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
61 if str(e) != "'module' object has no attribute 'post_msg'":
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
62 #logger.general(traceback.format_exc())
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
63 logger.general("EXCEPTION: " + str(e))
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
64 if tab.parsed == 0:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
65 s = self.NameSpaceE(s)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
66 s = self.Node(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
67 s = self.Dice(s)
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
68 s = self.Filter(s, tab)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
69 tab.parsed = 1
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
70 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
71
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
72 def Filter(self, s, tab):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
73 s = tab.GetFilteredText(s)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
74 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
75
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
76 def Node(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
77 """Parses player input for embedded nodes rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
78 cur_loc = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
79 #[a-zA-Z0-9 _\-\.]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
80 reg = re.compile("(!@(.*?)@!)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
81 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
82 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
83 newstr = self.Node(self.resolve_nodes(matches[i][1]))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
84 s = s.replace(matches[i][0], newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
85 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
86
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
87 def Dice(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
88 """Parses player input for embedded dice rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
89 reg = re.compile("\[([^]]*?)\]")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
90 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
91 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
92 newstr = self.Unknown(matches[i])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
93 qmode = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
94 newstr1 = newstr
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
95 if newstr[0].lower() == 'q':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
96 newstr = newstr[1:]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
97 qmode = 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
98 if newstr[0].lower() == '#':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
99 newstr = newstr[1:]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
100 qmode = 2
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
101 try: newstr = component.get('DiceManager').proccessRoll(newstr)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
102 except: pass
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
103 if qmode == 1:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
104 s = s.replace("[" + matches[i] + "]",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
105 "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
106 elif qmode == 2:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
107 s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
108 else: s = s.replace("[" + matches[i] + "]",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
109 "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
110 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
111
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
112 def Unknown(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
113 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
114 newstr = "0"
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
115 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
116 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
117 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
118 lb = "Replace '?' with: "
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
119 if len(matches[i][0]):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
120 lb = matches[i][1] + "?: "
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
121 dlg = TextEntryDialog(component.get('chat'), lb, "Missing Value?")
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
122 dlg.SetValue('')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
123 if matches[i][0] != '':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
124 dlg.SetTitle("Enter Value for " + matches[i][1])
194
44ef45e77880 Traipse Beta 'OpenRPG' {100201-03}
sirebral
parents: 192
diff changeset
125 if dlg.ShowModal() == ID_OK: newstr = dlg.GetValue()
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
126 if newstr == '': newstr = '0'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
127 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
128 dlg.Destroy()
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
129 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
130
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
131 def LocationCheck(self, node, tree_map, new_map, find):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
132 if node == 'Invalid Reference!': return node
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
133 namespace = node.getiterator('nodehandler'); tr = tree_map.split('::')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
134 newstr = ''
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
135 for name in namespace:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
136 try: t = new_map.index(name.get('name'))-1
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
137 except: t = 0
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
138 if find[0] == name.get('name'):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
139 s = '::'.join(new_map[:len(tr)-t])+'::'+'::'.join(find)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
140 newstr = self.NameSpaceE('!&' +s+ '&!')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
141 break
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
142 if newstr != '': return newstr
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
143 else:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
144 del new_map[len(new_map)-1]
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
145 node = self.get_node(new_map)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
146 newstr = self.LocationCheck(node, tree_map, new_map, find)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
147 return newstr
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
148
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
149 def FutureCheck(self, node, next):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
150 future = node.getiterator('nodehandler')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
151 for advance in future:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
152 if next == advance.get('name'): return True
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
153 return False
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
154
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
155 def NameSpaceI(self, s, node):
222
bb7b9648792c Traipse Beta 'OpenRPG' {100502-00}
sirebral
parents: 212
diff changeset
156 reg1 = re.compile('(!"(.*?)"!)') ## Easter Egg!
bb7b9648792c Traipse Beta 'OpenRPG' {100502-00}
sirebral
parents: 212
diff changeset
157 """If you found this you found my first easter egg. I was tired of people telling me multiple
bb7b9648792c Traipse Beta 'OpenRPG' {100502-00}
sirebral
parents: 212
diff changeset
158 references syntax for the game tree is confusing, so I dropped this in there without telling
bb7b9648792c Traipse Beta 'OpenRPG' {100502-00}
sirebral
parents: 212
diff changeset
159 anyone. Using !" :: "! will allow you to use an internal namespace from within another internal
bb7b9648792c Traipse Beta 'OpenRPG' {100502-00}
sirebral
parents: 212
diff changeset
160 namespace -- TaS, Prof. Ebral"""
bb7b9648792c Traipse Beta 'OpenRPG' {100502-00}
sirebral
parents: 212
diff changeset
161 reg2 = re.compile("(!=(.*?)=!)")
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
162 """Adding the Parent and Child references to Namespace Internal. Namespace 2.0 is powerful enough it
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
163 should be able to handle them with no problem. For future reference, if you are paying attention, Namespace
243
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
164 will include two methods for Internal and External. !@ :: @! and !& :: &! for External and !" :: "! and != :: =!
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
165 for Internal. See above Easter Egg for reasoning."""
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
166 reg3 = re.compile("(!!(.*?)!!)")
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
167 reg4 = re.compile("(!#(.*?)#!)")
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
168 matches = reg1.findall(s) + reg2.findall(s) + reg3.findall(s) + reg4.findall(s)
236
9230a33defd9 Traipse Beta 'OpenRPG' {100616-00}
sirebral
parents: 222
diff changeset
169 try: tree_map = node.get('map')
9230a33defd9 Traipse Beta 'OpenRPG' {100616-00}
sirebral
parents: 222
diff changeset
170 except: return node
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
171 for i in xrange(0,len(matches)):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
172 ## Build the new tree_map
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
173 new_map = tree_map.split('::')
245
682032381be8 Traipse Beta 'OpenRPG' {101130-00}
sirebral
parents: 243
diff changeset
174 if new_map == ['']: new_map = [node.get('name')]
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
175 find = matches[i][1].split('::')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
176 ## Backwards Reference the Parent Children
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
177 node = self.get_node(new_map)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
178 newstr = self.LocationCheck(node, tree_map, new_map, find)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
179 s = s.replace(matches[i][0], newstr, 1)
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
180 s = s.replace(u'\xa0', ' ')
245
682032381be8 Traipse Beta 'OpenRPG' {101130-00}
sirebral
parents: 243
diff changeset
181 s = self.NameSpaceI(s, node)
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
182 return s
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
183
243
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
184 def NameSpaceXE(self, s):
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
185 reg = re.compile("(!&(.*?)&!)")
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
186 matches = reg.findall(s)
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
187 nodeable = ['rpg_grid_handler', 'container_handler',
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
188 'group_handler', 'tabber_handler',
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
189 'splitter_handler', 'form_handler', 'textctrl_handler']
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
190
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
191 for i in xrange(0,len(matches)):
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
192 find = matches[i][1].split('::')
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
193 node = component.get('tree').xml_root
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
194 for x in xrange(0, len(find)):
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
195 namespace = node.getiterator('nodehandler')
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
196 for node in namespace:
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
197 if find[x] == node.get('name'):
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
198 if node.get('class') not in nodeable: continue
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
199 try:
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
200 if self.FutureCheck(node, find[x+1]): break
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
201 else: continue
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
202 except:
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
203 if x == len(find)-1:
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
204 return node
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
205 break
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
206 else: break
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
207 return None
3bbfd84619c0 Traipse Beta 'OpenRPG' {101018-00}
sirebral
parents: 242
diff changeset
208
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
209 def NameSpaceE(self, s):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
210 reg = re.compile("(!&(.*?)&!)")
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
211 matches = reg.findall(s)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
212 newstr = False
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
213 nodeable = ['rpg_grid_handler', 'container_handler',
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
214 'group_handler', 'tabber_handler',
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
215 'splitter_handler', 'form_handler', 'textctrl_handler']
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
216 for i in xrange(0,len(matches)):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
217 find = matches[i][1].split('::')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
218 node = component.get('tree').xml_root
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
219 if not iselement(node):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
220 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
221 s = self.NameSpaceE(s)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
222 return s
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
223 for x in xrange(0, len(find)):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
224 namespace = node.getiterator('nodehandler')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
225 for node in namespace:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
226 if find[x] == node.get('name'):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
227 if node.get('class') not in nodeable: continue
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
228 if node.get('class') == 'rpg_grid_handler':
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
229 try: newstr = self.NameSpaceGrid(find[x+1], node); break
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
230 except: newstr = 'Invalid Grid Reference!'
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
231 try:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
232 if self.FutureCheck(node, find[x+1]): break
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
233 else: continue
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
234 except:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
235 if x == len(find)-1:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
236 if node.find('text') != None: newstr = str(node.find('text').text)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
237 else: newstr = 'Invalid Reference!'
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
238 break
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
239 else: break
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
240 if not newstr: newstr = 'Invalid Reference!'
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
241 s = s.replace(matches[i][0], newstr, 1)
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
242 s = s.replace(u'\xa0', ' ') #Required for XSLT sheets
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
243 s = self.ParseLogic(s, node)
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
244 return s
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
245
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
246 def NameSpaceGrid(self, s, node):
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
247 cell = tuple(s.strip('(').strip(')').split(','))
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
248 grid = node.find('grid')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
249 rows = grid.findall('row')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
250 try:
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
251 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
252 s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
253 except: s = 'Invalid Grid Reference!'
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
254 return s
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
255
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
256 def NodeMap(self, s, node):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
257 """Parses player input for embedded nodes rolls"""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
258 cur_loc = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
259 reg = re.compile("(!!(.*?)!!)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
260 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
261 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
262 tree_map = node.get('map')
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
263 tree_map = str(tree_map + '::' + matches[i][1])
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
264 if tree_map[:2] == '::': tree_map = tree_map[2:]
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
265 newstr = '!@'+ str(tree_map) +'@!'
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
266 s = s.replace(matches[i][0], newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
267 s = self.Node(s)
238
b44dad398833 Traipse Beta 'OpenRPG' {100619-00}
sirebral
parents: 236
diff changeset
268 s = self.NodeParent(s, node)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
269 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
270
236
9230a33defd9 Traipse Beta 'OpenRPG' {100616-00}
sirebral
parents: 222
diff changeset
271 def NodeParent(self, s, node):
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
272 """Parses player input for embedded nodes rolls"""
236
9230a33defd9 Traipse Beta 'OpenRPG' {100616-00}
sirebral
parents: 222
diff changeset
273 if node == 'Invalid Reference!': return node
9230a33defd9 Traipse Beta 'OpenRPG' {100616-00}
sirebral
parents: 222
diff changeset
274 tree_map = node.get('map')
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
275 cur_loc = 0
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
276 reg = re.compile("(!#(.*?)#!)")
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
277 matches = reg.findall(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
278 for i in xrange(0,len(matches)):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
279 ## Build the new tree_map
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
280 new_map = tree_map.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
281 del new_map[len(new_map)-1]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
282 parent_map = matches[i][1].split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
283 ## Backwards Reference the Parent Children
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
284 child_node = self.get_node(new_map)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
285 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
286 s = s.replace(matches[i][0], newstr, 1)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
287 s = self.Node(s)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
288 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
289
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
290 def get_root(self, child_node, tree_map, new_map, parent_map):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
291 if child_node == 'Invalid Reference!': return child_node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
292 roots = child_node.getchildren(); tr = tree_map.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
293 newstr = ''
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
294 for root in roots:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
295 try: t = new_map.index(root.get('name'))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
296 except: t = 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
297 if parent_map[0] == root.get('name'):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
298 newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
299 if newstr != '': return newstr
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
300 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
301 del new_map[len(new_map)-1]
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
302 child_node = self.get_node(new_map)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
303 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
304 return newstr
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
305
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
306 def get_node(self, path):
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
307 return_node = 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
308 value = ""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
309 depth = len(path)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
310 try: node = component.get('tree').tree_map[path[0]]['node']
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
311 except Exception, e: return return_node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
312 return_node = self.resolve_get_loop(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
313 return return_node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
314
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
315 def resolve_get_loop(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
316 if step == depth: return node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
317 else:
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
318 child_list = node.getchildren()
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
319 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
320 if step == depth: break
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
321 if child.get('name') == path[step]:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
322 node = self.resolve_get_loop(child, path, step+1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
323 return node
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
324
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
325 def resolve_nodes(self, s):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
326 self.passed = False
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
327 string = 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
328 value = ""
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
329 path = s.split('::')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
330 depth = len(path)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
331 try: node = component.get('tree').tree_map[path[0]]['node']
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
332 except Exception, e: return string
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
333 if node.get('class') in ('dnd35char_handler',
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
334 "SWd20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
335 "d20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
336 "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
337 elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
338 else: string = self.resolve_loop(node, path, 1, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
339 return string
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
340
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
341 def resolve_loop(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
342 if step == depth: return self.resolution(node)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
343 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
344 child_list = node.findall('nodehandler')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
345 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
346 if step == depth: break
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
347 if child.get('name') == path[step]:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
348 node = child
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
349 step += 1
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
350 if node.get('class') in ('dnd35char_handler',
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
351 "SWd20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
352 "d20char_handler",
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
353 "dnd3echar_handler"):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
354 string = self.resolve_cust_loop(node, path, step, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
355 elif node.get('class') == 'rpg_grid_handler':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
356 string = self.resolve_grid(node, path, step, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
357 else: string = self.resolve_loop(node, path, step, depth)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
358 return string
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
359
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
360 def resolution(self, node):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
361 if self.passed == False:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
362 self.passed = True
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
363 if node.get('class') == 'textctrl_handler':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
364 s = str(node.find('text').text)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
365 else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!'
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
366 else: s = ''
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
367 s = self.ParseLogic(s, node)
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
368 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
369
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
370 def resolve_grid(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
371 if step == depth:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
372 return 'Invalid Grid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
373 cell = tuple(path[step].strip('(').strip(')').split(','))
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
374 grid = node.find('grid')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
375 rows = grid.findall('row')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
376 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
212
13054be69834 Traipse Beta 'OpenRPG' {100428-00}
sirebral
parents: 194
diff changeset
377 try: s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
191
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
378 except: s = 'Invalid Grid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
379 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
380
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
381 def resolve_cust_loop(self, node, path, step, depth):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
382 s = 'Invalid Reference!'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
383 node_class = node.get('class')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
384 ## 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
385 if step == depth: self.resolution(node)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
386 ##Build Abilities dictionary##
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
387 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
388 else: ab = node.find('abilities')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
389 ab_list = ab.findall('stat'); pc_stats = {}
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
390
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
391 for ability in ab_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
392 pc_stats[ability.get('name')] = (
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
393 str(ability.get('base')),
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
394 str((int(ability.get('base'))-10)/2) )
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
395 pc_stats[ability.get('abbr')] = (
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
396 str(ability.get('base')),
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
397 str((int(ability.get('base'))-10)/2) )
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
398
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
399 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
400 else: ab = node.find('saves')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
401 ab_list = ab.findall('save')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
402 for save in ab_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
403 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
404 if save.get('name') == 'Fortitude': abbr = 'Fort'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
405 if save.get('name') == 'Reflex': abbr = 'Ref'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
406 if save.get('name') == 'Will': abbr = 'Will'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
407 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
408
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
409 if path[step].lower() == 'skill':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
410 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
411 node = node.find('skills')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
412 child_list = node.findall('skill')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
413 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
414 if path[step+1].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
415 if step+2 == depth: s = child.get('rank')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
416 elif path[step+2].lower() == 'check':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
417 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
418 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
419
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
420 if path[step].lower() == 'feat':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
421 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
422 node = node.find('feats')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
423 child_list = node.findall('feat')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
424 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
425 if path[step+1].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
426 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
427 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
428 if path[step].lower() == 'cast':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
429 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
430 node = node.find('spells')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
431 child_list = node.findall('spell')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
432 for child in child_list:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
433 if path[step+1].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
434 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
435 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
436 if path[step].lower() == 'attack':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
437 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
438 if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
439 bonus_text = '(Melee)'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
440 bonus = node.find('attacks')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
441 bonus = bonus.find('melee')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
442 bonus = bonus.attrib; d = int(pc_stats['Str'][1])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
443 elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r':
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
444 bonus_text = '(Ranged)'
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
445 bonus = node.find('attacks')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
446 bonus = bonus.find('ranged')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
447 bonus = bonus.attrib; d = int(pc_stats['Dex'][1])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
448 for b in bonus:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
449 d += int(bonus[b])
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
450 bonus = str(d)
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
451 if path[step+2] == None: s= bonus
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
452 else:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
453 weapons = node.find('attacks')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
454 weapons = weapons.findall('weapon')
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
455 for child in weapons:
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
456 if path[step+2].lower() == child.get('name').lower():
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
457 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
458 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
459 elif pc_stats.has_key(path[step].title()):
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
460 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
461 elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1]
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
462 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
463 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
464 return s
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
465
a3d7e05085da Traipse Beta 'OpenRPG' {100201-00}
sirebral
parents:
diff changeset
466 Parse = InterParse()