Skip to content

Commit

Permalink
Change GetDebugGridText text from char to string
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron authored and AJenbo committed Feb 3, 2025
1 parent 5ed7ca9 commit 4f9e063
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
29 changes: 14 additions & 15 deletions Source/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,20 @@ void SetDebugGridTextType(DebugGridTextItem value)
SelectedDebugGridTextItem = value;
}

bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
bool GetDebugGridText(Point dungeonCoords, std::string &debugGridText)
{
int info = 0;
int blankValue = 0;
debugGridText.clear();
Point megaCoords = dungeonCoords.worldToMega();
switch (SelectedDebugGridTextItem) {
case DebugGridTextItem::coords:
*BufCopy(debugGridTextBuffer, dungeonCoords.x, ":", dungeonCoords.y) = '\0';
StrAppend(debugGridText, dungeonCoords.x, ":", dungeonCoords.y);
return true;
case DebugGridTextItem::cursorcoords:
if (dungeonCoords != cursPosition)
return false;
*BufCopy(debugGridTextBuffer, dungeonCoords.x, ":", dungeonCoords.y) = '\0';
StrAppend(debugGridText, dungeonCoords.x, ":", dungeonCoords.y);
return true;
case DebugGridTextItem::objectindex: {
info = 0;
Expand All @@ -167,23 +168,21 @@ bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
break;
}
case DebugGridTextItem::microTiles: {
std::string result;
const MICROS &micros = DPieceMicros[dPiece[dungeonCoords.x][dungeonCoords.y]];
for (const LevelCelBlock tile : micros.mt) {
if (!tile.hasValue()) break;
if (!result.empty()) result += '\n';
StrAppend(result, tile.frame(), " ");
if (!debugGridText.empty()) debugGridText += '\n';
StrAppend(debugGridText, tile.frame(), " ");
switch (tile.type()) {
case TileType::Square: StrAppend(result, "S"); break;
case TileType::TransparentSquare: StrAppend(result, "T"); break;
case TileType::LeftTriangle: StrAppend(result, "<"); break;
case TileType::RightTriangle: StrAppend(result, ">"); break;
case TileType::LeftTrapezoid: StrAppend(result, "\\"); break;
case TileType::RightTrapezoid: StrAppend(result, "/"); break;
case TileType::Square: StrAppend(debugGridText, "S"); break;
case TileType::TransparentSquare: StrAppend(debugGridText, "T"); break;
case TileType::LeftTriangle: StrAppend(debugGridText, "<"); break;
case TileType::RightTriangle: StrAppend(debugGridText, ">"); break;
case TileType::LeftTrapezoid: StrAppend(debugGridText, "\\"); break;
case TileType::RightTrapezoid: StrAppend(debugGridText, "/"); break;
}
}
if (result.empty()) return false;
*BufCopy(debugGridTextBuffer, result) = '\0';
if (debugGridText.empty()) return false;
return true;
} break;
case DebugGridTextItem::dPiece:
Expand Down Expand Up @@ -251,7 +250,7 @@ bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
}
if (info == blankValue)
return false;
*BufCopy(debugGridTextBuffer, info) = '\0';
StrAppend(debugGridText, info);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool IsDebugGridTextNeeded();
bool IsDebugGridInMegatiles();
DebugGridTextItem GetDebugGridTextType();
void SetDebugGridTextType(DebugGridTextItem value);
bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer);
bool GetDebugGridText(Point dungeonCoords, std::string &debugGridText);
bool IsDebugAutomapHighlightNeeded();
bool ShouldHighlightDebugAutomapTile(Point position);
void AddDebugAutomapMonsterHighlight(std::string_view name);
Expand Down
6 changes: 3 additions & 3 deletions Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ void DrawView(const Surface &out, Point startPosition)
if (debugGridTextNeeded || DebugGrid) {
// force redrawing or debug stuff stays on panel on 640x480 resolution
RedrawEverything();
char debugGridTextBuffer[10];
std::string debugGridText;
bool megaTiles = IsDebugGridInMegatiles();

for (auto [dunCoordVal, pixelCoords] : DebugCoordsMap) {
Expand All @@ -1169,11 +1169,11 @@ void DrawView(const Surface &out, Point startPosition)
pixelCoords += Displacement { 0, TILE_HEIGHT / 2 };
if (*GetOptions().Graphics.zoom)
pixelCoords *= 2;
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) {
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridText)) {
Size tileSize = { TILE_WIDTH, TILE_HEIGHT };
if (*GetOptions().Graphics.zoom)
tileSize *= 2;
DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize },
DrawString(out, debugGridText, { pixelCoords - Displacement { 0, tileSize.height }, tileSize },
{ .flags = UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter });
}
if (DebugGrid) {
Expand Down

0 comments on commit 4f9e063

Please sign in to comment.