Author: esr
Date: Mon Oct 13 22:18:37 2008
New Revision: 30140

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30140&view=rev
Log:
trackplacer: Sinplify by eliminating .trk files, we now read and write
.cfg files directly.

Removed:
    trunk/data/campaigns/Liberty/utils/journey.trk
Modified:
    trunk/data/campaigns/Liberty/utils/journey.cfg
    trunk/data/tools/trackplacer

Modified: trunk/data/campaigns/Liberty/utils/journey.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/campaigns/Liberty/utils/journey.cfg?rev=30140&r1=30139&r2=30140&view=diff
==============================================================================
--- trunk/data/campaigns/Liberty/utils/journey.cfg (original)
+++ trunk/data/campaigns/Liberty/utils/journey.cfg Mon Oct 13 22:18:37 2008
@@ -1,6 +1,8 @@
 # Automatically generated by trackplacer on Mon Oct 13 14:38:45 2008.
 # Don't hand-hack -- edit the associated track file
 # and then regenerate this instead.
+#
+# trackplacer: map=data/campaigns/Liberty/images/maps/wesnoth-liberty.png
 
 #define JOURNEY_STAGE_1
     {NEW_BATTLE 252 252}

Removed: trunk/data/campaigns/Liberty/utils/journey.trk
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/campaigns/Liberty/utils/journey.trk?rev=30139&view=auto
==============================================================================
--- trunk/data/campaigns/Liberty/utils/journey.trk (original)
+++ trunk/data/campaigns/Liberty/utils/journey.trk (removed)
@@ -1,22 +1,0 @@
-MAP data/campaigns/Liberty/images/maps/wesnoth-liberty.png
-BATTLE 252 252
-JOURNEY 247 248
-BATTLE 242 267
-JOURNEY 235 252
-BATTLE 229 248
-JOURNEY 232 270
-JOURNEY 224 290
-BATTLE 209 300
-JOURNEY 231 297
-JOURNEY 245 316
-JOURNEY 250 338
-BATTLE 273 346
-JOURNEY 279 360
-JOURNEY 283 380
-BATTLE 288 400
-JOURNEY 282 435
-JOURNEY 260 439
-JOURNEY 238 431
-BATTLE 223 412
-JOURNEY 215 407
-BATTLE 206 386

Modified: trunk/data/tools/trackplacer
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/trackplacer?rev=30140&r1=30139&r2=30140&view=diff
==============================================================================
--- trunk/data/tools/trackplacer (original)
+++ trunk/data/tools/trackplacer Mon Oct 13 22:18:37 2008
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-"""
+'''
 trackplacer -- map journey track editor.
 
 usage: trackplacer [-vh?] [filename]
@@ -9,16 +9,16 @@
 program; Selecting a file takes you to a main screen.  For command help on
 the main screen, click the Help button.
 
-Can be started with a map image, in which case we're editing a new journey.
-Can be started with a track file. A track file is a text file interpreted
-line-by-line; each line is interpreted as whitespace-separated fields.
-The first field of the first line must be MAP, and the second field
-of that line must be valid filename.  Subsequent lines must have three
-fields each: an action tag (JOURNEY, BATTLE, or REST) and two numeric
-coordinate fields.
+Can be started with a map image, in which case we are editing a new journey.
+Can be started with a .cfg file.  All parts of .cfg files other than the
+NEW_* macros placing tracking icons are ignored, except that a comment
+of the form "# trackplacer: map=fubar.png" is interpreted as a declaration
+that this track has the base map fubar.png (or similarly for any other
+fiilrename after the = sign). The NEW_* macros are interpreted snd their
+features appended to the track in the order they are given in the file.
 
 A journey is an object containing a map file name and a (possibly empty)
-track. This program exists to visually edit journeys represented in track
+track. This program exists to visually edit journeys represented in .cfg
 files.
 
 Normally, trackplacer assumes it is running within a Battle for
@@ -32,7 +32,7 @@
 The -d option sets the root directory to use.
 
 The -h or -? options display this summary.
-"""
+'''
 
 gui_help = '''\
 This is trackplacer, an editor for visually editing journey tracks on Battle 
