mirror of
https://github.com/geode-sdk/geode.git
synced 2025-04-24 05:14:40 -04:00
bring back ccobject* logging by wrapping code and downgrading to 10.0.0
This commit is contained in:
parent
1df146a516
commit
570a3b5904
3 changed files with 42 additions and 18 deletions
|
@ -81,7 +81,8 @@ if (PROJECT_IS_TOP_LEVEL AND NOT GEODE_BUILDING_DOCS)
|
|||
set(MAT_JSON_AS_INTERFACE ON)
|
||||
endif()
|
||||
CPMAddPackage("gh:geode-sdk/json#a47f570")
|
||||
CPMAddPackage("gh:fmtlib/fmt#10.1.1")
|
||||
# be careful before updating this! see Log.hpp
|
||||
CPMAddPackage("gh:fmtlib/fmt#10.0.0")
|
||||
CPMAddPackage("gh:gulrak/filesystem#3e5b930")
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} INTERFACE MAT_JSON_DYNAMIC=1)
|
||||
|
|
|
@ -9,12 +9,37 @@
|
|||
#include <chrono>
|
||||
#include <ghc/fs_fwd.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace geode {
|
||||
// these are here because theyre special :-)
|
||||
GEODE_DLL std::string format_as(cocos2d::CCObject const*);
|
||||
GEODE_DLL std::string format_as(cocos2d::CCArray*);
|
||||
GEODE_DLL std::string format_as(cocos2d::CCNode*);
|
||||
}
|
||||
|
||||
namespace geode::log::impl {
|
||||
// What is this all for? well, fmtlib disallows writing custom formatters for non-void pointer types.
|
||||
// So instead, we just wrap everything and pass it a string instead.
|
||||
// WARNING: This code breaks in fmtlib 10.1.1! I have no idea why, so be careful before updating it.
|
||||
|
||||
template <class T>
|
||||
GEODE_INLINE GEODE_HIDDEN decltype(auto) wrapCocosObj(T&& value) {
|
||||
if constexpr (std::is_convertible_v<T, const cocos2d::CCObject*>) {
|
||||
return geode::format_as(value);
|
||||
} else {
|
||||
return std::forward<T>(value);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
using TransformType = decltype(wrapCocosObj<T>(std::declval<T>()));
|
||||
|
||||
template <class... Args>
|
||||
using FmtStr = fmt::format_string<TransformType<Args>...>;
|
||||
}
|
||||
|
||||
namespace cocos2d {
|
||||
// ive had enough, fmtlib wont let me do what i want
|
||||
// GEODE_DLL std::string format_as(cocos2d::CCObject*);
|
||||
// GEODE_DLL std::string format_as(cocos2d::CCArray*);
|
||||
// GEODE_DLL std::string format_as(cocos2d::CCNode*);
|
||||
GEODE_DLL std::string format_as(cocos2d::ccColor3B const&);
|
||||
GEODE_DLL std::string format_as(cocos2d::ccColor4B const&);
|
||||
GEODE_DLL std::string format_as(cocos2d::ccColor4F const&);
|
||||
|
@ -50,27 +75,27 @@ namespace geode {
|
|||
GEODE_DLL void vlogImpl(Severity, Mod*, fmt::string_view format, fmt::format_args args);
|
||||
|
||||
template <typename... Args>
|
||||
inline void logImpl(Severity severity, Mod* mod, fmt::format_string<Args...> str, Args&&... args) {
|
||||
vlogImpl(severity, mod, str, fmt::make_format_args(args...));
|
||||
inline void logImpl(Severity severity, Mod* mod, impl::FmtStr<Args...> str, Args&&... args) {
|
||||
vlogImpl(severity, mod, str, fmt::make_format_args(impl::wrapCocosObj(args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void debug(fmt::format_string<Args...> str, Args&&... args) {
|
||||
inline void debug(impl::FmtStr<Args...> str, Args&&... args) {
|
||||
logImpl(Severity::Debug, getMod(), str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void info(fmt::format_string<Args...> str, Args&&... args) {
|
||||
inline void info(impl::FmtStr<Args...> str, Args&&... args) {
|
||||
logImpl(Severity::Info, getMod(), str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void warn(fmt::format_string<Args...> str, Args&&... args) {
|
||||
inline void warn(impl::FmtStr<Args...> str, Args&&... args) {
|
||||
logImpl(Severity::Warning, getMod(), str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void error(fmt::format_string<Args...> str, Args&&... args) {
|
||||
inline void error(impl::FmtStr<Args...> str, Args&&... args) {
|
||||
logImpl(Severity::Error, getMod(), str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,24 +25,23 @@ std::string geode::format_as(Mod* mod) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::string cocos2d::format_as(CCObject* obj) {
|
||||
std::string geode::format_as(CCObject const* obj) {
|
||||
if (obj) {
|
||||
// TODO: try catch incase typeid fails
|
||||
return fmt::format("{{ {}, {} }}", typeid(*obj).name(), utils::intToHex(obj));
|
||||
return fmt::format("{{ {}, {} }}", typeid(*obj).name(), fmt::ptr(obj));
|
||||
}
|
||||
else {
|
||||
return "{ CCObject, null }";
|
||||
}
|
||||
}
|
||||
|
||||
std::string cocos2d::format_as(CCNode* obj) {
|
||||
std::string geode::format_as(CCNode* obj) {
|
||||
if (obj) {
|
||||
auto bb = obj->boundingBox();
|
||||
return fmt::format(
|
||||
"{{ {}, {}, ({}, {} | {} : {}) }}",
|
||||
typeid(*obj).name(),
|
||||
utils::intToHex(obj),
|
||||
fmt::ptr(obj),
|
||||
bb.origin.x,
|
||||
bb.origin.y,
|
||||
bb.size.width,
|
||||
|
@ -54,7 +53,7 @@ std::string cocos2d::format_as(CCNode* obj) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string cocos2d::format_as(CCArray* arr) {
|
||||
std::string geode::format_as(CCArray* arr) {
|
||||
std::string out = "[";
|
||||
|
||||
if (arr && arr->count()) {
|
||||
|
@ -67,7 +66,6 @@ std::string cocos2d::format_as(CCArray* arr) {
|
|||
|
||||
return out + "]";
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string cocos2d::format_as(CCPoint const& pt) {
|
||||
return fmt::format("{}, {}", pt.x, pt.y);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue