mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Change container_element_type to vector container
This commit is contained in:
parent
d76c1d0e51
commit
5cf0d772bc
9 changed files with 168 additions and 138 deletions
|
@ -45,10 +45,9 @@ class GDScriptInstance;
|
|||
class GDScript;
|
||||
|
||||
class GDScriptDataType {
|
||||
private:
|
||||
GDScriptDataType *container_element_type = nullptr;
|
||||
|
||||
public:
|
||||
Vector<GDScriptDataType> container_element_types;
|
||||
|
||||
enum Kind {
|
||||
UNINITIALIZED,
|
||||
BUILTIN,
|
||||
|
@ -76,19 +75,20 @@ public:
|
|||
case BUILTIN: {
|
||||
Variant::Type var_type = p_variant.get_type();
|
||||
bool valid = builtin_type == var_type;
|
||||
if (valid && builtin_type == Variant::ARRAY && has_container_element_type()) {
|
||||
if (valid && builtin_type == Variant::ARRAY && has_container_element_type(0)) {
|
||||
Array array = p_variant;
|
||||
if (array.is_typed()) {
|
||||
GDScriptDataType array_container_type = get_container_element_type(0);
|
||||
Variant::Type array_builtin_type = (Variant::Type)array.get_typed_builtin();
|
||||
StringName array_native_type = array.get_typed_class_name();
|
||||
Ref<Script> array_script_type_ref = array.get_typed_script();
|
||||
|
||||
if (array_script_type_ref.is_valid()) {
|
||||
valid = (container_element_type->kind == SCRIPT || container_element_type->kind == GDSCRIPT) && container_element_type->script_type == array_script_type_ref.ptr();
|
||||
valid = (array_container_type.kind == SCRIPT || array_container_type.kind == GDSCRIPT) && array_container_type.script_type == array_script_type_ref.ptr();
|
||||
} else if (array_native_type != StringName()) {
|
||||
valid = container_element_type->kind == NATIVE && container_element_type->native_type == array_native_type;
|
||||
valid = array_container_type.kind == NATIVE && array_container_type.native_type == array_native_type;
|
||||
} else {
|
||||
valid = container_element_type->kind == BUILTIN && container_element_type->builtin_type == array_builtin_type;
|
||||
valid = array_container_type.kind == BUILTIN && array_container_type.builtin_type == array_builtin_type;
|
||||
}
|
||||
} else {
|
||||
valid = false;
|
||||
|
@ -147,24 +147,32 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
void set_container_element_type(const GDScriptDataType &p_element_type) {
|
||||
container_element_type = memnew(GDScriptDataType(p_element_type));
|
||||
}
|
||||
|
||||
GDScriptDataType get_container_element_type() const {
|
||||
ERR_FAIL_NULL_V(container_element_type, GDScriptDataType());
|
||||
return *container_element_type;
|
||||
}
|
||||
|
||||
bool has_container_element_type() const {
|
||||
return container_element_type != nullptr;
|
||||
}
|
||||
|
||||
void unset_container_element_type() {
|
||||
if (container_element_type) {
|
||||
memdelete(container_element_type);
|
||||
void set_container_element_type(int p_index, const GDScriptDataType &p_element_type) {
|
||||
ERR_FAIL_COND(p_index < 0);
|
||||
while (p_index >= container_element_types.size()) {
|
||||
container_element_types.push_back(GDScriptDataType());
|
||||
}
|
||||
container_element_type = nullptr;
|
||||
container_element_types.write[p_index] = GDScriptDataType(p_element_type);
|
||||
}
|
||||
|
||||
GDScriptDataType get_container_element_type(int p_index) const {
|
||||
ERR_FAIL_INDEX_V(p_index, container_element_types.size(), GDScriptDataType());
|
||||
return container_element_types[p_index];
|
||||
}
|
||||
|
||||
GDScriptDataType get_container_element_type_or_variant(int p_index) const {
|
||||
if (p_index < 0 || p_index >= container_element_types.size()) {
|
||||
return GDScriptDataType();
|
||||
}
|
||||
return container_element_types[p_index];
|
||||
}
|
||||
|
||||
bool has_container_element_type(int p_index) const {
|
||||
return p_index >= 0 && p_index < container_element_types.size();
|
||||
}
|
||||
|
||||
bool has_container_element_types() const {
|
||||
return !container_element_types.is_empty();
|
||||
}
|
||||
|
||||
GDScriptDataType() = default;
|
||||
|
@ -176,19 +184,14 @@ public:
|
|||
native_type = p_other.native_type;
|
||||
script_type = p_other.script_type;
|
||||
script_type_ref = p_other.script_type_ref;
|
||||
unset_container_element_type();
|
||||
if (p_other.has_container_element_type()) {
|
||||
set_container_element_type(p_other.get_container_element_type());
|
||||
}
|
||||
container_element_types = p_other.container_element_types;
|
||||
}
|
||||
|
||||
GDScriptDataType(const GDScriptDataType &p_other) {
|
||||
*this = p_other;
|
||||
}
|
||||
|
||||
~GDScriptDataType() {
|
||||
unset_container_element_type();
|
||||
}
|
||||
~GDScriptDataType() {}
|
||||
};
|
||||
|
||||
class GDScriptFunction {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue