mail[Wesnoth-commits] r25381 - /trunk/data/tools/wmlunits


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

Header


Content

Posted by esr on March 31, 2008 - 17:07:
Author: esr
Date: Mon Mar 31 17:07:31 2008
New Revision: 25381

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25381&view=rev
Log:
Collect all unit data in a single object so we can resolve basenames.

Modified:
    trunk/data/tools/wmlunits

Modified: trunk/data/tools/wmlunits
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wmlunits?rev=25381&r1=25380&r2=25381&view=diff
==============================================================================
--- trunk/data/tools/wmlunits (original)
+++ trunk/data/tools/wmlunits Mon Mar 31 17:07:31 2008
@@ -19,7 +19,10 @@
 import wesnoth.wmltools as wmltools
 
 class UnitList:
-    def __init__(self, units_filename, text_to_parse, description):
+    def __init__(self):
+        self.units_by_campaign = {}
+
+    def add(self, units_filename, text_to_parse, campaign):
         "Collect all units in the specified namespace, None = mainline."
 
         # Create a new parser.
@@ -38,15 +41,16 @@
         parser.parse_top(WML)
 
        # Collect unit data
-        self.units = WML.get_first("+units")
-
-        self.description = description
+        newunits = WML.get_first("+units").get_all("unit_type")
+        for unit in newunits:
+            unit.campaign = campaign
+        self.units_by_campaign[campaign] = newunits
 
 def report_unit_names(unitlist, isocode):
     tx = None
     doubles = {}
     races = {}
-    for u in  unitlist.units.get_all("unit_type"):
+    for u in  unitlist:
         # Fetch name of unit
         name = u.get_text_val("name")
         if name == None or name == "":
@@ -167,15 +171,17 @@
     wmltools.pop_to_top("wmlunits")
     datadir = os.getcwd() + "/data"
 
+    unitlist = UnitList()
+
     # Parse all unit data
-    allunits = [UnitList("data/core/units.cfg", None, " - mainline")]
+    unitlist.add("data/core/units.cfg", None, "mainline")
     campaigns = glob.glob("data/campaigns/*")
     for campaign in campaigns:
         dirname = campaign[5:] # strip leading data/
         description = dirname[10:].replace("_", " ")
-        allunits.append(UnitList(None,
-                                 "[+units]{%s/units}[/units]" % dirname,
-                                 " - " + description))
+        unitlist.add(None,
+                     "[+units]{%s/units}[/units]" % dirname,
+                     description)
 
     # Report generation
     if use_html:
@@ -183,8 +189,8 @@
     else:
         print '{| border="solid"'
 
-    for unitlist in allunits:
-        report_unit_names(unitlist, isocode)
+    for unitgroup in unitlist.units_by_campaign.values():
+        report_unit_names(unitgroup, isocode)
 
     if use_html:
         print "</body></html>"




Related Messages


Powered by MHonArc, Updated Mon Mar 31 17:21:37 2008