mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-18 20:26:45 -04:00
import ADV settings, platform files
This commit is contained in:
parent
9b86bed2d8
commit
ccebc91f0d
17 changed files with 244 additions and 14 deletions
|
@ -1,14 +1,48 @@
|
|||
SET(files error.cpp
|
||||
)
|
||||
|
||||
# Základní knihovna mylib
|
||||
add_library(skeldal_platform STATIC)
|
||||
|
||||
# Přidejte soubory společné pro všechny platformy
|
||||
target_sources(skeldal_platform PRIVATE
|
||||
legacy_coroutines.cpp
|
||||
platform.cpp
|
||||
int2ascii.c
|
||||
istr.c
|
||||
file_access.cpp
|
||||
config.cpp
|
||||
error.cpp
|
||||
timer.cpp
|
||||
)
|
||||
|
||||
add_library(skeldal_platform_libs ${files})
|
||||
set_property(TARGET skeldal_platform_libs PROPERTY CXX_STANDARD 20)
|
||||
# Podmínky pro platformu Windows
|
||||
if(WIN32)
|
||||
target_sources(skeldal_platform PRIVATE
|
||||
windows/save_folder.cpp
|
||||
)
|
||||
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_WINDOWS)
|
||||
message(STATUS "Building for Windows")
|
||||
|
||||
# Podmínky pro platformu Linux
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
target_sources(skeldal_platform PRIVATE
|
||||
linux/save_folder.cpp
|
||||
linux/map_file.cpp
|
||||
)
|
||||
target_compile_definitions(skeldal_platform PRIVATE PLATFORM_LINUX)
|
||||
message(STATUS "Building for Linux")
|
||||
|
||||
# Podmínky pro platformu macOS
|
||||
elseif(APPLE)
|
||||
target_sources(skeldal_platform PRIVATE
|
||||
mac_os/save_folder.cpp
|
||||
)
|
||||
target_compile_definitions(mylib PRIVATE PLATFORM_MACOS)
|
||||
message(STATUS "Building for macOS")
|
||||
else()
|
||||
error("Platform not detected, please add new platform here")
|
||||
endif()
|
||||
set_property(TARGET skeldal_platform PROPERTY CXX_STANDARD 20)
|
||||
|
||||
add_subdirectory(sdl)
|
||||
add_subdirectory(linux)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "config.h"
|
||||
#include "platform.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
@ -50,7 +51,7 @@ void parseIniStream(std::istream& input, Callback &&callback) {
|
|||
}
|
||||
|
||||
|
||||
const INI_CONFIG* ini_open(const char *filename) {
|
||||
INI_CONFIG* ini_open(const char *filename) {
|
||||
INI_CONFIG *c = new INI_CONFIG;
|
||||
|
||||
std::fstream input(filename);
|
||||
|
@ -168,3 +169,28 @@ int ini_get_boolean(const INI_CONFIG_SECTION *section, const char *key,
|
|||
}
|
||||
return defval;
|
||||
}
|
||||
|
||||
void ini_replace_key( INI_CONFIG_SECTION *section, const char *key, const char *value) {
|
||||
auto s = reinterpret_cast<INI_CONFIG::Section *>(section);
|
||||
(*s)[std::string(key)] = std::string(value);
|
||||
}
|
||||
|
||||
INI_CONFIG_SECTION* ini_create_section(INI_CONFIG *cfg, const char *section_name) {
|
||||
auto § = cfg->data[std::string(section_name)];
|
||||
return reinterpret_cast<INI_CONFIG_SECTION *>(§);
|
||||
}
|
||||
|
||||
INI_CONFIG* ini_create_empty(void) {
|
||||
INI_CONFIG *c = new INI_CONFIG;
|
||||
return c;
|
||||
}
|
||||
|
||||
void ini_store_to_file(const INI_CONFIG *config, const char *filename) {
|
||||
std::ofstream out(filename,std::ios::out|std::ios::trunc);
|
||||
for (const auto &[sname, s]: config->data) {
|
||||
out << '[' << sname << ']' << std::endl;
|
||||
for (const auto &[k,v]: s) {
|
||||
out << k << '=' << v << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ typedef struct ini_config_tag INI_CONFIG;
|
|||
typedef struct ini_config_section_tag INI_CONFIG_SECTION;
|
||||
|
||||
///Opens config, returns handle
|
||||
const INI_CONFIG *ini_open(const char *filename);
|
||||
INI_CONFIG *ini_open(const char *filename);
|
||||
///closes the config and frees memory
|
||||
void ini_close(const INI_CONFIG *config);
|
||||
void ini_close(INI_CONFIG *config);
|
||||
|
||||
///Opens section
|
||||
/**
|
||||
|
@ -54,6 +54,15 @@ double ini_get_value_double(const char *value, int *conv_ok);
|
|||
*/
|
||||
int ini_get_value_boolean(const char *value);
|
||||
|
||||
INI_CONFIG_SECTION* ini_create_section(INI_CONFIG *cfg, const char *section_name);
|
||||
|
||||
INI_CONFIG *ini_create_empty(void);
|
||||
|
||||
void ini_store_to_file(const INI_CONFIG *cfg, const char *filename);
|
||||
|
||||
|
||||
///Replace existing key with different value
|
||||
void ini_replace_key(INI_CONFIG_SECTION *section, const char *key, const char *value);
|
||||
|
||||
///retrieve string from ini
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,8 @@ extern "C" {
|
|||
|
||||
|
||||
void display_error(const char *text) {
|
||||
char failed_because_error = 0;
|
||||
std::cerr << "ERROR:" << text << std::endl;
|
||||
assert(failed_because_error);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
add_library(skeldal_linux map_file.cpp timer.cpp)
|
25
platform/linux/save_folder.cpp
Normal file
25
platform/linux/save_folder.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "../save_folder.h"
|
||||
#include "../error.h"
|
||||
#include <filesystem>
|
||||
|
||||
static std::string get_default_savegame_dir() {
|
||||
|
||||
// Linux
|
||||
char* home = std::getenv("HOME");
|
||||
if (home) {
|
||||
return std::filesystem::path(home) / ".local/share/" SAVEGAME_FOLDERNAME;
|
||||
} else {
|
||||
display_error("$HOME has no value (user with no home)");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const char *get_default_savegame_directory() {
|
||||
|
||||
static std::string dir = get_default_savegame_dir();
|
||||
return dir.c_str();
|
||||
|
||||
}
|
25
platform/mac_os/save_folder.cpp
Normal file
25
platform/mac_os/save_folder.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "../save_folder.h"
|
||||
#include "../error.h"
|
||||
#include <filesystem>
|
||||
|
||||
static std::string get_default_savegame_dir() {
|
||||
|
||||
// Linux
|
||||
char* home = std::getenv("HOME");
|
||||
if (home) {
|
||||
return std::filesystem::path(home) / ".local/share/" SAVEGAME_FOLDERNAME;
|
||||
} else {
|
||||
display_error("$HOME has no value (user with no home)");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const char *get_default_savegame_directory() {
|
||||
|
||||
static std::string dir = get_default_savegame_dir();
|
||||
return dir.c_str();
|
||||
|
||||
}
|
1
platform/mac_os/todo.txt
Normal file
1
platform/mac_os/todo.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Platform files are not complete
|
11
platform/save_folder.h
Normal file
11
platform/save_folder.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifdef __cplusplus__
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SAVEGAME_FOLDERNAME "Skeldal";
|
||||
|
||||
const char *get_default_savegame_directory();
|
||||
|
||||
#ifdef __cplusplus__
|
||||
}
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
#include "timer.h"
|
||||
#include <chrono>
|
||||
#include "../platform.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <thread>
|
||||
int get_timer_value() {
|
31
platform/windows/save_folder.cpp
Normal file
31
platform/windows/save_folder.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "../save_folder.h"
|
||||
#include "../error.h"
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <windows.h>
|
||||
|
||||
#pragma comment(lib, "shell32.lib")
|
||||
#pragma comment(lib, "ole32.lib")
|
||||
|
||||
// Pro získání uživatelské složky
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// Funkce pro získání složky "Saved Games"
|
||||
std::string getSavedGamesDirectory() {
|
||||
PWSTR path = nullptr;
|
||||
// Použití identifikátoru složky FOLDERID_SavedGames
|
||||
if (SUCCEEDED(SHGetKnownFolderPathA(FOLDERID_SavedGames, 0, NULL, &path))) {
|
||||
fs::path savedGamesPath(path);
|
||||
CoTaskMemFree(path); // Uvolnění paměti
|
||||
return savedGamesPath / SAVEGAME_FOLDERNAME
|
||||
} else {
|
||||
display_error("Failed to retrieve FOLDEROD_SavedGames");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
const char *get_default_savegame_directory() {
|
||||
|
||||
static std::string dir = get_default_savgetSavedGamesDirectoryegame_dir();
|
||||
return dir.c_str();
|
||||
|
||||
}
|
1
platform/windows/todo.txt
Normal file
1
platform/windows/todo.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Platform files are not complete
|
Loading…
Add table
Add a link
Reference in a new issue