Skip to content

Commit

Permalink
Implement default-behavior flag
Browse files Browse the repository at this point in the history
  • Loading branch information
grunt-lucas committed Oct 12, 2023
1 parent 63e2686 commit 6a0755b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 0 additions & 4 deletions src/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>(ctx.compilerConfig.defaultBehavior.c_str());
parseInteger<std::uint16_t>(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
Expand Down
13 changes: 13 additions & 0 deletions src/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint16_t>(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;
Expand All @@ -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;
Expand Down

0 comments on commit 6a0755b

Please sign in to comment.