Skip to content

Correct ConnectFlags classification (enum -> bitfield) #1002

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

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion godot-codegen/src/models/domain_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ impl UtilityFunction {
impl Enum {
pub fn from_json(json_enum: &JsonEnum, surrounding_class: Option<&TyName>) -> Self {
let godot_name = &json_enum.name;
let is_bitfield = json_enum.is_bitfield;
let is_bitfield = special_cases::is_enum_bitfield(surrounding_class, godot_name)
.unwrap_or(json_enum.is_bitfield);
let is_private = special_cases::is_enum_private(surrounding_class, godot_name);
let is_exhaustive = special_cases::is_enum_exhaustive(surrounding_class, godot_name);

Expand Down
15 changes: 15 additions & 0 deletions godot-codegen/src/special_cases/special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,21 @@ pub fn is_enum_exhaustive(class_name: Option<&TyName>, enum_name: &str) -> bool
}
}

/// Overrides Godot's enum/bitfield status.
/// * `Some(true)` -> bitfield
/// * `Some(false)` -> enum
/// * `None` -> keep default
#[rustfmt::skip]
pub fn is_enum_bitfield(class_name: Option<&TyName>, enum_name: &str) -> Option<bool> {
let class_name = class_name.map(|c| c.godot_ty.as_str());
match (class_name, enum_name) {
| (Some("Object"), "ConnectFlags")

=> Some(true),
_ => None
}
}

/// Whether an enum can be combined with another enum (return value) for bitmasking purposes.
///
/// If multiple masks are ever necessary, this can be extended to return a slice instead of Option.
Expand Down
Loading