#pragma once #include #include "general.hpp" #include "json.hpp" // support converting ccColor3B / ccColor4B to / from json namespace cocos2d { void GEODE_DLL to_json(nlohmann::json& json, cocos2d::ccColor3B const& color); void GEODE_DLL from_json(nlohmann::json const& json, cocos2d::ccColor3B& color); void GEODE_DLL to_json(nlohmann::json& json, cocos2d::ccColor4B const& color); void GEODE_DLL from_json(nlohmann::json const& json, cocos2d::ccColor4B& color); } namespace geode::cocos { inline void ccDrawColor4B(cocos2d::ccColor4B const& color) { cocos2d::ccDrawColor4B(color.r, color.g, color.b, color.a); } inline cocos2d::ccColor4B invert4B(cocos2d::ccColor4B const& color) { return { static_cast(255 - color.r), static_cast(255 - color.g), static_cast(255 - color.b), color.a }; } inline cocos2d::ccColor3B invert3B(cocos2d::ccColor3B const& color) { return { static_cast(255 - color.r), static_cast(255 - color.g), static_cast(255 - color.b) }; } inline cocos2d::ccColor3B lighten3B(cocos2d::ccColor3B const& color, int amount) { return { static_cast(utils::clamp(color.r + amount, 0, 255)), static_cast(utils::clamp(color.g + amount, 0, 255)), static_cast(utils::clamp(color.b + amount, 0, 255)), }; } inline cocos2d::ccColor3B darken3B(cocos2d::ccColor3B const& color, int amount) { return lighten3B(color, -amount); } inline cocos2d::ccColor3B to3B(cocos2d::ccColor4B const& color) { return { color.r, color.g, color.b }; } inline cocos2d::ccColor4B to4B(cocos2d::ccColor3B const& color, GLubyte alpha = 255) { return { color.r, color.g, color.b, alpha }; } inline cocos2d::ccColor4F to4F(cocos2d::ccColor4B const& color) { return { color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f }; } constexpr cocos2d::ccColor3B cc3x(int hexValue) { if (hexValue <= 0xf) return cocos2d::ccColor3B { static_cast(hexValue * 17), static_cast(hexValue * 17), static_cast(hexValue * 17) }; if (hexValue <= 0xff) return cocos2d::ccColor3B { static_cast(hexValue), static_cast(hexValue), static_cast(hexValue) }; if (hexValue <= 0xfff) return cocos2d::ccColor3B { static_cast((hexValue >> 8 & 0xf) * 17), static_cast((hexValue >> 4 & 0xf) * 17), static_cast((hexValue >> 0 & 0xf) * 17) }; else return cocos2d::ccColor3B { static_cast(hexValue >> 16 & 0xff), static_cast(hexValue >> 8 & 0xff), static_cast(hexValue >> 0 & 0xff) }; } GEODE_DLL Result cc3bFromHexString(std::string const& hexValue); GEODE_DLL Result cc4bFromHexString(std::string const& hexValue); GEODE_DLL std::string cc3bToHexString(cocos2d::ccColor3B const& color); GEODE_DLL std::string cc4bToHexString(cocos2d::ccColor4B const& color); template> > static cocos2d::CCArray* vectorToCCArray(std::vector const& vec) { auto res = cocos2d::CCArray::createWithCapacity(vec.size()); for (auto const& item : vec) res->addObject(item); return res; } template> > static cocos2d::CCArray* vectorToCCArray(std::vector const& vec, std::function convFunc) { auto res = cocos2d::CCArray::createWithCapacity(vec.size()); for (auto const& item : vec) res->addObject(convFunc(item)); return res; } template > > std::vector ccArrayToVector(cocos2d::CCArray* arr) { return std::vector(reinterpret_cast(arr->data->arr), reinterpret_cast(arr->data->arr) + arr->data->num); } template || std::is_same_v> > static cocos2d::CCDictionary* mapToCCDict(std::map const& map) { auto res = cocos2d::CCDictionary::create(); for (auto const& [key, value] : map) res->setObject(value, key); return res; } template || std::is_same_v> > static cocos2d::CCDictionary* mapToCCDict(std::map const& map, std::function convFunc) { auto res = cocos2d::CCDictionary::create(); for (auto const& [key, value] : map) res->setObject(value, convFunc(key)); return res; } // template || std::is_same_v> > // static std::map ccDictToMap(cocos2d::CCDictionary* dict) { // auto res = std::map(); // cocos2d::CCDictElement* element = nullptr; // CCDICT_FOREACH(dict, element) { // if constexpr (std::is_same_v) // res[element->getStrKey()] = element->getObject(); // if constexpr (std::is_same_v) // res[element->getIntKey()] = element->getObject(); // } // return res; // } }