changeset 516:e8816dc7c8bb

added /setnode similar to /addtonode and took out alias /add for /addtonode as it clashes with the popular plugin inittool2
author davidbyron
date Sun, 07 Mar 2010 19:09:57 -0600
parents 52dcb3fed083
children 23cd3f41252c
files orpg/chat/commands.py
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/orpg/chat/commands.py	Wed Feb 10 20:39:17 2010 -0600
+++ b/orpg/chat/commands.py	Sun Mar 07 19:09:57 2010 -0600
@@ -178,6 +178,8 @@
                         'This will toggle the Advanced Filter')
         self.addcommand('/addtonode', self.on_add,
                         '[number pathname] Add an integer to the value of a node')
+        self.addcommand('/setnode', self.on_setnode,
+                        '[number pathname] Set the value of a node')
         self.addcommand('/allaliases', self.on_all,
                         'The following line of text is spoken by all aliases in the alias lib in turn.')
         self.addcommand('/input', self.on_input,
@@ -195,7 +197,6 @@
         self.addshortcmd('/date', '/time')
         self.addshortcmd('/desc', '/description')
         self.addshortcmd('/d', '/description')
-        self.addshortcmd('/add', '/addtonode')
         self.addshortcmd('/all', '/allaliases')
 
         #This is just an example or a differant way the shorcmd can be used
@@ -762,6 +763,29 @@
         handler.set_value(str(value+number))
 
     @debugging
+    def on_setnode(self, cmdargs):
+        cmdargs.strip()
+        pos = cmdargs.find(" ")
+        try:
+            number = int(cmdargs[:pos])
+        except:
+            self.chat.InfoPost("First parameter must be an integer.")
+            return
+        path = cmdargs[pos:].strip()
+        tree = open_rpg.get_component('tree')
+        handler = tree.get_handler_by_path(path, self.context)
+        if handler is None:
+            self.chat.InfoPost("Second parameter must be an indexed node.")
+            return
+        value = handler.get_value()
+        try:
+            value = int(value)
+        except:
+            self.chat.InfoPost("Value of node must be an integer.")
+            return
+        handler.set_value(str(number))
+
+    @debugging
     def on_all(self, cmdargs):
         names = self.chat.aliasList.GetItems()
         if len(names) == 1: