* Add options.txt saving and loading to SDL target.

This commit is contained in:
iProgramInCpp
2023-08-25 19:58:18 +03:00
parent 5985e0d83b
commit cbe1853144
2 changed files with 58 additions and 0 deletions

View File

@@ -284,3 +284,58 @@ Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
LogMsg("Couldn't find file: %s", path.c_str());
return out;
}
#ifndef __EMSCRIPTEN__
std::vector<std::string> AppPlatform_windows::getOptionStrings()
{
std::vector<std::string> o;
std::ifstream ifs(_storageDir + "/options.txt");
if (!ifs.is_open())
{
LogMsg("Warning, options.txt doesn't exist, resetting to defaults");
return o;
}
std::string str;
while (true)
{
if (!std::getline(ifs, str, '\n'))
break;
if (str.empty() || str[0] == '#')
continue;
std::stringstream ss;
ss << str;
std::string key, value;
if (std::getline(ss, key, ':') && std::getline(ss, value))
{
o.push_back(key);
o.push_back(value);
}
}
return o;
}
void AppPlatform_sdl::setOptionStrings(const std::vector<std::string>& str)
{
assert(str.size() % 2 == 0);
std::ofstream os(_storageDir + "/options.txt");
if (!ifs.is_open())
{
LogMsg("Error, options.txt can't be opened");
return;
}
os << "#Config file for Minecraft PE. The # at the start denotes a comment, removing it makes it a command.\n\n";
for (int i = 0; i < int(str.size()); i += 2)
os << str[i] << ':' << str[i + 1] << '\n';
}
#endif

View File

@@ -11,6 +11,9 @@ public:
void saveScreenshot(const std::string& fileName, int width, int height) override;
Texture loadTexture(const std::string& path, bool b = false) override;
std::vector<std::string> getOptionStrings() override;
void setOptionStrings(const std::vector<std::string>& str) override;
protected:
void ensureDirectoryExists(const char* path) override;
};