Fix serializing variants into binary files.

This commit is contained in:
Relintai 2022-08-09 15:50:30 +02:00
parent 3a8ffc6df3
commit 5cd0ea7e60

View File

@ -1350,6 +1350,13 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_real(val.x); f->store_real(val.x);
f->store_real(val.y); f->store_real(val.y);
} break;
case Variant::VECTOR2I: {
f->store_32(VARIANT_VECTOR2I);
Vector2i val = p_property;
f->store_32(val.x);
f->store_32(val.y);
} break; } break;
case Variant::RECT2: { case Variant::RECT2: {
f->store_32(VARIANT_RECT2); f->store_32(VARIANT_RECT2);
@ -1359,6 +1366,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_real(val.size.x); f->store_real(val.size.x);
f->store_real(val.size.y); f->store_real(val.size.y);
} break;
case Variant::RECT2I: {
f->store_32(VARIANT_RECT2I);
Rect2i val = p_property;
f->store_32(val.position.x);
f->store_32(val.position.y);
f->store_32(val.size.x);
f->store_32(val.size.y);
} break; } break;
case Variant::VECTOR3: { case Variant::VECTOR3: {
f->store_32(VARIANT_VECTOR3); f->store_32(VARIANT_VECTOR3);
@ -1368,6 +1384,26 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_real(val.z); f->store_real(val.z);
} break; } break;
case Variant::VECTOR3I: {
f->store_32(VARIANT_VECTOR3I);
Vector3i val = p_property;
f->store_32(val.x);
f->store_32(val.y);
f->store_32(val.z);
} break;
case Variant::TRANSFORM2D: {
f->store_32(VARIANT_MATRIX32);
Transform2D val = p_property;
f->store_real(val.elements[0].x);
f->store_real(val.elements[0].y);
f->store_real(val.elements[1].x);
f->store_real(val.elements[1].y);
f->store_real(val.elements[2].x);
f->store_real(val.elements[2].y);
} break;
case Variant::PLANE: { case Variant::PLANE: {
f->store_32(VARIANT_PLANE); f->store_32(VARIANT_PLANE);
Plane val = p_property; Plane val = p_property;
@ -1396,17 +1432,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_real(val.size.y); f->store_real(val.size.y);
f->store_real(val.size.z); f->store_real(val.size.z);
} break;
case Variant::TRANSFORM2D: {
f->store_32(VARIANT_MATRIX32);
Transform2D val = p_property;
f->store_real(val.elements[0].x);
f->store_real(val.elements[0].y);
f->store_real(val.elements[1].x);
f->store_real(val.elements[1].y);
f->store_real(val.elements[2].x);
f->store_real(val.elements[2].y);
} break; } break;
case Variant::BASIS: { case Variant::BASIS: {
f->store_32(VARIANT_MATRIX3); f->store_32(VARIANT_MATRIX3);
@ -1422,6 +1447,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_real(val.elements[2].z); f->store_real(val.elements[2].z);
} break; } break;
case Variant::TRANSFORM: { case Variant::TRANSFORM: {
f->store_32(VARIANT_TRANSFORM); f->store_32(VARIANT_TRANSFORM);
Transform val = p_property; Transform val = p_property;
@ -1502,6 +1528,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
//internal resource //internal resource
} }
} break;
case Variant::STRING_NAME: {
f->store_32(VARIANT_STRING_NAME);
String val = p_property;
save_unicode_string(f, val);
} break; } break;
case Variant::DICTIONARY: { case Variant::DICTIONARY: {
f->store_32(VARIANT_DICTIONARY); f->store_32(VARIANT_DICTIONARY);
@ -1573,6 +1605,30 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
save_unicode_string(f, r[i]); save_unicode_string(f, r[i]);
} }
} break;
case Variant::POOL_VECTOR2_ARRAY: {
f->store_32(VARIANT_VECTOR2_ARRAY);
PoolVector<Vector2> arr = p_property;
int len = arr.size();
f->store_32(len);
PoolVector<Vector2>::Read r = arr.read();
for (int i = 0; i < len; i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
}
} break;
case Variant::POOL_VECTOR2I_ARRAY: {
f->store_32(VARIANT_VECTOR2I_ARRAY);
PoolVector<Vector2i> arr = p_property;
int len = arr.size();
f->store_32(len);
PoolVector<Vector2i>::Read r = arr.read();
for (int i = 0; i < len; i++) {
f->store_32(r[i].x);
f->store_32(r[i].y);
}
} break; } break;
case Variant::POOL_VECTOR3_ARRAY: { case Variant::POOL_VECTOR3_ARRAY: {
f->store_32(VARIANT_VECTOR3_ARRAY); f->store_32(VARIANT_VECTOR3_ARRAY);
@ -1587,15 +1643,16 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} }
} break; } break;
case Variant::POOL_VECTOR2_ARRAY: { case Variant::POOL_VECTOR3I_ARRAY: {
f->store_32(VARIANT_VECTOR2_ARRAY); f->store_32(VARIANT_VECTOR3I_ARRAY);
PoolVector<Vector2> arr = p_property; PoolVector<Vector3i> arr = p_property;
int len = arr.size(); int len = arr.size();
f->store_32(len); f->store_32(len);
PoolVector<Vector2>::Read r = arr.read(); PoolVector<Vector3i>::Read r = arr.read();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
f->store_real(r[i].x); f->store_32(r[i].x);
f->store_real(r[i].y); f->store_32(r[i].y);
f->store_32(r[i].z);
} }
} break; } break;