summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp11
-rw-r--r--src/resources/Resources.cpp5
-rw-r--r--src/resources/Resources.h1
-rw-r--r--src/resources/windows/WindowsResources.cpp52
-rw-r--r--src/resources/windows/WindowsResources.h4
5 files changed, 44 insertions, 29 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7de3c11..4ebb8e6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -52,20 +52,21 @@ int main(int argc, char **argv) {
#ifdef __linux__
Resources *res = new LinuxResources();
- res->loadDefaultLuaFile();
- res->loadFontFiles();
- res->loadLevels();
#endif // __linux__
#ifdef _WIN32
Resources *res = new WindowsResources();
#endif
+ res->loadDefaultLuaFile();
+ res->loadFontFiles();
+ res->loadLevels();
int levelIndex = 0;
std::cout << "Select level from list: " << std::endl;
int i = 0;
for (auto &p : res->getLevels()) {
- std::cout << "\t[" << i++ << "] " << p.parent_path().filename().c_str()
- << "/" << p.filename().c_str() << std::endl;
+ std::cout << "\t[" << i++ << "] "
+ << p.parent_path().filename().generic_string() << "/"
+ << p.filename().generic_string() << std::endl;
}
std::cout << "Enter Number: ";
std::cin >> levelIndex;
diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp
index 11f762f..3ae93f4 100644
--- a/src/resources/Resources.cpp
+++ b/src/resources/Resources.cpp
@@ -29,6 +29,11 @@
#include <cassert>
#include <iostream>
+Resources::Resources() {
+ this->font = std::make_shared<std::filesystem::path>();
+ this->defaultsLua = std::make_shared<std::filesystem::path>();
+}
+
void Resources::loadFontFiles() {
// We will search 1 level deep
for (auto &base : this->fontSearchDirs()) {
diff --git a/src/resources/Resources.h b/src/resources/Resources.h
index 194c031..6e1a95f 100644
--- a/src/resources/Resources.h
+++ b/src/resources/Resources.h
@@ -56,6 +56,7 @@ protected:
virtual vector<filesystem::path> fontSearchDirs() = 0;
public:
+ Resources();
void loadLevels();
void loadFontFiles();
void loadDefaultLuaFile();
diff --git a/src/resources/windows/WindowsResources.cpp b/src/resources/windows/WindowsResources.cpp
index cfe264f..4ef0e2e 100644
--- a/src/resources/windows/WindowsResources.cpp
+++ b/src/resources/windows/WindowsResources.cpp
@@ -23,32 +23,36 @@
// distribution.
//
//========================================================================
-#include "../Resources.h"
+#include "WindowsResources.h"
#include <libloaderapi.h>
#define MAX_BUF_SIZE 1024
-class WindowsResources : public Resources {
+std::filesystem::path exeDir;
+std::filesystem::path workingDir;
-protected:
- std::filesystem::path exeDir;
- std::filesystem::path workingDir;
+std::vector<std::filesystem::path> WindowsResources::levelSearchDirs() {
+ return {workingDir / "maps", exeDir / "maps"};
+}
+std::vector<std::filesystem::path> WindowsResources::defaultsSearchDirs() {
+ return {workingDir / "dnglib", exeDir / "dnglib"};
+}
+std::vector<std::filesystem::path> WindowsResources::fontSearchDirs() {
+ return {workingDir / "res", exeDir / "res"};
+}
+WindowsResources::WindowsResources() : Resources() {
+ this->workingDir = std::filesystem::current_path();
+ this->font = std::make_shared<std::filesystem::path>(workingDir / "res" /
+ DEFAULT_FONT);
- std::vector<std::filesystem::path> levelSearchDirs() override {
- return {workingDir / "maps", exeDir / "maps"};
- }
- std::vector<std::filesystem::path> defaultsSearchDirs() override {
- return {workingDir / "dnglib", exeDir / "dnglib"};
- }
- std::vector<std::filesystem::path> fontSearchDirs() override {
- return {workingDir / "res", exeDir / "res"};
- }
+ char exe_dir_str[255];
+ GetModuleFileNameA(nullptr, exe_dir_str, 255);
+ this->exeDir = std::filesystem::path{exe_dir_str}.remove_filename();
+}
-public:
- const char *convert_to_str(std::filesystem::path &path) override {
- std::setlocale(LC_ALL, "en_US.utf8"); // TODO more support?
- const wchar_t *wstr = path.c_str();
- size_t len = std::wcslen(wstr) + 1; // gotta get that \0
- char *ret = static_cast<char *>(malloc(sizeof(char) * len)); // buffered
- std::wcstombs(ret, path.c_str(), len);
- return ret;
- }
-}; \ No newline at end of file
+const char *WindowsResources::convert_to_str(std::filesystem::path &path) {
+ std::setlocale(LC_ALL, "en_US.utf8"); // TODO more support?
+ const wchar_t *wstr = path.c_str();
+ size_t len = std::wcslen(wstr) + 1; // gotta get that \0
+ char *ret = static_cast<char *>(malloc(sizeof(char) * len)); // buffered
+ std::wcstombs(ret, path.c_str(), len);
+ return ret;
+}
diff --git a/src/resources/windows/WindowsResources.h b/src/resources/windows/WindowsResources.h
index b6a1cd6..5ca662b 100644
--- a/src/resources/windows/WindowsResources.h
+++ b/src/resources/windows/WindowsResources.h
@@ -29,6 +29,10 @@
#include "../Resources.h"
class WindowsResources : public Resources {
+public:
+ WindowsResources();
+ const char *convert_to_str(std::filesystem::path &path) override;
+
protected:
std::filesystem::path exeDir;
std::filesystem::path workingDir;