Skip to content

Commit

Permalink
NodePath::subpath(): disable polyfill for >= 4.4 again
Browse files Browse the repository at this point in the history
Now that upstream bug is fixed, we can limit the polyfill to 4.3.
  • Loading branch information
Bromeon committed Jan 11, 2025
1 parent 0e945a5 commit a23bf9f
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions godot-core/src/builtin/string/node_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::fmt;

use godot_ffi as sys;
use godot_ffi::{ffi_methods, GodotFfi};
use godot_ffi::{ffi_methods, GdextBuild, GodotFfi};

use crate::builtin::inner;

Expand Down Expand Up @@ -142,19 +142,23 @@ impl NodePath {
#[cfg(since_api = "4.3")]
#[doc(alias = "slice")]
pub fn subpath(&self, begin: i32, exclusive_end: i32) -> NodePath {
// Polyfill for bug https://github.com/godotengine/godot/pull/100954.
// TODO(v0.3) make polyfill (everything but last line) conditional if PR is merged in 4.4.
let name_count = self.get_name_count() as i32;
let subname_count = self.get_subname_count() as i32;
let total_count = name_count + subname_count;

let mut begin = begin.clamp(-total_count, total_count);
if begin < 0 {
begin += total_count;
}
if begin > name_count {
begin += 1;
}
// Polyfill for bug https://github.com/godotengine/godot/pull/100954, fixed in 4.4.
let begin = if GdextBuild::since_api("4.4") {
begin
} else {
let name_count = self.get_name_count() as i32;
let subname_count = self.get_subname_count() as i32;
let total_count = name_count + subname_count;

let mut begin = begin.clamp(-total_count, total_count);
if begin < 0 {
begin += total_count;
}
if begin > name_count {
begin += 1;
}
begin
};

self.as_inner().slice(begin as i64, exclusive_end as i64)
}
Expand Down

0 comments on commit a23bf9f

Please sign in to comment.