From d05316c67d4f77d5d4c8ac9ae4f2462cb0b8da3e Mon Sep 17 00:00:00 2001 From: qndel Date: Sun, 12 Sep 2021 10:27:02 +0200 Subject: [PATCH] tiledata debug command --- Source/debug.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++ Source/debug.h | 22 +++++++++++++ Source/scrollrt.cpp | 17 +++++++--- 3 files changed, 112 insertions(+), 5 deletions(-) diff --git a/Source/debug.cpp b/Source/debug.cpp index a7811f1d8..c9a7be16e 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -36,6 +36,7 @@ bool DebugCoords = false; bool DebugCursorCoords = false; bool DebugGrid = false; std::unordered_map DebugCoordsMap; +DebugInfoFlags DebugInfoFlag; namespace { @@ -573,6 +574,49 @@ std::string DebugCmdSpawnMonster(const string_view parameter) return fmt::format("I could only summon {} Monsters. The rest strike for shorter working hours.", spawnedMonster); } +std::string DebugCmdShowTileData(const string_view parameter) +{ + std::string paramList[] = { + "dungeon", + "pdungeon", + "dflags", + "dPiece", + "dTransVal", + "dLight", + "dPreLight", + "dFlags", + "dPlayer", + "dMonster", + "dCorpse", + "dObject", + "dItem", + "dSpecial" + }; + + if (parameter == "clear") { + DebugInfoFlag = DebugInfoFlags::empty; + return "Tile data cleared!"; + } else if (parameter == "") { + std::string list = "clear"; + for (int i = 0; i < 14; i++) { + list += " / " + paramList[i]; + } + return list; + } + bool found = false; + for (int i = 0; i < 14; i++) { + if (parameter == paramList[i]) { + found = true; + DebugInfoFlag = static_cast(1 << i); + break; + } + } + if (!found) + return "Invalid name. Check names using tiledata command."; + + return "Special powers activated."; +} + std::vector DebugCmdList = { { "help", "Prints help overview or help for a specific command.", "({command})", &DebugCmdHelp }, { "give gold", "Fills the inventory with gold.", "", &DebugCmdGiveGoldCheat }, @@ -599,6 +643,7 @@ std::vector DebugCmdList = { { "grid", "Toggles showing grid.", "", &DebugCmdShowGrid }, { "seedinfo", "Show seed infos for current level.", "", &DebugCmdLevelSeed }, { "spawn", "Spawns monster {name}.", "({count}) {name}", &DebugCmdSpawnMonster }, + { "tiledata", "Toggles showing tile data {name} (leave name empty to see a list).", "{name}", &DebugCmdShowTileData }, }; } // namespace @@ -705,6 +750,39 @@ bool CheckDebugTextCommand(const string_view text) return true; } +int DebugGetTileData(Point dungeonCoords) +{ + switch (DebugInfoFlag) { + case DebugInfoFlags::dungeon: + return dungeon[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::pdungeon: + return pdungeon[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dflags: + return dflags[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dPiece: + return dPiece[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dTransVal: + return dTransVal[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dLight: + return dLight[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dPreLight: + return dPreLight[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dFlags: + return dFlags[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dPlayer: + return dPlayer[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dMonster: + return dMonster[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dCorpse: + return dCorpse[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dItem: + return dItem[dungeonCoords.x][dungeonCoords.y]; + case DebugInfoFlags::dSpecial: + return dSpecial[dungeonCoords.x][dungeonCoords.y]; + } + return 0; +} + } // namespace devilution #endif diff --git a/Source/debug.h b/Source/debug.h index 0165b9a35..e3abf464d 100644 --- a/Source/debug.h +++ b/Source/debug.h @@ -15,6 +15,26 @@ namespace devilution { +enum class DebugInfoFlags : uint16_t { + // clang-format off + empty = 0, + dungeon = 1 << 0, + pdungeon = 1 << 1, + dflags = 1 << 2, + dPiece = 1 << 3, + dTransVal = 1 << 4, + dLight = 1 << 5, + dPreLight = 1 << 6, + dFlags = 1 << 7, + dPlayer = 1 << 8, + dMonster = 1 << 9, + dCorpse = 1 << 10, + dObject = 1 << 11, + dItem = 1 << 12, + dSpecial = 1 << 13, + // clang-format on +}; + extern std::optional pSquareCel; extern bool DebugToggle; extern bool DebugGodMode; @@ -23,6 +43,7 @@ extern bool DebugCoords; extern bool DebugCursorCoords; extern bool DebugGrid; extern std::unordered_map DebugCoordsMap; +extern DebugInfoFlags DebugInfoFlag; void FreeDebugGFX(); void LoadDebugGFX(); @@ -32,5 +53,6 @@ void GetDebugMonster(); void NextDebugMonster(); void SetDebugLevelSeedInfos(uint32_t mid1Seed, uint32_t mid2Seed, uint32_t mid3Seed, uint32_t endSeed); bool CheckDebugTextCommand(const string_view text); +int DebugGetTileData(Point dungeonCoords); } // namespace devilution diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 4d0fd522c..8a43320e9 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1201,19 +1201,26 @@ void DrawView(const Surface &out, Point startPosition) DrawAutomap(out.subregionY(0, gnViewportHeight)); } #ifdef _DEBUG - if (DebugCoords || DebugGrid || DebugCursorCoords) { + bool debugInfo = DebugInfoFlag != DebugInfoFlags::empty; + if (DebugCoords || DebugGrid || DebugCursorCoords || debugInfo) { + // force redrawing or debug stuff stays on panel on 640x480 resolution + force_redraw = 255; for (auto m : DebugCoordsMap) { Point dunCoords = { m.first % MAXDUNX, m.first / MAXDUNX }; Point pixelCoords = m.second; if (!zoomflag) pixelCoords *= 2; - if (DebugCoords || (DebugCursorCoords && dunCoords == cursPosition)) { - char coordstr[10]; - sprintf(coordstr, "%d:%d", dunCoords.x, dunCoords.y); + if (DebugCoords || (DebugCursorCoords && dunCoords == cursPosition) || debugInfo) { + char buffer[10]; + if (!debugInfo) + sprintf(buffer, "%d:%d", dunCoords.x, dunCoords.y); + else + sprintf(buffer, "%d", DebugGetTileData(dunCoords)); + Size tileSize = { TILE_WIDTH, TILE_HEIGHT }; if (!zoomflag) tileSize *= 2; - DrawString(out, coordstr, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter); + DrawString(out, buffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter); } if (DebugGrid) { auto DrawLine = [&out](Point from, Point to, uint8_t col) {