Added fileCommon, added freebie font, start listening to SDL Keyboard text input

This commit is contained in:
2026-09-26 21:52:09 -05:00
parent 0c4be0ca87
commit b8d2270996
11 changed files with 312 additions and 194 deletions
+44
View File
@@ -0,0 +1,44 @@
#include "fileCommon.h"
#include "json.hpp"
bool OpenFile(fs::path path) {
path = fs::absolute(path);
if (!fs::exists(path)) {
printf("File Read error! Could not find file at: \n");
printf("%s\n", path.c_str());
return false;
}
stream.open(absolute(path));
if (!stream) {
printf("Error opening stream \n");
return false;
}
return true;
}
nlohmann::json GetData() {
if (!stream) {
printf("Open the file first! \n");
return nlohmann::json();
}
return nlohmann::json::parse(stream);
}
bool SaveJsonFile(fs::path path, nlohmann::json j) {
if (stream) {
printf("Stream open for reading! Please close stream before saving \n");
return false;
}
stream.open(absolute(path), std::fstream::in | std::fstream::out | std::fstream::app);
stream << std::setw(4) << j << std::endl;
stream.close();
}
+14
View File
@@ -0,0 +1,14 @@
#include <filesystem>
#include <fstream>
#include "json.hpp"
namespace fs = std::filesystem;
static std::fstream stream;
extern bool OpenFile(fs::path path);
extern nlohmann::json GetData();
/// Note we have a specific function for json for pretty printing purpose
bool SaveJsonFile(fs::path path, nlohmann::json j);
// bool SaveFile(fs::path path, void *dataToSave); // Leaving it commented out until later
inline void CloseFileStream() { stream.close(); }