Browse Source

Merge coords and cursorcoords in tiledata debug command

pull/2880/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
5d315b46b0
  1. 113
      Source/debug.cpp

113
Source/debug.cpp

@ -37,26 +37,24 @@ std::unordered_map<int, Point> DebugCoordsMap;
namespace { namespace {
enum class DebugInfoFlags : uint16_t { enum class DebugGridTextItem : uint16_t {
// clang-format off None,
empty = 0, dPiece,
dPiece = 1 << 0, dTransVal,
dTransVal = 1 << 1, dLight,
dLight = 1 << 2, dPreLight,
dPreLight = 1 << 3, dFlags,
dFlags = 1 << 4, dPlayer,
dPlayer = 1 << 5, dMonster,
dMonster = 1 << 6, dCorpse,
dCorpse = 1 << 7, dObject,
dObject = 1 << 8, dItem,
dItem = 1 << 9, dSpecial,
dSpecial = 1 << 10, coords,
// clang-format on cursorcoords,
}; };
bool DebugCoords = false; DebugGridTextItem SelectedDebugGridTextItem;
bool DebugCursorCoords = false;
DebugInfoFlags DebugInfoFlag;
int DebugPlayerId; int DebugPlayerId;
int DebugQuestId; int DebugQuestId;
@ -466,15 +464,6 @@ std::string DebugCmdTalkToTowner(const string_view parameter)
return "NPC not found."; return "NPC not found.";
} }
std::string DebugCmdShowCoords(const string_view parameter)
{
DebugCoords = !DebugCoords;
if (DebugCoords)
return "I love math.";
return "I hate math.";
}
std::string DebugCmdShowGrid(const string_view parameter) std::string DebugCmdShowGrid(const string_view parameter)
{ {
DebugGrid = !DebugGrid; DebugGrid = !DebugGrid;
@ -484,15 +473,6 @@ std::string DebugCmdShowGrid(const string_view parameter)
return "Back to boring."; return "Back to boring.";
} }
std::string DebugCmdShowCursorCoords(const string_view parameter)
{
DebugCursorCoords = !DebugCursorCoords;
if (DebugCursorCoords)
return "I am the master of coords and cursors!";
return "Cursor will never forget that.";
}
std::string DebugCmdLevelSeed(const string_view parameter) std::string DebugCmdLevelSeed(const string_view parameter)
{ {
return fmt::format("Seedinfo for level {}\nseed: {}\nMid1: {}\nMid2: {}\nMid3: {}\nEnd: {}", currlevel, glSeedTbl[currlevel], glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel], glEndSeed[currlevel]); return fmt::format("Seedinfo for level {}\nseed: {}\nMid1: {}\nMid2: {}\nMid3: {}\nEnd: {}", currlevel, glSeedTbl[currlevel], glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel], glEndSeed[currlevel]);
@ -605,26 +585,35 @@ std::string DebugCmdShowTileData(const string_view parameter)
"dCorpse", "dCorpse",
"dObject", "dObject",
"dItem", "dItem",
"dSpecial" "dSpecial",
"coords",
"cursorcoords",
}; };
if (parameter == "clear") { if (parameter == "clear") {
DebugInfoFlag = DebugInfoFlags::empty; SelectedDebugGridTextItem = DebugGridTextItem::None;
return "Tile data cleared!"; return "Tile data cleared!";
} else if (parameter == "") { } else if (parameter == "") {
std::string list = "clear"; std::string list = "clear";
for (int i = 0; i < 11; i++) { for (const auto &param : paramList) {
list += " / " + paramList[i]; list += " / " + param;
} }
return list; return list;
} }
bool found = false; bool found = false;
for (int i = 0; i < 11; i++) { int index = 0;
if (parameter == paramList[i]) { for (const auto &param : paramList) {
found = true; index++;
DebugInfoFlag = static_cast<DebugInfoFlags>(1 << i); if (parameter != param)
break; continue;
found = true;
auto newGridText = static_cast<DebugGridTextItem>(index);
if (newGridText == SelectedDebugGridTextItem) {
SelectedDebugGridTextItem = DebugGridTextItem::None;
return "Tile data toggled... now you see nothing.";
} }
SelectedDebugGridTextItem = newGridText;
break;
} }
if (!found) if (!found)
return "Invalid name. Check names using tiledata command."; return "Invalid name. Check names using tiledata command.";
@ -653,8 +642,6 @@ std::vector<DebugCmdItem> DebugCmdList = {
{ "talkto", "Interacts with a NPC whose name contains {name}.", "{name}", &DebugCmdTalkToTowner }, { "talkto", "Interacts with a NPC whose name contains {name}.", "{name}", &DebugCmdTalkToTowner },
{ "exit", "Exits the game.", "", &DebugCmdExit }, { "exit", "Exits the game.", "", &DebugCmdExit },
{ "arrow", "Changes arrow effect (normal, fire, lightning, explosion).", "{effect}", &DebugCmdArrow }, { "arrow", "Changes arrow effect (normal, fire, lightning, explosion).", "{effect}", &DebugCmdArrow },
{ "coords", "Toggles showing tile coords.", "", &DebugCmdShowCoords },
{ "cursorcoords", "Toggles showing cursor coords.", "", &DebugCmdShowCursorCoords },
{ "grid", "Toggles showing grid.", "", &DebugCmdShowGrid }, { "grid", "Toggles showing grid.", "", &DebugCmdShowGrid },
{ "seedinfo", "Show seed infos for current level.", "", &DebugCmdLevelSeed }, { "seedinfo", "Show seed infos for current level.", "", &DebugCmdLevelSeed },
{ "spawn", "Spawns monster {name}.", "({count}) {name}", &DebugCmdSpawnMonster }, { "spawn", "Spawns monster {name}.", "({count}) {name}", &DebugCmdSpawnMonster },
@ -767,51 +754,49 @@ bool CheckDebugTextCommand(const string_view text)
bool IsDebugGridTextNeeded() bool IsDebugGridTextNeeded()
{ {
return DebugCoords || DebugGrid || DebugCursorCoords || DebugInfoFlag != DebugInfoFlags::empty; return SelectedDebugGridTextItem != DebugGridTextItem::None;
} }
bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer) bool GetDebugGridText(Point dungeonCoords, char *debugGridTextBuffer)
{ {
if (DebugCoords) { int info = 0;
switch (SelectedDebugGridTextItem) {
case DebugGridTextItem::coords:
sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y); sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y);
return true; return true;
} case DebugGridTextItem::cursorcoords:
if (DebugCursorCoords) {
if (dungeonCoords != cursPosition) if (dungeonCoords != cursPosition)
return false; return false;
sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y); sprintf(debugGridTextBuffer, "%d:%d", dungeonCoords.x, dungeonCoords.y);
return true; return true;
} case DebugGridTextItem::dPiece:
int info = 0;
switch (DebugInfoFlag) {
case DebugInfoFlags::dPiece:
info = dPiece[dungeonCoords.x][dungeonCoords.y]; info = dPiece[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dTransVal: case DebugGridTextItem::dTransVal:
info = dTransVal[dungeonCoords.x][dungeonCoords.y]; info = dTransVal[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dLight: case DebugGridTextItem::dLight:
info = dLight[dungeonCoords.x][dungeonCoords.y]; info = dLight[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dPreLight: case DebugGridTextItem::dPreLight:
info = dPreLight[dungeonCoords.x][dungeonCoords.y]; info = dPreLight[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dFlags: case DebugGridTextItem::dFlags:
info = dFlags[dungeonCoords.x][dungeonCoords.y]; info = dFlags[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dPlayer: case DebugGridTextItem::dPlayer:
info = dPlayer[dungeonCoords.x][dungeonCoords.y]; info = dPlayer[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dMonster: case DebugGridTextItem::dMonster:
info = dMonster[dungeonCoords.x][dungeonCoords.y]; info = dMonster[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dCorpse: case DebugGridTextItem::dCorpse:
info = dCorpse[dungeonCoords.x][dungeonCoords.y]; info = dCorpse[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dItem: case DebugGridTextItem::dItem:
info = dItem[dungeonCoords.x][dungeonCoords.y]; info = dItem[dungeonCoords.x][dungeonCoords.y];
break; break;
case DebugInfoFlags::dSpecial: case DebugGridTextItem::dSpecial:
info = dSpecial[dungeonCoords.x][dungeonCoords.y]; info = dSpecial[dungeonCoords.x][dungeonCoords.y];
break; break;
} }

Loading…
Cancel
Save