2014-07-14 00:24:57 +08:00
|
|
|
// Aseprite Code Generator
|
2016-04-19 06:10:10 +08:00
|
|
|
// Copyright (c) 2014-2016 David Capello
|
2014-07-14 00:24:57 +08:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#include "base/file_handle.h"
|
2016-11-02 06:14:05 +08:00
|
|
|
#include "base/fs.h"
|
2014-07-14 00:24:57 +08:00
|
|
|
#include "base/program_options.h"
|
|
|
|
#include "base/string.h"
|
2014-12-15 07:19:31 +08:00
|
|
|
#include "gen/pref_types.h"
|
2015-02-16 02:29:16 +08:00
|
|
|
#include "gen/skin_class.h"
|
2014-07-14 00:24:57 +08:00
|
|
|
#include "gen/ui_class.h"
|
|
|
|
#include "tinyxml.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
typedef base::ProgramOptions PO;
|
|
|
|
|
|
|
|
static void run(int argc, const char* argv[])
|
|
|
|
{
|
|
|
|
PO po;
|
2014-11-06 20:42:09 +08:00
|
|
|
PO::Option& inputOpt = po.add("input").requiresValue("<filename>");
|
2014-07-14 00:24:57 +08:00
|
|
|
PO::Option& widgetId = po.add("widgetid").requiresValue("<filename>");
|
2014-12-15 07:19:31 +08:00
|
|
|
PO::Option& prefH = po.add("pref-h");
|
|
|
|
PO::Option& prefCpp = po.add("pref-cpp");
|
2015-02-16 02:29:16 +08:00
|
|
|
PO::Option& skin = po.add("skin");
|
2014-07-14 00:24:57 +08:00
|
|
|
po.parse(argc, argv);
|
|
|
|
|
|
|
|
// Try to load the XML file
|
|
|
|
TiXmlDocument* doc = NULL;
|
|
|
|
|
2014-11-06 20:42:09 +08:00
|
|
|
std::string inputFilename = po.value_of(inputOpt);
|
|
|
|
if (!inputFilename.empty()) {
|
|
|
|
base::FileHandle inputFile(base::open_file(inputFilename, "rb"));
|
2014-07-14 00:24:57 +08:00
|
|
|
doc = new TiXmlDocument();
|
2014-11-06 20:42:09 +08:00
|
|
|
doc->SetValue(inputFilename.c_str());
|
2016-04-19 06:10:10 +08:00
|
|
|
if (!doc->LoadFile(inputFile.get())) {
|
|
|
|
std::cerr << doc->Value() << ":"
|
|
|
|
<< doc->ErrorRow() << ":"
|
|
|
|
<< doc->ErrorCol() << ": "
|
|
|
|
<< "error " << doc->ErrorId() << ": "
|
|
|
|
<< doc->ErrorDesc() << "\n";
|
|
|
|
|
2014-07-14 00:24:57 +08:00
|
|
|
throw std::runtime_error("invalid input file");
|
2016-04-19 06:10:10 +08:00
|
|
|
}
|
2014-07-14 00:24:57 +08:00
|
|
|
}
|
|
|
|
|
2014-12-15 07:19:31 +08:00
|
|
|
if (doc) {
|
|
|
|
if (po.enabled(widgetId))
|
|
|
|
gen_ui_class(doc, inputFilename, po.value_of(widgetId));
|
|
|
|
else if (po.enabled(prefH))
|
|
|
|
gen_pref_header(doc, inputFilename);
|
|
|
|
else if (po.enabled(prefCpp))
|
|
|
|
gen_pref_impl(doc, inputFilename);
|
2015-02-16 02:29:16 +08:00
|
|
|
else if (po.enabled(skin))
|
|
|
|
gen_skin_class(doc, inputFilename);
|
2014-12-15 07:19:31 +08:00
|
|
|
}
|
2014-07-14 00:24:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[])
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
run(argc, argv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch (const std::exception& e) {
|
|
|
|
std::cerr << e.what() << "\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|