Skip to content

Commit

Permalink
Put the rest of the fmt formatting options in the epro namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
edo9300 committed Sep 6, 2024
1 parent 669c683 commit 42e897a
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 54 deletions.
3 changes: 1 addition & 2 deletions gframe/Android/COSAndroidOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <sys/utsname.h>
#include <android/api-level.h>
#include <fmt/format.h>
#include "COSAndroidOperator.h"
#include "porting_android.h"

Expand All @@ -19,7 +18,7 @@ COSAndroidOperator::COSAndroidOperator() {
#endif
struct utsname LinuxInfo;
uname(&LinuxInfo);
const auto verstring = fmt::format("Android version: {} {} {} {} {}",
const auto verstring = epro::format("Android version: {} {} {} {} {}",
android_get_device_api_level(), LinuxInfo.sysname, LinuxInfo.release, LinuxInfo.version, LinuxInfo.machine);
OperatingSystem = { verstring.data(), (u32)verstring.size() };
}
Expand Down
2 changes: 1 addition & 1 deletion gframe/CGUITTFont/CGUITTFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ CGUITTGlyphPage* CGUITTFont::getLastGlyphPage() const {

CGUITTGlyphPage* CGUITTFont::createGlyphPage(const u8& pixel_mode) {
// Name of our page.
auto name = fmt::format("TTFontGlyphPage_{}.{}.{}._{}",
auto name = epro::format("TTFontGlyphPage_{}.{}.{}._{}",
tt_face->family_name, tt_face->style_name, size, Glyph_Pages.size()); // The newly created page will be at the end of the collection.

// Create the new page.
Expand Down
2 changes: 1 addition & 1 deletion gframe/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Host Host::resolve(epro::stringview address, uint16_t port) {
hints.ai_flags = EVUTIL_AI_ADDRCONFIG;
auto getAddrInfo = [&](auto ai_family) {
hints.ai_family = ai_family;
return evutil_getaddrinfo(address.data(), fmt::to_string(port).data(), &hints, &answer) == 0;
return evutil_getaddrinfo(address.data(), epro::to_string(port).data(), &hints, &answer) == 0;
};
//Give priority to ipv4 addresses
if(getAddrInfo(AF_INET)) {
Expand Down
8 changes: 4 additions & 4 deletions gframe/client_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ void ClientCard::UpdateInfo(const CoreUtils::Query& query) {
if(attack < 0) {
atkstring = L"?";
} else
atkstring = fmt::to_wstring(attack);
atkstring = epro::to_wstring(attack);
}
}
if(query.flag & QUERY_DEFENSE) {
if(IsDifferent(defense, query.defense) || defstring.empty()) {
if(defense < 0) {
defstring = L"?";
} else
defstring = fmt::to_wstring(defense);
defstring = epro::to_wstring(defense);
}
}
/*if(query.flag & QUERY_REASON_CARD) {
Expand Down Expand Up @@ -100,11 +100,11 @@ void ClientCard::UpdateInfo(const CoreUtils::Query& query) {
}
if(query.flag & QUERY_LSCALE) {
if(IsDifferent(lscale, query.lscale) || lscstring.empty())
lscstring = fmt::to_wstring(lscale);
lscstring = epro::to_wstring(lscale);
}
if(query.flag & QUERY_RSCALE) {
if(IsDifferent(rscale, query.rscale) || rscstring.empty())
rscstring = fmt::to_wstring(rscale);
rscstring = epro::to_wstring(rscale);
}
if(query.flag & QUERY_LINK) {
if(IsDifferent(link, query.link) || linkstring.empty())
Expand Down
2 changes: 1 addition & 1 deletion gframe/client_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
}
} else {
if(sort_list[i]) {
curstring->setText(fmt::to_wstring(sort_list[i]).data());
curstring->setText(epro::to_wstring(sort_list[i]).data());
} else
curstring->setText(L"");
curstring->setBackgroundColor(skin::DUELFIELD_CARD_SELF_WINDOW_BACKGROUND_VAL);
Expand Down
2 changes: 1 addition & 1 deletion gframe/data_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ std::vector<uint16_t> DataManager::GetSetCode(const std::vector<epro::wstringvie
}
std::wstring DataManager::GetNumString(size_t num, bool bracket) const {
if(!bracket)
return fmt::to_wstring(num);
return epro::to_wstring(num);
return epro::format(L"({})", num);
}

Expand Down
2 changes: 1 addition & 1 deletion gframe/deck_con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ void DeckBuilder::FilterCards(bool force_refresh) {
SortList();
auto ip = std::unique(results.begin(), results.end());
results.resize(std::distance(results.begin(), ip));
result_string = fmt::to_wstring(results.size());
result_string = epro::to_wstring(results.size());
scroll_pos = 0;
if(results.size() > 7) {
mainGame->scrFilter->setVisible(true);
Expand Down
8 changes: 4 additions & 4 deletions gframe/deck_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ bool DeckManager::SaveDeck(epro::path_stringview name, const Deck& deck) {
deckfile << "#created by " << BufferIO::EncodeUTF8(mainGame->ebNickName->getText()) << "\n#main\n";
auto serializeDeck = [&deckfile](const auto& deck) {
for(auto card : deck)
deckfile << fmt::to_string(card->getRealCode()) << "\n";
deckfile << epro::to_string(card->getRealCode()) << "\n";
};
serializeDeck(deck.main);
deckfile << "#extra\n";
Expand All @@ -435,13 +435,13 @@ bool DeckManager::SaveDeck(epro::path_stringview name, const cardlist_type& main
return false;
deckfile << "#created by " << BufferIO::EncodeUTF8(mainGame->ebNickName->getText()) << "\n#main\n";
for(auto card : mainlist)
deckfile << fmt::to_string(card) << "\n";
deckfile << epro::to_string(card) << "\n";
deckfile << "#extra\n";
for(auto card : extralist)
deckfile << fmt::to_string(card) << "\n";
deckfile << epro::to_string(card) << "\n";
deckfile << "!side\n";
for(auto card : sidelist)
deckfile << fmt::to_string(card) << "\n";
deckfile << epro::to_string(card) << "\n";
return true;
}
const wchar_t* DeckManager::ExportDeckBase64(const Deck& deck) {
Expand Down
2 changes: 1 addition & 1 deletion gframe/discord_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void DiscordWrapper::UpdatePresence(PresenceType type) {
// a->address
// p->port
// s->password
auto ret = fmt::format_to_n(secret_buf, sizeof(secret_buf) - 1, R"({{"i":{},"a":"{}","p":{},"s":"{}"}})",
auto ret = epro::format_to_n(secret_buf, sizeof(secret_buf) - 1, R"({{"i":{},"a":"{}","p":{},"s":"{}"}})",
secret.game_id, secret.host.address, secret.host.port, BufferIO::EncodeUTF8(secret.pass));
*ret.out = '\0';
}
Expand Down
4 changes: 2 additions & 2 deletions gframe/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void Game::DrawMisc() {

if(lpframe > 0 && delta_frames) {
dInfo.lp[lpplayer] -= lpd * delta_frames;
dInfo.strLP[lpplayer] = fmt::to_wstring(std::max(0, dInfo.lp[lpplayer]));
dInfo.strLP[lpplayer] = epro::to_wstring(std::max(0, dInfo.lp[lpplayer]));
lpcalpha -= 0x19 * delta_frames;
lpframe -= delta_frames;
}
Expand Down Expand Up @@ -1251,7 +1251,7 @@ void Game::DrawDeckBd() {
const auto GetDeckSizeStr = [&](const Deck::Vector& deck, const Deck::Vector& pre_deck)->std::wstring {
if(is_siding)
return epro::format(L"{} ({})", deck.size(), pre_deck.size());
return fmt::to_wstring(deck.size());
return epro::to_wstring(deck.size());
};
const auto& current_deck = deckBuilder.GetCurrentDeck();

Expand Down
22 changes: 11 additions & 11 deletions gframe/duelclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,8 +1667,8 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
mainGame->dInfo.startlp = mainGame->dInfo.lp[mainGame->LocalPlayer(0)];
else
mainGame->dInfo.startlp = 8000;
mainGame->dInfo.strLP[0] = fmt::to_wstring(mainGame->dInfo.lp[0]);
mainGame->dInfo.strLP[1] = fmt::to_wstring(mainGame->dInfo.lp[1]);
mainGame->dInfo.strLP[0] = epro::to_wstring(mainGame->dInfo.lp[0]);
mainGame->dInfo.strLP[1] = epro::to_wstring(mainGame->dInfo.lp[1]);
uint16_t deckc = BufferIO::Read<uint16_t>(pbuf);
uint16_t extrac = BufferIO::Read<uint16_t>(pbuf);
mainGame->dField.Initial(mainGame->LocalPlayer(0), deckc, extrac);
Expand Down Expand Up @@ -3566,7 +3566,7 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
mainGame->lpcstring = L"";
}
mainGame->dInfo.lp[player] = final;
mainGame->dInfo.strLP[player] = fmt::to_wstring(mainGame->dInfo.lp[player]);
mainGame->dInfo.strLP[player] = epro::to_wstring(mainGame->dInfo.lp[player]);
return true;
}
case MSG_RECOVER: {
Expand All @@ -3588,7 +3588,7 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
mainGame->lpcstring = L"";
}
mainGame->dInfo.lp[player] = final;
mainGame->dInfo.strLP[player] = fmt::to_wstring(mainGame->dInfo.lp[player]);
mainGame->dInfo.strLP[player] = epro::to_wstring(mainGame->dInfo.lp[player]);
return true;
}
case MSG_EQUIP: {
Expand Down Expand Up @@ -3625,7 +3625,7 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
mainGame->WaitFrameSignal(11, lock);
}
mainGame->dInfo.lp[player] = val;
mainGame->dInfo.strLP[player] = fmt::to_wstring(mainGame->dInfo.lp[player]);
mainGame->dInfo.strLP[player] = epro::to_wstring(mainGame->dInfo.lp[player]);
return true;
}
case MSG_UNEQUIP: {
Expand Down Expand Up @@ -3694,7 +3694,7 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
mainGame->lpcstring = L"";
}
mainGame->dInfo.lp[player] = final;
mainGame->dInfo.strLP[player] = fmt::to_wstring(mainGame->dInfo.lp[player]);
mainGame->dInfo.strLP[player] = epro::to_wstring(mainGame->dInfo.lp[player]);
return true;
}
case MSG_ADD_COUNTER: {
Expand Down Expand Up @@ -3795,21 +3795,21 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
ClientCard* pcard = mainGame->dField.GetCard(info1.controler, info1.location, info1.sequence);
if(aatk != pcard->attack) {
pcard->attack = aatk;
pcard->atkstring = fmt::to_wstring(aatk);
pcard->atkstring = epro::to_wstring(aatk);
}
if(adef != pcard->defense) {
pcard->defense = adef;
pcard->defstring = fmt::to_wstring(adef);
pcard->defstring = epro::to_wstring(adef);
}
if(info2.location) {
pcard = mainGame->dField.GetCard(info2.controler, info2.location, info2.sequence);
if(datk != pcard->attack) {
pcard->attack = datk;
pcard->atkstring = fmt::to_wstring(datk);
pcard->atkstring = epro::to_wstring(datk);
}
if(ddef != pcard->defense) {
pcard->defense = ddef;
pcard->defstring = fmt::to_wstring(ddef);
pcard->defstring = epro::to_wstring(ddef);
}
}
return true;
Expand Down Expand Up @@ -4142,7 +4142,7 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
for(int i = 0; i < 2; ++i) {
int p = mainGame->LocalPlayer(i);
mainGame->dInfo.lp[p] = BufferIO::Read<uint32_t>(pbuf);
mainGame->dInfo.strLP[p] = fmt::to_wstring(mainGame->dInfo.lp[p]);
mainGame->dInfo.strLP[p] = epro::to_wstring(mainGame->dInfo.lp[p]);
for(int seq = 0; seq < 7; ++seq) {
const auto is_zone_used = !!BufferIO::Read<uint8_t>(pbuf);
if(!is_zone_used)
Expand Down
8 changes: 4 additions & 4 deletions gframe/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,13 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(offset + i >= select_max)
break;
if(sort_list[offset + i]) {
mainGame->stCardPos[i]->setText(fmt::to_wstring(sort_list[offset + i]).data());
mainGame->stCardPos[i]->setText(epro::to_wstring(sort_list[offset + i]).data());
} else mainGame->stCardPos[i]->setText(L"");
}
} else {
select_min++;
sort_list[sel_seq] = select_min;
mainGame->stCardPos[id - BUTTON_CARD_0]->setText(fmt::to_wstring(select_min).data());
mainGame->stCardPos[id - BUTTON_CARD_0]->setText(epro::to_wstring(select_min).data());
if(select_min == select_max) {
uint8_t respbuf[64];
for(uint32_t i = 0; i < select_max; ++i)
Expand Down Expand Up @@ -927,7 +927,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
std::wstring text = L"";
if(sort_list.size()) {
if(sort_list[pos + i] > 0)
text = fmt::to_wstring(sort_list[pos + i]);
text = epro::to_wstring(sort_list[pos + i]);
} else {
if(conti_selecting)
text = std::wstring{ DataManager::unknown_string };
Expand Down Expand Up @@ -1907,7 +1907,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event, bool& stopPropagation)
try {
gGameConfig->maxFPS = static_cast<int32_t>(std::stol(mainGame->gSettings.ebFPSCap->getText()));
} catch (...) {
mainGame->gSettings.ebFPSCap->setText(fmt::to_wstring(gGameConfig->maxFPS).data());
mainGame->gSettings.ebFPSCap->setText(epro::to_wstring(gGameConfig->maxFPS).data());
}
break;
}
Expand Down
12 changes: 12 additions & 0 deletions gframe/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ namespace epro {
using fmt::format;
using fmt::sprintf;
using fmt::print;
using fmt::format_to_n;
#if FMT_VERSION >= 60000
using fmt::to_string;
using fmt::to_wstring;
#else
template <typename T> inline std::string to_string(const T& value) {
return format("{}", value);
}
template <typename T> inline std::wstring to_wstring(const T& value) {
return format(L"{}", value);
}
#endif
}

#endif
4 changes: 2 additions & 2 deletions gframe/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ void Game::PopulateGameHostWindows() {
ReloadCBRule();
cbRule->setSelected(gGameConfig->lastallowedcards);
defaultStrings.emplace_back(env->addStaticText(gDataManager->GetSysString(1227).data(), Scale(20, 70, 220, 90), false, false, tDuelSettings), 1227);
#define WStr(i) fmt::to_wstring<int>(i).data()
#define WStr(i) epro::to_wstring<int>(i).data()
ebTeam1 = env->addEditBox(WStr(gGameConfig->team1count), Scale(140, 65, 170, 90), true, tDuelSettings, EDITBOX_TEAM_COUNT);
ebTeam1->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
auto vsstring = env->addStaticText(gDataManager->GetSysString(1380).data(), Scale(175, 65, 195, 90), false, false, tDuelSettings);
Expand Down Expand Up @@ -2751,7 +2751,7 @@ void Game::UpdateRepoInfo(const GitRepo* repo, RepoGui* grepo) {
grepo->history_button2->setEnabled(true);
if(!repo->is_language) {
script_dirs.insert(script_dirs.begin(), Utils::ToPathString(repo->script_path));
auto init_script = fmt::format(EPRO_TEXT("{}{}"), script_dirs.front(), EPRO_TEXT("init.lua"));
auto init_script = epro::format(EPRO_TEXT("{}{}"), script_dirs.front(), EPRO_TEXT("init.lua"));
if(Utils::FileExists(init_script))
init_scripts.push_back(std::move(init_script));
auto script_subdirs = Utils::FindSubfolders(Utils::ToPathString(repo->script_path), 2);
Expand Down
6 changes: 3 additions & 3 deletions gframe/game_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ uint8_t parseOption<uint8_t, ygo::GameConfig::BoolMaybeUndefined>(std::string& v

template<typename T>
std::string serializeOption(const T& value) {
return fmt::to_string(value);
return epro::to_string(value);
}

template<>
std::string serializeOption(const uint8_t& value) {
return fmt::to_string((int)value);
return epro::to_string((int)value);
}

template<>
Expand All @@ -173,7 +173,7 @@ std::string serializeOption(const float& value) {

template<>
std::string serializeOption(const bool& value) {
return fmt::to_string((int)value);
return epro::to_string((int)value);
}

template<>
Expand Down
16 changes: 8 additions & 8 deletions gframe/menu_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(sel == -1)
break;
const auto& selection = DuelClient::hosts[sel];
mainGame->ebJoinHost->setText(fmt::format(L"{}", selection.address).data());
mainGame->ebJoinPort->setText(fmt::to_wstring(selection.port).data());
mainGame->ebJoinHost->setText(epro::to_wstring(selection.address).data());
mainGame->ebJoinPort->setText(epro::to_wstring(selection.port).data());
break;
}
case LISTBOX_REPLAY_LIST: {
Expand Down Expand Up @@ -965,12 +965,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
switch (id) {
case COMBOBOX_DUEL_RULE: {
auto setDeckSizes = [&](const DeckSizes& size) {
mainGame->ebMainMin->setText(fmt::to_wstring<int>(size.main.min).data());
mainGame->ebMainMax->setText(fmt::to_wstring<int>(size.main.max).data());
mainGame->ebExtraMin->setText(fmt::to_wstring<int>(size.extra.min).data());
mainGame->ebExtraMax->setText(fmt::to_wstring<int>(size.extra.max).data());
mainGame->ebSideMin->setText(fmt::to_wstring<int>(size.side.min).data());
mainGame->ebSideMax->setText(fmt::to_wstring<int>(size.side.max).data());
mainGame->ebMainMin->setText(epro::to_wstring<int>(size.main.min).data());
mainGame->ebMainMax->setText(epro::to_wstring<int>(size.main.max).data());
mainGame->ebExtraMin->setText(epro::to_wstring<int>(size.extra.min).data());
mainGame->ebExtraMax->setText(epro::to_wstring<int>(size.extra.max).data());
mainGame->ebSideMin->setText(epro::to_wstring<int>(size.side.min).data());
mainGame->ebSideMax->setText(epro::to_wstring<int>(size.side.max).data());
};
static constexpr DeckSizes ocg_deck_sizes{ {40,60}, {0,15}, {0,15} };
static constexpr DeckSizes rush_deck_sizes{ {40,60}, {0,15}, {0,15} };
Expand Down
2 changes: 1 addition & 1 deletion gframe/old_replay_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace ygo {
mainGame->dInfo.lp[0] = start_lp;
mainGame->dInfo.lp[1] = start_lp;
mainGame->dInfo.startlp = start_lp;
mainGame->dInfo.strLP[0] = fmt::to_wstring(start_lp);
mainGame->dInfo.strLP[0] = epro::to_wstring(start_lp);
mainGame->dInfo.strLP[1] = mainGame->dInfo.strLP[0];
mainGame->dInfo.turn = 0;
if (!mainGame->dInfo.isSingleMode || (replay_header.base.flag & REPLAY_HAND_TEST)) {
Expand Down
2 changes: 1 addition & 1 deletion gframe/repo_cloner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int repo_cloner_main(const args_t& args) {
}
if(should_print) {
// prints a json array contaning all the info about the repos being cloned
fmt::print("[{{{}}}]\n", fmt::join(repos_to_clone.begin(), repos_to_clone.end(), "},{"));
epro::print("[{{{}}}]\n", fmt::join(repos_to_clone.begin(), repos_to_clone.end(), "},{"));
std::fflush(stdout);
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
Expand Down
2 changes: 1 addition & 1 deletion gframe/single_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int SingleMode::SinglePlayThread(DuelOptions&& duelOptions) {
mainGame->dInfo.compat_mode = false;
mainGame->dInfo.legacy_race_size = false;
mainGame->dInfo.startlp = mainGame->dInfo.lp[0] = mainGame->dInfo.lp[1] = duelOptions.startingLP;
mainGame->dInfo.strLP[0] = mainGame->dInfo.strLP[1] = fmt::to_wstring(mainGame->dInfo.lp[0]);
mainGame->dInfo.strLP[0] = mainGame->dInfo.strLP[1] = epro::to_wstring(mainGame->dInfo.lp[0]);
mainGame->dInfo.selfnames = { mainGame->ebNickName->getText() };
mainGame->dInfo.opponames = { L"" };
mainGame->dInfo.player_type = 0;
Expand Down
8 changes: 4 additions & 4 deletions gframe/windbot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ WindBot::launch_ret_t WindBot::Launch(int port, epro::wstringview pass, bool cha
nlohmann::json param({
{"HostInfo", BufferIO::EncodeUTF8(pass)},
{"Deck", BufferIO::EncodeUTF8(deck)},
{"Port", fmt::to_string(port)},
{"Version", fmt::to_string(version)},
{"Port", epro::to_string(port)},
{"Version", epro::to_string(version)},
{"Name", BufferIO::EncodeUTF8(name)},
{"Chat", fmt::to_string(static_cast<int>(chat))},
{"Hand", fmt::to_string(hand)}
{"Chat", epro::to_string(static_cast<int>(chat))},
{"Hand", epro::to_string(hand)}
});
if(overridedeck)
param["DeckFile"] = BufferIO::EncodeUTF8(overridedeck);
Expand Down
Loading

0 comments on commit 42e897a

Please sign in to comment.