forked from CraterCrash/godot-orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CraterCrashGH-444 Improve pin type-safety
- Loading branch information
Showing
101 changed files
with
2,166 additions
and
911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// This file is part of the Godot Orchestrator project. | ||
// | ||
// Copyright (c) 2023-present Vahera Studios LLC and its contributors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#include "common/property_utils.h" | ||
|
||
#include "string_utils.h" | ||
|
||
#include <godot_cpp/classes/ref_counted.hpp> | ||
#include <godot_cpp/templates/hash_map.hpp> | ||
|
||
namespace PropertyUtils | ||
{ | ||
static HashMap<uint32_t, String> get_property_usage_name_map() | ||
{ | ||
HashMap<uint32_t, String> names; | ||
names[PROPERTY_USAGE_NONE] = "None"; | ||
names[PROPERTY_USAGE_STORAGE] = "Storage"; | ||
names[PROPERTY_USAGE_EDITOR] = "Editor"; | ||
names[PROPERTY_USAGE_CLASS_IS_BITFIELD] ="ClassIsBitfield"; | ||
names[PROPERTY_USAGE_CLASS_IS_ENUM] = "ClassIsEnum"; | ||
names[PROPERTY_USAGE_NIL_IS_VARIANT] = "NilIsVariant"; | ||
names[PROPERTY_USAGE_DEFAULT] = "Default"; | ||
return names; | ||
} | ||
|
||
PropertyInfo create_object(const String& p_name, const String& p_class_name) | ||
{ | ||
PropertyHint hint = PROPERTY_HINT_NONE; | ||
String hint_string = ""; | ||
if (ClassDB::is_parent_class(p_class_name, RefCounted::get_class_static())) | ||
{ | ||
hint = PROPERTY_HINT_RESOURCE_TYPE; | ||
hint_string = p_class_name; | ||
} | ||
return PropertyInfo(Variant::OBJECT, p_name, hint, hint_string, PROPERTY_USAGE_DEFAULT, p_class_name); | ||
} | ||
|
||
PropertyInfo create_variant(const String& p_name) | ||
{ | ||
return PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT); | ||
} | ||
|
||
PropertyInfo create_enum_class(const String& p_name, const String& p_class_name) | ||
{ | ||
return PropertyInfo(Variant::INT, p_name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, p_class_name); | ||
} | ||
|
||
PropertyInfo create_class_enum(const String& p_name, const String& p_class_name, const String& p_enum_name) | ||
{ | ||
return create_enum_class(p_name, vformat("%s.%s", p_class_name, p_enum_name)); | ||
} | ||
|
||
PropertyInfo create_typed(const String& p_name, Variant::Type p_type, const String& p_class_name) | ||
{ | ||
if (p_type == Variant::NIL) | ||
return create_variant(p_name); | ||
else | ||
return PropertyInfo(p_type, p_name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, p_class_name); | ||
} | ||
|
||
PropertyInfo create_file(const String& p_name, const String& p_filters) | ||
{ | ||
return PropertyInfo(Variant::STRING, p_name, PROPERTY_HINT_FILE, p_filters, PROPERTY_USAGE_DEFAULT); | ||
} | ||
|
||
String get_property_type_name(const PropertyInfo& p_property) | ||
{ | ||
if (p_property.type == Variant::NIL && p_property.usage & PROPERTY_USAGE_NIL_IS_VARIANT) | ||
return "Variant"; | ||
|
||
if (p_property.usage & PROPERTY_USAGE_CLASS_IS_ENUM || p_property.usage & PROPERTY_USAGE_CLASS_IS_BITFIELD) | ||
return "Enum"; | ||
|
||
if (p_property.type == Variant::OBJECT) | ||
{ | ||
if (!p_property.class_name.is_empty() && !p_property.class_name.contains(".")) | ||
return p_property.class_name; | ||
} | ||
|
||
return Variant::get_type_name(p_property.type); | ||
} | ||
|
||
String usage_to_string(uint32_t p_usage) | ||
{ | ||
static HashMap<uint32_t, String> usage_names = get_property_usage_name_map(); | ||
|
||
PackedStringArray values; | ||
for (const KeyValue<uint32_t, String>& E : usage_names) | ||
if (E.key & p_usage) | ||
values.push_back(E.value); | ||
|
||
return StringUtils::join(", ", values); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// This file is part of the Godot Orchestrator project. | ||
// | ||
// Copyright (c) 2023-present Vahera Studios LLC and its contributors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef ORCHESTRATOR_PROPERTY_UTILS_H | ||
#define ORCHESTRATOR_PROPERTY_UTILS_H | ||
|
||
#include <godot_cpp/core/property_info.hpp> | ||
|
||
using namespace godot; | ||
|
||
namespace PropertyUtils | ||
{ | ||
/// Create a simple PropertyInfo for an object type with a given class name. | ||
/// @param p_name the property name | ||
/// @param p_class_name the object class name | ||
/// @return the property info structure | ||
PropertyInfo create_object(const String& p_name, const String& p_class_name = String()); | ||
|
||
/// Creates a simple PropertyInfo for a Variant type. | ||
/// @param p_name the property name | ||
/// @return the property info structure | ||
PropertyInfo create_variant(const String& p_name); | ||
|
||
/// Creates a property info for a global enum type. | ||
/// @param p_name the property name | ||
/// @param p_class_name the global enum class name | ||
/// @return the property info structure | ||
PropertyInfo create_enum_class(const String& p_name, const String& p_class_name); | ||
|
||
/// Creates a property info for a nested class-specific enum type. | ||
/// @param p_name the property name | ||
/// @param p_class_name the class that owns the enum | ||
/// @param p_enum_name the enumeration name | ||
/// @return the property info structure | ||
PropertyInfo create_class_enum(const String& p_name, const String& p_class_name, const String& p_enum_name); | ||
|
||
/// Creates a property from a variant type | ||
/// @param p_name the property name | ||
/// @param p_type the variant type | ||
/// @param p_class_name optional class name | ||
/// @return the property info structure | ||
PropertyInfo create_typed(const String& p_name, Variant::Type p_type, const String& p_class_name = String()); | ||
|
||
/// Create a property for a file selection | ||
/// @param p_name the property name | ||
/// @param p_filters optional file filters | ||
/// @return the property info structure | ||
PropertyInfo create_file(const String& p_name, const String& p_filters = String()); | ||
|
||
// Utility methods | ||
_FORCE_INLINE_ bool is_nil(const PropertyInfo& p_property) { return p_property.type == Variant::NIL; } | ||
_FORCE_INLINE_ bool is_object(const PropertyInfo& p_property) { return p_property.type == Variant::OBJECT; } | ||
_FORCE_INLINE_ bool is_variant(const PropertyInfo& p_property) { return p_property.usage & PROPERTY_USAGE_NIL_IS_VARIANT; } | ||
_FORCE_INLINE_ bool is_class_enum(const PropertyInfo& p_property) { return p_property.usage & PROPERTY_USAGE_CLASS_IS_ENUM; } | ||
_FORCE_INLINE_ bool is_class_bitfield(const PropertyInfo& p_property) { return p_property.usage & PROPERTY_USAGE_CLASS_IS_BITFIELD; } | ||
|
||
/// Get the type name for the specified property | ||
/// @param p_property the property | ||
/// @return the property type name | ||
String get_property_type_name(const PropertyInfo& p_property); | ||
|
||
/// Converts a property info's <code>usage</code> bitfield to a string. | ||
/// @param p_usage the property usage flags bitfield value | ||
/// @return comma-separated string of property usage flags | ||
String usage_to_string(uint32_t p_usage); | ||
}; | ||
|
||
#endif // ORCHESTRATOR_PROPERTY_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.