mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-24 20:59:29 +00:00

The python2 trackplacer included both the handling of the file format, and the GUI application. This trackplacer3 is a library for the file format, without the GUI. The new tmx_trackplacer is a command-line tool for exporting the data to Tiled's .tmx format, and re-importing it back to .cfg files, so that the GUI of Tiled can be used to avoid reimplementing the GUI of Trackplacer in Python 3. The implementation uses Tiled's Object Layers (not Tile Layers). This allows additional journey markers to be added with the "Insert Tile" tool, and additional journeys to be added as new layers. It can also read in a .cfg and then re-export it to a new .cfg file, to see if the data is preserved. The format is chosen by the output filename. The old trackplacer2 isn't removed in this commit - before removing it, I think trackplacer3 needs some way to preview the animation. ----- Comments on the mainline campaigns: ----- AToTB, DM, LoW, NR and THoT will work with this. But: Northern Rebirth's bigmap.cfg has a track RECOVERY whose STAGE1 starts with an OLD_REST - that isn't handled by trackplacer, it must have been hand-edited. That OLD_REST will be lost when read by either trackplacer2 or trackplacer3, similarly the OLD_BATTLE of LoW's SAURIANS track will be lost. Delfador's Memoirs SEARCH_STAGE1 is omitted from all subsequent parts of SEARCH. Also in DM, SEARCH_STAGE3 has a point which is then moved in STAGE4 onwards - I guess a hand edit. Both of this will be overwritten if the file is edited with either this tool or with the python2 trackplacer. SotA's journey_chapter*.cfg files and WoV's bigmap.cfg file have some of the trackplacer comments removed, they won't be handled by this tool, at least not until better error handling is added.
72 lines
2.9 KiB
Python
Executable File
72 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
# encoding: utf-8
|
||
"""
|
||
tmx_trackplacer -- a tool for placing map tracks using Tiled
|
||
|
||
This creates .tmx files (Tiled's format) based on the trackplacer's journey data.
|
||
The journey can be edited in Tiled using the "Insert Tile" tool, and then the .tmx
|
||
data converted back to the trackplacer parts of the .cfg file.
|
||
|
||
It can also read in a .cfg and then re-export it to a new .cfg file, to see if the
|
||
data is preserved. The format is chosen by the filename given to the --output option.
|
||
|
||
If a .jpg or .png file is given as the input, then the output will be a template .tmx
|
||
or .cfg file for drawing a track on top of that image.
|
||
|
||
Example usage:
|
||
* data/tools/tmx_trackplacer images/campaign_map.png --output temp.tmx
|
||
* data/tools/tmx_trackplacer data/campaigns/Northern_Rebirth/utils/bigmap.cfg --output temp.tmx
|
||
* data/tools/tmx_trackplacer data/campaigns/Northern_Rebirth/utils/bigmap.cfg --output temp.cfg
|
||
"""
|
||
|
||
import wesnoth.trackplacer3 as tp3
|
||
|
||
import argparse
|
||
|
||
if __name__ == "__main__":
|
||
ap = argparse.ArgumentParser(usage=__doc__)
|
||
ap.add_argument("file", metavar="string", help="Read input from this file")
|
||
ap.add_argument("-o", "--output", metavar="string",
|
||
help='Write output into the specified file')
|
||
ap.add_argument("--data-dir", metavar="dir",
|
||
help='Same as Wesnoth’s “--data-dir” argument')
|
||
options = ap.parse_args()
|
||
|
||
if options.data_dir is None:
|
||
import os, sys
|
||
APP_DIR,APP_NAME=os.path.split(os.path.realpath(sys.argv[0]))
|
||
WESNOTH_ROOT_DIR=os.sep.join(APP_DIR.split(os.sep)[:-2]) # pop out "data" and "tools"
|
||
options.data_dir=os.path.join(WESNOTH_ROOT_DIR,"data")
|
||
|
||
journey = None
|
||
if options.file:
|
||
if options.file.endswith(".cfg"):
|
||
reader = tp3.CfgFileFormat()
|
||
(journey, metadata) = reader.read(options.file)
|
||
elif options.file.endswith(".tmx"):
|
||
reader = tp3.TmxFileFormat(wesnoth_data_dir=options.data_dir)
|
||
(journey, metadata) = reader.read(options.file)
|
||
elif options.file.endswith(".png") or options.file.endswith(".jpg"):
|
||
journey = tp3.Journey()
|
||
journey.mapfile = options.file
|
||
metadata = None
|
||
else:
|
||
raise RuntimeError("Don't know how to handle input from this file type")
|
||
|
||
if journey:
|
||
print("Read data:", str(journey))
|
||
else:
|
||
raise RuntimeError("Failed to read journey data")
|
||
|
||
if options.output:
|
||
if options.output.endswith(".cfg"):
|
||
print("Exporting as cfg")
|
||
exporter = tp3.CfgFileFormat()
|
||
exporter.write(options.output, journey, metadata)
|
||
elif options.output.endswith(".tmx"):
|
||
print("Exporting as tmx")
|
||
exporter = tp3.TmxFileFormat(wesnoth_data_dir=options.data_dir)
|
||
exporter.write(options.output, journey, metadata)
|
||
else:
|
||
raise RuntimeError("Don't know how to handle output to this file type")
|