import ADV settings, platform files

This commit is contained in:
Ondřej Novák 2025-01-30 20:43:42 +01:00
parent 9b86bed2d8
commit ccebc91f0d
17 changed files with 244 additions and 14 deletions

View file

@ -32,6 +32,7 @@ setup.c
chargen.c chargen.c
sndandmus.c sndandmus.c
specproc.c specproc.c
advconfig.c
temp_storage.cpp temp_storage.cpp
${CMAKE_BINARY_DIR}/default_font.cpp ${CMAKE_BINARY_DIR}/default_font.cpp
) )
@ -39,7 +40,6 @@ ${CMAKE_BINARY_DIR}/default_font.cpp
add_executable(skeldal ${files}) add_executable(skeldal ${files})
target_link_libraries(skeldal target_link_libraries(skeldal
skeldal_libs skeldal_libs
skeldal_platform_libs skeldal_platform
skeldal_linux
skeldal_sdl skeldal_sdl
${SDL2_LIBRARIES} pthread) ${SDL2_LIBRARIES} pthread)

56
game/advconfig.c Normal file
View file

@ -0,0 +1,56 @@
#include <platform.h>
#include "advconfig.h"
#include <alloca.h>
#include <string.h>
static void process_row(INI_CONFIG_SECTION *sec, const char *row) {
char *buff = strcpy((char *)alloca(strlen(row)+1), row);
char *sep = strchr(buff,' ');
if (sep == NULL) return;
*sep = 0;
const char *key = buff;
const char *value = sep+1;
if (stricmp(key,"CESTA_GRAFIKA") == 0) {
ini_replace_key(sec, "graphics", value);
} else if (stricmp(key, "CESTA_ZVUKY") == 0) {
ini_replace_key(sec, "sounds", value);
} else if (stricmp(key, "CESTA_FONTY") == 0) {
ini_replace_key(sec, "fonts", value);
} else if (stricmp(key, "CESTA_MAPY") == 0) {
ini_replace_key(sec, "maps", value);
} else if (stricmp(key, "CESTA_MUSIC") == 0) {
ini_replace_key(sec, "music_adv", value);
} else if (stricmp(key, "CESTA_BGRAFIKA") == 0) {
ini_replace_key(sec, "gui", value);
} else if (stricmp(key, "CESTA_ITEMY") == 0) {
ini_replace_key(sec, "items", value);
} else if (stricmp(key, "CESTA_ENEMY") == 0) {
ini_replace_key(sec, "enemy", value);
} else if (stricmp(key, "CESTA_VIDEO") == 0) {
ini_replace_key(sec, "video", value);
} else if (stricmp(key, "CESTA_DIALOGY") == 0) {
ini_replace_key(sec, "dialogs", value);
}
}
void adv_patch_config(INI_CONFIG *srcconfig, TSTR_LIST lst) {
INI_CONFIG_SECTION *sect = ini_create_section(srcconfig, "paths");
int cnt = str_count(lst);
for (int i = 0; i < cnt; ++i) {
const char *row = lst[i];
if (row) {
process_row(sect, row);
}
}
}

14
game/advconfig.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef SKELDAL_GAME_ADVCONFIG_H_
#define SKELDAL_GAME_ADVCONFIG_H_
#include <strlite.h>
#include <config.h>
void adv_patch_config(INI_CONFIG *srcconfig, TSTR_LIST lst);
#endif /* SKELDAL_GAME_ADVCONFIG_H_ */

View file

@ -1,14 +1,48 @@
SET(files error.cpp 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 legacy_coroutines.cpp
platform.cpp platform.cpp
int2ascii.c int2ascii.c
istr.c istr.c
file_access.cpp file_access.cpp
config.cpp config.cpp
error.cpp
timer.cpp
) )
add_library(skeldal_platform_libs ${files}) # Podmínky pro platformu Windows
set_property(TARGET skeldal_platform_libs PROPERTY CXX_STANDARD 20) 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(sdl)
add_subdirectory(linux)

View file

@ -1,6 +1,7 @@
#include "config.h" #include "config.h"
#include "platform.h" #include "platform.h"
#include <fstream> #include <fstream>
#include <iostream>
#include <map> #include <map>
#include <string> #include <string>
#include <string_view> #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; INI_CONFIG *c = new INI_CONFIG;
std::fstream input(filename); std::fstream input(filename);
@ -168,3 +169,28 @@ int ini_get_boolean(const INI_CONFIG_SECTION *section, const char *key,
} }
return defval; 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 &sect = cfg->data[std::string(section_name)];
return reinterpret_cast<INI_CONFIG_SECTION *>(&sect);
}
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;
}
}
}

View file

@ -7,9 +7,9 @@ typedef struct ini_config_tag INI_CONFIG;
typedef struct ini_config_section_tag INI_CONFIG_SECTION; typedef struct ini_config_section_tag INI_CONFIG_SECTION;
///Opens config, returns handle ///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 ///closes the config and frees memory
void ini_close(const INI_CONFIG *config); void ini_close(INI_CONFIG *config);
///Opens section ///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); 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 ///retrieve string from ini
/** /**

View file

@ -9,9 +9,8 @@ extern "C" {
void display_error(const char *text) { void display_error(const char *text) {
char failed_because_error = 0;
std::cerr << "ERROR:" << text << std::endl; std::cerr << "ERROR:" << text << std::endl;
assert(failed_because_error); abort();
} }

View file

@ -1,2 +0,0 @@
add_library(skeldal_linux map_file.cpp timer.cpp)

View 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();
}

View 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
View file

@ -0,0 +1 @@
Platform files are not complete

11
platform/save_folder.h Normal file
View file

@ -0,0 +1,11 @@
#ifdef __cplusplus__
extern "C" {
#endif
#define SAVEGAME_FOLDERNAME "Skeldal";
const char *get_default_savegame_directory();
#ifdef __cplusplus__
}
#endif

View file

@ -1,6 +1,6 @@
#include "timer.h" #include "timer.h"
#include <chrono> #include <chrono>
#include "../platform.h" #include "platform.h"
#include <thread> #include <thread>
int get_timer_value() { int get_timer_value() {

View 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();
}

View file

@ -0,0 +1 @@
Platform files are not complete

View file

@ -7,7 +7,7 @@
# savegame = path to savegame, if not defined, retrieved from platform settings # savegame = path to savegame, if not defined, retrieved from platform settings
[path] [paths]
game_path=/home/ondra/skeldal_game/ game_path=/home/ondra/skeldal_game/
# maps=./maps/ # maps=./maps/
# video=./video/ # video=./video/