move internal mod json data to an actual json file + move platform

console from a cmake arg to an in-game setting
This commit is contained in:
HJfod 2022-09-28 17:38:02 +03:00
parent 1297f93294
commit 5af74e9ab7
13 changed files with 161 additions and 66 deletions

2
.gitignore vendored
View file

@ -43,6 +43,6 @@ build
bin
loader/src/internal/about.hpp
loader/resources/loader-mod.json
fods-catgirl-hideout.txt

View file

@ -4,6 +4,8 @@ project(geode-loader VERSION 0.2.0 LANGUAGES C CXX)
set(PROJECT_VERSION_TYPE Alpha)
# Package info file for internal representation
configure_file(resources/loader-mod.json.in ${CMAKE_CURRENT_SOURCE_DIR}/resources/loader-mod.json)
file(READ resources/loader-mod.json LOADER_MOD_JSON)
file(READ resources/about.md LOADER_ABOUT_MD)
configure_file(src/internal/about.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/internal/about.hpp)
@ -106,7 +108,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
# For profiling
set_property(TARGET ${PROJECT_NAME} PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
target_compile_definitions(${PROJECT_NAME} PUBLIC GEODE_EXPORTING GEODE_PLATFORM_CONSOLE)
target_compile_definitions(${PROJECT_NAME} PUBLIC GEODE_EXPORTING)
# Markdown support
add_subdirectory(md4c)

View file

@ -6,4 +6,4 @@
#include "loader/Mod.hpp"
#include "loader/Loader.hpp"
#include "loader/Interface.hpp"
// #include "loader/Setting.hpp"
#include "loader/Setting.hpp"

View file

@ -248,5 +248,14 @@ namespace geode {
* @param func Function to run
*/
void queueInGDThread(std::function<void GEODE_CALL(void)> func);
/**
* Open the platform-specific external console (if one exists)
*/
static void openPlatformConsole();
/**
* Close the platform-specific external console (if one exists)
*/
static void closePlatfromConsole();
};
}

View file

@ -0,0 +1,56 @@
{
"geode": "v@PROJECT_VERSION@",
"id": "geode.loader",
"version": "v@PROJECT_VERSION@",
"name": "Geode",
"developer": "Geode Team",
"description": "The Geode mod loader",
"repository": "https://github.com/geode-sdk/geode",
"resources": {
"fonts": {
"mdFont": {
"path": "fonts/Ubuntu-Regular.ttf",
"size": 80
},
"mdFontB": {
"path": "fonts/Ubuntu-Bold.ttf",
"size": 80
},
"mdFontI": {
"path": "fonts/Ubuntu-Italic.ttf",
"size": 80
},
"mdFontBI": {
"path": "fonts/Ubuntu-BoldItalic.ttf",
"size": 80
},
"mdFontMono": {
"path": "fonts/UbuntuMono-Regular.ttf",
"size": 80
}
},
"files": [
"images/*.png",
"sounds/*.ogg"
],
"spritesheets": {
"LogoSheet": [
"logos/*.png"
],
"APISheet": [
"*.png"
],
"BlankSheet": [
"blanks/*.png"
]
}
},
"settings": {
"show-platform-console": {
"type": "bool",
"default": false,
"name": "Show Platform Console",
"description": "Show the native console (if one exists). <cr>This setting is meant for developers</c>."
}
}
}

View file

@ -36,4 +36,4 @@
"blanks/*.png"
]
}
}
}

View file

