adonthell-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-commits] CVS: adonthell/src/tools/dlgedit dialogue.py,1.2,1.3


From: Kai Sterker <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/src/tools/dlgedit dialogue.py,1.2,1.3 dlg_cmdline.cc,1.1,1.2 dlg_cmdline.h,1.1,1.2 dlg_compiler.cc,1.3,1.4 dlg_module.cc,1.2,1.3 main.cc,1.54,1.55
Date: Fri, 12 Apr 2002 11:35:43 -0400

Update of /cvsroot/adonthell/adonthell/src/tools/dlgedit
In directory subversions:/tmp/cvs-serv19047/src/tools/dlgedit

Modified Files:
        dialogue.py dlg_cmdline.cc dlg_cmdline.h dlg_compiler.cc 
        dlg_module.cc main.cc 
Log Message:
ADDED new dialogue engine with i18n support
FIXED bugs with the dialogue compiler


Index: dialogue.py
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/tools/dlgedit/dialogue.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** dialogue.py 7 Apr 2002 09:51:28 -0000       1.2
--- dialogue.py 12 Apr 2002 15:35:41 -0000      1.3
***************
*** 25,30 ****
      #       to be used for the next selection. Also append the speaker
      #       associated with each line of text.
-     #    3) return whether the next choice is to be made by the Dialogue
-     #       Engine (1) or the Player (0)
      #
      #    All data for these actions is retrieved from the derived class.
--- 25,28 ----
***************
*** 32,46 ****
          self.speech = []
          self.speaker = []
!         
          # -- get the code to execute, the hint fot the dialogue engine
          #    and the list of following dialogue options
!         code, stop, follow = self.dlg[index][1:]
          
          # -- if there is code, try to execute it
          if code != -1: 
!             self.execute (self.code[code])
      
          # -- for each following option:
!         for speech, operation, cond in follow:
              
              # -- if we're in an elif or else part of a condition
--- 30,45 ----
          self.speech = []
          self.speaker = []
!         result = 0
!                 
          # -- get the code to execute, the hint fot the dialogue engine
          #    and the list of following dialogue options
!         code, followers = self.dlg[index][1:]
          
          # -- if there is code, try to execute it
          if code != -1: 
!             self.execute (self.code[code], 1)
      
          # -- for each following option:
!         for (speech, operation, cond) in followers:
              
              # -- if we're in an elif or else part of a condition
***************
*** 50,80 ****
              # -- try to ececute the condition, if there is one
              if cond != -1:
!                 result = self.execute (self.cond[cond])
!             else
                  result = 1
              
              # -- only append the option if the condition was met
              if result == 1:
                  self.speech.append (speech)
-                 self.speaker.append (self.dlg[speech][0])
  
!         # -- finally, tell the dialogue engine what to do            
!         return stop
      
      
      # -- Execute some arbitrary Python code
!     def execute (self, statement):
          try:
!             # -- try to execute the code
!             retval = exec (statement)
!             return retval
          except:
              # -- in case of an error, print what happened and continue
              err_type, value = sys.exc_info ()[:2]
!             print "Error:\n  " + str (err_type) + ":\n  \"" + str (value) + 
"\""
  
          return 0
  
  
      # -- Allow usage of undeclared variables
      def __getattr__ (self, name):
--- 49,95 ----
              # -- try to ececute the condition, if there is one
              if cond != -1:
!                 result = self.execute (self.cond[cond], 0)
!             else:
                  result = 1
              
              # -- only append the option if the condition was met
              if result == 1:
+                 speaker = self.dlg[speech][0]
+                 if speaker == "Default": speaker = self.the_npc.get_name ()
+                 self.speaker.append (speaker)
                  self.speech.append (speech)
  
!         # -- finally, return           
!         return
      
      
      # -- Execute some arbitrary Python code
!     def execute (self, statement, multiline):
          try:
!             # -- this is for multiline code without retval
!             if multiline == 1:
!                 code = compile (statement, "", "exec")
!                 return eval (code, self.namespace, locals ())
!             # -- this is for single line statements with retval
!             else:
!                 return eval (statement, self.namespace, locals ())
          except:
              # -- in case of an error, print what happened and continue
              err_type, value = sys.exc_info ()[:2]
!             print "Error in statement\n  %s  %s:\n    '%s'" \
!                 % (statement, str (err_type), str (value))
  
          return 0
  
  
