MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / write_variant

Method write_variant

core/io/resource_format_binary.cpp:1626–2047  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1624}
1625
1626void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const Variant &p_property, HashMap<Ref<Resource>, int> &resource_map, HashMap<Ref<Resource>, int> &external_resources, HashMap<StringName, int> &string_map, const PropertyInfo &p_hint) {
1627 switch (p_property.get_type()) {
1628 case Variant::NIL: {
1629 f->store_32(VARIANT_NIL);
1630 // don't store anything
1631 } break;
1632 case Variant::BOOL: {
1633 f->store_32(VARIANT_BOOL);
1634 bool val = p_property;
1635 f->store_32(val);
1636 } break;
1637 case Variant::INT: {
1638 int64_t val = p_property;
1639 if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) {
1640 f->store_32(VARIANT_INT64);
1641 f->store_64(uint64_t(val));
1642
1643 } else {
1644 f->store_32(VARIANT_INT);
1645 f->store_32(uint32_t(p_property));
1646 }
1647
1648 } break;
1649 case Variant::FLOAT: {
1650 double d = p_property;
1651 float fl = d;
1652 if (double(fl) != d) {
1653 f->store_32(VARIANT_DOUBLE);
1654 f->store_double(d);
1655 } else {
1656 f->store_32(VARIANT_FLOAT);
1657 f->store_real(fl);
1658 }
1659
1660 } break;
1661 case Variant::STRING: {
1662 f->store_32(VARIANT_STRING);
1663 String val = p_property;
1664 save_unicode_string(f, val);
1665
1666 } break;
1667 case Variant::VECTOR2: {
1668 f->store_32(VARIANT_VECTOR2);
1669 Vector2 val = p_property;
1670 f->store_real(val.x);
1671 f->store_real(val.y);
1672
1673 } break;
1674 case Variant::VECTOR2I: {
1675 f->store_32(VARIANT_VECTOR2I);
1676 Vector2i val = p_property;
1677 f->store_32(uint32_t(val.x));
1678 f->store_32(uint32_t(val.y));
1679
1680 } break;
1681 case Variant::RECT2: {
1682 f->store_32(VARIANT_RECT2);
1683 Rect2 val = p_property;

Callers

nothing calls this directly

Calls 15

store_32Method · 0.80
store_64Method · 0.80
store_doubleMethod · 0.80
store_realMethod · 0.80
store_floatMethod · 0.80
store_16Method · 0.80
get_name_countMethod · 0.80
get_subname_countMethod · 0.80
is_absoluteMethod · 0.80
get_subnameMethod · 0.80
is_built_inMethod · 0.80
sizeMethod · 0.65

Tested by

no test coverage detected