X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/987c3c8b0cac8854e8802dfbd8e7192739e51b57..4292be14c78b8f30075c9e4837dd026f6fec532e:/mock/tools/level-converter.cc diff --git a/mock/tools/level-converter.cc b/mock/tools/level-converter.cc index 54be8f7..eb8b1c6 100644 --- a/mock/tools/level-converter.cc +++ b/mock/tools/level-converter.cc @@ -6,6 +6,7 @@ extern "C" { } #include +#include #include #include @@ -21,7 +22,7 @@ enum { LEVEL_LINE_COUNT = 14 }; -#define PATH_PREFIX "../badge/jumpnrun/" +#define PATH_PREFIX "../badge/jumpnrun/levels/" namespace jnrcpp { struct descriptors { @@ -69,15 +70,15 @@ namespace jnrcpp { struct level_name_map { level_name_map() { - std::ifstream in(PATH_PREFIX "levels.txt"); + std::ifstream in("levels.txt"); if(!in) { - throw std::logic_error(PATH_PREFIX "levels.txt konnte nicht geöffnet werden."); + throw std::logic_error("levels.txt konnte nicht geöffnet werden."); } std::string name; while(std::getline(in, name)) { - if(name != "") { + if(boost::trim_copy(name) != "") { names.push_back(name); } } @@ -114,10 +115,12 @@ namespace jnrcpp { objmap = &item_types; } else if(line == "[enemies]") { objmap = &enemy_types; + } else if(line == "[parameters]") { + objmap = &level_params; } else { throw std::invalid_argument("Unkown type: " + line); } - } else if(line != "") { + } else if(boost::trim_right_copy(line) != "") { char c; std::string tok; std::istringstream parser(line); @@ -236,8 +239,21 @@ namespace jnrcpp { static_cast(player_pos.second) }; - dest.write(static_cast(static_cast(head)), sizeof(head)); - dest.write(static_cast(static_cast(spos)), sizeof(spos)); + uint8_t lives = 3; + { + std::map::const_iterator iter = level_params.find('L'); + if(iter != level_params.end()) { + unsigned x; + std::istringstream parser(iter->second); + if(parser >> x) { + lives = static_cast(x); + } + } + } + + dest.write(static_cast(static_cast(head )), sizeof(head )); + dest.write(static_cast(static_cast(spos )), sizeof(spos )); + dest.write(static_cast(static_cast(&lives)), sizeof(lives)); dump_tiles(dest); dump_items(dest); @@ -250,6 +266,7 @@ namespace jnrcpp { std::map tile_types; std::map item_types; std::map enemy_types; + std::map level_params; }; }