From 8237e29a164211eb2ec4cd161eb4183cc1947fee Mon Sep 17 00:00:00 2001 From: Cheng Hann Gan Date: Thu, 9 Sep 2021 19:22:48 -0400 Subject: Defined more in-dungeon structs and enums (#53) * Defined DungeonEntity * Rename EntityType enums * Revert EntityType rename * Defined more in-dungeon structs and enums * Added more dungeon global structs/enums * Prefixed dungeonGlobalData with g * Fixed compile errors * Removed some CRLFs * Fixed compile after merge * Revert Makefile * Rename DungeonEntityData.entityType Co-authored-by: Seth Barberee * Renamed symbols per PR comments Co-authored-by: Cheng Hann Gan Co-authored-by: Seth Barberee --- tools/jsonproc/jsonproc.cpp | 218 ++++++++++++++++++++++---------------------- 1 file changed, 109 insertions(+), 109 deletions(-) (limited to 'tools/jsonproc/jsonproc.cpp') diff --git a/tools/jsonproc/jsonproc.cpp b/tools/jsonproc/jsonproc.cpp index 5372194..2ba5fd0 100644 --- a/tools/jsonproc/jsonproc.cpp +++ b/tools/jsonproc/jsonproc.cpp @@ -1,109 +1,109 @@ -// jsonproc.cpp - -#include "jsonproc.h" - -#include - -#include -using std::string; using std::to_string; - -#include -using namespace inja; -using json = nlohmann::json; - -std::map customVars; - -void set_custom_var(string key, string value) -{ - customVars[key] = value; -} - -string get_custom_var(string key) -{ - return customVars[key]; -} - -int main(int argc, char *argv[]) -{ - if (argc != 4) - FATAL_ERROR("USAGE: jsonproc \n"); - - string jsonfilepath = argv[1]; - string templateFilepath = argv[2]; - string outputFilepath = argv[3]; - - Environment env; - - // Add custom command callbacks. - env.add_callback("doNotModifyHeader", 0, [jsonfilepath, templateFilepath](Arguments& args) { - return "//\n// DO NOT MODIFY THIS FILE! It is auto-generated from " + jsonfilepath +" and Inja template " + templateFilepath + "\n//\n"; - }); - - env.add_callback("subtract", 2, [](Arguments& args) { - int minuend = args.at(0)->get(); - int subtrahend = args.at(1)->get(); - - return minuend - subtrahend; - }); - - env.add_callback("setVar", 2, [=](Arguments& args) { - string key = args.at(0)->get(); - string value = args.at(1)->get(); - set_custom_var(key, value); - return ""; - }); - - env.add_callback("setVarInt", 2, [=](Arguments& args) { - string key = args.at(0)->get(); - string value = to_string(args.at(1)->get()); - set_custom_var(key, value); - return ""; - }); - - env.add_callback("getVar", 1, [=](Arguments& args) { - string key = args.at(0)->get(); - return get_custom_var(key); - }); - - env.add_callback("concat", 2, [](Arguments& args) { - string first = args.at(0)->get(); - string second = args.at(1)->get(); - return first + second; - }); - - env.add_callback("removePrefix", 2, [](Arguments& args) { - string rawValue = args.at(0)->get(); - string prefix = args.at(1)->get(); - string::size_type i = rawValue.find(prefix); - if (i != 0) - return rawValue; - - return rawValue.erase(0, prefix.length()); - }); - - env.add_callback("removeSuffix", 2, [](Arguments& args) { - string rawValue = args.at(0)->get(); - string suffix = args.at(1)->get(); - string::size_type i = rawValue.rfind(suffix); - if (i == string::npos) - return rawValue; - - return rawValue.substr(0, i); - }); - - // single argument is a json object - env.add_callback("isEmpty", 1, [](Arguments& args) { - return args.at(0)->empty(); - }); - - try - { - env.write_with_json_file(templateFilepath, jsonfilepath, outputFilepath); - } - catch (const std::exception& e) - { - FATAL_ERROR("JSONPROC_ERROR: %s\n", e.what()); - } - - return 0; -} +// jsonproc.cpp + +#include "jsonproc.h" + +#include + +#include +using std::string; using std::to_string; + +#include +using namespace inja; +using json = nlohmann::json; + +std::map customVars; + +void set_custom_var(string key, string value) +{ + customVars[key] = value; +} + +string get_custom_var(string key) +{ + return customVars[key]; +} + +int main(int argc, char *argv[]) +{ + if (argc != 4) + FATAL_ERROR("USAGE: jsonproc \n"); + + string jsonfilepath = argv[1]; + string templateFilepath = argv[2]; + string outputFilepath = argv[3]; + + Environment env; + + // Add custom command callbacks. + env.add_callback("doNotModifyHeader", 0, [jsonfilepath, templateFilepath](Arguments& args) { + return "//\n// DO NOT MODIFY THIS FILE! It is auto-generated from " + jsonfilepath +" and Inja template " + templateFilepath + "\n//\n"; + }); + + env.add_callback("subtract", 2, [](Arguments& args) { + int minuend = args.at(0)->get(); + int subtrahend = args.at(1)->get(); + + return minuend - subtrahend; + }); + + env.add_callback("setVar", 2, [=](Arguments& args) { + string key = args.at(0)->get(); + string value = args.at(1)->get(); + set_custom_var(key, value); + return ""; + }); + + env.add_callback("setVarInt", 2, [=](Arguments& args) { + string key = args.at(0)->get(); + string value = to_string(args.at(1)->get()); + set_custom_var(key, value); + return ""; + }); + + env.add_callback("getVar", 1, [=](Arguments& args) { + string key = args.at(0)->get(); + return get_custom_var(key); + }); + + env.add_callback("concat", 2, [](Arguments& args) { + string first = args.at(0)->get(); + string second = args.at(1)->get(); + return first + second; + }); + + env.add_callback("removePrefix", 2, [](Arguments& args) { + string rawValue = args.at(0)->get(); + string prefix = args.at(1)->get(); + string::size_type i = rawValue.find(prefix); + if (i != 0) + return rawValue; + + return rawValue.erase(0, prefix.length()); + }); + + env.add_callback("removeSuffix", 2, [](Arguments& args) { + string rawValue = args.at(0)->get(); + string suffix = args.at(1)->get(); + string::size_type i = rawValue.rfind(suffix); + if (i == string::npos) + return rawValue; + + return rawValue.substr(0, i); + }); + + // single argument is a json object + env.add_callback("isEmpty", 1, [](Arguments& args) { + return args.at(0)->empty(); + }); + + try + { + env.write_with_json_file(templateFilepath, jsonfilepath, outputFilepath); + } + catch (const std::exception& e) + { + FATAL_ERROR("JSONPROC_ERROR: %s\n", e.what()); + } + + return 0; +} -- cgit v1.2.3