+     # -- Decide whether the dialogue engine should return control to the
+     #    player (1) or not (0) 
+     def stop (self, index):
+         followers = self.dlg[index][2]
+ 
+         if len (followers) > 0 and self.dlg[followers[0][0]][0] == None: 
return 0
+         else: return 1
+ 
+         
      # -- Allow usage of undeclared variables
      def __getattr__ (self, name):

Index: dlg_cmdline.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/tools/dlgedit/dlg_cmdline.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** dlg_cmdline.cc      9 Apr 2002 13:16:24 -0000       1.1
--- dlg_cmdline.cc      12 Apr 2002 15:35:41 -0000      1.2
***************
*** 31,34 ****
--- 31,37 ----
  std::string DlgCmdline::datadir = DATA_DIR"/games";
  
+ // the default project
+ std::string DlgCmdline::project = "";
+ 
  // index of the first dialgoue source in argv[]
  int DlgCmdline::sources;
***************
*** 40,44 ****
      
      // Check for options
!     while ((c = getopt (argc, argv, "cdhvg:")) != -1)
      {
          switch (c)
--- 43,47 ----
      
      // Check for options
!     while ((c = getopt (argc, argv, "cdhvg:j:")) != -1)
      {
          switch (c)
***************
*** 61,65 ****
                  break;
              }
! 
              case 'g':
              {
--- 64,74 ----
                  break;
              }
!             
!             case 'j':
!             {
!                 project = optarg;
!                 break;
!             }
!             
              case 'g':
              {
***************
*** 105,108 ****
      cout << "-v         print version and exit" << endl; 
      cout << "-c         compile all SOURCES and exit" << endl;
!     cout << "-p dir     specify a custom project directory" << endl;         
  }
--- 114,118 ----
      cout << "-v         print version and exit" << endl; 
      cout << "-c         compile all SOURCES and exit" << endl;
!     cout << "-p dir     specify a custom project directory" << endl;
!     cout << "-j project specify a default project" << endl;   
  }

Index: dlg_cmdline.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/tools/dlgedit/dlg_cmdline.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** dlg_cmdline.h       9 Apr 2002 13:16:24 -0000       1.1
--- dlg_cmdline.h       12 Apr 2002 15:35:41 -0000      1.2
***************
*** 26,37 ****
  
  /**
!  *
   */
  class DlgCmdline
  {
  public:
      static bool parse (int argc, char* argv[]);
      static std::string datadir;
      static bool compile;
      static int sources;
      
--- 26,67 ----
  
  /**
!  * Apart from the above, DlgCmdline stores the various options
!  * that can be specified on the command line 
   */
  class DlgCmdline
  {
  public:
+     /**
+      * The method doing all the work. To be called right after
+      * dlgedit is launched.
+      * @param argc argument count
+      * @param argv argument vector
+      * @return <b>false</b> indicates that the program shall quit
+      */
      static bool parse (int argc, char* argv[]);
+ 
+     /**
+      * The directory where dlgedit searches for projects.
+      */
      static std::string datadir;
+     
+     /**
+      * The project. This is the directory that contains the character-
+      * and quest data dlgedit needs to (properly) compile dialogues
+      * making use of advanced Python scripting features.
+      */
+     static std::string project;
+     
+     /**
+      * This is set to <b>true</b> to indicate that only the dialogue
+      * compiler should be run on the given sourcefiles, without launching
+      * the GUI. After all files are compiled, dlgedit exits.
+      */
      static bool compile;
+     
+     /**
+      * The index in the argument vector pointing to the first non-option.
+      * With a bit of luck, this is one or more dialogue sources.
+      */
      static int sources;
      

Index: dlg_compiler.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/tools/dlgedit/dlg_compiler.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** dlg_compiler.cc     9 Apr 2002 13:15:37 -0000       1.3
--- dlg_compiler.cc     12 Apr 2002 15:35:41 -0000      1.4
***************
*** 216,219 ****
--- 216,220 ----
      // constructor
      file << "\n\tdef __init__(self, p, n):"
+          << "\n\t\tself.namespace = globals ()"
           << "\n\t\tself.the_player = p"
           << "\n\t\tself.the_npc = n\n";
***************
*** 434,438 ****
      file << "\t# -- (speaker, code, stop, (text, operation, condition, ...))"
           << "\n\tdlg = [\\\n"
!          << "\t\t(None, -1, 1, (";
      
      // write the "followers" (in this case the start nodes)
--- 435,439 ----
      file << "\t# -- (speaker, code, stop, (text, operation, condition, ...))"
           << "\n\tdlg = [\\\n"
!          << "\t\t(None, -1, (";
      
      // write the "followers" (in this case the start nodes)
***************
*** 442,449 ****
  
          for (i = start.begin (); i != start.end (); i++)
-         {
-             if (i != start.begin ()) file << ", ";
              writeFollower (*i);
-         }
      }
  }
