Author: esr
Date: Mon Oct 13 18:57:51 2008
New Revision: 30125

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30125&view=rev
Log:
trackplacer: can now write progressive macros in .cfg format.

Modified:
    trunk/data/tools/trackplacer

Modified: trunk/data/tools/trackplacer
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/trackplacer?rev=30125&r1=30124&r2=30125&view=diff
==============================================================================
--- trunk/data/tools/trackplacer (original)
+++ trunk/data/tools/trackplacer Mon Oct 13 18:57:51 2008
@@ -48,7 +48,7 @@
 Design and implementation by Eric S. Raymond, October 2008.
 '''
 
-import sys, os, exceptions, getopt
+import sys, os, time, exceptions, getopt
 
 import pygtk
 pygtk.require('2.0')
@@ -67,7 +67,7 @@
     "REST":    imagedir + "misc/flag-red.png",
     }
 icon_presentation_order = ("JOURNEY", "BATTLE", "REST")
-
+segmenters = ("BATTLE","REST")
 
 # Size of the rectangle around the mouse pointer within which the code
 # will seek tracking dots. Should be about (N-1)/2 where N is the
@@ -97,8 +97,33 @@
             fp.write("MAP %s\n" % self.mapfile)
             for location in self.track:
                 fp.write("%s %d %d\n" % location)
+            fp.close()
         elif fp.name.endswith(".cfg"):
-            sys.stderr.write(".cfg eriting is not yet implemented.")
+            fp.write("# Automatically generated by trackplacer on %s.\n" % \
+                     time.ctime(time.time()))
+            fp.write("# Don't hand-hack -- edit the associated track file\n")
+            fp.write("# and then regenerate this instead.\n\n")
+            index_tuples = zip(range(len(self.track)), self.track)
+            index_tuples = filter(lambda (i, (a, x, y)): a in segmenters,
+                                  index_tuples)
+            endpoints = map(lambda (i, t): i, index_tuples)
+            if self.track[-1][0] not in segmenters:
+                endpoints.append(len(self.track)-1)
+            for (i, e) in enumerate(endpoints):
+                fp.write("#define STAGE_%d\n" % (i+1,))
+                for j in range(0, e+1):
+                    age="OLD"
+                    if i == 0 or j > endpoints[i-1]:
+                        age = "NEW"
+                    waypoint = (age,) + tuple(self.track[j])
+                    fp.write("    {%s_%s %d %d}\n" % waypoint)
+                fp.write("#enddef\n\n")
+            fp.write("#define STAGE_COMPLETE\n")
+            for j in range(len(self.track)):
+                waypoint = self.track[j]
+                fp.write("    {OLD_%s %d %d}\n" % tuple(waypoint))
+            fp.write("#enddef\n\n")
+            fp.close()
         else:
             raise IOException("File must have a .trk or .cfg extension.", 
fp.name)
     def read(self, fp):
@@ -133,7 +158,8 @@
             except ValuError:
                 raise IOException("Invalid coordinate field.", fp.name, i+1)
             self.initial_track.append((tag, x, y))
-        self.track = self.initial_track
+        fp.close()
+        self.track = self.initial_track[:]
     def has_unsaved_changes(self):
         return self.track != self.initial_track
     def __getitem__(self, n):
@@ -216,7 +242,9 @@
         self.journey.read(path)
         if path.endswith(".trk"):
             self.last_read = path
+        self.log("Initial track is %s" % self.journey)
         self.action = "JOURNEY"
+
         # Backing pixmap for drawing area
         self.pixmap = None
 
@@ -328,10 +356,8 @@
         # if the map is too large to fit on the screen.
         WINDOW_FRAME_WIDTH = 8
         WINDOW_FRAME_HEIGHT = 28
-        #screen_width = gtk.gdk.screen_width()
-        #screen_height = gtk.gdk.screen_height()
-        screen_width = 640
-        screen_height = 480
+        screen_width = gtk.gdk.screen_width()
+        screen_height = gtk.gdk.screen_height()
         self.log("Map size = (%d,%d)" % (self.map_width, self.map_height))
         self.log("Screen size = (%d,%d)" % (screen_width, screen_height))
         controls_width, controls_height = controls.size_request() 
@@ -529,7 +555,6 @@
             except IOError:
                 raise IOException("Cannot write file.", w.path)
             self.journey.write(fp)
-            fp.close()
 
     def conditional_save_handler(self, widget, id):
         self.save_confirm = (id == gtk.RESPONSE_ACCEPT)            


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to