mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
merge help and version commands
This commit is contained in:
@@ -10,13 +10,12 @@ tmx2gba is a simple command line utility that converts [Tiled](http://www.mapedi
|
||||
|
||||
## Usage ##
|
||||
```
|
||||
tmx2gba [-hv] [-r offset] [-lyc name] [-p 0-15] [-m name;id] <-i inpath> <-o outpath>
|
||||
tmx2gba [-h] [-r offset] [-lyc name] [-p 0-15] [-m name;id] <-i inpath> <-o outpath>
|
||||
```
|
||||
|
||||
| Command | Required | Notes |
|
||||
|--------------|----------|------------------------------------------------------------------------------------|
|
||||
| -h | N/A | Display help & command info |
|
||||
| -v | No | Display version & quit |
|
||||
| -h | N/A | Display program help & command info then quit |
|
||||
| -l (name) | No | Name of layer to use (default first layer in TMX) |
|
||||
| -y (name) | No | Layer for palette mappings |
|
||||
| -c (name) | No | Output a separate 8bit collision map of the specified layer |
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#define CONFIG_H
|
||||
|
||||
#define TMX2GBA_VERSION "@PROJECT_VERSION@"
|
||||
#define TMX2GBA_DESCRIPTION "@PROJECT_DESCRIPTION@"
|
||||
#define TMX2GBA_HOMEPAGE "@PROJECT_HOMEPAGE_URL@"
|
||||
|
||||
#cmakedefine USE_ZLIB
|
||||
|
||||
#endif//CONFIG_H
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// SPDX-License-Identifier: Zlib
|
||||
// SPDX-FileCopyrightText: (c) 2015-2024 a dinosaur
|
||||
|
||||
#include <string_view>
|
||||
constexpr std::string_view copyrightStr("(c) 2015-2024 a dinosaur");
|
||||
|
||||
#include "argparse.hpp"
|
||||
#include "tmxreader.hpp"
|
||||
#include "convert.hpp"
|
||||
@@ -21,15 +24,14 @@ struct Arguments
|
||||
int offset = 0;
|
||||
int palette = 0;
|
||||
std::vector<std::string> objMappings;
|
||||
bool help = false, showVersion = false;
|
||||
bool help = false;
|
||||
};
|
||||
|
||||
using ArgParse::Option;
|
||||
|
||||
static const ArgParse::Options options =
|
||||
{
|
||||
Option::Optional('h', {}, "Display this help & command info"),
|
||||
Option::Optional('v', {}, "Display version & quit"),
|
||||
Option::Optional('h', {}, "Display help & command info"),
|
||||
Option::Optional('l', "name", "Name of layer to use (default first layer in TMX)"),
|
||||
Option::Optional('y', "name", "Layer for palette mappings"),
|
||||
Option::Optional('c', "name", "Output a separate 8bit collision map of the specified layer"),
|
||||
@@ -53,7 +55,6 @@ static bool ParseArgs(int argc, char** argv, Arguments& params)
|
||||
switch (opt)
|
||||
{
|
||||
case 'h': params.help = true; return ParseCtrl::QUIT_EARLY;
|
||||
case 'v': params.showVersion = true; return ParseCtrl::QUIT_EARLY;
|
||||
case 'l': params.layer = arg; return ParseCtrl::CONTINUE;
|
||||
case 'c': params.collisionlay = arg; return ParseCtrl::CONTINUE;
|
||||
case 'y': params.paletteLay = arg; return ParseCtrl::CONTINUE;
|
||||
@@ -71,11 +72,8 @@ static bool ParseArgs(int argc, char** argv, Arguments& params)
|
||||
catch (std::out_of_range const&) { return ParseCtrl::QUIT_ERR_RANGE; }
|
||||
});
|
||||
|
||||
if (!parser.Parse(std::span(argv + 1, argc - 1)))
|
||||
return false;
|
||||
|
||||
if (params.help || params.showVersion)
|
||||
return true;
|
||||
if (!parser.Parse(std::span(argv + 1, argc - 1))) { return false; }
|
||||
if (params.help) { return true; }
|
||||
|
||||
if (!params.flagFile.empty())
|
||||
{
|
||||
@@ -140,18 +138,13 @@ static std::string SanitiseLabel(const std::string_view ident)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Arguments p;
|
||||
if (!ParseArgs(argc, argv, p))
|
||||
return 1;
|
||||
if (!ParseArgs(argc, argv, p)) { return 1; }
|
||||
if (p.help)
|
||||
{
|
||||
std::cout << "tmx2gba v" << TMX2GBA_VERSION << ", " << copyrightStr << std::endl;
|
||||
options.ShowHelpUsage(argv[0], std::cout);
|
||||
return 0;
|
||||
}
|
||||
if (p.showVersion)
|
||||
{
|
||||
std::cout << "tmx2gba version " << TMX2GBA_VERSION << ", (c) 2015-2024 a dinosaur" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Object mappings
|
||||
std::map<std::string, uint32_t> objMapping;
|
||||
@@ -237,8 +230,7 @@ int main(int argc, char** argv)
|
||||
if (tmx.HasCollisionTiles())
|
||||
{
|
||||
std::vector<uint8_t> collisionDat;
|
||||
if (!convert::ConvertCollision(collisionDat, tmx))
|
||||
return 1;
|
||||
if (!convert::ConvertCollision(collisionDat, tmx)) { return 1; }
|
||||
|
||||
outH.WriteCollision(collisionDat);
|
||||
outS.WriteArray("Collision", collisionDat, 32);
|
||||
@@ -247,8 +239,7 @@ int main(int argc, char** argv)
|
||||
if (tmx.HasObjects())
|
||||
{
|
||||
std::vector<uint32_t> objDat;
|
||||
if (!convert::ConvertObjects(objDat, tmx))
|
||||
return 1;
|
||||
if (!convert::ConvertObjects(objDat, tmx)) { return 1; }
|
||||
|
||||
outH.WriteObjects(objDat);
|
||||
outS.WriteArray("Objdat", objDat);
|
||||
|
||||
Reference in New Issue
Block a user