Browse Source

Change GetDebugGridText text from char to string

pull/7710/head
obligaron 1 year ago committed by Anders Jenbo
parent
commit
4f9e063197
  1. 29
      Source/debug.cpp
  2. 2
      Source/debug.h
  3. 6
      Source/engine/render/scrollrt.cpp

29
Source/debug.cpp

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

2
Source/debug.h

@ -73,7 +73,7 @@ bool IsDebugGridTextNeeded();
bool IsDebugGridInMegatiles(); bool IsDebugGridInMegatiles();
DebugGridTextItem GetDebugGridTextType(); DebugGridTextItem GetDebugGridTextType();
void SetDebugGridTextType(DebugGridTextItem value); void SetDebugGridTextType(DebugGridTextItem value);
bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer); bool GetDebugGridText(Point dungeonCoords, std::string &debugGridText);
bool IsDebugAutomapHighlightNeeded(); bool IsDebugAutomapHighlightNeeded();
bool ShouldHighlightDebugAutomapTile(Point position); bool ShouldHighlightDebugAutomapTile(Point position);
void AddDebugAutomapMonsterHighlight(std::string_view name); void AddDebugAutomapMonsterHighlight(std::string_view name);

6
Source/engine/render/scrollrt.cpp

@ -1158,7 +1158,7 @@ void DrawView(const Surface &out, Point startPosition)
if (debugGridTextNeeded || DebugGrid) { if (debugGridTextNeeded || DebugGrid) {
// force redrawing or debug stuff stays on panel on 640x480 resolution // force redrawing or debug stuff stays on panel on 640x480 resolution
RedrawEverything(); RedrawEverything();
char debugGridTextBuffer[10]; std::string debugGridText;
bool megaTiles = IsDebugGridInMegatiles(); bool megaTiles = IsDebugGridInMegatiles();
for (auto [dunCoordVal, pixelCoords] : DebugCoordsMap) { for (auto [dunCoordVal, pixelCoords] : DebugCoordsMap) {
@ -1169,11 +1169,11 @@ void DrawView(const Surface &out, Point startPosition)
pixelCoords += Displacement { 0, TILE_HEIGHT / 2 }; pixelCoords += Displacement { 0, TILE_HEIGHT / 2 };
if (*GetOptions().Graphics.zoom) if (*GetOptions().Graphics.zoom)
pixelCoords *= 2; pixelCoords *= 2;
if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) { if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridText)) {
Size tileSize = { TILE_WIDTH, TILE_HEIGHT }; Size tileSize = { TILE_WIDTH, TILE_HEIGHT };
if (*GetOptions().Graphics.zoom) if (*GetOptions().Graphics.zoom)
tileSize *= 2; 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 }); { .flags = UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter });
} }
if (DebugGrid) { if (DebugGrid) {

Loading…
Cancel
Save