#pragma once #include #include #include #include #include #include #include namespace Unvirt::Docstring { constexpr char8_t INVALID_ENUM_NAME[] = u8"[undefined]"; #pragma region Size Formatter std::u8string GetReadableFileSize(uint64_t _size); #pragma endregion #pragma region CKERROR CK_CLASSID Data std::u8string GetCkErrorName(LibCmo::CK2::CKERROR err); std::u8string GetCkErrorDescription(LibCmo::CK2::CKERROR err); std::u8string GetClassIdName(LibCmo::CK2::CK_CLASSID cls); std::u8string GetClassIdHierarchy(LibCmo::CK2::CK_CLASSID cls); #pragma endregion #pragma region Other Enums struct GenericReflection { const char8_t* mName; }; template requires std::is_enum_v using GenericReflectionArray = std::vector>; namespace Arrays { // clang-format off extern const GenericReflectionArray CK_FILE_WRITEMODE; extern const GenericReflectionArray CK_FO_OPTIONS; extern const GenericReflectionArray CK_STATECHUNK_CHUNKOPTIONS; extern const GenericReflectionArray CK_STATECHUNK_DATAVERSION; extern const GenericReflectionArray CK_STATECHUNK_CHUNKVERSION; extern const GenericReflectionArray CK_OBJECT_FLAGS; extern const GenericReflectionArray CK_3DENTITY_FLAGS; extern const GenericReflectionArray CK_TEXTURE_SAVEOPTIONS; extern const GenericReflectionArray CK_BITMAPDATA_FLAGS; extern const GenericReflectionArray CK_CAMERA_PROJECTION; extern const GenericReflectionArray VX_PIXELFORMAT; extern const GenericReflectionArray VXLIGHT_TYPE; extern const GenericReflectionArray VXTEXTURE_BLENDMODE; extern const GenericReflectionArray VXTEXTURE_FILTERMODE; extern const GenericReflectionArray VXBLEND_MODE; extern const GenericReflectionArray VXTEXTURE_ADDRESSMODE; extern const GenericReflectionArray VXFILL_MODE; extern const GenericReflectionArray VXSHADE_MODE; extern const GenericReflectionArray VXCMPFUNC; extern const GenericReflectionArray VX_EFFECT; extern const GenericReflectionArray VX_MOVEABLE_FLAGS; extern const GenericReflectionArray VXMESH_FLAGS; extern const GenericReflectionArray VXMESH_LITMODE; extern const GenericReflectionArray VXTEXTURE_WRAPMODE; // clang-format on } // namespace Arrays template requires std::is_enum_v const GenericReflectionArray& GetEnumReflectionArray() { if constexpr (std::is_same_v) { return Arrays::CK_FILE_WRITEMODE; } else if constexpr (std::is_same_v) { return Arrays::CK_FO_OPTIONS; } else if constexpr (std::is_same_v) { return Arrays::CK_STATECHUNK_CHUNKOPTIONS; } else if constexpr (std::is_same_v) { return Arrays::CK_STATECHUNK_DATAVERSION; } else if constexpr (std::is_same_v) { return Arrays::CK_STATECHUNK_CHUNKVERSION; } else if constexpr (std::is_same_v) { return Arrays::CK_OBJECT_FLAGS; } else if constexpr (std::is_same_v) { return Arrays::CK_3DENTITY_FLAGS; } else if constexpr (std::is_same_v) { return Arrays::CK_TEXTURE_SAVEOPTIONS; } else if constexpr (std::is_same_v) { return Arrays::CK_BITMAPDATA_FLAGS; } else if constexpr (std::is_same_v) { return Arrays::CK_CAMERA_PROJECTION; } else if constexpr (std::is_same_v) { return Arrays::VX_PIXELFORMAT; } else if constexpr (std::is_same_v) { return Arrays::VXLIGHT_TYPE; } else if constexpr (std::is_same_v) { return Arrays::VXTEXTURE_BLENDMODE; } else if constexpr (std::is_same_v) { return Arrays::VXTEXTURE_FILTERMODE; } else if constexpr (std::is_same_v) { return Arrays::VXBLEND_MODE; } else if constexpr (std::is_same_v) { return Arrays::VXTEXTURE_ADDRESSMODE; } else if constexpr (std::is_same_v) { return Arrays::VXFILL_MODE; } else if constexpr (std::is_same_v) { return Arrays::VXSHADE_MODE; } else if constexpr (std::is_same_v) { return Arrays::VXCMPFUNC; } else if constexpr (std::is_same_v) { return Arrays::VX_EFFECT; } else if constexpr (std::is_same_v) { return Arrays::VX_MOVEABLE_FLAGS; } else if constexpr (std::is_same_v) { return Arrays::VXMESH_FLAGS; } else if constexpr (std::is_same_v) { return Arrays::VXMESH_LITMODE; } else if constexpr (std::is_same_v) { return Arrays::VXTEXTURE_WRAPMODE; } else { static_assert(false, "Unknown enum type"); } } template requires std::is_enum_v std::u8string GetEnumName(T val) { std::u8string strl; for (auto& item : GetEnumReflectionArray()) { if (item.first == val) { strl = item.second.mName; return strl; } } strl = yycc::string::op::printf(u8"%s (0x%08" PRIXCKDWORD ")", INVALID_ENUM_NAME, static_cast(val)); return strl; } template requires std::is_enum_v std::u8string GetFlagEnumName(T val, const char8_t* splitor = u8" ", const char8_t* indent = u8"") { std::u8string strl, cache; for (auto& item : GetEnumReflectionArray()) { // if it have exacelt same entry, return directly if (item.first == val) { strl = yycc::string::op::printf(u8"%s (0x%08" PRIXCKDWORD ")", item.second.mName, static_cast(item.first)); return strl; } // check flag match if (yycc::cenum::has(val, item.first)) { // add splittor if it not the first entry if (strl.size() != 0u && splitor != nullptr) { strl += splitor; } // add indent if possible if (indent != nullptr) { strl += indent; } // add value self. cache = yycc::string::op::printf(u8"%s (0x%08" PRIXCKDWORD ")", item.second.mName, static_cast(item.first)); strl += cache; } } // if nothing was gotten. set to undefined if (strl.size() == 0u) { strl = yycc::string::op::printf(u8"%s (0x%08" PRIXCKDWORD ")", INVALID_ENUM_NAME, static_cast(val)); } return strl; } #pragma endregion } // namespace Unvirt::Docstring