| 1042 | } |
| 1043 | |
| 1044 | uint32_t ECS::register_or_update_script_component( |
| 1045 | const StringName &p_name, |
| 1046 | const LocalVector<ScriptProperty> &p_properties, |
| 1047 | StorageType p_storage_type, |
| 1048 | Vector<StringName> p_spawners) { |
| 1049 | godex::component_id id = get_component_id(p_name); |
| 1050 | DynamicComponentInfo *info; |
| 1051 | |
| 1052 | if (id == godex::COMPONENT_NONE) { |
| 1053 | // This is a new component. |
| 1054 | id = components_info.size(); |
| 1055 | info = memnew(DynamicComponentInfo); |
| 1056 | info->component_id = id; |
| 1057 | |
| 1058 | components.push_back(p_name); |
| 1059 | components_info.push_back(ComponentInfo()); |
| 1060 | components_info[id].dynamic_component_info = info; |
| 1061 | } else { |
| 1062 | // This is an old component, verify is a script component. |
| 1063 | ERR_FAIL_COND_V_MSG(components_info[id].dynamic_component_info == nullptr, godex::COMPONENT_NONE, "This component " + p_name + " is not a script component and can't be updated. Your component must be an unique name."); |
| 1064 | info = components_info[id].dynamic_component_info; |
| 1065 | } |
| 1066 | |
| 1067 | info->property_map.resize(p_properties.size()); |
| 1068 | info->properties.resize(p_properties.size()); |
| 1069 | info->defaults.resize(p_properties.size()); |
| 1070 | |
| 1071 | // Validate and initialize the parameters. |
| 1072 | for (uint32_t i = 0; i < p_properties.size(); i += 1) { |
| 1073 | // Is type supported? |
| 1074 | switch (p_properties[i].property.type) { |
| 1075 | case Variant::NIL: |
| 1076 | case Variant::RID: |
| 1077 | case Variant::OBJECT: |
| 1078 | case Variant::SIGNAL: |
| 1079 | case Variant::CALLABLE: |
| 1080 | // TODO what about dictionary and arrays? |
| 1081 | ERR_PRINT("The script component " + p_name + " is using a pointer variable. This is unsafe, so not supported. Please use a databag."); |
| 1082 | return UINT32_MAX; |
| 1083 | default: |
| 1084 | // Valid! |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | // Is default type correct? |
| 1089 | if (p_properties[i].property.type != p_properties[i].default_value.get_type()) { |
| 1090 | ERR_PRINT("The script variable " + p_name + "::" + p_properties[i].property.name + " is being initialized with a different default variable type."); |
| 1091 | return UINT32_MAX; |
| 1092 | } |
| 1093 | |
| 1094 | info->property_map[i] = p_properties[i].property.name; |
| 1095 | info->properties[i] = p_properties[i].property; |
| 1096 | info->defaults[i] = p_properties[i].default_value; |
| 1097 | } |
| 1098 | |
| 1099 | info->storage_type = p_storage_type; |
| 1100 | |
| 1101 | // Extract the spawners. |
nothing calls this directly
no test coverage detected