--- 443,447 ----
***************
*** 456,460 ****
      DlgCircle *circle, *child;
      DlgCircleEntry *entry;
-     int index;
          
      for (i = nodes.begin (); i != nodes.end (); i++)
--- 454,457 ----
***************
*** 489,504 ****
          
          // write code
!         file << ", " << codeTable[circle->index ()] << ", "
                  
!         // write action
!              << checkFollowers (circle) << ", (";
          
          // write all followers
!         index = 0;
!         for (child = circle->child (FIRST); child != NULL; child = 
circle->child (NEXT), index++)
!         {
!             if (index != 0) file << ", ";
              writeFollower (child);
-         }
      }
      
--- 486,497 ----
          
          // write code
!         file << ", " << codeTable[circle->index ()] << ", (";
                  
!         // check whether the followers are valid
!         checkFollowers (circle);
          
          // write all followers
!         for (child = circle->child (FIRST); child != NULL; child = 
circle->child (NEXT))
              writeFollower (child);
      }
      
***************
*** 510,515 ****
  void DlgCompiler::writeFollower (DlgNode *node)
  {
!     file << node->index () << ", " << operationTable[node->index ()] 
!          << ", " << conditionTable[node->index ()];
  }
  
--- 503,508 ----
  void DlgCompiler::writeFollower (DlgNode *node)
  {
!     file << "(" << node->index () << ", " << operationTable[node->index ()] 
!          << ", " << conditionTable[node->index ()] << "), ";
  }
  
***************
*** 520,525 ****
  
      // search the proper place for insertion
!     if (!start.empty ()) 
!         while (i != start.end () && *node < *(*i)) i++;
      
      // insert
--- 513,521 ----
  
      // search the proper place for insertion
!     while (i != start.end ())
!     {
!         if (*node < *(*i)) break;
!         i++;
!     }
      
      // insert
***************
*** 624,628 ****
  {
      DlgNode *child = circle->child (FIRST);
!     if (child == NULL) return 1;
      
      node_type type = child->type ();
--- 620,624 ----
  {
      DlgNode *child = circle->child (FIRST);
!     if (child == NULL) return 0;
      
      node_type type = child->type ();
***************
*** 651,657 ****
          }
      }
!     
!     if (type == PLAYER) return 0;
!     else return 1;
  }
  
--- 647,652 ----
          }
      }
! 
!     return 1;
  }
  

Index: dlg_module.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/tools/dlgedit/dlg_module.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** dlg_module.cc       7 Apr 2002 09:51:28 -0000       1.2
--- dlg_module.cc       12 Apr 2002 15:35:41 -0000      1.3
***************
*** 24,28 ****
  #include "dlg_circle.h"
  #include "dlg_arrow.h"
! 
  
  // ctor
--- 24,28 ----
  #include "dlg_circle.h"
  #include "dlg_arrow.h"
! #include "dlg_cmdline.h"
  
  // ctor
***************
*** 188,191 ****
--- 188,195 ----
      std::string s;
  
+     // load the default project if there is one
+     if (DlgCmdline::project != "")
+         entry_.setProject (DlgCmdline::project);
+     
      // load all nodes and toplevel items
      while (i)

Index: main.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/tools/dlgedit/main.cc,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -r1.54 -r1.55
*** main.cc     9 Apr 2002 13:15:37 -0000       1.54
--- main.cc     12 Apr 2002 15:35:41 -0000      1.55
***************
*** 26,30 ****
  #include <gtk/gtk.h>
  #include <locale.h>
- #include <getopt.h>
  #include "gettext.h"
  #include "game.h"
--- 26,29 ----
***************
*** 88,92 ****
              }
              
!             module = new DlgModule (dialogue, "");
              
              // try to load from file
--- 87,91 ----
              }
              
!             module = new DlgModule (dialogue + "-1", "");
              
              // try to load from file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]