summaryrefslogtreecommitdiff
path: root/tmxcopy/tmxcollide.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-02-02 02:59:55 +0200
committerAndrei Karas <akaras@inbox.ru>2011-02-02 02:59:55 +0200
commit30ede65e73a18ed774ebd5671c4244fc763481d1 (patch)
tree51c841d17c3db16c7cda8f9f2e28c8520caa70cd /tmxcopy/tmxcollide.cpp
parentf36332ff10ab2eedac1138c7b2739b709f94173c (diff)
downloadtools-30ede65e73a18ed774ebd5671c4244fc763481d1.tar.gz
tools-30ede65e73a18ed774ebd5671c4244fc763481d1.tar.bz2
tools-30ede65e73a18ed774ebd5671c4244fc763481d1.tar.xz
tools-30ede65e73a18ed774ebd5671c4244fc763481d1.zip
Add moved tools from manaplus. http://www.gitorious.org/manaplus/
Diffstat (limited to 'tmxcopy/tmxcollide.cpp')
-rw-r--r--tmxcopy/tmxcollide.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/tmxcopy/tmxcollide.cpp b/tmxcopy/tmxcollide.cpp
new file mode 100644
index 0000000..75b0a6a
--- /dev/null
+++ b/tmxcopy/tmxcollide.cpp
@@ -0,0 +1,103 @@
+/*
+ * TMXTranslate / TMXCollide
+ * Copyright (C) 2007 Philipp Sehmisch
+ * Copyright (C) 2009 Steve Cotton
+ *
+ * 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 2 of the License, or
+ * 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/>.
+ */
+
+#include <iostream>
+#include <string>
+#include <unistd.h>
+
+#include "map.hpp"
+
+void printUsage()
+{
+ std::cerr<<"Usage: tmxcollide [-c] mapFile destLayer templateFile [-o outfile]"<<std::endl
+ <<" -c create layers, if they don't already exist in the target"<<std::endl
+ <<" -o save results to outfile, instead of overwriting the original"<<std::endl
+ <<std::endl
+ <<"Using the template, translate visible layers to the collision layer"<<std::endl
+ <<"See readme.txt for full documentation"<<std::endl;
+}
+
+int main(int argc, char * argv[] )
+{
+ ConfigurationOptions config = {0};
+ std::string outFile;
+
+ int opt;
+ while ((opt = getopt(argc, argv, "co:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'c':
+ config.createMissingLayers = true;
+ break;
+ case 'o':
+ if (optarg)
+ {
+ outFile = optarg;
+ } else {
+ printUsage();
+ return -1;
+ }
+ break;
+ case '?':
+ std::cerr<<"Unrecognized option"<<std::endl;
+ printUsage();
+ return -1;
+ }
+ }
+
+ if ((argc-optind) < 3)
+ {
+ std::cerr<<"Too few args"<<std::endl;
+ printUsage();
+ return -1;
+ }
+ if ((argc-optind) > 3)
+ {
+ std::cerr<<"Too many args"<<std::endl;
+ printUsage();
+ return -1;
+ }
+
+ std::string mapFile = argv[optind+0];
+ std::string destLayer = argv[optind+1];
+ std::string templateFile = argv[optind+2];
+ if (outFile.empty())
+ {
+ outFile = mapFile;
+ }
+
+ try
+ {
+ Map* mainMap = new Map(mapFile);
+ Map* templateMap = new Map(templateFile);
+ if (mainMap->translateAllLayers(templateMap, destLayer, config))
+ {
+ mainMap->save(outFile);
+ } else {
+ return -1;
+ }
+ delete mainMap;
+ delete templateMap;
+ }
+ catch (int)
+ {
+ return -1;
+ }
+}