summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp4
-rw-r--r--src/resources/Resources.cpp47
-rw-r--r--src/resources/Resources.h15
-rw-r--r--src/resources/macos/MacResources.cpp2
-rw-r--r--src/resources/macos/MacResources.h16
5 files changed, 38 insertions, 46 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 51722dd..c8d7b2d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,16 +34,12 @@
#include "resources/Resources.h"
#ifdef __linux__
#include "resources/linux/LinuxResources.h"
-#include <filesystem>
#endif // __linux__
#ifdef _WIN32
#include "resources/windows/WindowsResources.h"
-#include <filesystem>
#endif // _WIN32
#ifdef __APPLE__
#include "resources/macos/MacResources.h"
-#include <experimental/filesystem>
-namespace std::filesystem = std::experimental::filesystem;
#endif // __APPLE__
#include <SFML/Graphics.hpp>
#include <cmath>
diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp
index 3ae93f4..ee43002 100644
--- a/src/resources/Resources.cpp
+++ b/src/resources/Resources.cpp
@@ -30,18 +30,18 @@
#include <iostream>
Resources::Resources() {
- this->font = std::make_shared<std::filesystem::path>();
- this->defaultsLua = std::make_shared<std::filesystem::path>();
+ this->font = std::make_shared<fs::path>();
+ this->defaultsLua = std::make_shared<fs::path>();
}
void Resources::loadFontFiles() {
// We will search 1 level deep
for (auto &base : this->fontSearchDirs()) {
- if (std::filesystem::exists(base) && std::filesystem::is_directory(base)) {
- for (auto &item : std::filesystem::directory_iterator(base)) {
+ if (fs::exists(base) && fs::is_directory(base)) {
+ for (auto &item : fs::directory_iterator(base)) {
// only 1 deep
if (item.exists() && item.is_directory()) {
- for (auto &file : std::filesystem::directory_iterator(item)) {
+ for (auto &file : fs::directory_iterator(item)) {
if (file.exists() && file.is_regular_file()) {
auto ext = file.path().extension();
bool matched =
@@ -84,10 +84,10 @@ void Resources::loadFontFiles() {
void Resources::loadLevels() {
for (auto &base : this->levelSearchDirs()) {
- if (std::filesystem::exists(base) && std::filesystem::is_directory(base)) {
- for (auto &dir : std::filesystem::directory_iterator(base)) {
+ if (fs::exists(base) && fs::is_directory(base)) {
+ for (auto &dir : fs::directory_iterator(base)) {
if (dir.exists() && dir.is_directory()) {
- if (std::filesystem::exists(dir / DNG_MAP)) {
+ if (fs::exists(dir / DNG_MAP)) {
this->levels.push_back(dir.path());
}
}
@@ -99,42 +99,35 @@ void Resources::loadLevels() {
void Resources::loadDefaultLuaFile() {
for (auto &base : this->defaultsSearchDirs()) {
auto f = base / DEFAULT_LUA;
- if (std::filesystem::exists(f)) {
+ if (fs::exists(f)) {
*this->defaultsLua = f;
break;
}
}
}
-std::vector<std::filesystem::path> Resources::getFontFiles() {
- return this->fonts;
-}
-std::vector<std::filesystem::path> Resources::getLevels() {
- return this->levels;
-}
-shared_ptr<std::filesystem::path> Resources::getFontFile() {
- return this->font;
-}
-shared_ptr<std::filesystem::path> Resources::updateFont(int idx) {
+std::vector<fs::path> Resources::getFontFiles() { return this->fonts; }
+std::vector<fs::path> Resources::getLevels() { return this->levels; }
+shared_ptr<fs::path> Resources::getFontFile() { return this->font; }
+shared_ptr<fs::path> Resources::updateFont(int idx) {
auto f = this->fonts[idx];
*this->font = f;
return getFontFile();
}
-shared_ptr<std::filesystem::path> Resources::getDefaultsLuaFile() {
+shared_ptr<fs::path> Resources::getDefaultsLuaFile() {
return this->defaultsLua;
}
-shared_ptr<std::filesystem::path> Resources::getLevelMap(int idx) {
+shared_ptr<fs::path> Resources::getLevelMap(int idx) {
auto lvlBase = this->levels[idx];
- std::filesystem::path dngMap = lvlBase / DNG_MAP;
+ fs::path dngMap = lvlBase / DNG_MAP;
// existence of the level dng.map is asserted in the initializer
- assert(std::filesystem::exists(dngMap));
- return std::make_shared<std::filesystem::path>(dngMap);
+ assert(fs::exists(dngMap));
+ return std::make_shared<fs::path>(dngMap);
}
-std::optional<shared_ptr<std::filesystem::path>>
-Resources::getLevelProcLua(int idx) {
+std::optional<shared_ptr<fs::path>> Resources::getLevelProcLua(int idx) {
auto lvlBase = this->levels[idx];
auto procLua = lvlBase / PROC_LUA;
if (exists(procLua)) {
- return std::make_shared<std::filesystem::path>(procLua);
+ return std::make_shared<fs::path>(procLua);
} else {
return nullopt;
}
diff --git a/src/resources/Resources.h b/src/resources/Resources.h
index 21bf8a7..2e0e7c0 100644
--- a/src/resources/Resources.h
+++ b/src/resources/Resources.h
@@ -30,9 +30,10 @@
#ifdef __APPLE__
#include <experimental/filesystem>
-namespace std::filesystem = std::experimental::filesystem;
+namespace fs = std::experimental::filesystem;
#else
#include <filesystem>
+namespace fs = std::filesystem;
#endif
#include <optional>
#include <vector>
@@ -53,7 +54,7 @@ static const char *DEFAULT_FONT = "PressStart2P-vaV7.ttf";
class Resources {
protected:
- shared_ptr<std::filesystem::path> font; // chosen font
+ shared_ptr<fs::path> font; // chosen font
shared_ptr<filesystem::path> defaultsLua; // defaults lua file
vector<filesystem::path> fonts; // all found maps
vector<filesystem::path> levels; // all found maps
@@ -68,11 +69,11 @@ public:
void loadDefaultLuaFile();
vector<filesystem::path> getFontFiles();
vector<filesystem::path> getLevels();
- shared_ptr<std::filesystem::path> updateFont(int idx);
- shared_ptr<std::filesystem::path> getFontFile();
- shared_ptr<std::filesystem::path> getDefaultsLuaFile();
- shared_ptr<std::filesystem::path> getLevelMap(int idx);
- optional<shared_ptr<std::filesystem::path>> getLevelProcLua(int idx);
+ shared_ptr<fs::path> updateFont(int idx);
+ shared_ptr<fs::path> getFontFile();
+ shared_ptr<fs::path> getDefaultsLuaFile();
+ shared_ptr<fs::path> getLevelMap(int idx);
+ optional<shared_ptr<fs::path>> getLevelProcLua(int idx);
/* Helper method to convert any path to a const char *
* Windows uses wchar_t so this can help provide a common way to
* interact with files
diff --git a/src/resources/macos/MacResources.cpp b/src/resources/macos/MacResources.cpp
index 90f43c8..2b41daa 100644
--- a/src/resources/macos/MacResources.cpp
+++ b/src/resources/macos/MacResources.cpp
@@ -26,7 +26,7 @@
//========================================================================
#include "MacResources.h"
-namespace std::filesystem = std::experimental::filesystem;
+namespace fs = std::experimental::filesystem;
MacResources::MacResources() : Resources() {
this->workingDir = std::filesystem::current_path();
diff --git a/src/resources/macos/MacResources.h b/src/resources/macos/MacResources.h
index 7af24b6..1d19575 100644
--- a/src/resources/macos/MacResources.h
+++ b/src/resources/macos/MacResources.h
@@ -28,20 +28,22 @@
#ifndef DNG_MACRESOURCES_H
#define DNG_MACRESOURCES_H
#include "../Resources.h"
-namespace std::filesystem = std::experimental::filesystem;
+
+namespace fs = std::experimental::filesystem;
+
class MacResources : public Resources {
public:
MacResources();
protected:
public:
- const char *convert_to_str(std::filesystem::path &path) override;
+ const char *convert_to_str(fs::path &path) override;
protected:
- std::filesystem::path exeDir;
- std::filesystem::path workingDir;
- std::vector<std::filesystem::path> levelSearchDirs() override;
- std::vector<std::filesystem::path> defaultsSearchDirs() override;
- std::vector<std::filesystem::path> fontSearchDirs() override;
+ fs::path exeDir;
+ fs::path workingDir;
+ std::vector<fs::path> levelSearchDirs() override;
+ std::vector<fs::path> defaultsSearchDirs() override;
+ std::vector<fs::path> fontSearchDirs() override;
};
#endif // DNG_MACRESOURCES_H