Browse Source

Add TRN debug command and support for optional class TRNs

pull/5233/head
qndel 4 years ago committed by Anders Jenbo
parent
commit
5dc95550ce
  1. 31
      Source/debug.cpp
  2. 1
      Source/debug.h
  3. 14
      Source/engine/load_file.hpp
  4. 40
      Source/engine/trn.cpp
  5. 4
      Source/engine/trn.hpp
  6. 6
      Source/player.cpp

31
Source/debug.cpp

@ -42,6 +42,7 @@ bool DebugVision = false;
bool DebugGrid = false;
std::unordered_map<int, Point> DebugCoordsMap;
bool DebugScrollViewEnabled = false;
std::string debugTRN;
namespace {
@ -954,6 +955,35 @@ std::string DebugCmdToggleFPS(const string_view parameter)
return "";
}
std::string DebugCmdChangeTRN(const string_view parameter)
{
std::stringstream paramsStream(parameter.data());
std::string first;
std::string out;
if (std::getline(paramsStream, first, ' ')) {
std::string second;
if (std::getline(paramsStream, second, ' ')) {
std::string prefix;
if (first == "mon") {
prefix = "Monsters\\Monsters\\";
} else if (first == "plr") {
prefix = "PlrGFX\\";
}
debugTRN = prefix + second + ".TRN";
} else {
debugTRN = first + ".TRN";
}
out = fmt::format("I am a pretty butterfly. \n(Loading TRN: {:s})", debugTRN);
} else {
debugTRN = "";
out = "I am a big brown potato.";
}
auto &player = *MyPlayer;
InitPlayerGFX(player);
StartStand(player, player._pdir);
return out;
}
std::vector<DebugCmdItem> DebugCmdList = {
{ "help", "Prints help overview or help for a specific command.", "({command})", &DebugCmdHelp },
{ "give gold", "Fills the inventory with gold.", "", &DebugCmdGiveGoldCheat },
@ -990,6 +1020,7 @@ std::vector<DebugCmdItem> DebugCmdList = {
{ "questinfo", "Shows info of quests.", "{id}", &DebugCmdQuestInfo },
{ "playerinfo", "Shows info of player.", "{playerid}", &DebugCmdPlayerInfo },
{ "fps", "Toggles displaying FPS", "", &DebugCmdToggleFPS },
{ "trn", "Makes player use TRN {trn} - Write 'plr' before it to look in PlrGFX\\ or 'mon' to look in Monsters\\Monsters\\ - example: trn plr infra is equal to 'PlrGFX\\Infra.TRN'", "{trn}", &DebugCmdChangeTRN },
};
} // namespace

1
Source/debug.h

@ -21,6 +21,7 @@ extern bool DebugVision;
extern bool DebugGrid;
extern std::unordered_map<int, Point> DebugCoordsMap;
extern bool DebugScrollViewEnabled;
extern std::string debugTRN;
void FreeDebugGFX();
void LoadDebugGFX();

14
Source/engine/load_file.hpp

@ -18,11 +18,11 @@ namespace devilution {
class SFile {
public:
explicit SFile(const char *path)
explicit SFile(const char *path, bool isOptional = false)
{
handle_ = OpenAsset(path);
if (handle_ == nullptr) {
if (!HeadlessMode) {
if (!HeadlessMode && !isOptional) {
app_fatal(StrCat("Failed to open file:\n", path, "\n\n", SDL_GetError()));
}
}
@ -74,6 +74,16 @@ void LoadFileInMem(const char *path, T *data, std::size_t count)
file.Read(reinterpret_cast<byte *>(data), count * sizeof(T));
}
template <typename T>
bool LoadOptionalFileInMem(const char *path, T *data, std::size_t count)
{
SFile file { path, true };
if (!file.Ok())
return false;
file.Read(reinterpret_cast<byte *>(data), count * sizeof(T));
return true;
}
template <typename T, std::size_t N>
void LoadFileInMem(const char *path, std::array<T, N> &data)
{

40
Source/engine/trn.cpp

@ -1,6 +1,9 @@
#include <fmt/format.h>
#include <unordered_map>
#ifdef _DEBUG
#include "debug.h"
#endif
#include "engine/load_file.hpp"
#include "engine/trn.hpp"
#include "lighting.h"
@ -22,4 +25,41 @@ uint8_t *GetPauseTRN()
return &LightTables[18 * 256];
}
std::optional<std::array<uint8_t, 256>> GetClassTRN(Player &player)
{
std::array<uint8_t, 256> trn;
const char *path;
switch (player._pClass) {
case HeroClass::Warrior:
path = "PlrGFX\\warrior.TRN";
break;
case HeroClass::Rogue:
path = "PlrGFX\\rogue.TRN";
break;
case HeroClass::Sorcerer:
path = "PlrGFX\\sorcerer.TRN";
break;
case HeroClass::Monk:
path = "PlrGFX\\monk.TRN";
break;
case HeroClass::Bard:
path = "PlrGFX\\bard.TRN";
break;
case HeroClass::Barbarian:
path = "PlrGFX\\barbarian.TRN";
break;
}
#ifdef _DEBUG
if (!debugTRN.empty()) {
path = debugTRN.c_str();
}
#endif
if (LoadOptionalFileInMem(path, &trn, 256)) {
return trn;
}
return std::nullopt;
}
} // namespace devilution

4
Source/engine/trn.hpp

@ -5,10 +5,14 @@
*/
#pragma once
#include "player.h"
#include "utils/stdcompat/optional.hpp"
namespace devilution {
uint8_t *GetInfravisionTRN();
uint8_t *GetStoneTRN();
uint8_t *GetPauseTRN();
std::optional<std::array<uint8_t, 256>> GetClassTRN(Player &player);
} // namespace devilution

6
Source/player.cpp

@ -20,6 +20,8 @@
#include "engine/load_file.hpp"
#include "engine/points_in_rectangle_range.hpp"
#include "engine/random.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/trn.hpp"
#include "engine/world_tile.hpp"
#include "gamemenu.h"
#include "help.h"
@ -2234,6 +2236,10 @@ void LoadPlrGFX(Player &player, player_graphic graphic)
*fmt::format_to(pszName, FMT_COMPILE(R"(PlrGFX\{0}\{1}\{1}{2}.CL2)"), path, string_view(prefix, 3), szCel) = 0;
const uint16_t animationWidth = GetPlayerSpriteWidth(cls, graphic, animWeaponId);
animationData.sprites = LoadCl2Sheet(pszName, animationWidth);
std::optional<std::array<uint8_t, 256>> trn = GetClassTRN(player);
if (trn) {
ClxApplyTrans(*animationData.sprites, trn->data());
}
}
void InitPlayerGFX(Player &player)

Loading…
Cancel
Save