123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!/usr/bin/env python3
- # Flexlay - A Generic 2D Game Editor
- # Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- import argparse
- import logging
- import sys
- from flexlay.util.config import Config
- from supertux.level import Level
- from supertux.config import make_config
- def main():
- has_error = False
- parser = argparse.ArgumentParser(description="SuperTux Level Tool")
- parser.add_argument("LEVELFILE", action="store", type=str, nargs="+",
- help=".stl file to load")
- parser.add_argument("-d", "--datadir", metavar="DIR", action="store", type=str,
- help="SuperTux data directory directory")
- parser.add_argument("-o", "--output", metavar="FILE", action="store", type=str,
- help="Load and resave the level to FILE")
- parser.add_argument("--resave", action="store_true", default=False,
- help="Load and resave level in place")
- args = parser.parse_args()
- config = make_config()
- if args.datadir is not None:
- config.datadir = args.datadir
- elif not config.datadir:
- raise RuntimeError("datadir missing, use --datadir DIR")
- for levelfile in args.LEVELFILE:
- logging.info("Loading {}".format(levelfile))
- try:
- level = Level.from_file(levelfile)
- if args.output:
- level.save(args.output)
- elif args.resave:
- print("resaving {}".format(levelfile))
- level.save(levelfile)
- except Exception as err:
- logging.exception("ERROR: {}", err)
- has_error = True
- return 1 if has_error else 0
- if __name__ == "__main__":
- sys.exit(main())
- # EOF #
|