This commit is contained in:
@@ -15,9 +15,7 @@ AppMenu::AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings>
|
||||
settings(settings),
|
||||
renderWindow(renderWindow) {
|
||||
|
||||
const Asset& file = getResource(AssetName::data_fonts_pressstart_prstartk_ttf);
|
||||
|
||||
this->pressStartFont = sf::Font(file.data, file.size);
|
||||
this->pressStartFont = sf::Font(AssetManager::getResourcePath("data/fonts/pressstart/prstart.ttf"));
|
||||
}
|
||||
|
||||
void AppMenu::updateMetaBinds() {
|
||||
|
||||
@@ -23,9 +23,7 @@ SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menu
|
||||
std::string textureName = ACTION_NAMES[action];
|
||||
textureName = std::regex_replace(textureName, std::regex(" "), "");
|
||||
|
||||
const Asset& textureData = getResource("data/images/keybinds/" + textureName + ".png");
|
||||
|
||||
this->iconTextures[action] = sf::Texture(textureData.data, textureData.size, false, {{0, 0}, {16, 16}});
|
||||
this->iconTextures[action] = sf::Texture(AssetManager::getResourcePath("data/images/keybinds/" + textureName + ".png"), false, {{0, 0}, {16, 16}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <set>
|
||||
#include <fstream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "../Utils/AssetManager.h"
|
||||
|
||||
|
||||
Keybinds::Keybinds(int layoutNumber) :
|
||||
@@ -20,7 +21,7 @@ Keybinds::Keybinds(int layoutNumber) :
|
||||
}
|
||||
|
||||
void Keybinds::loadKeybindsFromFile() {
|
||||
std::ifstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::binary);
|
||||
std::ifstream layoutFile(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::binary);
|
||||
|
||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||
this->keybinds.at(action).clear();
|
||||
@@ -47,7 +48,7 @@ void Keybinds::loadKeybindsFromFile() {
|
||||
void Keybinds::saveKeybindsToFile() const {
|
||||
if (!this->modifiable) return;
|
||||
|
||||
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::trunc | std::ios::binary);
|
||||
std::ofstream layoutFile(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::trunc | std::ios::binary);
|
||||
|
||||
char byte;
|
||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../Core/Menu.h"
|
||||
#include "Keybinds.h"
|
||||
#include "PiecesType.h"
|
||||
#include "../Utils/AssetManager.h"
|
||||
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
@@ -49,7 +50,7 @@ void Settings::loadPieces(int loadablePiecesSizeRequest) {
|
||||
}
|
||||
|
||||
void Settings::loadSettingsFromFile(bool loadPieces, std::optional<int> loadablePiecesSizeRequest) {
|
||||
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
||||
std::ifstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::binary);
|
||||
char byte;
|
||||
|
||||
// file format version
|
||||
@@ -158,7 +159,7 @@ void Settings::saveSettingsToFile() const {
|
||||
|
||||
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
|
||||
|
||||
std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary);
|
||||
std::ofstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::trunc | std::ios::binary);
|
||||
char byte;
|
||||
|
||||
// file format version
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include "../Utils/AssetManager.h"
|
||||
|
||||
[[nodiscard]] bool resetSettingsFile();
|
||||
[[nodiscard]] bool resetKeybindFile(int layout);
|
||||
|
||||
@@ -18,7 +20,7 @@ int main() {
|
||||
PiecesFiles pf;
|
||||
bool warned = false;
|
||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
||||
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin"))) {
|
||||
#ifndef DEBUG
|
||||
if (!warned && i > DEBUG_PIECES_SIZE) {
|
||||
std::cout << "IMPORTANT: You are currently in release mode, if you do not wish to generate big pieces (can take several minutes), type 'xmake f -m debug'." << std::endl;
|
||||
@@ -36,7 +38,7 @@ int main() {
|
||||
|
||||
bool releasePiecesGenerated = true;
|
||||
for (int i = DEBUG_PIECES_SIZE + 1; i <= RELEASE_PIECES_SIZE; i++) {
|
||||
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin"))) {
|
||||
releasePiecesGenerated = false;
|
||||
}
|
||||
}
|
||||
@@ -47,29 +49,29 @@ int main() {
|
||||
|
||||
bool everythingGenerated = true;
|
||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
||||
std::string filePath = "data/pieces/" + std::to_string(i) + "minos.bin";
|
||||
auto filePath = AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin");
|
||||
|
||||
if (!std::filesystem::exists(filePath)) {
|
||||
std::cout << "ERROR: Could not open file " + filePath << std::endl;
|
||||
std::cout << "ERROR: Could not open file " << filePath << std::endl;
|
||||
everythingIsOK &= false;
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK CONFIG FILES
|
||||
|
||||
if (!std::filesystem::exists("data/config/settings.bin")) {
|
||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/settings.bin"))) {
|
||||
std::cout << "INFO: Settings file not found, generating..." << std::endl;
|
||||
everythingIsOK &= resetSettingsFile();
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) {
|
||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(i) + ".bin"))) {
|
||||
std::cout << "INFO: Keybind file number " << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
|
||||
everythingIsOK &= resetKeybindFile(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
||||
std::ifstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::binary);
|
||||
char byte;
|
||||
|
||||
settingsFile.get(byte);
|
||||
@@ -99,14 +101,14 @@ int main() {
|
||||
|
||||
|
||||
bool resetSettingsFile() {
|
||||
if (!std::filesystem::exists("data/config")) {
|
||||
std::filesystem::create_directories("data/config");
|
||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config"))) {
|
||||
std::filesystem::create_directories(AssetManager::getResourcePath("data/config"));
|
||||
}
|
||||
|
||||
std::string filePath ="data/config/settings.bin";
|
||||
auto filePath = AssetManager::getResourcePath("data/config/settings.bin");
|
||||
std::ofstream settingsFile(filePath, std::ios::trunc | std::ios::binary);
|
||||
if (!settingsFile.good()) {
|
||||
std::cerr << "ERROR: Could not open file " + filePath << std::endl;
|
||||
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -180,14 +182,14 @@ bool resetKeybindFile(int layout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists("data/config/keybinds")) {
|
||||
std::filesystem::create_directories("data/config/keybinds");
|
||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds"))) {
|
||||
std::filesystem::create_directories(AssetManager::getResourcePath("data/config/keybinds"));
|
||||
}
|
||||
|
||||
std::string filePath = "data/config/keybinds/layout" + std::to_string(layout) + ".bin";
|
||||
auto filePath = AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(layout) + ".bin");
|
||||
std::ofstream layoutFile(filePath, std::ios::trunc | std::ios::binary);
|
||||
if (!layoutFile.good()) {
|
||||
std::cerr << "ERROR: Could not open file " + filePath << std::endl;
|
||||
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user