Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using TypedArray with an enum causes 'get_class_static' is not a member of ... #1584

Open
ZacharieBeauchemin opened this issue Sep 14, 2024 · 2 comments

Comments

@ZacharieBeauchemin
Copy link

ZacharieBeauchemin commented Sep 14, 2024

Godot version

4.3

godot-cpp version

4.3

System information

Windows 11

Issue description

When creating a TypedArray the following error occurs:

error: 'get_class_static' is not a member of ...
set_typed(Variant::OBJECT, T::get_class_static(), Variant());

Steps to reproduce

Create an enum like so:

namespace Game {
    enum Direction {
        Up,
        Down,
        Left,
        Right
    };
}

VARIANT_ENUM_CAST(Game::Direction)

Try to use it as the type for a TypedArray like so:

godot::TypedArray<Game::Direction> sequence;

Minimal reproduction project

N/A

@aaronfranke
Copy link
Member

Does it work if you use MAKE_TYPED_ARRAY_INFO(Game::Direction, Variant::INT)?

@ZacharieBeauchemin
Copy link
Author

ZacharieBeauchemin commented Sep 18, 2024

I might be missing something but I don't seem to be able to use MAKE_TYPED_ARRAY_INFO. I tried to add it to the end of my Direction.hpp file after VARIANT_ENUM_CAST and also tried to add #include <godot_cpp/core/type_info.hpp> but it doesn't seem to be recognized.

I also tried to add what would be result of the macro directly in the Direction.hpp file but I still get the same error 'get_class_static' is not a member of 'Game::Direction'

#pragma once

namespace Game {
	enum Direction {
		Up,
		Down,
		Left,
		Right
	};
}

VARIANT_ENUM_CAST(Game::Direction)

namespace godot {
	template<>
	struct GetTypeInfo<TypedArray<Game::Direction>> {
		static constexpr GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_ARRAY;
		static constexpr GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;

		static inline PropertyInfo get_class_info() {
			return make_property_info(Variant::Type::ARRAY,
			                          "",
			                          PROPERTY_HINT_ARRAY_TYPE,
			                          Variant::get_type_name(Variant::INT).utf8().get_data());
		}
	};

	template<>
	struct GetTypeInfo<const TypedArray<Game::Direction>&> {
		static constexpr GDExtensionVariantType VARIANT_TYPE = GDEXTENSION_VARIANT_TYPE_ARRAY;
		static constexpr GDExtensionClassMethodArgumentMetadata METADATA = GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE;

		static inline PropertyInfo get_class_info() {
			return make_property_info(Variant::Type::ARRAY,
			                          "",
			                          PROPERTY_HINT_ARRAY_TYPE,
			                          Variant::get_type_name(Variant::INT).utf8().get_data());
		}
	};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants