-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
98 lines (85 loc) · 2.31 KB
/
Main.hx
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import sys.FileSystem;
import sys.io.File;
import haxe.io.Path;
class Main {
static var numLevelsConverted:Int = 0;
static public function main():Void {
var args = Sys.args();
if (args.length == 0 || args[0] == "--help") {
trace("Usage: ogmo-conv.py [-p projectFile] [-l levelFile] [-r rootLevelDirectory]");
Sys.exit(0);
}
var projectFile: String = "";
var levelFiles: Array<String> = new Array<String>();
var rootDirectory: String = "";
// Process arguments
var flagType = "";
for (arg in args) {
// Read flags
if (arg == "-p" || arg == "-l" || arg == "-r") {
flagType = arg;
continue;
}
// Read argument data
if (flagType == "-p") {
if (projectFile != "") {
trace("ERROR: Only one project file can be specified at a time!");
Sys.exit(1);
}
projectFile = arg;
}
else if (flagType == "-l") {
levelFiles.push(arg);
}
else if (flagType == "-r") {
rootDirectory = arg;
}
else {
trace("ERROR: Unknown argument or flag '" + arg + "'.");
Sys.exit(1);
}
// Reset
flagType = "";
}
if (projectFile == "") {
trace("ERROR: No project file specified!");
Sys.exit(1);
}
// Convert the project file
var projectConverter = new ProjectConverter();
projectConverter.convert(projectFile, rootDirectory);
// Convert any levels specified
var levelConverter = new LevelConverter();
for (level in levelFiles) {
levelConverter.convert(level, projectConverter.projectData);
numLevelsConverted++;
}
// Convert all levels in the root directory and its subdirectories
if (rootDirectory != "") {
convertDirectoryRecursive(
projectConverter,
levelConverter,
rootDirectory
);
}
// Display a "done!" message
trace("Finished! Converted " + numLevelsConverted + " levels!");
}
private static function convertDirectoryRecursive(
projConv:ProjectConverter,
levelConv:LevelConverter,
rootDirectory:String
) {
var paths = FileSystem.readDirectory(rootDirectory);
for (path in paths) {
var fullPath = Path.addTrailingSlash(rootDirectory) + path;
if (Path.extension(fullPath) == "oel") {
levelConv.convert(fullPath, projConv.projectData);
numLevelsConverted++;
}
else if (FileSystem.isDirectory(fullPath)) {
convertDirectoryRecursive(projConv, levelConv, fullPath);
}
}
}
}