[godot] Fix more handling of CJK in names, see #2788

This commit is contained in:
Mario Zechner 2025-04-18 14:47:00 +02:00
parent 88f69fb2a6
commit 56cd91047c
10 changed files with 42 additions and 16 deletions

View File

@ -47,7 +47,9 @@ void SpineAnimation::_bind_methods() {
String SpineAnimation::get_name() { String SpineAnimation::get_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
float SpineAnimation::get_duration() { float SpineAnimation::get_duration() {

View File

@ -250,7 +250,9 @@ Ref<Animation> SpineAnimationTrack::create_animation(spine::Animation *animation
Ref<Animation> animation_ref; Ref<Animation> animation_ref;
INSTANTIATE(animation_ref); INSTANTIATE(animation_ref);
animation_ref->set_name(String(animation->getName().buffer()) + (loop ? "" : "_looped")); String name;
name.parse_utf8(animation.getName().buffer());
animation_ref->set_name(name + (loop ? "" : "_looped"));
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
// animation_ref->set_loop(!loop); // animation_ref->set_loop(!loop);
#else #else
@ -260,7 +262,7 @@ Ref<Animation> SpineAnimationTrack::create_animation(spine::Animation *animation
animation_ref->add_track(Animation::TYPE_VALUE); animation_ref->add_track(Animation::TYPE_VALUE);
animation_ref->track_set_path(0, NodePath(".:animation_name")); animation_ref->track_set_path(0, NodePath(".:animation_name"));
animation_ref->track_insert_key(0, 0, animation->getName().buffer()); animation_ref->track_insert_key(0, 0, name);
animation_ref->add_track(Animation::TYPE_VALUE); animation_ref->add_track(Animation::TYPE_VALUE);
animation_ref->track_set_path(1, NodePath(".:loop")); animation_ref->track_set_path(1, NodePath(".:loop"));
@ -298,7 +300,9 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
} }
auto current_entry = animation_state->getCurrent(track_index); auto current_entry = animation_state->getCurrent(track_index);
bool should_set_mix = mix_duration >= 0; bool should_set_mix = mix_duration >= 0;
bool should_set_animation = !current_entry || (animation_name != current_entry->getAnimation()->getName().buffer() || current_entry->getLoop() != loop); String other_name;
if (current_entry) other_name.parse_utf8(current_entry->getAnimation()->getName().buffer());
bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop);
if (should_set_animation) { if (should_set_animation) {
if (!EMPTY(animation_name)) { if (!EMPTY(animation_name)) {
@ -316,7 +320,7 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
if (debug) print_line(String("Setting animation {0} with mix_duration {1} on track {2} on {3}").format(varray(animation_name, mix_duration, track_index, sprite->get_name())).utf8().ptr()); if (debug) print_line(String("Setting animation {0} with mix_duration {1} on track {2} on {3}").format(varray(animation_name, mix_duration, track_index, sprite->get_name())).utf8().ptr());
} else { } else {
if (!current_entry || (String("<empty>") != current_entry->getAnimation()->getName().buffer())) { if (!current_entry || (String("<empty>") != other_name)) {
auto entry = animation_state->setEmptyAnimation(track_index, should_set_mix ? mix_duration : 0); auto entry = animation_state->setEmptyAnimation(track_index, should_set_mix ? mix_duration : 0);
entry->setTrackEnd(FLT_MAX); entry->setTrackEnd(FLT_MAX);
if (debug) print_line(String("Setting empty animation with mix_duration {0} on track {1} on {2}").format(varray(mix_duration, track_index, sprite->get_name())).utf8().ptr()); if (debug) print_line(String("Setting empty animation with mix_duration {0} on track {1} on {2}").format(varray(mix_duration, track_index, sprite->get_name())).utf8().ptr());
@ -423,7 +427,9 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
if (animation_player->is_playing()) { if (animation_player->is_playing()) {
auto current_entry = animation_state->getCurrent(track_index); auto current_entry = animation_state->getCurrent(track_index);
bool should_set_mix = mix_duration >= 0; bool should_set_mix = mix_duration >= 0;
bool should_set_animation = !current_entry || (animation_name != current_entry->getAnimation()->getName().buffer() || current_entry->getLoop() != loop) || animation_changed; String other_name;
if (current_entry) other_name.parse_utf8(current_entry->getAnimation()->getName().buffer());
bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop) || animation_changed;
animation_changed = false; animation_changed = false;
if (should_set_animation) { if (should_set_animation) {
@ -442,7 +448,7 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
if (debug) print_line(String("Setting animation {0} with mix_duration {1} on track {2} on {3}").format(varray(animation_name, mix_duration, track_index, sprite->get_name())).utf8().ptr()); if (debug) print_line(String("Setting animation {0} with mix_duration {1} on track {2} on {3}").format(varray(animation_name, mix_duration, track_index, sprite->get_name())).utf8().ptr());
} else { } else {
if (!current_entry || (String("<empty>") != current_entry->getAnimation()->getName().buffer())) { if (!current_entry || (String("<empty>") != other_name)) {
auto entry = animation_state->setEmptyAnimation(track_index, should_set_mix ? mix_duration : 0); auto entry = animation_state->setEmptyAnimation(track_index, should_set_mix ? mix_duration : 0);
entry->setTrackEnd(FLT_MAX); entry->setTrackEnd(FLT_MAX);
if (debug) print_line(String("Setting empty animation with mix_duration {0} on track {1} on {2}").format(varray(mix_duration, track_index, sprite->get_name())).utf8().ptr()); if (debug) print_line(String("Setting empty animation with mix_duration {0} on track {1} on {2}").format(varray(mix_duration, track_index, sprite->get_name())).utf8().ptr());

View File

@ -41,7 +41,9 @@ SpineAttachment::~SpineAttachment() {
String SpineAttachment::get_attachment_name() { String SpineAttachment::get_attachment_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
Ref<SpineAttachment> SpineAttachment::copy() { Ref<SpineAttachment> SpineAttachment::copy() {

View File

@ -68,7 +68,9 @@ int SpineBoneData::get_index() {
String SpineBoneData::get_bone_name() { String SpineBoneData::get_bone_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
Ref<SpineBoneData> SpineBoneData::get_parent() { Ref<SpineBoneData> SpineBoneData::get_parent() {

View File

@ -41,7 +41,9 @@ void SpineConstraintData::_bind_methods() {
String SpineConstraintData::get_constraint_name() { String SpineConstraintData::get_constraint_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
int SpineConstraintData::get_order() { int SpineConstraintData::get_order() {

View File

@ -48,7 +48,9 @@ void SpineEventData::_bind_methods() {
String SpineEventData::get_event_name() { String SpineEventData::get_event_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
int SpineEventData::get_int_value() { int SpineEventData::get_int_value() {

View File

@ -627,7 +627,9 @@ SpineSkeletonDataResource::find_physics_constraint(
String SpineSkeletonDataResource::get_skeleton_name() const { String SpineSkeletonDataResource::get_skeleton_name() const {
SPINE_CHECK(skeleton_data, "") SPINE_CHECK(skeleton_data, "")
return skeleton_data->getName().buffer(); String name;
name.parse_utf8(skeleton_data->getName().buffer());
return name;
} }
Array SpineSkeletonDataResource::get_bones() const { Array SpineSkeletonDataResource::get_bones() const {

View File

@ -123,7 +123,9 @@ Array SpineSkin::find_attachments_for_slot(int slot_index) {
String SpineSkin::get_name() { String SpineSkin::get_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
void SpineSkin::add_skin(Ref<SpineSkin> other) { void SpineSkin::add_skin(Ref<SpineSkin> other) {

View File

@ -53,7 +53,9 @@ int SpineSlotData::get_index() {
String SpineSlotData::get_name() { String SpineSlotData::get_name() {
SPINE_CHECK(get_spine_object(), String("")) SPINE_CHECK(get_spine_object(), String(""))
return get_spine_object()->getName().buffer(); String name;
name.parse_utf8(get_spine_object()->getName().buffer());
return name;
} }
Ref<SpineBoneData> SpineSlotData::get_bone_data() { Ref<SpineBoneData> SpineSlotData::get_bone_data() {

View File

@ -1223,7 +1223,9 @@ void SpineSprite::draw() {
float inverse_zoom = 1 / get_viewport()->get_global_canvas_transform().get_scale().x * editor_scale; float inverse_zoom = 1 / get_viewport()->get_global_canvas_transform().get_scale().x * editor_scale;
Vector<String> hover_text_lines; Vector<String> hover_text_lines;
if (hovered_slot) { if (hovered_slot) {
hover_text_lines.push_back(String("Slot: ") + hovered_slot->getData().getName().buffer()); String name;
name.parse_utf8(hovered_slot->getData().getName().buffer());
hover_text_lines.push_back(String("Slot: ") + name);
} }
if (hovered_bone) { if (hovered_bone) {
@ -1231,7 +1233,9 @@ void SpineSprite::draw() {
debug_bones_thickness *= 1.1; debug_bones_thickness *= 1.1;
draw_bone(hovered_bone, Color(debug_bones_color.r, debug_bones_color.g, debug_bones_color.b, 1)); draw_bone(hovered_bone, Color(debug_bones_color.r, debug_bones_color.g, debug_bones_color.b, 1));
debug_bones_thickness = thickness; debug_bones_thickness = thickness;
hover_text_lines.push_back(String("Bone: ") + hovered_bone->getData().getName().buffer()); String name;
name.parse_utf8(hovered_bone->getData().getName().buffer());
hover_text_lines.push_back(String("Bone: ") + name);
} }
auto global_scale = get_global_scale(); auto global_scale = get_global_scale();