-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsupertux-level
executable file
·68 lines (55 loc) · 2.29 KB
/
supertux-level
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# Flexlay - A Generic 2D Game Editor
# Copyright (C) 2014 Ingo Ruhnke <[email protected]>
#
# 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 #