Skip to content

Commit

Permalink
Work around two conflicting methods AnimationNodeExtension::process()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Dec 14, 2024
1 parent 579bbb8 commit 99d6f32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions godot-codegen/src/models/domain_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl ClassMethod {
"hash present for virtual class method"
);

let rust_method_name = Self::make_virtual_method_name(&method.name);
let rust_method_name = Self::make_virtual_method_name(class_name, &method.name);

Self::from_json_inner(
method,
Expand Down Expand Up @@ -488,13 +488,13 @@ impl ClassMethod {
})
}

fn make_virtual_method_name(godot_method_name: &str) -> &str {
fn make_virtual_method_name<'m>(class_name: &TyName, godot_method_name: &'m str) -> &'m str {
// Remove leading underscore from virtual method names.
let method_name = godot_method_name
.strip_prefix('_')
.unwrap_or(godot_method_name);

special_cases::maybe_rename_virtual_method(method_name)
special_cases::maybe_rename_virtual_method(class_name, method_name)
}
}

Expand Down
17 changes: 12 additions & 5 deletions godot-codegen/src/special_cases/special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,26 @@ pub fn is_utility_function_deleted(function: &JsonUtilityFunction, ctx: &mut Con
}

pub fn maybe_rename_class_method<'m>(class_name: &TyName, godot_method_name: &'m str) -> &'m str {
// This is for non-virtual methods only. For virtual methods, use other handler below.

match (class_name.godot_ty.as_str(), godot_method_name) {
// GDScript, GDScriptNativeClass, possibly more in the future
(_, "new") => "instantiate",

_ => godot_method_name,
}
}

// Maybe merge with above?
pub fn maybe_rename_virtual_method(rust_method_name: &str) -> &str {
// A few classes define a virtual method called "_init" (distinct from the constructor)
// -> rename those to avoid a name conflict in I* interface trait.
match rust_method_name {
"init" => "init_ext",
pub fn maybe_rename_virtual_method<'m>(class_name: &TyName, rust_method_name: &'m str) -> &'m str {
match (class_name.godot_ty.as_str(), rust_method_name) {
// Workaround for 2 methods of same name; see https://github.com/godotengine/godot/pull/99181#issuecomment-2543311415.
("AnimationNodeExtension", "process") => "process_animation",

// A few classes define a virtual method called "_init" (distinct from the constructor)
// -> rename those to avoid a name conflict in I* interface trait.
(_, "init") => "init_ext",

_ => rust_method_name,
}
}
Expand Down

0 comments on commit 99d6f32

Please sign in to comment.