@ -9,16 +9,10 @@
#include <Geode/Geode.hpp>
#include <thread>
InternalLoader::InternalLoader() : Loader() {
#ifdef GEODE_PLATFORM_CONSOLE
this->setupPlatformConsole();
#endif
}
InternalLoader::InternalLoader() : Loader() {}
InternalLoader::~InternalLoader() {
#ifdef GEODE_PLATFORM_CONSOLE
this->closePlatformConsole();
#endif
}
InternalLoader* InternalLoader::get() {
@ -87,8 +81,8 @@ void InternalLoader::loadInfoAlerts(nlohmann::json& json) {
}
#if defined(GEODE_IS_WINDOWS)
void InternalLoader::platformMessageBox(const char* title, const char* info) {
MessageBoxA(nullptr, title, info, MB_OK);
void InternalLoader::platformMessageBox(const char* title, std::string const& info) {
MessageBoxA(nullptr, info.c_str(), title, MB_ICONERROR);
}
void InternalLoader::setupPlatformConsole() {
@ -104,9 +98,9 @@ void InternalLoader::setupPlatformConsole() {
void InternalLoader::awaitPlatformConsole() {
if (!m_platformConsoleReady) return;
for (auto const& log : this->m_logQueue) {
for (auto const& log : m_logQueue) {
std::cout << log->toString(true) << "\n";
this->m_logQueue.clear();
m_logQueue.clear();
}
std::string inp;
@ -118,7 +112,7 @@ void InternalLoader::awaitPlatformConsole() {
while (ss >> inpa) args.push_back(inpa);
ss.clear();
if (inp != "e") this->awaitPlatformConsole();
this->awaitPlatformConsole();
}
void InternalLoader::closePlatformConsole() {
@ -132,7 +126,7 @@ void InternalLoader::closePlatformConsole() {
#elif defined(GEODE_IS_MACOS)
#include <iostream>
void InternalLoader::platformMessageBox(const char* title, const char* info) {
void InternalLoader::platformMessageBox(const char* title, std::string const& info) {
std::cout << title << ": " << info << std::endl;
}
@ -141,7 +135,6 @@ void InternalLoader::setupPlatformConsole() {
}
void InternalLoader::awaitPlatformConsole() {
}
void InternalLoader::closePlatformConsole() {
@ -153,7 +146,7 @@ void InternalLoader::closePlatformConsole() {
#include <sys/types.h>
#include <pwd.h>
void InternalLoader::platformMessageBox(const char* title, const char* info) {
void InternalLoader::platformMessageBox(const char* title, std::string const& info) {
std::cout << title << ": " << info << std::endl;
}

View file

@ -48,12 +48,12 @@ public:
void queueInGDThread(std::function<void GEODE_CALL(void)> func);
void executeGDThreadQueue();
bool platformConsoleReady() const;
void queueConsoleMessage(LogPtr*);
bool platformConsoleReady() const;
void setupPlatformConsole();
void awaitPlatformConsole();
void closePlatformConsole();
static void platformMessageBox(const char* title, const char* info);
static void platformMessageBox(const char* title, std::string const& info);
friend int geodeEntry(void* platformData);
};

View file

@ -1,5 +1,6 @@
#include "InternalMod.hpp"
#include "about.hpp"
#include "InternalLoader.hpp"
static auto SUPPORT_INFO = R"MD(
**Geode** is funded through your gracious <cy>**donations**</c>!
@ -7,27 +8,40 @@ You can support our work by sending <cp>**catgirl pictures**</c> to [HJfod](user
)MD";
static ModInfo getInternalModInfo() {
ModInfo info;
info.m_id = "geode.loader";
info.m_name = "Geode";
info.m_developer = "Geode Team";
info.m_description = "The mod loader";
info.m_details = LOADER_ABOUT_MD;
info.m_version = LOADER_VERSION;
info.m_supportInfo = SUPPORT_INFO;
info.m_repository = "https://github.com/geode-sdk/geode";
info.m_supportsDisabling = false;
info.m_spritesheets = {
"geode.loader/LogoSheet",
"geode.loader/APISheet",
"geode.loader/BlankSheet"
};
return info;
try {
auto json = ModJson::parse(LOADER_MOD_JSON);
auto infoRes = ModInfo::create(json);
if (infoRes.is_error()) {
InternalLoader::platformMessageBox(
"Fatal Internal Error",
"Unable to parse loader mod.json: \"" + infoRes.error() + "\"\n"
"This is a fatal internal error in the loader, please "
"contact Geode developers immediately!"
);
exit(1);
}
auto info = infoRes.value();
info.m_details = LOADER_ABOUT_MD;
info.m_supportInfo = SUPPORT_INFO;
info.m_supportsDisabling = false;
return info;
} catch(std::exception& e) {
InternalLoader::platformMessageBox(
"Fatal Internal Error",
"Unable to parse loader mod.json: \"" + std::string(e.what()) + "\"\n"
"This is a fatal internal error in the loader, please "
"contact Geode developers immediately!"
);
exit(1);
}
}
InternalMod::InternalMod() : Mod(getInternalModInfo()) {}
InternalMod::InternalMod() : Mod(getInternalModInfo()) {
auto sett = this->loadSettings();
if (!sett) {
this->logInfo(sett.error(), Severity::Error);
}
}
InternalMod::~InternalMod() {}

View file

@ -13,3 +13,4 @@ static constexpr geode::VersionInfo LOADER_VERSION = {
@PROJECT_VERSION_PATCH@
};
static constexpr const char* LOADER_VERSION_TYPE = "@PROJECT_VERSION_TYPE@";
static constexpr const char* LOADER_MOD_JSON = R"JSON_SEPARATOR(@LOADER_MOD_JSON@)JSON_SEPARATOR";

View file

@ -183,19 +183,39 @@ size_t Loader::refreshMods() {
Result<> Loader::saveSettings() {
auto json = nlohmann::json::object();
// save mod enabled / disabled states
json["mods"] = nlohmann::json::object();
for (auto [id, mod] : m_mods) {
if (mod->isUninstalled()) continue;
auto value = nlohmann::json::object();
value["enabled"] = mod->m_enabled;
mod->saveSettings();
// save mod's settings
auto saveSett = mod->saveSettings();
if (!saveSett) {
return Err(saveSett.error());
}
json["mods"][id] = value;
}
json["succesfully-closed"] = true;
// save loader settings
auto saveIS = InternalMod::get()->saveSettings();
if (!saveIS) {
return Err(saveIS.error());
}
// save info alerts
InternalLoader::get()->saveInfoAlerts(json);
auto path = this->getGeodeSaveDirectory() / "mods.json";
return utils::file::writeString(path, json.dump(4));
// mark the game as not having crashed
json["succesfully-closed"] = true;
return utils::file::writeString(
this->getGeodeSaveDirectory() / "mods.json",
json.dump(4)
);
}
Result<> Loader::loadSettings() {
@ -204,6 +224,7 @@ Result<> Loader::loadSettings() {
return Ok();
}
// read mods.json
auto read = utils::file::readString(path);
if (!read) {
return read;
@ -355,13 +376,11 @@ Loader::~Loader() {
void Loader::pushLog(LogPtr* logptr) {
m_logs.push_back(logptr);
#ifdef GEODE_PLATFORM_CONSOLE
if (InternalLoader::get()->platformConsoleReady()) {
std::cout << logptr->toString(true);
} else {
InternalLoader::get()->queueConsoleMessage(logptr);
}
#endif
m_logStream << logptr->toString(true) << std::endl;
}
@ -437,3 +456,16 @@ bool Loader::supportedModVersion(VersionInfo const& version) {
version >= s_supportedVersionMin &&
version <= s_supportedVersionMax;
}
void Loader::openPlatformConsole() {
if (!InternalLoader::get()->platformConsoleReady()) {
InternalLoader::get()->setupPlatformConsole();
std::thread([]() {
InternalLoader::get()->awaitPlatformConsole();
}).detach();
}
}
void Loader::closePlatfromConsole() {
InternalLoader::get()->closePlatformConsole();
}

View file

@ -136,9 +136,9 @@ void Log::flush() {
Log::~Log() {
this->flush();
#ifdef GEODE_PLATFORM_CONSOLE
std::cout << std::endl;
#endif
if (InternalLoader::get()->platformConsoleReady()) {
std::cout << std::endl;
}
}
Log& Log::operator<<(Severity::type s) {

View file

@ -106,23 +106,11 @@ int geodeEntry(void* platformData) {
InternalMod::get()->log()
<< Severity::Debug
<< "Set up loader";
// debugging console
#ifdef GEODE_PLATFORM_CONSOLE
InternalMod::get()->log()
<< Severity::Debug
<< "Loading Console...";
InternalLoader::get()->setupPlatformConsole();
InternalLoader::get()->awaitPlatformConsole();
InternalLoader::get()->closePlatformConsole();
InternalMod::get()->log()
<< Severity::Debug
<< "Cleaning up...";
//delete InternalLoader::get();
#endif
if (InternalMod::get()->getSettingValue<bool>("show-platform-console")) {
InternalLoader::get()->setupPlatformConsole();
InternalLoader::get()->awaitPlatformConsole();
}
InternalMod::get()->log()
<< Severity::Debug