From 6a0755b88a1daa7558498d71b1a452b79ff6f7bf Mon Sep 17 00:00:00 2001 From: grunt-lucas Date: Thu, 12 Oct 2023 12:15:59 -0400 Subject: [PATCH] Implement default-behavior flag --- Todo.md | 4 +--- src/cli_parser.cpp | 4 ---- src/driver.cpp | 2 +- src/importer.cpp | 13 +++++++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Todo.md b/Todo.md index 95ec566a..680db25c 100644 --- a/Todo.md +++ b/Todo.md @@ -20,9 +20,7 @@ + will require key frame detection / key frame hints at CLI + attributes / behavior changes - + allow user to specify default behavior value using CLI option `-default-behavior` - + this option takes a string defined in the behavior header - + also have `-default-terrain-type` and `-default-encounter-type` + + implement a `-default-terrain-type` and `-default-encounter-type` that works like `-default-behavior` + More assign algorithms? + Maybe some kind of A-star? diff --git a/src/cli_parser.cpp b/src/cli_parser.cpp index a449e0ca..78b97c3c 100644 --- a/src/cli_parser.cpp +++ b/src/cli_parser.cpp @@ -511,10 +511,6 @@ static void parseSubcommandOptions(PtContext &ctx, int argc, char *const *argv) ctx.compilerConfig.transparencyColor = parseRgbColor(ctx.err, TRANSPARENCY_COLOR, optarg); break; case DEFAULT_BEHAVIOR_VAL: - /* - * TODO FIXME : finish implementing the -default-behavior logic - * Can either be integral or a behavior label defined in the behaviors header - */ ctx.compilerConfig.defaultBehavior = std::string{optarg}; break; diff --git a/src/driver.cpp b/src/driver.cpp index ae80fee2..db74da73 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -639,7 +639,7 @@ static void driveCompile(PtContext &ctx) * it against the behavior header here and replace that label string with the integral value. */ try { - parseInteger(ctx.compilerConfig.defaultBehavior.c_str()); + parseInteger(ctx.compilerConfig.defaultBehavior.c_str()); } catch (const std::exception &e) { // If the parse fails, assume the user provided a behavior label and try to parse diff --git a/src/importer.cpp b/src/importer.cpp index 0215a6e3..73d77568 100644 --- a/src/importer.cpp +++ b/src/importer.cpp @@ -155,6 +155,18 @@ DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx, std::size_t widthInMetatiles = bottom.get_width() / METATILE_SIDE_LENGTH; std::size_t heightInMetatiles = bottom.get_height() / METATILE_SIDE_LENGTH; + // grab the supplied default behavior + std::uint16_t defaultBehavior; + try { + defaultBehavior = parseInteger(ctx.compilerConfig.defaultBehavior.c_str()); + } + catch (const std::exception &e) { + defaultBehavior = 0; + fatalerror(ctx.err, ctx.compilerSrcPaths, ctx.compilerConfig.mode, + fmt::format("supplied default behavior '{}' was not valid", + fmt::styled(ctx.compilerConfig.defaultBehavior, fmt::emphasis::bold))); + } + for (size_t metatileIndex = 0; metatileIndex < widthInMetatiles * heightInMetatiles; metatileIndex++) { size_t metatileRow = metatileIndex / widthInMetatiles; size_t metatileCol = metatileIndex % widthInMetatiles; @@ -165,6 +177,7 @@ DecompiledTileset importLayeredTilesFromPngs(PtContext &ctx, // Attributes are per-metatile so we can compute them once here Attributes metatileAttributes{}; metatileAttributes.baseGame = ctx.targetBaseGame; + metatileAttributes.metatileBehavior = defaultBehavior; if (attributesMap.contains(metatileIndex)) { const Attributes &fromMap = attributesMap.at(metatileIndex); metatileAttributes.metatileBehavior = fromMap.metatileBehavior;