view plugins/xxhiddendice.py @ 242:72e0cce81a47 beta

Traipse Beta 'OpenRPG' {100817-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 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
author sirebral
date Tue, 17 Aug 2010 14:53:04 -0500
parents a00b40ee92fc
children
line wrap: on
line source

import os, re, wx
import orpg.pluginhandler
from orpg.tools.InterParse import Parse
from orpg.dieroller.base import die_rollers
from orpg.dieroller.utils import roller_manager

class Plugin(orpg.pluginhandler.PluginHandler):
    # Initialization subroutine.
    #
    # !self : instance of self
    # !openrpg : instance of the the base openrpg control
    def __init__(self, plugindb, parent):
        orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)

        # The Following code should be edited to contain the proper information
        self.name = 'Hidden Dice'
        self.author = 'mDuo13'
        self.help = 'Roll with curly brackets to hide your roll,\n'
        self.help += 'having it display only for you. Other players will\n'
        self.help += 'get a message that only says you are rolling.\n'
        self.help += 'Useful for GMs who want to roll secretly.'

        #You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled
        #to set their proper values.
        self.hiddenrolls = []
        #self.dicere = "\{([0-9]*d[0-9]*.+)\}"

    def plugin_menu(self):
        self.menu = wx.Menu()
        self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
        self.topframe.Bind(wx.EVT_MENU, self.plugin_toggle, self.toggle)
        self.toggle.Check(True)

    def plugin_toggle(self, evt):
        pass

    def plugin_enabled(self):
        pass

    def plugin_disabled(self):
        pass

    def pre_parse(self, text):
        if self.toggle.IsChecked() == True:
            ## Changes added for non standard dice rolls. Prof.Ebral (TaS)
            math = '[\(0-9\/\*\-\+\)]+'
            dicere = '\{('+math+'d\s*([0-9]+|'+math+'|[fF]))\}'
            m = re.search(dicere, text)
            if m is None:
                dicere = '\{('+die_rollers._rollers[roller_manager().getRoller()].regExpression+')\}'
                m = re.search(dicere, text)
            while m:
                roll = "[" + m.group(1) + "]"
                self.hiddenrolls += [Parse.Dice(roll)]
                text = text[:m.start()] + "(hidden roll)" + text[m.end():]
                m = re.search(dicere, text)
        return text

    def post_msg(self, text, myself):
        if self.toggle.IsChecked() == True:
            c = 0
            a = text.find("(hidden roll)")
            while len(self.hiddenrolls) > c and a > -1:
                text = text[:a+14].replace("(hidden roll)", self.hiddenrolls[c]) + text[a+14:]
                a = text.find("(hidden roll)")
                c += 1
            if c > 0:
                self.hiddenrolls = []
        return text