Skip to content

Commit 60710df

Browse files
committed
Merge pull request #94047 from KoBeWi/resource_printer
Improve `to_string()` and add it to Resource
2 parents 769505f + e6783db commit 60710df

File tree

13 files changed

+53
-61
lines changed

13 files changed

+53
-61
lines changed

core/input/input_event.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ String InputEventWithModifiers::as_text() const {
277277
}
278278
}
279279

280-
String InputEventWithModifiers::to_string() {
280+
String InputEventWithModifiers::_to_string() {
281281
return as_text();
282282
}
283283

@@ -488,7 +488,7 @@ String InputEventKey::as_text() const {
488488
return mods_text.is_empty() ? kc : mods_text + "+" + kc;
489489
}
490490

491-
String InputEventKey::to_string() {
491+
String InputEventKey::_to_string() {
492492
String p = is_pressed() ? "true" : "false";
493493
String e = is_echo() ? "true" : "false";
494494

@@ -848,7 +848,7 @@ String InputEventMouseButton::as_text() const {
848848
return full_string;
849849
}
850850

851-
String InputEventMouseButton::to_string() {
851+
String InputEventMouseButton::_to_string() {
852852
String p = is_pressed() ? "true" : "false";
853853
String canceled_state = is_canceled() ? "true" : "false";
854854
String d = double_click ? "true" : "false";
@@ -988,7 +988,7 @@ String InputEventMouseMotion::as_text() const {
988988
return vformat(RTR("Mouse motion at position (%s) with velocity (%s)"), String(get_position()), String(get_velocity()));
989989
}
990990

991-
String InputEventMouseMotion::to_string() {
991+
String InputEventMouseMotion::_to_string() {
992992
BitField<MouseButtonMask> mouse_button_mask = get_button_mask();
993993
String button_mask_string = itos((int64_t)mouse_button_mask);
994994

@@ -1184,7 +1184,7 @@ String InputEventJoypadMotion::as_text() const {
11841184
return vformat(RTR("Joypad Motion on Axis %d (%s) with Value %.2f"), axis, desc, axis_value);
11851185
}
11861186

1187-
String InputEventJoypadMotion::to_string() {
1187+
String InputEventJoypadMotion::_to_string() {
11881188
return vformat("InputEventJoypadMotion: axis=%d, axis_value=%.2f", axis, axis_value);
11891189
}
11901190

@@ -1303,7 +1303,7 @@ String InputEventJoypadButton::as_text() const {
13031303
return text;
13041304
}
13051305

1306-
String InputEventJoypadButton::to_string() {
1306+
String InputEventJoypadButton::_to_string() {
13071307
String p = is_pressed() ? "true" : "false";
13081308
return vformat("InputEventJoypadButton: button_index=%d, pressed=%s, pressure=%.2f", button_index, p, pressure);
13091309
}
@@ -1386,7 +1386,7 @@ String InputEventScreenTouch::as_text() const {
13861386
return vformat(RTR("Screen %s at (%s) with %s touch points"), status, String(get_position()), itos(index));
13871387
}
13881388

1389-
String InputEventScreenTouch::to_string() {
1389+
String InputEventScreenTouch::_to_string() {
13901390
String p = pressed ? "true" : "false";
13911391
String canceled_state = canceled ? "true" : "false";
13921392
String double_tap_string = double_tap ? "true" : "false";
@@ -1514,7 +1514,7 @@ String InputEventScreenDrag::as_text() const {
15141514
return vformat(RTR("Screen dragged with %s touch points at position (%s) with velocity of (%s)"), itos(index), String(get_position()), String(get_velocity()));
15151515
}
15161516

1517-
String InputEventScreenDrag::to_string() {
1517+
String InputEventScreenDrag::_to_string() {
15181518
return vformat("InputEventScreenDrag: index=%d, position=(%s), relative=(%s), velocity=(%s), pressure=%.2f, tilt=(%s), pen_inverted=(%s)", index, String(get_position()), String(get_relative()), String(get_velocity()), get_pressure(), String(get_tilt()), get_pen_inverted());
15191519
}
15201520

@@ -1656,7 +1656,7 @@ String InputEventAction::as_text() const {
16561656
return String();
16571657
}
16581658

1659-
String InputEventAction::to_string() {
1659+
String InputEventAction::_to_string() {
16601660
String p = is_pressed() ? "true" : "false";
16611661
return vformat("InputEventAction: action=\"%s\", pressed=%s", action, p);
16621662
}
@@ -1727,7 +1727,7 @@ String InputEventMagnifyGesture::as_text() const {
17271727
return vformat(RTR("Magnify Gesture at (%s) with factor %s"), String(get_position()), rtos(get_factor()));
17281728
}
17291729

1730-
String InputEventMagnifyGesture::to_string() {
1730+
String InputEventMagnifyGesture::_to_string() {
17311731
return vformat("InputEventMagnifyGesture: factor=%.2f, position=(%s)", factor, String(get_position()));
17321732
}
17331733

@@ -1769,7 +1769,7 @@ String InputEventPanGesture::as_text() const {
17691769
return vformat(RTR("Pan Gesture at (%s) with delta (%s)"), String(get_position()), String(get_delta()));
17701770
}
17711771

1772-
String InputEventPanGesture::to_string() {
1772+
String InputEventPanGesture::_to_string() {
17731773
return vformat("InputEventPanGesture: delta=(%s), position=(%s)", String(get_delta()), String(get_position()));
17741774
}
17751775

@@ -1850,7 +1850,7 @@ String InputEventMIDI::as_text() const {
18501850
return vformat(RTR("MIDI Input on Channel=%s Message=%s"), itos(channel), itos((int64_t)message));
18511851
}
18521852

1853-
String InputEventMIDI::to_string() {
1853+
String InputEventMIDI::_to_string() {
18541854
String ret;
18551855
switch (message) {
18561856
case MIDIMessage::NOTE_ON:
@@ -1926,7 +1926,7 @@ String InputEventShortcut::as_text() const {
19261926
return vformat(RTR("Input Event with Shortcut=%s"), shortcut->get_as_text());
19271927
}
19281928

1929-
String InputEventShortcut::to_string() {
1929+
String InputEventShortcut::_to_string() {
19301930
ERR_FAIL_COND_V(shortcut.is_null(), "None");
19311931

19321932
return vformat("InputEventShortcut: shortcut=%s", shortcut->get_as_text());

core/input/input_event.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class InputEventWithModifiers : public InputEventFromWindow {
146146
BitField<KeyModifierMask> get_modifiers_mask() const;
147147

148148
virtual String as_text() const override;
149-
virtual String to_string() override;
149+
virtual String _to_string() override;
150150

151151
InputEventWithModifiers() {}
152152
};
@@ -200,7 +200,7 @@ class InputEventKey : public InputEventWithModifiers {
200200
virtual String as_text_key_label() const;
201201
virtual String as_text_location() const;
202202
virtual String as_text() const override;
203-
virtual String to_string() override;
203+
virtual String _to_string() override;
204204

205205
static Ref<InputEventKey> create_reference(Key p_keycode_with_modifier_masks, bool p_physical = false);
206206

@@ -263,7 +263,7 @@ class InputEventMouseButton : public InputEventMouse {
263263

264264
virtual bool is_action_type() const override { return true; }
265265
virtual String as_text() const override;
266-
virtual String to_string() override;
266+
virtual String _to_string() override;
267267

268268
InputEventType get_type() const final override { return InputEventType::MOUSE_BUTTON; }
269269

@@ -308,7 +308,7 @@ class InputEventMouseMotion : public InputEventMouse {
308308

309309
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
310310
virtual String as_text() const override;
311-
virtual String to_string() override;
311+
virtual String _to_string() override;
312312

313313
virtual bool accumulate(const Ref<InputEvent> &p_event) override;
314314

@@ -337,7 +337,7 @@ class InputEventJoypadMotion : public InputEvent {
337337

338338
virtual bool is_action_type() const override { return true; }
339339
virtual String as_text() const override;
340-
virtual String to_string() override;
340+
virtual String _to_string() override;
341341

342342
// The default device ID is `InputMap::ALL_DEVICES`.
343343
static Ref<InputEventJoypadMotion> create_reference(JoyAxis p_axis, float p_value, int p_device = -1);
@@ -370,7 +370,7 @@ class InputEventJoypadButton : public InputEvent {
370370
virtual bool is_action_type() const override { return true; }
371371

372372
virtual String as_text() const override;
373-
virtual String to_string() override;
373+
virtual String _to_string() override;
374374

375375
// The default device ID is `InputMap::ALL_DEVICES`.
376376
static Ref<InputEventJoypadButton> create_reference(JoyButton p_btn_index, int p_device = -1);
@@ -404,7 +404,7 @@ class InputEventScreenTouch : public InputEventFromWindow {
404404

405405
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
406406
virtual String as_text() const override;
407-
virtual String to_string() override;
407+
virtual String _to_string() override;
408408

409409
InputEventType get_type() const final override { return InputEventType::SCREEN_TOUCH; }
410410

@@ -456,7 +456,7 @@ class InputEventScreenDrag : public InputEventFromWindow {
456456

457457
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
458458
virtual String as_text() const override;
459-
virtual String to_string() override;
459+
virtual String _to_string() override;
460460

461461
virtual bool accumulate(const Ref<InputEvent> &p_event) override;
462462

@@ -495,7 +495,7 @@ class InputEventAction : public InputEvent {
495495
virtual bool is_action_type() const override { return true; }
496496

497497
virtual String as_text() const override;
498-
virtual String to_string() override;
498+
virtual String _to_string() override;
499499

500500
InputEventType get_type() const final override { return InputEventType::ACTION; }
501501

@@ -528,7 +528,7 @@ class InputEventMagnifyGesture : public InputEventGesture {
528528

529529
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
530530
virtual String as_text() const override;
531-
virtual String to_string() override;
531+
virtual String _to_string() override;
532532

533533
InputEventType get_type() const final override { return InputEventType::MAGNIFY_GESTURE; }
534534

@@ -548,7 +548,7 @@ class InputEventPanGesture : public InputEventGesture {
548548

549549
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
550550
virtual String as_text() const override;
551-
virtual String to_string() override;
551+
virtual String _to_string() override;
552552

553553
InputEventType get_type() const final override { return InputEventType::PAN_GESTURE; }
554554

@@ -596,7 +596,7 @@ class InputEventMIDI : public InputEvent {
596596
int get_controller_value() const;
597597

598598
virtual String as_text() const override;
599-
virtual String to_string() override;
599+
virtual String _to_string() override;
600600

601601
InputEventType get_type() const final override { return InputEventType::MIDI; }
602602

@@ -616,7 +616,7 @@ class InputEventShortcut : public InputEvent {
616616
Ref<Shortcut> get_shortcut();
617617

618618
virtual String as_text() const override;
619-
virtual String to_string() override;
619+
virtual String _to_string() override;
620620

621621
InputEventType get_type() const final override { return InputEventType::SHORTCUT; }
622622

core/io/resource.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,10 @@ void Resource::reset_local_to_scene() {
660660
// Restores the state as if setup_local_to_scene() hadn't been called.
661661
}
662662

663+
String Resource::_to_string() {
664+
return (name.is_empty() ? "" : String(name) + " ") + "(" + path_cache + "):" + Object::_to_string();
665+
}
666+
663667
Node *(*Resource::_get_local_scene_func)() = nullptr;
664668
void (*Resource::_update_configuration_warning)() = nullptr;
665669

core/io/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Resource : public RefCounted {
122122
GDVIRTUAL0(_reset_state);
123123

124124
virtual Ref<Resource> _duplicate(const DuplicateParams &p_params) const;
125+
virtual String _to_string() override;
125126

126127
public:
127128
static Node *(*_get_local_scene_func)(); // Used by the editor.

core/object/object.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ String Object::to_string() {
10441044
return ret;
10451045
}
10461046
}
1047-
return "<" + get_class() + "#" + itos(get_instance_id()) + ">";
1047+
return _to_string();
10481048
}
10491049

10501050
void Object::set_script(const Variant &p_script) {
@@ -1839,6 +1839,10 @@ void Object::notify_property_list_changed() {
18391839
emit_signal(CoreStringName(property_list_changed));
18401840
}
18411841

1842+
String Object::_to_string() {
1843+
return "<" + get_class() + "#" + itos(get_instance_id()) + ">";
1844+
}
1845+
18421846
void Object::_bind_methods() {
18431847
ClassDB::bind_method(D_METHOD("get_class"), &Object::get_class);
18441848
ClassDB::bind_method(D_METHOD("is_class", "class"), &Object::is_class);

core/object/object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ class Object {
738738
void _notification_backward(int p_notification);
739739
virtual void _notification_forwardv(int p_notification) {}
740740
virtual void _notification_backwardv(int p_notification) {}
741+
virtual String _to_string();
741742

742743
static void _bind_methods();
743744
static void _bind_compatibility_methods() {}
@@ -919,7 +920,7 @@ class Object {
919920
}
920921
}
921922

922-
virtual String to_string();
923+
String to_string();
923924

924925
// Used mainly by script, get and set all INCLUDING string.
925926
virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const;

core/object/script_backtrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ class ScriptBacktrace : public RefCounted {
8484
Variant get_member_variable_value(int p_frame_index, int p_variable_index) const;
8585

8686
String format(int p_indent_all = 0, int p_indent_frames = 4) const;
87-
virtual String to_string() override { return format(); }
87+
virtual String _to_string() override { return format(); }
8888
};

platform/android/api/java_class_wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class JavaClass : public RefCounted {
205205
bool has_java_method(const StringName &p_method) const;
206206

207207
#ifdef ANDROID_ENABLED
208-
virtual String to_string() override;
208+
virtual String _to_string() override;
209209
#endif
210210

211211
JavaClass();
@@ -232,7 +232,7 @@ class JavaObject : public RefCounted {
232232
bool has_java_method(const StringName &p_method) const;
233233

234234
#ifdef ANDROID_ENABLED
235-
virtual String to_string() override;
235+
virtual String _to_string() override;
236236

237237
jobject get_instance() { return instance; }
238238

platform/android/java_class_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ Ref<JavaClass> JavaClass::get_java_parent_class() const {
826826
return ret;
827827
}
828828

829-
String JavaClass::to_string() {
829+
String JavaClass::_to_string() {
830830
return "<JavaClass:" + java_class_name + ">";
831831
}
832832

@@ -874,11 +874,11 @@ Ref<JavaClass> JavaObject::get_java_class() const {
874874
return base_class;
875875
}
876876

877-
String JavaObject::to_string() {
877+
String JavaObject::_to_string() {
878878
if (base_class.is_valid() && instance) {
879879
return "<JavaObject:" + base_class->java_class_name + " \"" + (String)call("toString") + "\">";
880880
}
881-
return RefCounted::to_string();
881+
return RefCounted::_to_string();
882882
}
883883

884884
bool JavaObject::has_java_method(const StringName &p_method) const {

scene/animation/tween.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ Variant Tween::interpolate_variant(const Variant &p_initial_val, const Variant &
459459
return ret;
460460
}
461461

462-
String Tween::to_string() {
463-
String ret = Object::to_string();
462+
String Tween::_to_string() {
463+
String ret = Object::_to_string();
464464
Node *node = get_bound_node();
465465
if (node) {
466466
ret += vformat(" (bound to %s)", node->get_name());

0 commit comments

Comments
 (0)