view plugins/xxgvm.py @ 218:b8091ede042a alpha

Traipse Alpha 'OpenRPG' {100430-01} 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) New Features: New Namespace method with two new syntaxes New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode New to Update Manager, checks Repo for updates on software start New to Mini Lin 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 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
author sirebral
date Fri, 30 Apr 2010 11:37:37 -0500
parents c54768cffbd4
children
line wrap: on
line source

import os
import orpg.pluginhandler
import string

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 = 'Game Variable Manager'
        self.author = 'mDuo13'
        self.help = 'This plugin is used to manage variables in your idle status. That way,\n'
        self.help += 'you can keep as many numbers as you want in your idle status, and you can update \n'
        self.help += 'them without having to go to the Settings menu.\n'
        self.help += '\n'
        self.help += 'First you must create some variables. You can do that by typing \n'
        self.help += '"/gvm set *var*=*value*" where *var* is the variables name (no $ symbol), and\n'
        self.help += '*value* is the variables starting value. The variables name can be any word,\n'
        self.help += 'but dont put spaces between the variables name and value.\n'
        self.help += '\n'
        self.help += 'You can look up the value of a variable by typing "/gvm get *var*"\n'
        self.help += '\n'
        self.help += 'To set your status, type "/gvm status *message*" where *message* is the message \n'
        self.help += 'you want your status to have. To include variables, simply the variables name, \n'
        self.help += 'STARTING WITH A $ SYMBOL. For example, you could create a status with \n'
        self.help += '"/gvm status HP:$hp MP:$mp AC:$ac" which, if $hp was 20, $mp was 10, and $ac\n'
        self.help += 'was 5, would make your status "HP:20 MP:10 AC:5".\n'
        self.help += '\n'
        self.help += 'If you later change the values of any of the variables in your status, they will \n'
        self.help += 'be automatically updated; to update a value, just type\n'
        self.help += '"/gvm set *var*=*variable*" the same way you used it to create the variable.\n'
        self.help += '\n'
        self.help += 'You can list the current variables with the "/gvm list" command. You can also\n'
        self.help += 'now roll dice with curly brackets, and have filters apply to them, like this:\n'
        self.help += '"{4d6.takeHighest(3)+$bonus}". Any other filters you have (i.e. the Alias \n'
        self.help += 'Library) will also apply to curly bracket rolls automatically.\n'
        self.help += '\n'
        self.help += 'Note that the GVM plugin conflicts with the NowPlaying and GSC plugins, so if\n'
        self.help += 'you have both plugin enabled at the same time, they may not work quite right.\n'
        self.help += '\n'
        self.help += 'You can now save a group of variables with "/gvm save *name*". You can also load\n'
        self.help += 'a group of previously saved variables with "/gvm open *name*"\n'

        #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.vars = {}
        self.status_scrip=""
        self.status_on=0


    def plugin_enabled(self):
        #You can add new /commands like
        # self.plugin_addcommand(cmd, function, helptext)
        self.plugin_addcommand('/gvm', self.on_gvm, '[set name=value | calc name=value | get name | status | list | save set_name |  open set_name] - This plugin is used to manage variables that you can use in your status bar or in dice rolls')
        self.plugin_addcommand('/gvmq', self.on_gvmq, '[set name=value | calc name=value | get name | status | list | save set_name |  open set_name] - This plugin is used to manage variables that you can use in your status bar or in dice rolls', False)
        self.plugin_addcommand('/=', self.on_comment, '', False)

    def plugin_disabled(self):
        #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
        #such as closing windows created by the plugin
        self.plugin_removecmd('/gvm')
        self.plugin_removecmd('/gvmq')
        self.plugin_removecmd('/=')

    def on_comment(self, cmdargs):
        pass

    def on_gvm(self, cmdargs):
        for key in self.vars.keys():
            cmdargs = cmdargs.replace("$" + key, self.vars[key])

        args = cmdargs.split(None,-1)
        if len(args) == 0:
            args = [' ']
        if args[0]=="set":
            cmd = cmdargs[len(args[0])+1:].strip().split("=")
            self.vars[cmd[0]] = cmd[1]
            self.chat.InfoPost("GVM: Set variable $" + cmd[0] + " to be: " + cmd[1])
            if self.status_on:
                self.gvm_status(self.status_scrip)

        elif args[0]=="calc":
            cmd = cmdargs[len(args[0])+1:].strip().split("=")
            val = str(eval(cmd[1]))
            self.vars[cmd[0]] = val
            self.chat.InfoPost("GVM: Set variable $" + cmd[0] + " to be: " + val)
            if self.status_on:
                self.gvm_status(self.status_scrip)

        elif args[0]=="get":
            if args[1] in self.vars.keys():
                self.chat.InfoPost("GVM: Variable $" + args[1] + " is: " + self.vars[args[1]])
            else:
                self.chat.InfoPost("GVM: Variable $" + args[1] + " does not exist!")

        elif args[0]=="status":
            self.status_scrip = cmdargs[len(args[0])+1:]
            status_on = 1
            self.gvm_status(self.status_scrip)

        elif args[0]=="save":
            fname = cmdargs[len(args[0])+1:]
            self.plugindb.SetDict("xxgvm", fname, self.vars)
            self.chat.InfoPost("GVM: Successfully saved variable set " + fname + "!")

        elif args[0]=="open":
            fname = cmdargs[len(args[0])+1:]
            self.vars = self.plugindb.GetDict("xxgvm", fname, {})
            self.chat.InfoPost("GVM: Loaded the file " + fname + ". Variables contained are:<br />" + self.make_list())

        elif args[0] == "list":
            self.chat.Post(self.make_list())

        else:
            self.chat.InfoPost("GVM: SYNTAX ERROR. <br />USEAGE: /gvm [set name=value | get name | status | list | save set_name |  open set_name]")

    def on_gvmq(self, cmdargs):
        for key in self.vars.keys():
            cmdargs = cmdargs.replace("$" + key, self.vars[key])
        args = cmdargs.split(None,-1)
        if len(args) == 0:
            args = [' ']
        if args[0]=="set":
            cmd = cmdargs[len(args[0])+1:].strip().split("=")
            self.vars[cmd[0]] = cmd[1]
            if self.status_on:
                self.gvm_status(self.status_scrip)

        elif args[0]=="calc":
            cmd = cmdargs[len(args[0])+1:].strip().split("=")
            self.vars[cmd[0]] = str(eval(cmd[1]))
            if self.status_on:
                self.gvm_status(self.status_scrip)

        elif args[0]=="get":
            if args[1] in self.vars.keys():
                self.chat.InfoPost("GVM: Variable $" + args[1] + " is: " + self.vars[args[1]])
            else:
                self.chat.InfoPost("GVM: Variable $" + args[1] + " does not exist!")

        elif args[0]=="status":
            self.status_scrip = cmdargs[len(args[0])+1:]
            status_on = 1
            self.gvm_status(self.status_scrip)

        elif args[0]=="save":
            fname = cmdargs[len(args[0])+1:]
            self.plugindb.SetDict("xxgvm", fname, self.vars)

        elif args[0]=="open":
            fname = cmdargs[len(args[0])+1:]
            self.vars = self.plugindb.GetDict("xxgvm", fname, {})

        elif args[0] == "list":
            self.chat.Post(self.make_list())

        else:
            self.chat.InfoPost("GVM: SYNTAX ERROR. <br />USEAGE: /gvmq [set name=value | get name | status | list | save set_name |  open set_name]")


    def pre_parse(self, text):
        try:
            for key in self.vars.keys():
                text = text.replace("$" + key, self.vars[key])
        except Exception, e:
            print e
            print key
            self.vars[key]

        return text

    def gvm_status(self, cmd):
        keychain = self.vars.keys()
        keychain.sort()
        newchain = []
        for key in keychain:
            newchain = [key] + newchain
        for key in keychain:
            cmd = cmd.replace("$" + key, self.vars[key])
        self.settings.set_setting("IdleStatusAlias", cmd)
        self.session.set_text_status(cmd)

    def make_list(self):
        keychain = self.vars.keys()
        lister = ""
        for key in keychain:
            lister += "$" + key + "\t::\t" + self.vars[key] + "<br />"
        if len(keychain)==0:
            return "No variables!"
        else:
            return lister