annotate orpg/tools/InterParse.py @ 34:1fb663829ef6 ornery-orc

Traipse 'OpenRPG' {100504-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) http://traipse.assembla.com/wiki/show/traipse/Patch-2 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 Namespace 2.0 documentation in the User Manual New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @! New Mini Library with minis from Devin Knight 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 New to Mini Lib node, change title in design mode New to Game Tree, never lose a node, appends a number to the end of corrupted trees New to Server GUI, Traipse Suite's Debug Console New Warhammer PC Sheet Updates: Update to White Board layer, uses a pencil image for color button Update to Grid Layer, uses a grid image for color button Update to Chat Window, size of drop down menus Update to default lobby message Update to template Text node Update to 4e PC Sheet node Update to how display names are acquired Update to Server, added some 'Pious' technology Update to features node 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 Fix to Mini Lib node that was preventing use Fix to plugins that parce dice but did not call InterParse Fix to nodes for name changing by double click Fix to Game Tree, node ordering on drag and drop corrected Fix to Game Tree, corrupted error message was not showing Fix to Update Manager, checks for internet connection Fix to Update Manager, Auto Update corrections Fix to Server GUI's broadcast, room, player messaging
author sirebral
date Tue, 04 May 2010 10:43:29 -0500
parents fc48380f0c9f
children d02e9197c066
rev   line source
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
1 #!/usr/bin/env python
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
2 # Copyright (C) 2000-2010 The OpenRPG Project
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
3 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
4 # openrpg-dev@lists.sourceforge.net
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
5 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
6 # This program is free software; you can redistribute it and/or modify
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
7 # it under the terms of the GNU General Public License as published by
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
9 # (at your option) any later version.
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
10 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
11 # This program is distributed in the hope that it will be useful,
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
14 # GNU General Public License for more details.
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
15 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
16 # You should have received a copy of the GNU General Public License
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
17 # along with this program; if not, write to the Free Software
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
19 # --
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
20 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
21 # File: InterParse.py
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
22 # Author:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
23 # Maintainer: Tyler Starke (Traipse)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
24 # Version:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
25 # $Id: InterParse.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
26 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
27 # Description: InterParse = Interpretor Parser. This class parses all of the node referencing.
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
28 #
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
29
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
30 from orpg.orpgCore import component
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
31 import re
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
32 from orpg.tools.orpg_log import logger
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
33 from wx import TextEntryDialog, ID_OK
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
34 from xml.etree.ElementTree import iselement
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
35
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
36 class InterParse():
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
37
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
38 def __init__(self):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
39 pass
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
40
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
41 def Post(self, s, tab=False, send=False, myself=False):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
42 if not tab: tab = component.get('chat')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
43 s = self.Normalize(s, tab)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
44 tab.set_colors()
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
45 tab.Post(s, send, myself)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
46
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
47 def ParseLogic(self, s, node):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
48 'Nodes now parse through ParsLogic. Easily add new parse rules right here!!'
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
49 s = self.NameSpaceE(s)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
50 s = self.NameSpaceI(s, node)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
51 s = self.NodeMap(s, node)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
52 s = self.NodeParent(s, node.get('map'))
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
53 return s
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
54
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
55 def Normalize(self, s, tab):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
56 for plugin_fname in tab.activeplugins.keys():
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
57 plugin = tab.activeplugins[plugin_fname]
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
58 try: s = plugin.pre_parse(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
59 except Exception, e:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
60 if str(e) != "'module' object has no attribute 'post_msg'":
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
61 #logger.general(traceback.format_exc())
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
62 logger.general("EXCEPTION: " + str(e))
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
63 if tab.parsed == 0:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
64 s = self.NameSpaceE(s)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
65 s = self.Node(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
66 s = self.Dice(s)
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
67 s = self.Filter(s, tab)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
68 tab.parsed = 1
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
69 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
70
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
71 def Filter(self, s, tab):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
72 s = tab.GetFilteredText(s)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
73 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
74
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
75 def Node(self, s):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
76 """Parses player input for embedded nodes rolls"""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
77 cur_loc = 0
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
78 #[a-zA-Z0-9 _\-\.]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
79 reg = re.compile("(!@(.*?)@!)")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
80 matches = reg.findall(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
81 for i in xrange(0,len(matches)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
82 newstr = self.Node(self.resolve_nodes(matches[i][1]))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
83 s = s.replace(matches[i][0], newstr, 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
84 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
85
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
86 def Dice(self, s):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
87 """Parses player input for embedded dice rolls"""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
88 reg = re.compile("\[([^]]*?)\]")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
89 matches = reg.findall(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
90 for i in xrange(0,len(matches)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
91 newstr = self.Unknown(matches[i])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
92 qmode = 0
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
93 newstr1 = newstr
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
94 if newstr[0].lower() == 'q':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
95 newstr = newstr[1:]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
96 qmode = 1
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
97 if newstr[0].lower() == '#':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
98 newstr = newstr[1:]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
99 qmode = 2
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
100 try: newstr = component.get('DiceManager').proccessRoll(newstr)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
101 except: pass
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
102 if qmode == 1:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
103 s = s.replace("[" + matches[i] + "]",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
104 "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
105 elif qmode == 2:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
106 s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
107 else: s = s.replace("[" + matches[i] + "]",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
108 "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
109 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
110
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
111 def Unknown(self, s):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
112 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
113 newstr = "0"
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
114 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
115 matches = reg.findall(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
116 for i in xrange(0,len(matches)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
117 lb = "Replace '?' with: "
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
118 if len(matches[i][0]):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
119 lb = matches[i][1] + "?: "
30
8e77f169f324 Traipse 'OpenRPG' {100219-00}
sirebral
parents: 28
diff changeset
120 dlg = TextEntryDialog(component.get('chat'), lb, "Missing Value?")
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
121 dlg.SetValue('')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
122 if matches[i][0] != '':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
123 dlg.SetTitle("Enter Value for " + matches[i][1])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
124 if dlg.ShowModal() == ID_OK: newstr = dlg.GetValue()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
125 if newstr == '': newstr = '0'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
126 s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
127 dlg.Destroy()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
128 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
129
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
130 def LocationCheck(self, node, tree_map, new_map, find):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
131 if node == 'Invalid Reference!': return node
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
132 namespace = node.getiterator('nodehandler'); tr = tree_map.split('::')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
133 newstr = ''
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
134 for name in namespace:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
135 try: t = new_map.index(name.get('name'))-1
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
136 except: t = 0
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
137 if find[0] == name.get('name'):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
138 s = '::'.join(new_map[:len(tr)-t])+'::'+'::'.join(find)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
139 newstr = self.NameSpaceE('!&' +s+ '&!')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
140 break
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
141 if newstr != '': return newstr
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
142 else:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
143 del new_map[len(new_map)-1]
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
144 node = self.get_node(new_map)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
145 newstr = self.LocationCheck(node, tree_map, new_map, find)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
146 return newstr
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
147
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
148 def FutureCheck(self, node, next):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
149 future = node.getiterator('nodehandler')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
150 for advance in future:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
151 if next == advance.get('name'): return True
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
152 return False
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
153
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
154 def NameSpaceI(self, s, node):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
155 reg1 = re.compile('(!"(.*?)"!)') ## Easter Egg!
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
156 """If you found this you found my first easter egg. I was tired of people telling me multiple
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
157 references syntax for the game tree is confusing, so I dropped this in there without telling
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
158 anyone. Using !" :: "! will allow you to use an internal namespace from within another internal
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
159 namespace -- TaS, Prof. Ebral"""
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
160 reg2 = re.compile("(!=(.*?)=!)")
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
161 matches = reg1.findall(s) + reg2.findall(s)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
162 tree_map = node.get('map')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
163 for i in xrange(0,len(matches)):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
164 ## Build the new tree_map
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
165 new_map = tree_map.split('::')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
166 find = matches[i][1].split('::')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
167 ## Backwards Reference the Parent Children
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
168 node = self.get_node(new_map)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
169 newstr = self.LocationCheck(node, tree_map, new_map, find)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
170 s = s.replace(matches[i][0], newstr, 1)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
171 s = self.ParseLogic(s, node)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
172 return s
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
173
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
174 def NameSpaceE(self, s):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
175 reg = re.compile("(!&(.*?)&!)")
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
176 matches = reg.findall(s)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
177 newstr = False
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
178 nodeable = ['rpg_grid_handler', 'container_handler',
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
179 'group_handler', 'tabber_handler',
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
180 'splitter_handler', 'form_handler', 'textctrl_handler']
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
181 for i in xrange(0,len(matches)):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
182 find = matches[i][1].split('::')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
183 node = component.get('tree').xml_root
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
184 if not iselement(node):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
185 s = s.replace(matches[i][0], 'Invalid Reference!', 1);
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
186 s = self.NameSpaceE(s)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
187 return s
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
188 for x in xrange(0, len(find)):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
189 namespace = node.getiterator('nodehandler')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
190 for node in namespace:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
191 if find[x] == node.get('name'):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
192 if node.get('class') not in nodeable: continue
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
193 if node.get('class') == 'rpg_grid_handler':
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
194 try: newstr = self.NameSpaceGrid(find[x+1], node); break
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
195 except: newstr = 'Invalid Grid Reference!'
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
196 try:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
197 if self.FutureCheck(node, find[x+1]): break
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
198 else: continue
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
199 except:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
200 if x == len(find)-1:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
201 if node.find('text') != None: newstr = str(node.find('text').text)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
202 else: newstr = 'Invalid Reference!'
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
203 break
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
204 else: break
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
205 if not newstr: newstr = 'Invalid Reference!'
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
206 s = s.replace(matches[i][0], newstr, 1)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
207 s = self.ParseLogic(s, node)
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
208 return s
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
209
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
210 def NameSpaceGrid(self, s, node):
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
211 cell = tuple(s.strip('(').strip(')').split(','))
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
212 grid = node.find('grid')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
213 rows = grid.findall('row')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
214 try:
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
215 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
216 s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
217 except: s = 'Invalid Grid Reference!'
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
218 return s
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
219
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
220 def NodeMap(self, s, node):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
221 """Parses player input for embedded nodes rolls"""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
222 cur_loc = 0
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
223 reg = re.compile("(!!(.*?)!!)")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
224 matches = reg.findall(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
225 for i in xrange(0,len(matches)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
226 tree_map = node.get('map')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
227 tree_map = tree_map + '::' + matches[i][1]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
228 newstr = '!@'+ tree_map +'@!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
229 s = s.replace(matches[i][0], newstr, 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
230 s = self.Node(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
231 s = self.NodeParent(s, tree_map)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
232 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
233
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
234 def NodeParent(self, s, tree_map):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
235 """Parses player input for embedded nodes rolls"""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
236 cur_loc = 0
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
237 reg = re.compile("(!#(.*?)#!)")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
238 matches = reg.findall(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
239 for i in xrange(0,len(matches)):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
240 ## Build the new tree_map
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
241 new_map = tree_map.split('::')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
242 del new_map[len(new_map)-1]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
243 parent_map = matches[i][1].split('::')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
244 ## Backwards Reference the Parent Children
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
245 child_node = self.get_node(new_map)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
246 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
247 s = s.replace(matches[i][0], newstr, 1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
248 s = self.Node(s)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
249 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
250
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
251 def get_root(self, child_node, tree_map, new_map, parent_map):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
252 if child_node == 'Invalid Reference!': return child_node
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
253 roots = child_node.getchildren(); tr = tree_map.split('::')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
254 newstr = ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
255 for root in roots:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
256 try: t = new_map.index(root.get('name'))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
257 except: t = 1
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
258 if parent_map[0] == root.get('name'):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
259 newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
260 if newstr != '': return newstr
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
261 else:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
262 del new_map[len(new_map)-1]
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
263 child_node = self.get_node(new_map)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
264 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
265 return newstr
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
266
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
267 def get_node(self, path):
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
268 return_node = 'Invalid Reference!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
269 value = ""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
270 depth = len(path)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
271 try: node = component.get('tree').tree_map[path[0]]['node']
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
272 except Exception, e: return return_node
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
273 return_node = self.resolve_get_loop(node, path, 1, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
274 return return_node
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
275
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
276 def resolve_get_loop(self, node, path, step, depth):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
277 if step == depth: return node
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
278 else:
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
279 child_list = node.getchildren()
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
280 for child in child_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
281 if step == depth: break
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
282 if child.get('name') == path[step]:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
283 node = self.resolve_get_loop(child, path, step+1, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
284 return node
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
285
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
286 def resolve_nodes(self, s):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
287 self.passed = False
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
288 string = 'Invalid Reference!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
289 value = ""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
290 path = s.split('::')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
291 depth = len(path)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
292 try: node = component.get('tree').tree_map[path[0]]['node']
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
293 except Exception, e: return string
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
294 if node.get('class') in ('dnd35char_handler',
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
295 "SWd20char_handler",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
296 "d20char_handler",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
297 "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
298 elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
299 else: string = self.resolve_loop(node, path, 1, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
300 return string
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
301
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
302 def resolve_loop(self, node, path, step, depth):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
303 if step == depth: return self.resolution(node)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
304 else:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
305 child_list = node.findall('nodehandler')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
306 for child in child_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
307 if step == depth: break
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
308 if child.get('name') == path[step]:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
309 node = child
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
310 step += 1
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
311 if node.get('class') in ('dnd35char_handler',
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
312 "SWd20char_handler",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
313 "d20char_handler",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
314 "dnd3echar_handler"):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
315 string = self.resolve_cust_loop(node, path, step, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
316 elif node.get('class') == 'rpg_grid_handler':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
317 string = self.resolve_grid(node, path, step, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
318 else: string = self.resolve_loop(node, path, step, depth)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
319 return string
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
320
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
321 def resolution(self, node):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
322 if self.passed == False:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
323 self.passed = True
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
324 if node.get('class') == 'textctrl_handler':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
325 s = str(node.find('text').text)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
326 else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!'
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
327 else: s = ''
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
328 s = self.ParseLogic(s, node)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
329 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
330
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
331 def resolve_grid(self, node, path, step, depth):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
332 if step == depth:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
333 return 'Invalid Grid Reference!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
334 cell = tuple(path[step].strip('(').strip(')').split(','))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
335 grid = node.find('grid')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
336 rows = grid.findall('row')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
337 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
31
fc48380f0c9f Traipse Beta 'OpenRPG' {100503-00}
sirebral
parents: 30
diff changeset
338 try: s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
339 except: s = 'Invalid Grid Reference!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
340 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
341
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
342 def resolve_cust_loop(self, node, path, step, depth):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
343 s = 'Invalid Reference!'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
344 node_class = node.get('class')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
345 ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ##
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
346 if step == depth: self.resolution(node)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
347 ##Build Abilities dictionary##
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
348 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
349 else: ab = node.find('abilities')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
350 ab_list = ab.findall('stat'); pc_stats = {}
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
351
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
352 for ability in ab_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
353 pc_stats[ability.get('name')] = (
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
354 str(ability.get('base')),
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
355 str((int(ability.get('base'))-10)/2) )
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
356 pc_stats[ability.get('abbr')] = (
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
357 str(ability.get('base')),
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
358 str((int(ability.get('base'))-10)/2) )
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
359
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
360 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
361 else: ab = node.find('saves')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
362 ab_list = ab.findall('save')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
363 for save in ab_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
364 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]) ) )
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
365 if save.get('name') == 'Fortitude': abbr = 'Fort'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
366 if save.get('name') == 'Reflex': abbr = 'Ref'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
367 if save.get('name') == 'Will': abbr = 'Will'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
368 pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
369
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
370 if path[step].lower() == 'skill':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
371 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
372 node = node.find('skills')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
373 child_list = node.findall('skill')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
374 for child in child_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
375 if path[step+1].lower() == child.get('name').lower():
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
376 if step+2 == depth: s = child.get('rank')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
377 elif path[step+2].lower() == 'check':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
378 s = '<b>Skill Check:</b> ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
379 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
380
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
381 if path[step].lower() == 'feat':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
382 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
383 node = node.find('feats')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
384 child_list = node.findall('feat')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
385 for child in child_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
386 if path[step+1].lower() == child.get('name').lower():
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
387 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
388 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
389 if path[step].lower() == 'cast':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
390 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
391 node = node.find('spells')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
392 child_list = node.findall('spell')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
393 for child in child_list:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
394 if path[step+1].lower() == child.get('name').lower():
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
395 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
396 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
397 if path[step].lower() == 'attack':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
398 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
399 if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
400 bonus_text = '(Melee)'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
401 bonus = node.find('attacks')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
402 bonus = bonus.find('melee')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
403 bonus = bonus.attrib; d = int(pc_stats['Str'][1])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
404 elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r':
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
405 bonus_text = '(Ranged)'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
406 bonus = node.find('attacks')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
407 bonus = bonus.find('ranged')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
408 bonus = bonus.attrib; d = int(pc_stats['Dex'][1])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
409 for b in bonus:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
410 d += int(bonus[b])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
411 bonus = str(d)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
412 if path[step+2] == None: s= bonus
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
413 else:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
414 weapons = node.find('attacks')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
415 weapons = weapons.findall('weapon')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
416 for child in weapons:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
417 if path[step+2].lower() == child.get('name').lower():
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
418 s = '<b>Attack: '+bonus_text+'</b> '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
419 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
420 elif pc_stats.has_key(path[step].title()):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
421 if step+1 == depth: s = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
422 elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1]
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
423 elif path[step+1].title() == 'Check': s = '<b>'+path[step].title()+' Check:</b> [1d20+'+str(pc_stats[path[step].title()][1])+']'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
424 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
425 return s
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
426
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents:
diff changeset
427 Parse = InterParse()