From 2cc1ffc5432a588188099ebc5da5e71e2b1a1a28 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 11 Jul 2014 10:54:50 +0200 Subject: [PATCH] Re-add --backend to allow overriding auto-detected backend --- TileGenerator.cpp | 19 ++++++++++++++----- TileGenerator.h | 1 + mapper.cpp | 9 +++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 453959e..f46a880 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -96,6 +96,7 @@ TileGenerator::TileGenerator(): m_drawScale(false), m_drawAlpha(false), m_shading(true), + m_backend(""), m_border(0), m_image(0), m_xMin(INT_MAX), @@ -181,6 +182,11 @@ void TileGenerator::setShading(bool shading) m_shading = shading; } +void TileGenerator::setBackend(std::string backend) +{ + m_backend = backend; +} + void TileGenerator::setGeometry(int x, int y, int w, int h) { if (x > 0) { @@ -284,11 +290,14 @@ void TileGenerator::parseColorsStream(std::istream &in) void TileGenerator::openDb(const std::string &input) { - std::ifstream ifs((input + "/world.mt").c_str()); - if(!ifs.good()) - throw std::runtime_error("Failed to read world.mt"); - std::string backend = get_setting("backend", ifs); - ifs.close(); + std::string backend = m_backend; + if(backend == "") { + std::ifstream ifs((input + "/world.mt").c_str()); + if(!ifs.good()) + throw std::runtime_error("Failed to read world.mt"); + backend = get_setting("backend", ifs); + ifs.close(); + } if(backend == "sqlite3") m_db = new DBSQLite3(input); diff --git a/TileGenerator.h b/TileGenerator.h index 42ac4bb..cc243bb 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -86,6 +86,7 @@ private: bool m_drawScale; bool m_drawAlpha; bool m_shading; + std::string m_backend; int m_border; DB *m_db; diff --git a/mapper.cpp b/mapper.cpp index 80be4b6..9bf4be5 100644 --- a/mapper.cpp +++ b/mapper.cpp @@ -34,6 +34,7 @@ void usage() " --noshading\n" " --min-y \n" " --max-y \n" + " --backend \n" " --geometry x:y+w+h\n" "Color format: '#000000'\n"; std::cout << usage_text; @@ -55,6 +56,7 @@ int main(int argc, char *argv[]) {"drawscale", no_argument, 0, 'S'}, {"drawalpha", no_argument, 0, 'e'}, {"noshading", no_argument, 0, 'H'}, + {"backend", required_argument, 0, 'd'}, {"geometry", required_argument, 0, 'g'}, {"min-y", required_argument, 0, 'a'}, {"max-y", required_argument, 0, 'c'} @@ -109,11 +111,14 @@ int main(int argc, char *argv[]) generator.setDrawScale(true); break; case 'e': - generator.setDrawAlpha(true); - break; + generator.setDrawAlpha(true); + break; case 'H': generator.setShading(false); break; + case 'd': + generator.setBackend(optarg); + break; case 'a': { istringstream iss; iss.str(optarg);