Browse Source

Use `StrCat` in a few more places

Now `fmt` is only used for more complex formatting and for translations.
pull/5030/head
Gleb Mazovetskiy 4 years ago committed by Anders Jenbo
parent
commit
ea1087dfeb
  1. 5
      Source/DiabloUI/diabloui.cpp
  2. 5
      Source/diablo.cpp
  3. 15
      Source/discord/discord.cpp
  4. 9
      Source/engine/demomode.cpp
  5. 4
      Source/mpq/mpq_writer.cpp

5
Source/DiabloUI/diabloui.cpp

@ -3,8 +3,6 @@
#include <algorithm>
#include <string>
#include <fmt/compile.h>
#include "DiabloUI/art_draw.h"
#include "DiabloUI/button.h"
#include "DiabloUI/dialogs.h"
@ -28,6 +26,7 @@
#include "utils/sdl_compat.h"
#include "utils/sdl_geometry.h"
#include "utils/sdl_wrap.h"
#include "utils/str_cat.hpp"
#include "utils/stubs.h"
#include "utils/utf8.hpp"
@ -547,7 +546,7 @@ void LoadHeros()
for (size_t i = 0; i <= enum_size<HeroClass>::value; ++i) {
char portraitPath[18];
*fmt::format_to(portraitPath, FMT_COMPILE("ui_art\\hero{}.pcx"), i) = '\0';
*BufCopy(portraitPath, "ui_art\\hero", i, ".pcx") = '\0';
SDL_RWops *handle = OpenAsset(portraitPath);
if (handle == nullptr) {

5
Source/diablo.cpp

@ -79,6 +79,7 @@
#include "utils/language.h"
#include "utils/paths.h"
#include "utils/stdcompat/string_view.hpp"
#include "utils/str_cat.hpp"
#include "utils/utf8.hpp"
#ifdef __vita__
@ -967,8 +968,8 @@ void DiabloInitScreen()
void SetApplicationVersions()
{
*fmt::format_to_n(gszProductName, sizeof(gszProductName) - 1, "{} v{}", PROJECT_NAME, PROJECT_VERSION).out = '\0';
CopyUtf8(gszVersionNumber, fmt::format(fmt::runtime(_("version {:s}")), PROJECT_VERSION), sizeof(gszVersionNumber));
*BufCopy(gszProductName, PROJECT_NAME, " v", PROJECT_VERSION) = '\0';
*BufCopy(gszVersionNumber, "version ", PROJECT_VERSION) = '\0';
}
void DiabloInit()

15
Source/discord/discord.cpp

@ -110,13 +110,14 @@ std::string GetTooltipString()
std::string GetPlayerAssetString()
{
char heroChar = CharChar[static_cast<int>(MyPlayer->_pClass)];
char armourChar = ArmourChar[tracked_data.playerGfx >> 4];
char wpnChar = WepChar[tracked_data.playerGfx & 0xF];
std::string result = fmt::format("{}{}{}as", heroChar, armourChar, wpnChar);
std::transform(std::begin(result), std::end(result), std::begin(result), [](char c) { return static_cast<char>(std::tolower(c)); });
return result;
char chars[5] {
CharChar[static_cast<int>(MyPlayer->_pClass)] - ('a' - 'A'),
ArmourChar[tracked_data.playerGfx >> 4] - ('a' - 'A'),
WepChar[tracked_data.playerGfx & 0xF] - ('a' - 'A'),
'a',
's'
};
return std::string(chars, 5);
}
void ResetStartTime()

9
Source/engine/demomode.cpp

@ -12,6 +12,7 @@
#include "pfile.h"
#include "utils/display.h"
#include "utils/paths.h"
#include "utils/str_cat.hpp"
namespace devilution {
@ -75,9 +76,7 @@ void WriteToDemo(T value)
bool LoadDemoMessages(int i)
{
std::ifstream demofile;
char demoFilename[16];
*fmt::format_to_n(demoFilename, 15, "demo_{}.dmo", i).out = '\0';
demofile.open(paths::PrefPath() + demoFilename, std::fstream::binary);
demofile.open(StrCat(paths::PrefPath(), "demo_", i, ".dmo"), std::fstream::binary);
if (!demofile.is_open()) {
return false;
}
@ -269,9 +268,7 @@ void RecordMessage(tagMSG *lpMsg)
void NotifyGameLoopStart()
{
if (IsRecording()) {
char demoFilename[16];
*fmt::format_to_n(demoFilename, 15, "demo_{}.dmo", RecordNumber).out = '\0';
DemoRecording.open(paths::PrefPath() + demoFilename, std::fstream::trunc | std::fstream::binary);
DemoRecording.open(StrCat(paths::PrefPath(), "demo_", RecordNumber, ".dmo"), std::fstream::trunc | std::fstream::binary);
constexpr uint8_t version = 0;
WriteToDemo<uint8_t>(version);
WriteToDemo<uint32_t>(gSaveNumber);

4
Source/mpq/mpq_writer.cpp

@ -6,8 +6,6 @@
#include <memory>
#include <type_traits>
#include <fmt/core.h>
#include "appfat.h"
#include "encrypt.h"
#include "engine.h"
@ -160,7 +158,7 @@ MpqWriter::MpqWriter(const char *path)
}
return;
on_error:
app_fatal(fmt::format("{}\n{}\n{}", _("Failed to open archive for writing."), path, error));
app_fatal(StrCat(_("Failed to open archive for writing."), "\n", path, "\n", error));
}
MpqWriter::~MpqWriter()

Loading…
Cancel
Save