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