make attributes use json::Value instead of std::any

This commit is contained in:
hjfod 2023-03-29 15:23:57 +03:00
parent 38575ac825
commit 7963469f1e
4 changed files with 9 additions and 9 deletions

View file

@ -146,7 +146,7 @@ endif()
add_library(GeodeCodegenSources ${GEODE_CODEGEN_PATH}/Geode/GeneratedSource.cpp ${GEODE_CODEGEN_PATH}/Geode/GeneratedAddress.cpp)
target_link_directories(GeodeCodegenSources PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/loader/include/link)
target_link_libraries(GeodeCodegenSources PRIVATE ghc_filesystem GeodeFilesystemImpl fmt TulipHookInclude)
target_link_libraries(GeodeCodegenSources PRIVATE ghc_filesystem GeodeFilesystemImpl fmt TulipHookInclude mat-json)
target_include_directories(GeodeCodegenSources PRIVATE
${GEODE_CODEGEN_PATH}
${GEODE_LOADER_PATH}/include

View file

@ -38,8 +38,8 @@
#include "../script_support/CCScriptSupport.h"
#include "../include/CCProtocols.h"
#include "Layout.hpp"
#include <any>
#include "../../loader/Event.hpp"
#include <json.hpp>
NS_CC_BEGIN
@ -851,7 +851,7 @@ private:
friend class geode::modifier::FieldContainer;
GEODE_DLL geode::modifier::FieldContainer* getFieldContainer();
GEODE_DLL std::optional<std::any> getAttributeInternal(std::string const& attribute);
GEODE_DLL std::optional<json::Value> getAttributeInternal(std::string const& attribute);
GEODE_DLL void addEventListenerInternal(geode::EventListenerProtocol* protocol);
public:
@ -931,7 +931,7 @@ public:
* @param value The value of the attribute
* @note Geode addition
*/
GEODE_DLL void setAttribute(std::string const& attribute, std::any value);
GEODE_DLL void setAttribute(std::string const& attribute, json::Value const& value);
/**
* Get an attribute from the node. Attributes may be anything
* @param attribute The attribute key
@ -943,7 +943,7 @@ public:
std::optional<T> getAttribute(std::string const& attribute) {
if (auto value = this->getAttributeInternal(attribute)) {
try {
return std::any_cast<T>(value.value());
return value.value().template as<T>();
} catch(...) {
return std::nullopt;
}

View file

@ -21,7 +21,7 @@ private:
std::string m_id = "";
Ref<Layout> m_layout = nullptr;
std::unique_ptr<LayoutOptions> m_layoutOptions = nullptr;
std::unordered_map<std::string, std::any> m_attributes;
std::unordered_map<std::string, json::Value> m_attributes;
std::vector<EventListenerProtocol*> m_eventListeners;
friend class ProxyCCNode;
@ -169,11 +169,11 @@ void CCNode::updateLayout(bool updateChildOrder) {
}
}
void CCNode::setAttribute(std::string const& attr, std::any value) {
void CCNode::setAttribute(std::string const& attr, json::Value const& value) {
GeodeNodeMetadata::set(this)->m_attributes[attr] = value;
}
std::optional<std::any> CCNode::getAttributeInternal(std::string const& attr) {
std::optional<json::Value> CCNode::getAttributeInternal(std::string const& attr) {
auto meta = GeodeNodeMetadata::set(this);
if (meta->m_attributes.count(attr)) {
return meta->m_attributes.at(attr);

View file

@ -17,6 +17,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE
target_compile_definitions(${PROJECT_NAME} PRIVATE -DGEODE_DONT_WARN_INCORRECT_MEMBERS)
target_link_libraries(${PROJECT_NAME} PRIVATE ghc_filesystem)
target_link_libraries(${PROJECT_NAME} PRIVATE ghc_filesystem mat-json)
add_dependencies(${PROJECT_NAME} CodegenRun)