Skip to content

Commit

Permalink
Codegen: override enum/bitfield status; change ConnectFlags to bitfield
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Jan 1, 2025
1 parent b619959 commit 11dfcde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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 @@ -562,7 +562,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

0 comments on commit 11dfcde

Please sign in to comment.