mail[Wesnoth-commits] r24684 - in /trunk: changelog src/game_events.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by benoit . timbert on March 16, 2008 - 00:54:
Author: noyga
Date: Sun Mar 16 00:54:06 2008
New Revision: 24684

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24684&view=rev
Log:
New [switch] WML tag.
It shall save us for the sometimetime highly nested [if]s.
Here is the basic syntax :
[switch]
   variable=foo
   [case]
      value="A"
      ... code if foo=A ...
   [/case]
   [case]
      value="B"
      ... code if foo=B ...
   [/case]
   [else]
      ... code if foo has another value ...
   [/else]
[/switch]

Modified:
    trunk/changelog
    trunk/src/game_events.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=24684&r1=24683&r2=24684&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Mar 16 00:54:06 2008
@@ -33,6 +33,7 @@
      wmllint can safely do this up-conversion.
    * it's now possible to specify with loop= how many times a sample
      associated with a sound source should be played
+   * new [switch] conditional command
  * miscellaneous and bug fixes:
    * wmlxgettext now print some context information about the strings
      extracted (patch #993)

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=24684&r1=24683&r2=24684&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Sun Mar 16 00:54:06 2008
@@ -1413,6 +1413,35 @@
                        for(vconfig::child_list::const_iterator cmd = 
commands.begin();
                        cmd != commands.end(); ++cmd) {
                                if(!handle_event(event_info, *cmd)) {
+                                       mutated = false;
+                               }
+                       }
+               }
+       }
+
+       else if(cmd == "switch") {
+               assert(state_of_game != NULL);
+
+               const std::string var_name = cfg["variable"];
+               const std::string& var = 
state_of_game->get_variable_const(var_name);
+               
+               bool not_found = true;
+               const vconfig::child_list& cases = cfg.get_children("case");
+               // execute all cases where the value matches
+               for(vconfig::child_list::const_iterator c = cases.begin(); c 
!= cases.end(); ++c) {
+                       const std::string value = (*c)["value"];
+                       if (var == value) {
+                               not_found = false;
+                               if(!handle_event(event_info, *c)) {
+                                       mutated = false;
+                               }
+                       }
+               }
+               if (not_found) {
+                       // otherwise execute 'else' statements
+                       const vconfig::child_list elses = 
cfg.get_children("else");
+                       for(vconfig::child_list::const_iterator e = 
elses.begin(); e != elses.end(); ++e) {
+                               if(!handle_event(event_info, *e)) {
                                        mutated = false;
                                }
                        }




Related Messages


Powered by MHonArc, Updated Sun Mar 16 02:01:18 2008