# HG changeset patch # User sirebral # Date 1265039827 21600 # Node ID a3d7e05085dae0fab74349900e9206c562803f32 # Parent 15488fe94f52abdc62fa8e62e1846a453b25d832 Traipse Beta 'OpenRPG' {100201-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml diff -r 15488fe94f52 -r a3d7e05085da orpg/chat/chatwnd.py --- a/orpg/chat/chatwnd.py Mon Jan 25 12:07:48 2010 -0600 +++ b/orpg/chat/chatwnd.py Mon Feb 01 09:57:07 2010 -0600 @@ -61,6 +61,7 @@ from orpg.tools.orpg_settings import settings import orpg.tools.predTextCtrl from orpg.tools.orpg_log import logger, debug +from orpg.tools.InterParse import Parse from orpg.orpgCore import component from xml.etree.ElementTree import tostring @@ -1029,7 +1030,7 @@ sound_file = self.settings.get_setting("SendSound") if sound_file != '': component.get('sound').play(sound_file) if s[0] != "/": ## it's not a slash command - s = self.ParsePost( s, True, True ) + s = Parse.Post( s, True, True ) else: self.chat_cmds.docmd(s) # emote is in chatutils.py def on_chat_key_down(self, event): @@ -1168,7 +1169,7 @@ if len(dieMod) and dieMod[0] not in "*/-+": dieMod = "+" + dieMod dieText += dieMod dieText = "[" + dieText + "]" - self.ParsePost(dieText, 1, 1) + Parse.Post(dieText, 1, 1) self.chattxt.SetFocus() def on_chat_save(self, evt): @@ -1298,7 +1299,7 @@ return text def emote_message(self, text): - text = self.NormalizeParse(text) + text = Parse.Normalize(text) text = self.colorize(self.emotecolor, text) if self.type == MAIN_TAB and self.sendtarget == 'all': self.send_chat_message(text,chat_msg.EMOTE_MESSAGE) elif self.type == MAIN_TAB and self.sendtarget == "gm": @@ -1316,7 +1317,7 @@ def whisper_to_players(self, text, player_ids): tabbed_whispers_p = self.settings.get_setting("tabbedwhispers") - text = self.NormalizeParse(text) + text = Parse.Normalize(text) player_names = "" for m in player_ids: id = m.strip() @@ -1588,86 +1589,6 @@ logger.general("EXCEPTION: " + str(e)) return "[ERROR]" - #### Post with parsing dice #### - - def ParsePost(self, s, send=False, myself=False): - s = self.NormalizeParse(s) - self.set_colors() - self.Post(s,send,myself) - - def NormalizeParse(self, s): - for plugin_fname in self.activeplugins.keys(): - plugin = self.activeplugins[plugin_fname] - try: s = plugin.pre_parse(s) - except Exception, e: - if str(e) != "'module' object has no attribute 'post_msg'": - logger.general(traceback.format_exc()) - logger.general("EXCEPTION: " + str(e)) - if self.parsed == 0: - s = self.ParseNode(s) - s = self.ParseDice(s) - s = self.ParseFilter(s) - self.parsed = 1 - return s - - def ParseFilter(self, s): - s = self.GetFilteredText(s) - return s - - def ParseNode(self, s): - """Parses player input for embedded nodes rolls""" - cur_loc = 0 - #[a-zA-Z0-9 _\-\.] - reg = re.compile("(!@(.*?)@!)") - matches = reg.findall(s) - for i in xrange(0,len(matches)): - newstr = self.ParseNode(self.resolve_nodes(matches[i][1])) - s = s.replace(matches[i][0], newstr, 1) - return s - - def ParseDice(self, s): - """Parses player input for embedded dice rolls""" - reg = re.compile("\[([^]]*?)\]") - matches = reg.findall(s) - for i in xrange(0,len(matches)): - newstr = self.PraseUnknowns(matches[i]) - qmode = 0 - newstr1 = newstr - if newstr[0].lower() == 'q': - newstr = newstr[1:] - qmode = 1 - if newstr[0].lower() == '#': - newstr = newstr[1:] - qmode = 2 - try: newstr = component.get('DiceManager').proccessRoll(newstr) - except: pass - if qmode == 1: - s = s.replace("[" + matches[i] + "]", - "" + newstr, 1) - elif qmode == 2: - s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1) - else: s = s.replace("[" + matches[i] + "]", - "[" + newstr1 + "] => " + newstr, 1) - return s - - def PraseUnknowns(self, s): - # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY - newstr = "0" - reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)") - matches = reg.findall(s) - for i in xrange(0,len(matches)): - lb = "Replace '?' with: " - if len(matches[i][0]): - lb = matches[i][1] + "?: " - dlg = wx.TextEntryDialog(self, lb, "Missing Value?") - dlg.SetValue('') - if matches[i][0] != '': - dlg.SetTitle("Enter Value for " + matches[i][1]) - if dlg.ShowModal() == wx.ID_OK: newstr = dlg.GetValue() - if newstr == '': newstr = '0' - s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1) - dlg.Destroy() - return s # This subroutine builds a chat display name. # @@ -1708,179 +1629,3 @@ i += 1 return rs - def resolve_loop(self, node, path, step, depth): - if step == depth: - return self.resolution(node) - else: - child_list = node.findall('nodehandler') - for child in child_list: - if step == depth: break - if child.get('name') == path[step]: - node = child - step += 1 - if node.get('class') in ('dnd35char_handler', - "SWd20char_handler", - "d20char_handler", - "dnd3echar_handler"): self.resolve_cust_loop(node, path, step, depth) - elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, step, depth) - else: self.resolve_loop(node, path, step, depth) - - def resolve_grid(self, node, path, step, depth): - if step == depth: - self.data = 'Invalid Grid Reference!' - return - cell = tuple(path[step].strip('(').strip(')').split(',')) - grid = node.find('grid') - rows = grid.findall('row') - col = rows[int(self.ParseDice(cell[0]))-1].findall('cell') - try: self.data = self.ParseMap(col[int(self.ParseDice(cell[1]))-1].text, node) or 'No Cell Data' - except: self.data = 'Invalid Grid Reference!' - return - - def resolution(self, node): - if self.passed == False: - self.passed = True - if node.get('class') == 'textctrl_handler': - s = str(node.find('text').text) - else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!' - else: - s = '' - s = self.ParseMap(s, node) - s = self.ParseParent(s, node.get('map')) - self.data = s - - def ParseMap(self, s, node): - """Parses player input for embedded nodes rolls""" - cur_loc = 0 - reg = re.compile("(!!(.*?)!!)") - matches = reg.findall(s) - for i in xrange(0,len(matches)): - tree_map = node.get('map') - tree_map = tree_map + '::' + matches[i][1] - newstr = '!@'+ tree_map +'@!' - s = s.replace(matches[i][0], newstr, 1) - s = self.ParseNode(s) - s = self.ParseParent(s, tree_map) - return s - - def ParseParent(self, s, tree_map): - """Parses player input for embedded nodes rolls""" - cur_loc = 0 - reg = re.compile("(!#(.*?)#!)") - matches = reg.findall(s) - for i in xrange(0,len(matches)): - ## Build the new tree_map - new_map = tree_map.split('::') - del new_map[len(new_map)-1] - parent_map = matches[i][1].split('::') - ## Find an index or use 1 for ease of use. - try: index = new_map.index(parent_map[0]) - except: index = 1 - ## Just replace the old tree_map from the index. - new_map[index:len(new_map)] = parent_map - newstr = '::'.join(new_map) - newstr = '!@'+ newstr +'@!' - s = s.replace(matches[i][0], newstr, 1) - s = self.ParseNode(s) - return s - - def resolve_nodes(self, s): - self.passed = False - self.data = 'Invalid Reference!' - value = "" - path = s.split('::') - depth = len(path) - self.gametree = component.get('tree') - try: node = self.gametree.tree_map[path[0]]['node'] - except Exception, e: return self.data - if node.get('class') in ('dnd35char_handler', - "SWd20char_handler", - "d20char_handler", - "dnd3echar_handler"): self.resolve_cust_loop(node, path, 1, depth) - elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth) - else: self.resolve_loop(node, path, 1, depth) - return self.data - - def resolve_cust_loop(self, node, path, step, depth): - node_class = node.get('class') - ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ## - if step == depth: self.resolution(node) - ##Build Abilities dictionary## - if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities') - else: ab = node.find('abilities') - ab_list = ab.findall('stat'); pc_stats = {} - - for ability in ab_list: - pc_stats[ability.get('name')] = ( - str(ability.get('base')), - str((int(ability.get('base'))-10)/2) ) - pc_stats[ability.get('abbr')] = ( - str(ability.get('base')), - str((int(ability.get('base'))-10)/2) ) - - if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves') - else: ab = node.find('saves') - ab_list = ab.findall('save') - for save in ab_list: - 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]) ) ) - if save.get('name') == 'Fortitude': abbr = 'Fort' - if save.get('name') == 'Reflex': abbr = 'Ref' - if save.get('name') == 'Will': abbr = 'Will' - pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) ) - - if path[step].lower() == 'skill': - if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf') - node = node.find('skills') - child_list = node.findall('skill') - for child in child_list: - if path[step+1].lower() == child.get('name').lower(): - if step+2 == depth: self.data = child.get('rank') - elif path[step+2].lower() == 'check': - self.data = 'Skill Check: ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']' - return - - if path[step].lower() == 'feat': - if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf') - node = node.find('feats') - child_list = node.findall('feat') - for child in child_list: - if path[step+1].lower() == child.get('name').lower(): - if step+2 == depth: self.data = ''+child.get('name')+''+': '+child.get('desc') - return - if path[step].lower() == 'cast': - if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp') - node = node.find('spells') - child_list = node.findall('spell') - for child in child_list: - if path[step+1].lower() == child.get('name').lower(): - if step+2 == depth: self.data = ''+child.get('name')+''+': '+child.get('desc') - return - if path[step].lower() == 'attack': - if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat') - if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm': - bonus_text = '(Melee)' - bonus = node.find('attacks') - bonus = bonus.find('melee') - bonus = bonus.attrib; d = int(pc_stats['Str'][1]) - elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r': - bonus_text = '(Ranged)' - bonus = node.find('attacks') - bonus = bonus.find('ranged') - bonus = bonus.attrib; d = int(pc_stats['Dex'][1]) - for b in bonus: - d += int(bonus[b]) - bonus = str(d) - if path[step+2] == None: self.data = bonus - else: - weapons = node.find('attacks') - weapons = weapons.findall('weapon') - for child in weapons: - if path[step+2].lower() == child.get('name').lower(): - self.data = 'Attack: '+bonus_text+' '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']' - return - elif pc_stats.has_key(path[step].title()): - if step+1 == depth: self.data = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')' - elif path[step+1].title() == 'Mod': self.data = pc_stats[path[step].title()][1] - elif path[step+1].title() == 'Check': self.data = ''+path[step].title()+' Check: [1d20+'+str(pc_stats[path[step].title()][1])+']' - return - diff -r 15488fe94f52 -r a3d7e05085da orpg/gametree/gametree.py --- a/orpg/gametree/gametree.py Mon Jan 25 12:07:48 2010 -0600 +++ b/orpg/gametree/gametree.py Mon Feb 01 09:57:07 2010 -0600 @@ -37,7 +37,7 @@ from orpg.orpgCore import component from orpg.dirpath import dir_struct from nodehandlers import core -import string, urllib, time, os +import string, urllib, time, os, shutil from orpg.orpg_xml import xml from orpg.tools.validate import validate @@ -82,6 +82,12 @@ TOP_FEATURES = wx.NewId() EZ_REF = wx.NewId() +def exists(path): + try: + os.stat(path) + return True + except: return False + class game_tree(wx.TreeCtrl): def __init__(self, parent, id): @@ -233,11 +239,14 @@ self.xml_root = None if not self.xml_root: - os.rename(filename,filename+".corrupt") + count = 1 + while exists(filename[:len(filename)-4]+'-bad-'+str(count)+'.xml'): count += 1 + shutil.copy(filename, filename[:len(filename)-4]+'-bad-'+str(count)+'.xml') + shutil.copyfile(dir_struct["template"]+'default_tree.xml', filename) emsg = "Your gametree is being regenerated.\n\n"\ "To salvage a recent version of your gametree\n"\ "exit OpenRPG and copy the lastgood.xml file in\n"\ - "your myfiles directory to "+filename+ "\n"\ + "your myfiles directory to "+filename[:len(filename)-4]+'-bad-'+str(count)+'.xml'+ "\n"\ "in your myfiles directory.\n\n"\ "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ "Would you like to select a different gametree file to use?\n"\ @@ -279,8 +288,11 @@ except Exception, e: logger.exception(traceback.format_exc()) + count = 1 + while exists(filename[:len(filename)-4]+'-bad-'+str(count)+'.xml'): count += 1 + shutil.copy(filename, filename[:len(filename)-4]+'-bad-'+str(count)+'.xml') + shutil.copyfile(dir_struct["template"]+'default_tree.xml', filename) wx.MessageBox("Corrupt Tree!\nYour game tree is being regenerated. To\nsalvage a recent version of your gametree\nexit OpenRPG and copy the lastgood.xml\nfile in your myfiles directory\nto "+filename+ "\nin your myfiles directory.\nlastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.") - os.rename(filename,filename+".corrupt") validate.config_file("tree.xml","default_tree.xml") self.load_tree(error=1) diff -r 15488fe94f52 -r a3d7e05085da orpg/gametree/nodehandlers/forms.py --- a/orpg/gametree/nodehandlers/forms.py Mon Jan 25 12:07:48 2010 -0600 +++ b/orpg/gametree/nodehandlers/forms.py Mon Feb 01 09:57:07 2010 -0600 @@ -33,6 +33,7 @@ from orpg.orpg_xml import xml from wx.lib.scrolledpanel import ScrolledPanel from orpg.tools.settings import settings +from orpg.tools.InterParse import Parse def bool2int(b): #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. @@ -262,16 +263,16 @@ def on_send(self, evt): txt = self.text.GetValue() - txt = self.chat.ParseMap(txt, self.handler.xml) - txt = self.chat.ParseParent(txt, self.handler.xml.get('map')) + txt = Parse.NodeMap(txt, self.handler.xml) + txt = Parse.NodeParent(txt, self.handler.xml.get('map')) if not self.handler.is_raw_send(): - self.chat.ParsePost(self.handler.tohtml(), True, True) + Parse.Post(self.handler.tohtml(), True, True) return 1 actionlist = txt.split("\n") for line in actionlist: if(line != ""): if line[0] != "/": ## it's not a slash command - self.chat.ParsePost(line, True, True) + Parse.Post(line, True, True) else: action = line self.chat.chat_cmds.docmd(action) @@ -595,18 +596,18 @@ def on_send_to_chat(self, evt): txt = self.get_selected_text() - txt = self.chat.ParseMap(txt, self.xml) - txt = self.chat.ParseParent(txt, self.xml.get('map')) + txt = Parse.NodeMap(txt, self.xml) + txt = Parse.NodeParent(txt, self.xml.get('map')) if not self.is_raw_send(): - self.chat.ParsePost(self.tohtml(), True, True) + Parse.Post(self.tohtml(), True, True) return 1 actionlist = self.get_selections_text() for line in actionlist: - line = self.chat.ParseMap(line, self.xml) - line = self.chat.ParseParent(line, self.xml.get('map')) + line = Parse.NodeMap(line, self.xml) + line = Parse.NodeParent(line, self.xml.get('map')) if(line != ""): if line[0] != "/": ## it's not a slash command - self.chat.ParsePost(line, True, True) + Parse.Post(line, True, True) else: action = line self.chat.chat_cmds.docmd(action) diff -r 15488fe94f52 -r a3d7e05085da orpg/gametree/nodehandlers/rpg_grid.py --- a/orpg/gametree/nodehandlers/rpg_grid.py Mon Jan 25 12:07:48 2010 -0600 +++ b/orpg/gametree/nodehandlers/rpg_grid.py Mon Feb 01 09:57:07 2010 -0600 @@ -31,6 +31,7 @@ from core import * from forms import * from orpg.tools.orpg_log import debug +from orpg.tools.InterParse import Parse class rpg_grid_handler(node_handler): """ Node handler for rpg grid tool @@ -88,8 +89,8 @@ html_str += "" text = c.text if text == None or text == '': text = '
' - s = component.get('chat').ParseMap(text, self.xml) - s = component.get('chat').NormalizeParse(s) + s = Parse.NodeMap(text, self.xml) + s = Parse.Normalize(s) try: text = str(eval(s)) except: text = s html_str += text + "" @@ -326,8 +327,8 @@ text = '' cells[i].text = text if self.mode == 0: - s = component.get('chat').ParseMap(text, self.handler.xml) - s = component.get('chat').ParseParent(s, self.handler.xml.get('map')) + s = Parse.NodeMap(text, self.handler.xml) + s = Parse.NodeParent(s, self.handler.xml.get('map')) try: text = str(eval(s)) except: text = s self.SetCellValue(rowi,i,text) diff -r 15488fe94f52 -r a3d7e05085da orpg/main.py --- a/orpg/main.py Mon Jan 25 12:07:48 2010 -0600 +++ b/orpg/main.py Mon Feb 01 09:57:07 2010 -0600 @@ -59,6 +59,7 @@ from orpg.tools.passtool import PassTool from orpg.tools.orpg_log import logger, crash, debug from orpg.tools.metamenus import MenuBarEx +from orpg.tools.InterParse import Parse from xml.etree.ElementTree import ElementTree, Element, parse from xml.etree.ElementTree import fromstring, tostring @@ -674,7 +675,7 @@ logger.debug("Status Window Created") # Create and show the floating dice toolbar - self.dieToolBar = orpg.tools.toolBars.DiceToolBar(self, callBack = self.chat.ParsePost) + self.dieToolBar = orpg.tools.toolBars.DiceToolBar(self, callBack = Parse.Post) wndinfo = AUI.AuiPaneInfo() menuid = wx.NewId() self.mainwindows[menuid] = "Dice Tool Bar" diff -r 15488fe94f52 -r a3d7e05085da orpg/orpg_version.py --- a/orpg/orpg_version.py Mon Jan 25 12:07:48 2010 -0600 +++ b/orpg/orpg_version.py Mon Feb 01 09:57:07 2010 -0600 @@ -4,7 +4,7 @@ #BUILD NUMBER FORMAT: "YYMMDD-##" where ## is the incremental daily build index (if needed) DISTRO = "Traipse Beta" DIS_VER = "Ornery Orc" -BUILD = "100125-01" +BUILD = "100201-00" # This version is for network capability. PROTOCOL_VERSION = "1.2" diff -r 15488fe94f52 -r a3d7e05085da orpg/tools/InterParse.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/tools/InterParse.py Mon Feb 01 09:57:07 2010 -0600 @@ -0,0 +1,300 @@ +from orpg.orpgCore import component +import re +from orpg.tools.orpg_log import logger + +class InterParse(): + + def __init__(self): + pass + + def Post(self, s, send=False, myself=False): + s = self.Normalize(s) + component.get('chat').set_colors() + component.get('chat').Post(s,send,myself) + + def Normalize(self, s): + for plugin_fname in component.get('chat').activeplugins.keys(): + plugin = component.get('chat').activeplugins[plugin_fname] + try: s = plugin.pre_parse(s) + except Exception, e: + if str(e) != "'module' object has no attribute 'post_msg'": + logger.general(traceback.format_exc()) + logger.general("EXCEPTION: " + str(e)) + if component.get('chat').parsed == 0: + s = self.Node(s) + s = self.Dice(s) + s = self.Filter(s) + component.get('chat').parsed = 1 + return s + + def Filter(self, s): + s = component.get('chat').GetFilteredText(s) + return s + + def Node(self, s): + """Parses player input for embedded nodes rolls""" + cur_loc = 0 + #[a-zA-Z0-9 _\-\.] + reg = re.compile("(!@(.*?)@!)") + matches = reg.findall(s) + for i in xrange(0,len(matches)): + newstr = self.Node(self.resolve_nodes(matches[i][1])) + s = s.replace(matches[i][0], newstr, 1) + return s + + def Dice(self, s): + """Parses player input for embedded dice rolls""" + reg = re.compile("\[([^]]*?)\]") + matches = reg.findall(s) + for i in xrange(0,len(matches)): + newstr = self.Unknown(matches[i]) + qmode = 0 + newstr1 = newstr + if newstr[0].lower() == 'q': + newstr = newstr[1:] + qmode = 1 + if newstr[0].lower() == '#': + newstr = newstr[1:] + qmode = 2 + try: newstr = component.get('DiceManager').proccessRoll(newstr) + except: pass + if qmode == 1: + s = s.replace("[" + matches[i] + "]", + "" + newstr, 1) + elif qmode == 2: + s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1) + else: s = s.replace("[" + matches[i] + "]", + "[" + newstr1 + "] => " + newstr, 1) + return s + + def Unknown(self, s): + # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY + newstr = "0" + reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)") + matches = reg.findall(s) + for i in xrange(0,len(matches)): + lb = "Replace '?' with: " + if len(matches[i][0]): + lb = matches[i][1] + "?: " + dlg = wx.TextEntryDialog(self, lb, "Missing Value?") + dlg.SetValue('') + if matches[i][0] != '': + dlg.SetTitle("Enter Value for " + matches[i][1]) + if dlg.ShowModal() == wx.ID_OK: newstr = dlg.GetValue() + if newstr == '': newstr = '0' + s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1) + dlg.Destroy() + return s + + def NodeMap(self, s, node): + """Parses player input for embedded nodes rolls""" + cur_loc = 0 + reg = re.compile("(!!(.*?)!!)") + matches = reg.findall(s) + for i in xrange(0,len(matches)): + tree_map = node.get('map') + tree_map = tree_map + '::' + matches[i][1] + newstr = '!@'+ tree_map +'@!' + s = s.replace(matches[i][0], newstr, 1) + s = self.Node(s) + s = self.NodeParent(s, tree_map) + return s + + def NodeParent(self, s, tree_map): + """Parses player input for embedded nodes rolls""" + cur_loc = 0 + reg = re.compile("(!#(.*?)#!)") + matches = reg.findall(s) + for i in xrange(0,len(matches)): + ## Build the new tree_map + new_map = tree_map.split('::') + del new_map[len(new_map)-1] + parent_map = matches[i][1].split('::') + ## Backwards Reference the Parent Children + child_node = self.get_node('::'.join(new_map)) + newstr = self.get_root(child_node, tree_map, new_map, parent_map) + s = s.replace(matches[i][0], newstr, 1) + s = self.Node(s) + return s + + def get_root(self, child_node, tree_map, new_map, parent_map): + if child_node == 'Invalid Reference!': return child_node + roots = child_node.getchildren(); tr = tree_map.split('::') + newstr = '' + for root in roots: + try: t = new_map.index(root.get('name')) + except: t = 1 + if parent_map[0] == root.get('name'): + newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!' + if newstr != '': return newstr + else: + del new_map[len(new_map)-1] + child_node = self.get_node('::'.join(new_map)) + newstr = self.get_root(child_node, tree_map, new_map, parent_map) + return newstr + + def get_node(self, s): + return_node = 'Invalid Reference!' + value = "" + path = s.split('::') + depth = len(path) + try: node = component.get('tree').tree_map[path[0]]['node'] + except Exception, e: return return_node + return_node = self.resolve_get_loop(node, path, 1, depth) + return return_node + + def resolve_get_loop(self, node, path, step, depth): + if step == depth: return node + else: + child_list = node.findall('nodehandler') + for child in child_list: + if step == depth: break + if child.get('name') == path[step]: + node = self.resolve_get_loop(child, path, step+1, depth) + return node + + def resolve_nodes(self, s): + self.passed = False + string = 'Invalid Reference!' + value = "" + path = s.split('::') + depth = len(path) + try: node = component.get('tree').tree_map[path[0]]['node'] + except Exception, e: return string + if node.get('class') in ('dnd35char_handler', + "SWd20char_handler", + "d20char_handler", + "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth) + elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth) + else: string = self.resolve_loop(node, path, 1, depth) + return string + + def resolve_loop(self, node, path, step, depth): + if step == depth: return self.resolution(node) + else: + child_list = node.findall('nodehandler') + for child in child_list: + if step == depth: break + if child.get('name') == path[step]: + node = child + step += 1 + if node.get('class') in ('dnd35char_handler', + "SWd20char_handler", + "d20char_handler", + "dnd3echar_handler"): + string = self.resolve_cust_loop(node, path, step, depth) + elif node.get('class') == 'rpg_grid_handler': + string = self.resolve_grid(node, path, step, depth) + else: string = self.resolve_loop(node, path, step, depth) + return string + + def resolution(self, node): + if self.passed == False: + self.passed = True + if node.get('class') == 'textctrl_handler': + s = str(node.find('text').text) + else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!' + else: + s = '' + s = self.NodeMap(s, node) + s = self.NodeParent(s, node.get('map')) + return s + + def resolve_grid(self, node, path, step, depth): + if step == depth: + return 'Invalid Grid Reference!' + cell = tuple(path[step].strip('(').strip(')').split(',')) + grid = node.find('grid') + rows = grid.findall('row') + col = rows[int(self.Dice(cell[0]))-1].findall('cell') + try: s = self.NodeMap(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data' + except: s = 'Invalid Grid Reference!' + return s + + def resolve_cust_loop(self, node, path, step, depth): + s = 'Invalid Reference!' + node_class = node.get('class') + ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ## + if step == depth: self.resolution(node) + ##Build Abilities dictionary## + if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities') + else: ab = node.find('abilities') + ab_list = ab.findall('stat'); pc_stats = {} + + for ability in ab_list: + pc_stats[ability.get('name')] = ( + str(ability.get('base')), + str((int(ability.get('base'))-10)/2) ) + pc_stats[ability.get('abbr')] = ( + str(ability.get('base')), + str((int(ability.get('base'))-10)/2) ) + + if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves') + else: ab = node.find('saves') + ab_list = ab.findall('save') + for save in ab_list: + 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]) ) ) + if save.get('name') == 'Fortitude': abbr = 'Fort' + if save.get('name') == 'Reflex': abbr = 'Ref' + if save.get('name') == 'Will': abbr = 'Will' + pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) ) + + if path[step].lower() == 'skill': + if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf') + node = node.find('skills') + child_list = node.findall('skill') + for child in child_list: + if path[step+1].lower() == child.get('name').lower(): + if step+2 == depth: s = child.get('rank') + elif path[step+2].lower() == 'check': + s = 'Skill Check: ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']' + print s + return s + + if path[step].lower() == 'feat': + if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf') + node = node.find('feats') + child_list = node.findall('feat') + for child in child_list: + if path[step+1].lower() == child.get('name').lower(): + if step+2 == depth: s = ''+child.get('name')+''+': '+child.get('desc') + return s + if path[step].lower() == 'cast': + if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp') + node = node.find('spells') + child_list = node.findall('spell') + for child in child_list: + if path[step+1].lower() == child.get('name').lower(): + if step+2 == depth: s = ''+child.get('name')+''+': '+child.get('desc') + return s + if path[step].lower() == 'attack': + if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat') + if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm': + bonus_text = '(Melee)' + bonus = node.find('attacks') + bonus = bonus.find('melee') + bonus = bonus.attrib; d = int(pc_stats['Str'][1]) + elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r': + bonus_text = '(Ranged)' + bonus = node.find('attacks') + bonus = bonus.find('ranged') + bonus = bonus.attrib; d = int(pc_stats['Dex'][1]) + for b in bonus: + d += int(bonus[b]) + bonus = str(d) + if path[step+2] == None: s= bonus + else: + weapons = node.find('attacks') + weapons = weapons.findall('weapon') + for child in weapons: + if path[step+2].lower() == child.get('name').lower(): + s = 'Attack: '+bonus_text+' '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']' + return s + elif pc_stats.has_key(path[step].title()): + if step+1 == depth: s = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')' + elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1] + elif path[step+1].title() == 'Check': s = ''+path[step].title()+' Check: [1d20+'+str(pc_stats[path[step].title()][1])+']' + return s + return s + +Parse = InterParse()