mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 07:57:51 -05:00
edit is_jsons to be more detailed
This commit is contained in:
parent
d61112d870
commit
803df4faeb
2 changed files with 25 additions and 3 deletions
|
@ -240,7 +240,11 @@ struct matjson::Serialize<V> {
|
|||
}
|
||||
|
||||
static bool is_json(matjson::Value const& json) {
|
||||
return json.is_string();
|
||||
if (json.is_string()) {
|
||||
auto ver = V::parse(json.as_string());
|
||||
return !ver.isErr();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static V from_json(matjson::Value const& json) {
|
||||
|
|
|
@ -8,7 +8,16 @@
|
|||
using namespace geode::prelude;
|
||||
|
||||
bool matjson::Serialize<ccColor3B>::is_json(matjson::Value const& json) {
|
||||
return json.is_array() || json.is_object() || json.is_string();
|
||||
if (json.is_array()) {
|
||||
return json.as_array().size() == 3;
|
||||
}
|
||||
if (json.is_object()) {
|
||||
return json.contains("r") && json.contains("g") && json.contains("b");
|
||||
}
|
||||
if (json.is_string()) {
|
||||
return !cc3bFromHexString(json.as_string()).isErr();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
matjson::Value matjson::Serialize<ccColor3B>::to_json(ccColor3B const& color) {
|
||||
|
@ -54,7 +63,16 @@ ccColor3B matjson::Serialize<ccColor3B>::from_json(matjson::Value const& json) {
|
|||
}
|
||||
|
||||
bool matjson::Serialize<ccColor4B>::is_json(matjson::Value const& json) {
|
||||
return json.is_array() || json.is_object() || json.is_string();
|
||||
if (json.is_array()) {
|
||||
return json.as_array().size() == 4;
|
||||
}
|
||||
if (json.is_object()) {
|
||||
return json.contains("r") && json.contains("g") && json.contains("b") && json.contains("a");
|
||||
}
|
||||
if (json.is_string()) {
|
||||
return !cc4bFromHexString(json.as_string()).isErr();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
matjson::Value matjson::Serialize<ccColor4B>::to_json(ccColor4B const& color) {
|
||||
|
|
Loading…
Reference in a new issue