LevelSettingsLayer string ids

This commit is contained in:
camila314 2022-12-12 13:32:44 -06:00
parent c8e7ce0b18
commit 98bae53959
12 changed files with 299 additions and 166 deletions

View file

@ -3864,6 +3864,7 @@ class CustomSongLayerDelegate {
class LevelSettingsLayer : FLAlertLayer, ColorSelectDelegate, SelectArtDelegate, FLAlertLayerProtocol, CustomSongLayerDelegate {
static LevelSettingsLayer* create(LevelSettingsObject* levelSettings, LevelEditorLayer* editor) = win 0x170d90;
bool init(LevelSettingsObject* levelSettings, LevelEditorLayer* editor) = mac 0xa7e00, win 0x170e50;
PAD = mac 0x50;
LevelSettingsObject* m_settingsObject;
}

View file

@ -4,6 +4,6 @@
GEODE_API void GEODE_CALL geode_implicit_load(geode::Mod* m) {
geode::Mod::setSharedMod(m);
geode::log::releaseSchedules(m);
geode::log::Logger::runScheduled(m);
geode::Loader::get()->dispatchScheduledFunctions(m);
}

View file

@ -118,7 +118,8 @@ target_include_directories(${PROJECT_NAME} PRIVATE
)
# For profiling
set_property(TARGET ${PROJECT_NAME} PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
target_compile_options(${PROJECT_NAME} PUBLIC "-ftime-trace")
#set_property(TARGET ${PROJECT_NAME} PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
target_compile_definitions(${PROJECT_NAME} PUBLIC GEODE_EXPORTING)

View file

@ -3,11 +3,13 @@
#include "Types.hpp"
#include <Geode/DefaultInclude.hpp>
#include <Geode/utils/ranges.hpp>
#include <ccTypes.h>
#include <chrono>
#include <fs/filesystem.hpp>
#include <sstream>
#include <vector>
#include <span>
#ifndef __cpp_lib_concepts
namespace std {
@ -27,25 +29,26 @@ namespace geode {
namespace log {
using log_clock = std::chrono::system_clock;
GEODE_DLL std::string generateLogName();
// Parse overloads
GEODE_DLL std::string parse(cocos2d::CCArray*);
GEODE_DLL std::string parse(cocos2d::ccColor3B const&);
GEODE_DLL std::string parse(cocos2d::ccColor4B const&);
GEODE_DLL std::string parse(cocos2d::ccColor4F const&);
GEODE_DLL std::string parse(cocos2d::CCNode*);
GEODE_DLL std::string parse(cocos2d::CCObject*);
GEODE_DLL std::string parse(cocos2d::CCPoint const&);
GEODE_DLL std::string parse(cocos2d::CCRect const&);
GEODE_DLL std::string parse(cocos2d::CCSize const&);
GEODE_DLL std::string parse(Mod*);
template <class T>
requires std::convertible_to<T*, cocos2d::CCNode*>
std::string parse(T* node) {
return parse(static_cast<cocos2d::CCNode*>(node));
}
GEODE_DLL std::string parse(cocos2d::CCPoint const&);
GEODE_DLL std::string parse(cocos2d::CCSize const&);
GEODE_DLL std::string parse(cocos2d::CCRect const&);
GEODE_DLL std::string parse(cocos2d::CCArray*);
GEODE_DLL std::string parse(cocos2d::ccColor3B const&);
GEODE_DLL std::string parse(cocos2d::ccColor4B const&);
GEODE_DLL std::string parse(cocos2d::ccColor4F const&);
GEODE_DLL std::string parse(cocos2d::CCObject*);
template <class T>
requires(
std::convertible_to<T*, cocos2d::CCObject*> &&
@ -55,8 +58,6 @@ namespace geode {
return parse(static_cast<cocos2d::CCObject*>(node));
}
GEODE_DLL std::string parse(Mod*);
template <typename T>
requires requires(T b) {
std::stringstream() << b;
@ -67,6 +68,8 @@ namespace geode {
return buf.str();
}
// Log component system
struct GEODE_DLL ComponentTrait {
virtual ~ComponentTrait() {}
@ -87,26 +90,17 @@ namespace geode {
}
};
/*template <typename T> requires requires(T b) { std::stringstream() << b; }
struct Component<T> : ComponentBase<T> {
inline static std::string toString(T const& thing) {
std::stringstream buf;
buf << thing;
return buf.str();
}
};*/
// Log
class GEODE_DLL Log final {
private:
static std::vector<std::function<void(Mod*)>>& scheduled();
protected:
Mod* m_sender;
log_clock::time_point m_time;
std::vector<ComponentTrait*> m_components;
Severity m_severity;
friend class Logger;
public:
~Log();
Log(Mod* mod, Severity sev);
Log(Log&& l) = default;
Log& operator=(Log&& l) = default;
@ -119,103 +113,86 @@ namespace geode {
Mod* getSender() const;
Severity getSeverity() const;
~Log();
template <typename... Args>
friend void schedule(Severity sev, Args... args);
friend void GEODE_DLL releaseSchedules(Mod* m);
void addFormat(std::string_view formatStr, std::span<ComponentTrait*> comps);
};
class GEODE_DLL Logs {
class GEODE_DLL Logger {
private:
static inline std::vector<Log> s_logs;
static inline std::ofstream s_logStream;
Logs() = delete;
~Logs() = delete;
Logger() = delete;
~Logger() = delete;
// Unscheduled logs
static void _push(Log&& log);
// Scheduled functions
template <class = void>
static inline std::vector<Log>& scheduled() {
static std::vector<Log> scheduledLogs;
return scheduledLogs;
}
static void run(Mod* m, std::vector<Log>& scheduled);
public:
static void setup();
static void push(Log&& log);
static void pop(Log* log);
static inline void push(Log&& log) {
if (log.m_sender == nullptr)
Logger::scheduled().push_back(std::move(log));
else
Logger::_push(std::move(log));
}
static inline void pop(Log* log) {
if (log->m_sender == nullptr)
geode::utils::ranges::remove(Logger::scheduled(), *log);
else
geode::utils::ranges::remove(Logger::s_logs, *log);
}
static std::vector<Log*> list();
static void clear();
};
void GEODE_DLL vlogImpl(
Severity, Mod*, std::string_view, std::function<void(Log&)>*, size_t
);
static inline void runScheduled(Mod* m) {
Logger::run(m, Logger::scheduled());
}
};
template <typename... Args>
requires requires(Args... b) {
(parse(b), ...);
}
void log(Severity severity, Mod* mod, std::string_view formatStr, Args... args) {
static constexpr auto pushSomething = [](Log& log, auto something) {
// i think this line of code is very sad
log.getComponents().push_back(new ComponentBase(something));
};
void internalLog(Severity sev, Mod* m, std::string_view formatStr, Args... args) {
Log l(m, sev);
std::array<std::function<void(Log&)>, sizeof...(Args)> comps = { [&](Log& log) {
pushSomething(log, args);
}... };
// tfw no std::span
vlogImpl(severity, mod, formatStr, comps.data(), comps.size());
}
std::array<ComponentTrait*, sizeof...(Args)> comps = { static_cast<ComponentTrait*>(new ComponentBase(args))... };
l.addFormat(formatStr, comps);
void GEODE_DLL releaseSchedules(Mod* m);
template <typename... Args>
void schedule(Severity sev, Args... args) {
auto m = getMod();
if (m) return log(sev, m, args...);
Log::scheduled().push_back([=](Mod* m2) {
log(sev, m2, args...);
});
Logger::push(std::move(l));
}
template <typename... Args>
void debug(Args... args) {
#ifdef GEODE_DEBUG
schedule(Severity::Debug, args...);
internalLog(Severity::Debug, getMod(), args...);
#endif
}
template <typename... Args>
void info(Args... args) {
schedule(Severity::Info, args...);
}
template <typename... Args>
void notice(Args... args) {
schedule(Severity::Notice, args...);
internalLog(Severity::Info, getMod(), args...);
}
template <typename... Args>
void warn(Args... args) {
schedule(Severity::Warning, args...);
internalLog(Severity::Warning, getMod(), args...);
}
template <typename... Args>
void error(Args... args) {
schedule(Severity::Error, args...);
}
template <typename... Args>
void critical(Args... args) {
schedule(Severity::Critical, args...);
}
template <typename... Args>
void alert(Args... args) {
schedule(Severity::Alert, args...);
}
template <typename... Args>
void emergency(Args... args) {
schedule(Severity::Emergency, args...);
internalLog(Severity::Error, getMod(), args...);
}
}
}

View file

@ -72,4 +72,4 @@ static CCMenu* detachAndCreateMenu(CCNode* parent, const char* menuID, Layout* l
(switchToMenu(args, newMenu), ...);
return newMenu;
}
}

View file

@ -0,0 +1,163 @@
#include <Geode/Modify.hpp>
#include <Geode/Bindings.hpp>
#include <Geode/utils/cocos.hpp>
#include "AddIDs.hpp"
USE_GEODE_NAMESPACE();
$register_ids(LevelSettingsLayer) {
if (auto menu = getChildOfType<CCMenu>(m_mainLayer, 0)) {
menu->setID("song-select-menu");
setIDs(menu, 0,
"bg-color-button",
"g-color-button",
"g2-color-button",
"line-color-button",
"obj-color-button",
"more-color-button",
"3dl-color-button",
"bg-quick-edit-button",
"g-quick-edit-button",
"g2-quick-edit-button",
"line-quick-edit-button",
"cube-button",
"ship-button",
"ball-button",
"ufo-button",
"wave-button",
"robot-button",
"spider-button",
"background-select-button",
"ground-select-button",
"mini-toggle",
"dual-toggle",
"font-button",
"ok-button",
"2-player-toggle",
"2-player-help-button",
"prev-song-button",
"next-song-button",
"normal-song-button",
"custom-song-button",
"select-custom-song-button",
"new-song-button",
"half-speed-button",
"normal-speed-button",
"2x-speed-button",
"3x-speed-button",
"4x-speed-button"
);
detachAndCreateMenu(
this,
"color-button-menu",
RowLayout::create(),
menu->getChildByID("bg-color-button"),
menu->getChildByID("g-color-button"),
menu->getChildByID("g2-color-button"),
menu->getChildByID("line-color-button"),
menu->getChildByID("obj-color-button"),
menu->getChildByID("3dl-color-button"),
menu->getChildByID("more-color-button")
);
detachAndCreateMenu(
this,
"color-quick-edit-menu",
RowLayout::create(),
menu->getChildByID("bg-quick-edit-button"),
menu->getChildByID("g-quick-edit-button"),
menu->getChildByID("g2-quick-edit-button"),
menu->getChildByID("line-quick-edit-button")
);
detachAndCreateMenu(
this,
"vehicle-selection-menu",
RowLayout::create(),
menu->getChildByID("cube-button"),
menu->getChildByID("ship-button"),
menu->getChildByID("ball-button"),
menu->getChildByID("ufo-button"),
menu->getChildByID("wave-button"),
menu->getChildByID("robot-button"),
menu->getChildByID("spider-button")
);
detachAndCreateMenu(
this,
"scenery-selection-menu",
ColumnLayout::create(),
menu->getChildByID("background-select-button"),
menu->getChildByID("ground-select-button")
);
detachAndCreateMenu(
this,
"right-toggle-menu",
ColumnLayout::create(),
menu->getChildByID("mini-toggle"),
menu->getChildByID("dual-toggle")
);
detachAndCreateMenu(
this,
"font-button-menu",
RowLayout::create()->setAlignment(Alignment::End),
menu->getChildByID("font-button")
);
detachAndCreateMenu(
this,
"2-player-menu",
ColumnLayout::create(),
menu->getChildByID("2-player-help-button"),
menu->getChildByID("2-player-toggle")
);
detachAndCreateMenu(
this,
"speed-selection-menu",
ColumnLayout::create(),
menu->getChildByID("half-speed-button"),
menu->getChildByID("normal-song-button"),
menu->getChildByID("2x-speed-button"),
menu->getChildByID("3x-speed-button"),
menu->getChildByID("4x-speed-button")
);
}
setIDs(m_mainLayer, 2,
"select-color-label",
"bg-color-label",
"g-color-label",
"g2-color-label",
"3dl-color-label",
"line-color-label",
"obj-color-label",
"more-color-label",
"select-mode-label",
"bg-selection-label",
"g-selection-label",
"mini-label",
"dual-label",
"2-player-label-1",
"2-player-label-2",
"select-song-label",
"default-song-label",
"custom-song-widget",
"speed-label"
);
}
class $modify(LevelSettingsLayer) {
bool init(LevelSettingsObject* levelSettings, LevelEditorLayer* editor) {
if (!LevelSettingsLayer::init(levelSettings, editor))
return false;
NodeIDs::get()->provide(this);
return true;
}
};

View file

@ -49,7 +49,7 @@ InternalMod::InternalMod() : Mod(getInternalModInfo()) {
auto sett = this->loadData();
if (!sett) {
log::log(Severity::Error, this, "{}", sett.unwrapErr());
log::internalLog(Severity::Error, this, "{}", sett.unwrapErr());
}
}

View file

@ -56,7 +56,7 @@ Result<> Loader::Impl::setup() {
return Ok();
}
log::Logs::setup();
log::Logger::setup();
if (crashlog::setupPlatformHandler()) {
log::debug("Set up platform crash logger");
@ -413,7 +413,7 @@ void Loader::Impl::reset() {
delete mod;
}
m_mods.clear();
log::Logs::clear();
log::Logger::clear();
ghc::filesystem::remove_all(dirs::getModRuntimeDir());
ghc::filesystem::remove_all(dirs::getTempDir());
}
@ -431,7 +431,7 @@ bool Loader::Impl::loadHooks() {
for (auto const& hook : m_internalHooks) {
auto res = hook.second->addHook(hook.first);
if (!res) {
log::log(Severity::Error, hook.second, "{}", res.unwrapErr());
log::internalLog(Severity::Error, hook.second, "{}", res.unwrapErr());
thereWereErrors = true;
}
}

View file

@ -13,17 +13,7 @@ USE_GEODE_NAMESPACE();
using namespace geode::log;
using namespace cocos2d;
std::vector<std::function<void(Mod*)>>& Log::scheduled() {
static std::vector<std::function<void(Mod*)>> ret;
return ret;
}
void log::releaseSchedules(Mod* m) {
for (auto& func : Log::scheduled()) {
func(m);
}
Log::scheduled().clear();
}
// Parse overloads
std::string log::parse(Mod* mod) {
if (mod) {
@ -95,8 +85,16 @@ std::string log::parse(cocos2d::ccColor4B const& col) {
return fmt::format("rgba({}, {}, {}, {})", col.r, col.g, col.b, col.a);
}
// Log
Log::Log(Mod* mod, Severity sev) : m_sender(mod), m_time(log_clock::now()), m_severity(sev) {}
Log::~Log() {
for (auto comp : m_components) {
delete comp;
}
}
bool Log::operator==(Log const& l) {
return this == &l;
}
@ -117,36 +115,6 @@ std::string Log::toString(bool logTime) const {
return res;
}
void Logs::setup() {
s_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName());
}
void Logs::push(Log&& log) {
std::string logStr = log.toString(true);
LoaderImpl::get()->logConsoleMessage(logStr);
s_logStream << logStr << std::endl;
s_logs.emplace_back(std::forward<Log>(log));
}
void Logs::pop(Log* log) {
ranges::remove(s_logs, *log);
}
std::vector<Log*> Logs::list() {
std::vector<Log*> logs;
logs.reserve(s_logs.size());
for (auto& log : s_logs) {
logs.push_back(&log);
}
return logs;
}
void Logs::clear() {
s_logs.clear();
}
std::vector<ComponentTrait*>& Log::getComponents() {
return m_components;
}
@ -163,26 +131,7 @@ Severity Log::getSeverity() const {
return m_severity;
}
Log::~Log() {
for (auto comp : m_components) {
delete comp;
}
}
std::string geode::log::generateLogName() {
return fmt::format("Geode {:%d %b %H.%M.%S}.log", log_clock::now());
}
void geode::log::vlogImpl(
Severity severity, Mod* mod, std::string_view formatStr, std::function<void(Log&)>* components,
size_t componentsSize
) {
Log log(mod, severity);
auto const pushSomething = [](Log& log, auto something) {
// i think this line of code is very sad
log.getComponents().push_back(new ComponentBase(something));
};
void Log::addFormat(std::string_view formatStr, std::span<ComponentTrait*> components) {
size_t compIndex = 0;
std::string current;
@ -197,10 +146,12 @@ void geode::log::vlogImpl(
continue;
}
if (next == '}') {
if (compIndex >= componentsSize)
if (compIndex >= components.size())
throw std::runtime_error("Not enough arguments for format string");
pushSomething(log, current);
components[compIndex++](log);
m_components.push_back(new ComponentBase(current));
m_components.push_back(components[compIndex++]);
current.clear();
++i;
continue;
@ -221,14 +172,54 @@ void geode::log::vlogImpl(
current.push_back(formatStr[i]);
}
if (!current.empty()) pushSomething(log, current);
if (!current.empty())
m_components.push_back(new ComponentBase(current));
if (compIndex != componentsSize) {
if (compIndex != components.size()) {
throw std::runtime_error("You have left over arguments.. silly head");
// show_silly_error(formatStr);
}
// (l.getComponents().push_back(new ComponentBase(args)), ...);
Logs::push(std::move(log));
}
// Logger
void Logger::setup() {
s_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName());
}
void Logger::_push(Log&& log) {
std::string logStr = log.toString(true);
LoaderImpl::get()->logConsoleMessage(logStr);
s_logStream << logStr << std::endl;
s_logs.emplace_back(std::forward<Log>(log));
}
std::vector<Log*> Logger::list() {
std::vector<Log*> logs;
logs.reserve(s_logs.size());
for (auto& log : s_logs) {
logs.push_back(&log);
}
return logs;
}
void Logger::clear() {
s_logs.clear();
}
void Logger::run(Mod* m, std::vector<Log>& scheduled) {
for (auto&& log : scheduled) {
log.m_sender = m;
Logger::_push(std::move(log));
}
scheduled.clear();
}
// Misc
std::string geode::log::generateLogName() {
return fmt::format("Geode {:%d %b %H.%M.%S}.log", log_clock::now());
}

View file

@ -125,7 +125,7 @@ Result<> Mod::loadData() {
return Err("Unable to load value for setting \"" + key + "\"");
}
else {
log::log(
log::internalLog(
Severity::Warning,
this,
"Encountered unknown setting \"{}\" while loading "

View file

@ -20,7 +20,7 @@ void Loader::Impl::platformMessageBox(char const* title, std::string const& info
void Loader::Impl::openPlatformConsole() {
m_platformConsoleOpen = true;
for (auto const& log : log::Logs::list()) {
for (auto const& log : log::Logger::list()) {
std::cout << log->toString(true) << "\n";
}
}

View file

@ -24,7 +24,7 @@ void Loader::Impl::openPlatformConsole() {
m_platformConsoleOpen = true;
for (auto const& log : log::Logs::list()) {
for (auto const& log : log::Logger::list()) {
std::cout << log->toString(true) << "\n";
}
}