For Wesnoth maps.
@@ -50,7 +50,7 @@
 Design and implementation by Eric S. Raymond, October 2008.
 '''
 
-import sys, os, time, exceptions, getopt
+import sys, os, re, time, exceptions, getopt
 
 import pygtk
 pygtk.require('2.0')
@@ -95,16 +95,12 @@
         self.initial_track = []
     def write(self, fp, prefix="JOURNEY_"):
         "Record a journey track."
-        if fp.name.endswith(".trk"):
-            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"):
-            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")
+        if fp.name.endswith(".cfg"):
+            fp.write("# Edited by trackplacer on 
%s.\n"%time.ctime(time.time()))
+            fp.write("# Hand-hack strictly at your own risk\n")
+            fp.write("#\n")
+            fp.write("# trackplacer: map=%s\n" % self.mapfile)
+            fp.write("#\n")
             index_tuples = zip(range(len(self.track)), self.track)
             index_tuples = filter(lambda (i, (a, x, y)): a in segmenters,
                                   index_tuples)
@@ -140,26 +136,29 @@
         if fp.name.endswith(".png") or fp.name.endswith(".jpg"):
             self.mapfile = fp.name
             return
-        if not fp.name.endswith(".trk"):
+        if not fp.name.endswith(".cfg"):
             raise IOException("Cannot read this filetype.", fp.name)
-        header = fp.readline().split()
-        if header[0] != 'MAP':
-            raise IOException("Missing MAP element.", fp.name, 1)
+        waypoint_re = re.compile("{NEW_(" + "|".join(icon_presentation_order) 
+ ")" \
+                                 + " +([0-9]+) +([0-9]+)}")
+        property_re = re.compile("# *trackplacer: ([^=]+)=(.*)")
+        self.properties = {}
+        for line in fp:
+            m = re.search(waypoint_re, line)
+            if m:
+                try:
+                    tag = m.group(1)
+                    x = int(m.group(2))
+                    y = int(m.group(3))
+                    self.initial_track.append((tag, x, y))
+                except ValueError:
+                    raise IOException("Invalid coordinate field.", fp.name, 
i+1)
+            m = re.search(property_re, line)
+            if m:
+                self.properties[m.group(1)] = m.group(2)
+        if "map" in self.properties:
+            self.mapfile = self.properties['map']
         else:
-            self.mapfile = header[1]
-        for (i, line) in enumerate(fp):
-            fields = line.split()
-            if len(fields) != 3:
-                raise IOException("Ill-formed track file line.", fp.name, i+1)
-            (tag, x, y) = fields
-            if tag not in ("JOURNEY", "BATTLE", "REST"):
-                raise IOException("Invalid tag field on track file line.", 
fp.name, i+1)
-            try:
-                x = int(x)
-                y = int(y)
-            except ValueError:
-                raise IOException("Invalid coordinate field.", fp.name, i+1)
-            self.initial_track.append((tag, x, y))
+            raise IOException("Missing map declaration.", fp.name)
         fp.close()
         self.track = self.initial_track[:]
     def has_unsaved_changes(self):
@@ -348,18 +347,7 @@
         # A save button
         button = gtk.Button("Save")
         buttonbox.pack_end(button, expand=False, fill=False, padding=10)
-        button.connect_object("clicked",
-                              lambda w: self.save_handler(".trk", w),
-                              window)
-        tooltips.set_tip(button, "Save track in .trk format.")
-        button.show()
-
-        # A write-cfg button
-        button = gtk.Button("Write")
-        buttonbox.pack_end(button, expand=False, fill=False, padding=10)
-        button.connect_object("clicked",
-                              lambda w: self.save_handler(".cfg", w),
-                              window)
+        button.connect_object("clicked", self.save_handler, window)
         tooltips.set_tip(button, "Save track in .cfg format.")
         button.show()
 
@@ -543,9 +531,9 @@
         w.run()
         w.destroy()
 
-    def save_handler(self, ext, w):
+    def save_handler(self, w):
         "Save track data,"
-        if ext == ".trk" and not self.journey.has_unsaved_changes():
+        if not self.journey.has_unsaved_changes():
             w = gtk.MessageDialog(type=gtk.MESSAGE_INFO,
                                   flags=gtk.DIALOG_DESTROY_WITH_PARENT,
                                   buttons=gtk.BUTTONS_OK)
@@ -553,15 +541,10 @@
             w.run()
             w.destroy()
         else:
-            dflt = None
-            if self.last_read:
-                if ext == ".trk":
-                    dflt = self.last_read
-                else:
-                    dflt = self.last_read.replace(".trk", ".cfg")
-            w = ModalFileSelector(default=dflt, legend="Save track to file")
-            if not w.path.endswith(ext):
-                raise IOException("File must have a %s extension."%ext, w.path)
+            w = ModalFileSelector(default=self.last_read,
+                                  legend="Save track to file")
+            if not w.path.endswith(".cfg"):
+                raise IOException("File must have a .cfg extension.", w.path)
             if w.path != self.last_read and os.path.exists(w.path):
                 self.save_check = gtk.Dialog(title="Really overwrite?",
                                              parent=None, 
@@ -623,7 +606,10 @@
         try:
             TrackEditor(path=os.path.join(here, arguments[0]), verbose=verbose)
         except IOException, e:
-            sys.stderr.write(('"%s", line %d: ' % (e.path, e.lineno)) + 
e.message + "\n")
+            if e.lineno:
+                sys.stderr.write(('"%s", line %d: ' % (e.path, e.lineno)) + 
e.message + "\n")
+            else:
+                sys.stderr.write(e.path + ": " + e.message + "\n") 
     else:
         while True:
             try:


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

Reply via email to