Browse Source

tiledata debug command

pull/2851/head
qndel 5 years ago committed by Anders Jenbo
parent
commit
d05316c67d
  1. 78
      Source/debug.cpp
  2. 22
      Source/debug.h
  3. 17
      Source/scrollrt.cpp

78
Source/debug.cpp

@ -36,6 +36,7 @@ bool DebugCoords = false;
bool DebugCursorCoords = false;
bool DebugGrid = false;
std::unordered_map<int, Point> 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<DebugInfoFlags>(1 << i);
break;
}
}
if (!found)
return "Invalid name. Check names using tiledata command.";
return "Special powers activated.";
}
std::vector<DebugCmdItem> 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<DebugCmdItem> 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

22
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<CelSprite> pSquareCel;
extern bool DebugToggle;
extern bool DebugGodMode;
@ -23,6 +43,7 @@ extern bool DebugCoords;
extern bool DebugCursorCoords;
extern bool DebugGrid;
extern std::unordered_map<int, Point> 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

17
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) {

Loading…
Cancel
Save