summaryrefslogtreecommitdiff
path: root/tools/tmxcopy/main.cpp
blob: ab67afe65874089e8f78aea3472ad576033755ca (plain) (blame)
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
/*
 *  TMXCopy
 *  Copyright (C) 2007  Philipp Sehmisch
 *
 *  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, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <iostream>
#include <string>

#include "map.hpp"

int main(int argc, char * argv[] )
{
    // parsing command line options
    if (argc < 9 || argc > 10)
    {
        std::cerr<<"Usage: srcFile x y width height tgtFile x y [outfile]";
        return -1;
    }

    std::string srcFile = argv[1];
    int srcX= atoi(argv[2]);
    int srcY= atoi(argv[3]);
    int width= atoi(argv[4]);
    int height=atoi(argv[5]);
    std::string tgtFile = argv[6];
    int destX=atoi(argv[7]);
    int destY=atoi(argv[8]);
    std::string outFile = tgtFile;
    if (argc == 10) outFile = argv[9];

    // plausibility check of command line options
    if (height < 1 || width < 1 || srcX < 0 || srcY < 0 || destX < 0 || destY < 0)
    {
        std::cerr<<"Illegal coordinates!"<<std::endl;
        std::cerr<<"Usage: sourceFile x y height width targetFile x y [outputFile]"<<std::endl;
        return -1;
    }

    try
    {
        Map* srcMap = new Map(srcFile);
        Map* tgtMap = new Map(tgtFile);
        if (tgtMap->overwrite(srcMap, srcX, srcY, width, height, destX, destY))
        {
            tgtMap->save(outFile);
        } else {
            return -1;
        }
    }
    catch (int)
    {
        return -1;
    }

}