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 bin
loader/src/internal/about.hpp loader/src/internal/about.hpp
loader/resources/loader-mod.json
fods-catgirl-hideout.txt 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) set(PROJECT_VERSION_TYPE Alpha)
# Package info file for internal representation # 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) file(READ resources/about.md LOADER_ABOUT_MD)
configure_file(src/internal/about.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/internal/about.hpp) 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 # For profiling
set_property(TARGET ${PROJECT_NAME} PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time") 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 # Markdown support
add_subdirectory(md4c) add_subdirectory(md4c)

View file

@ -6,4 +6,4 @@
#include "loader/Mod.hpp" #include "loader/Mod.hpp"
#include "loader/Loader.hpp" #include "loader/Loader.hpp"
#include "loader/Interface.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 * @param func Function to run
*/ */
void queueInGDThread(std::function<void GEODE_CALL(void)> func); 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" "blanks/*.png"
] ]
} }
} }

View file

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

View file

@ -48,12 +48,12 @@ public:
void queueInGDThread(std::function<void GEODE_CALL(void)> func); void queueInGDThread(std::function<void GEODE_CALL(void)> func);
void executeGDThreadQueue(); void executeGDThreadQueue();
bool platformConsoleReady() const;
void queueConsoleMessage(LogPtr*); void queueConsoleMessage(LogPtr*);
bool platformConsoleReady() const;
void setupPlatformConsole(); void setupPlatformConsole();
void awaitPlatformConsole(); void awaitPlatformConsole();
void closePlatformConsole(); 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); friend int geodeEntry(void* platformData);
}; };

View file

@ -1,5 +1,6 @@
#include "InternalMod.hpp" #include "InternalMod.hpp"
#include "about.hpp" #include "about.hpp"
#include "InternalLoader.hpp"
static auto SUPPORT_INFO = R"MD( static auto SUPPORT_INFO = R"MD(
**Geode** is funded through your gracious <cy>**donations**</c>! **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"; )MD";
static ModInfo getInternalModInfo() { static ModInfo getInternalModInfo() {
ModInfo info; try {
auto json = ModJson::parse(LOADER_MOD_JSON);
info.m_id = "geode.loader"; auto infoRes = ModInfo::create(json);
info.m_name = "Geode"; if (infoRes.is_error()) {
info.m_developer = "Geode Team"; InternalLoader::platformMessageBox(
info.m_description = "The mod loader"; "Fatal Internal Error",
info.m_details = LOADER_ABOUT_MD; "Unable to parse loader mod.json: \"" + infoRes.error() + "\"\n"
info.m_version = LOADER_VERSION; "This is a fatal internal error in the loader, please "
info.m_supportInfo = SUPPORT_INFO; "contact Geode developers immediately!"
info.m_repository = "https://github.com/geode-sdk/geode"; );
info.m_supportsDisabling = false; exit(1);
info.m_spritesheets = { }
"geode.loader/LogoSheet", auto info = infoRes.value();
"geode.loader/APISheet", info.m_details = LOADER_ABOUT_MD;
"geode.loader/BlankSheet" info.m_supportInfo = SUPPORT_INFO;
}; info.m_supportsDisabling = false;
return info;
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() {} InternalMod::~InternalMod() {}

View file

@ -13,3 +13,4 @@ static constexpr geode::VersionInfo LOADER_VERSION = {
@PROJECT_VERSION_PATCH@ @PROJECT_VERSION_PATCH@
}; };
static constexpr const char* LOADER_VERSION_TYPE = "@PROJECT_VERSION_TYPE@"; 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() { Result<> Loader::saveSettings() {
auto json = nlohmann::json::object(); auto json = nlohmann::json::object();
// save mod enabled / disabled states
json["mods"] = nlohmann::json::object(); json["mods"] = nlohmann::json::object();
for (auto [id, mod] : m_mods) { for (auto [id, mod] : m_mods) {
if (mod->isUninstalled()) continue; if (mod->isUninstalled()) continue;
auto value = nlohmann::json::object(); auto value = nlohmann::json::object();
value["enabled"] = mod->m_enabled; 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["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); 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() { Result<> Loader::loadSettings() {
@ -204,6 +224,7 @@ Result<> Loader::loadSettings() {
return Ok(); return Ok();
} }
// read mods.json
auto read = utils::file::readString(path); auto read = utils::file::readString(path);
if (!read) { if (!read) {
return read; return read;
@ -355,13 +376,11 @@ Loader::~Loader() {
void Loader::pushLog(LogPtr* logptr) { void Loader::pushLog(LogPtr* logptr) {
m_logs.push_back(logptr); m_logs.push_back(logptr);
#ifdef GEODE_PLATFORM_CONSOLE
if (InternalLoader::get()->platformConsoleReady()) { if (InternalLoader::get()->platformConsoleReady()) {
std::cout << logptr->toString(true); std::cout << logptr->toString(true);
} else { } else {
InternalLoader::get()->queueConsoleMessage(logptr); InternalLoader::get()->queueConsoleMessage(logptr);
} }
#endif
m_logStream << logptr->toString(true) << std::endl; m_logStream << logptr->toString(true) << std::endl;
} }
@ -437,3 +456,16 @@ bool Loader::supportedModVersion(VersionInfo const& version) {
version >= s_supportedVersionMin && version >= s_supportedVersionMin &&
version <= s_supportedVersionMax; 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() { Log::~Log() {
this->flush(); this->flush();
#ifdef GEODE_PLATFORM_CONSOLE if (InternalLoader::get()->platformConsoleReady()) {
std::cout << std::endl; std::cout << std::endl;
#endif }
} }
Log& Log::operator<<(Severity::type s) { Log& Log::operator<<(Severity::type s) {

View file

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