Resources priority update
This commit is contained in:
@@ -156,6 +156,8 @@ void ContentLoader::load(ContentBuilder* builder) {
|
|||||||
fixPackIndices();
|
fixPackIndices();
|
||||||
|
|
||||||
auto folder = pack->folder;
|
auto folder = pack->folder;
|
||||||
|
if (!fs::is_regular_file(pack->getContentFile()))
|
||||||
|
return;
|
||||||
std::unique_ptr<json::JObject> root (files::read_json(pack->getContentFile()));
|
std::unique_ptr<json::JObject> root (files::read_json(pack->getContentFile()));
|
||||||
|
|
||||||
json::JArray* blocksarr = root->arr("blocks");
|
json::JArray* blocksarr = root->arr("blocks");
|
||||||
|
|||||||
+24
-25
@@ -7,20 +7,17 @@
|
|||||||
#define SCREENSHOTS_FOLDER "screenshots"
|
#define SCREENSHOTS_FOLDER "screenshots"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
using fs::path;
|
|
||||||
|
|
||||||
path EnginePaths::getUserfiles() const {
|
fs::path EnginePaths::getUserfiles() const {
|
||||||
return userfiles;
|
return userfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
path EnginePaths::getResources() const {
|
fs::path EnginePaths::getResources() const {
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
path EnginePaths::getScreenshotFile(string ext) {
|
fs::path EnginePaths::getScreenshotFile(std::string ext) {
|
||||||
path folder = userfiles/path(SCREENSHOTS_FOLDER);
|
fs::path folder = userfiles/fs::path(SCREENSHOTS_FOLDER);
|
||||||
if (!fs::is_directory(folder)) {
|
if (!fs::is_directory(folder)) {
|
||||||
fs::create_directory(folder);
|
fs::create_directory(folder);
|
||||||
}
|
}
|
||||||
@@ -31,51 +28,53 @@ path EnginePaths::getScreenshotFile(string ext) {
|
|||||||
const char* format = "%Y-%m-%d_%H-%M-%S";
|
const char* format = "%Y-%m-%d_%H-%M-%S";
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::put_time(&tm, format);
|
ss << std::put_time(&tm, format);
|
||||||
string datetimestr = ss.str();
|
std::string datetimestr = ss.str();
|
||||||
|
|
||||||
path filename = folder/path("screenshot-"+datetimestr+"."+ext);
|
fs::path filename = folder/fs::path("screenshot-"+datetimestr+"."+ext);
|
||||||
uint index = 0;
|
uint index = 0;
|
||||||
while (fs::exists(filename)) {
|
while (fs::exists(filename)) {
|
||||||
filename = folder/path("screenshot-"+datetimestr+"-"+std::to_string(index)+"."+ext);
|
filename = folder/fs::path("screenshot-"+datetimestr+"-"+std::to_string(index)+"."+ext);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
path EnginePaths::getWorldsFolder() {
|
fs::path EnginePaths::getWorldsFolder() {
|
||||||
return userfiles/path("worlds");
|
return userfiles/fs::path("worlds");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EnginePaths::isWorldNameUsed(string name) {
|
bool EnginePaths::isWorldNameUsed(std::string name) {
|
||||||
return fs::exists(EnginePaths::getWorldsFolder()/fs::u8path(name));
|
return fs::exists(EnginePaths::getWorldsFolder()/fs::u8path(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnginePaths::setUserfiles(path folder) {
|
void EnginePaths::setUserfiles(fs::path folder) {
|
||||||
this->userfiles = folder;
|
this->userfiles = folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnginePaths::setResources(path folder) {
|
void EnginePaths::setResources(fs::path folder) {
|
||||||
this->resources = folder;
|
this->resources = folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResPaths::ResPaths(path mainRoot, vector<path> roots)
|
ResPaths::ResPaths(fs::path mainRoot, std::vector<fs::path> roots)
|
||||||
: mainRoot(mainRoot), roots(roots) {
|
: mainRoot(mainRoot), roots(roots) {
|
||||||
}
|
}
|
||||||
|
|
||||||
path ResPaths::find(const string& filename) const {
|
fs::path ResPaths::find(const std::string& filename) const {
|
||||||
for (auto& root : roots) {
|
for (int i = roots.size()-1; i >= 0; i--) {
|
||||||
path file = root / path(filename);
|
auto& root = roots[i];
|
||||||
|
fs::path file = root / fs::path(filename);
|
||||||
if (fs::exists(file)) {
|
if (fs::exists(file)) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mainRoot / path(filename);
|
return mainRoot / fs::path(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<path> ResPaths::listdir(const string& folderName) const {
|
std::vector<fs::path> ResPaths::listdir(const std::string& folderName) const {
|
||||||
vector<path> entries;
|
std::vector<fs::path> entries;
|
||||||
for (auto& root : roots) {
|
for (int i = roots.size()-1; i >= 0; i--) {
|
||||||
path folder = root / path(folderName);
|
auto& root = roots[i];
|
||||||
|
fs::path folder = root / fs::path(folderName);
|
||||||
if (!fs::is_directory(folder))
|
if (!fs::is_directory(folder))
|
||||||
continue;
|
continue;
|
||||||
for (const auto& entry : fs::directory_iterator(folder)) {
|
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||||
@@ -83,7 +82,7 @@ vector<path> ResPaths::listdir(const string& folderName) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
path folder = mainRoot / path(folderName);
|
fs::path folder = mainRoot / fs::path(folderName);
|
||||||
if (!fs::is_directory(folder))
|
if (!fs::is_directory(folder))
|
||||||
return entries;
|
return entries;
|
||||||
for (const auto& entry : fs::directory_iterator(folder)) {
|
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ void create_new_world_panel(Engine* engine, PagesControl* menu) {
|
|||||||
|
|
||||||
// Basic validation
|
// Basic validation
|
||||||
if (!util::is_valid_filename(name) ||
|
if (!util::is_valid_filename(name) ||
|
||||||
paths->isWorldNameUsed(nameutf8)) {
|
paths->isWorldNameUsed(nameutf8)) {
|
||||||
// blink red two times
|
// blink red two times
|
||||||
panel->listenInterval(0.1f, [worldNameInput, basecolor]() {
|
panel->listenInterval(0.1f, [worldNameInput, basecolor]() {
|
||||||
static bool flag = true;
|
static bool flag = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user