summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/core_bind.cpp75
-rw-r--r--core/core_bind.h48
-rw-r--r--core/input/input_event.cpp85
-rw-r--r--core/input/input_event.h16
-rw-r--r--core/input/input_map.cpp5
-rw-r--r--core/io/json.cpp57
-rw-r--r--core/io/json.h38
-rw-r--r--core/io/marshalls.cpp505
-rw-r--r--core/io/marshalls.h32
-rw-r--r--core/object/script_language.h8
-rw-r--r--core/register_core_types.cpp9
-rw-r--r--core/variant/variant.cpp6
-rw-r--r--core/variant/variant.h1
-rw-r--r--doc/classes/@GlobalScope.xml13
-rw-r--r--doc/classes/CallbackTweener.xml29
-rw-r--r--doc/classes/InputEvent.xml15
-rw-r--r--doc/classes/IntervalTweener.xml16
-rw-r--r--doc/classes/JSON.xml69
-rw-r--r--doc/classes/JSONParseResult.xml51
-rw-r--r--doc/classes/JSONParser.xml57
-rw-r--r--doc/classes/MethodTweener.xml43
-rw-r--r--doc/classes/Node.xml10
-rw-r--r--doc/classes/PropertyTweener.xml78
-rw-r--r--doc/classes/SceneTree.xml14
-rw-r--r--doc/classes/Tween.xml509
-rw-r--r--doc/classes/Tweener.xml22
-rw-r--r--editor/code_editor.cpp65
-rw-r--r--editor/code_editor.h9
-rw-r--r--editor/editor_feature_profile.cpp43
-rw-r--r--editor/editor_node.cpp9
-rw-r--r--editor/editor_settings.cpp2
-rw-r--r--editor/export_template_manager.cpp8
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp8
-rw-r--r--editor/plugins/script_text_editor.cpp79
-rw-r--r--editor/plugins/script_text_editor.h3
-rw-r--r--editor/plugins/shader_editor_plugin.cpp4
-rw-r--r--editor/settings_config_dialog.cpp2
-rw-r--r--modules/fbx/tools/validation_tools.h3
-rw-r--r--modules/gdnative/include/pluginscript/godot_pluginscript.h2
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp2
-rw-r--r--modules/gdnative/nativescript/nativescript.h2
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.cpp19
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.h2
-rw-r--r--modules/gdscript/gdscript.h2
-rw-r--r--modules/gdscript/gdscript_editor.cpp20
-rw-r--r--modules/gdscript/language_server/gdscript_extend_parser.cpp10
-rw-r--r--modules/gdscript/language_server/gdscript_language_protocol.cpp5
-rw-r--r--modules/gltf/editor_scene_importer_gltf.cpp1
-rw-r--r--modules/gltf/editor_scene_importer_gltf.h1
-rw-r--r--modules/gltf/gltf_document.cpp24
-rw-r--r--modules/jsonrpc/jsonrpc.cpp13
-rw-r--r--modules/mono/class_db_api_json.cpp3
-rw-r--r--modules/mono/csharp_script.cpp1
-rw-r--r--modules/mono/csharp_script.h5
-rw-r--r--modules/visual_script/visual_script.cpp2
-rw-r--r--modules/visual_script/visual_script.h2
-rw-r--r--platform/android/export/export.cpp2
-rw-r--r--platform/javascript/export/export.cpp9
-rw-r--r--scene/animation/tween.cpp2113
-rw-r--r--scene/animation/tween.h307
-rw-r--r--scene/gui/shortcut.cpp2
-rw-r--r--scene/main/node.cpp9
-rw-r--r--scene/main/node.h5
-rw-r--r--scene/main/scene_tree.cpp55
-rw-r--r--scene/main/scene_tree.h5
-rw-r--r--scene/register_scene_types.cpp5
-rw-r--r--scene/resources/packed_scene.cpp11
-rw-r--r--servers/rendering/renderer_scene_cull.cpp5
-rw-r--r--servers/rendering/renderer_scene_cull.h2
-rw-r--r--tests/test_json.h61
-rw-r--r--thirdparty/misc/easing_equations.cpp4
71 files changed, 2112 insertions, 2645 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 912512d993..912c89a9d2 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -35,7 +35,6 @@
#include "core/debugger/engine_debugger.h"
#include "core/io/file_access_compressed.h"
#include "core/io/file_access_encrypted.h"
-#include "core/io/json.h"
#include "core/io/marshalls.h"
#include "core/math/geometry_2d.h"
#include "core/math/geometry_3d.h"
@@ -2155,80 +2154,6 @@ void _Engine::_bind_methods() {
_Engine *_Engine::singleton = nullptr;
-////// _JSON //////
-
-void JSONParseResult::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_error"), &JSONParseResult::get_error);
- ClassDB::bind_method(D_METHOD("get_error_string"), &JSONParseResult::get_error_string);
- ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParseResult::get_error_line);
- ClassDB::bind_method(D_METHOD("get_result"), &JSONParseResult::get_result);
-
- ClassDB::bind_method(D_METHOD("set_error", "error"), &JSONParseResult::set_error);
- ClassDB::bind_method(D_METHOD("set_error_string", "error_string"), &JSONParseResult::set_error_string);
- ClassDB::bind_method(D_METHOD("set_error_line", "error_line"), &JSONParseResult::set_error_line);
- ClassDB::bind_method(D_METHOD("set_result", "result"), &JSONParseResult::set_result);
-
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "error", PROPERTY_HINT_NONE, "Error", PROPERTY_USAGE_CLASS_IS_ENUM), "set_error", "get_error");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "error_string"), "set_error_string", "get_error_string");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "error_line"), "set_error_line", "get_error_line");
- ADD_PROPERTY(PropertyInfo(Variant::NIL, "result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_result", "get_result");
-}
-
-void JSONParseResult::set_error(Error p_error) {
- error = p_error;
-}
-
-Error JSONParseResult::get_error() const {
- return error;
-}
-
-void JSONParseResult::set_error_string(const String &p_error_string) {
- error_string = p_error_string;
-}
-
-String JSONParseResult::get_error_string() const {
- return error_string;
-}
-
-void JSONParseResult::set_error_line(int p_error_line) {
- error_line = p_error_line;
-}
-
-int JSONParseResult::get_error_line() const {
- return error_line;
-}
-
-void JSONParseResult::set_result(const Variant &p_result) {
- result = p_result;
-}
-
-Variant JSONParseResult::get_result() const {
- return result;
-}
-
-void _JSON::_bind_methods() {
- ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys", "full_precision"), &_JSON::print, DEFVAL(String()), DEFVAL(false), DEFVAL(false));
- ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse);
-}
-
-String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys, bool p_full_precision) {
- return JSON::print(p_value, p_indent, p_sort_keys, p_full_precision);
-}
-
-Ref<JSONParseResult> _JSON::parse(const String &p_json) {
- Ref<JSONParseResult> result;
- result.instance();
-
- result->error = JSON::parse(p_json, result->result, result->error_string, result->error_line);
-
- if (result->error != OK) {
- ERR_PRINT(vformat("Error parsing JSON at line %s: %s", result->error_line, result->error_string));
- }
- return result;
-}
-
-_JSON *_JSON::singleton = nullptr;
-
////// _EngineDebugger //////
void _EngineDebugger::_bind_methods() {
diff --git a/core/core_bind.h b/core/core_bind.h
index 5ab81547d7..74b6a5b26f 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -659,54 +659,6 @@ public:
_Engine() { singleton = this; }
};
-class _JSON;
-
-class JSONParseResult : public RefCounted {
- GDCLASS(JSONParseResult, RefCounted);
-
- friend class _JSON;
-
- Error error;
- String error_string;
- int error_line = -1;
-
- Variant result;
-
-protected:
- static void _bind_methods();
-
-public:
- void set_error(Error p_error);
- Error get_error() const;
-
- void set_error_string(const String &p_error_string);
- String get_error_string() const;
-
- void set_error_line(int p_error_line);
- int get_error_line() const;
-
- void set_result(const Variant &p_result);
- Variant get_result() const;
-
- JSONParseResult() {}
-};
-
-class _JSON : public Object {
- GDCLASS(_JSON, Object);
-
-protected:
- static void _bind_methods();
- static _JSON *singleton;
-
-public:
- static _JSON *get_singleton() { return singleton; }
-
- String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false, bool p_full_precision = false);
- Ref<JSONParseResult> parse(const String &p_json);
-
- _JSON() { singleton = this; }
-};
-
class _EngineDebugger : public Object {
GDCLASS(_EngineDebugger, Object);
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 9c1cf15342..72fb409b63 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -88,7 +88,7 @@ bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, f
return false;
}
-bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const {
+bool InputEvent::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
return false;
}
@@ -110,7 +110,7 @@ void InputEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
- ClassDB::bind_method(D_METHOD("shortcut_match", "event"), &InputEvent::shortcut_match);
+ ClassDB::bind_method(D_METHOD("is_match", "event", "exact_match"), &InputEvent::is_match, DEFVAL(true));
ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
@@ -194,6 +194,23 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif
set_meta_pressed(event->is_meta_pressed());
}
+uint32_t InputEventWithModifiers::get_modifiers_mask() const {
+ uint32_t mask = 0;
+ if (is_ctrl_pressed()) {
+ mask |= KEY_MASK_CTRL;
+ }
+ if (is_shift_pressed()) {
+ mask |= KEY_MASK_SHIFT;
+ }
+ if (is_alt_pressed()) {
+ mask |= KEY_MASK_ALT;
+ }
+ if (is_meta_pressed()) {
+ mask |= KEY_MASK_META;
+ }
+ return mask;
+}
+
String InputEventWithModifiers::as_text() const {
Vector<String> mod_names;
@@ -313,39 +330,11 @@ bool InputEventKey::is_echo() const {
}
uint32_t InputEventKey::get_keycode_with_modifiers() const {
- uint32_t sc = keycode;
- if (is_ctrl_pressed()) {
- sc |= KEY_MASK_CTRL;
- }
- if (is_alt_pressed()) {
- sc |= KEY_MASK_ALT;
- }
- if (is_shift_pressed()) {
- sc |= KEY_MASK_SHIFT;
- }
- if (is_meta_pressed()) {
- sc |= KEY_MASK_META;
- }
-
- return sc;
+ return keycode | get_modifiers_mask();
}
uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
- uint32_t sc = physical_keycode;
- if (is_ctrl_pressed()) {
- sc |= KEY_MASK_CTRL;
- }
- if (is_alt_pressed()) {
- sc |= KEY_MASK_ALT;
- }
- if (is_shift_pressed()) {
- sc |= KEY_MASK_SHIFT;
- }
- if (is_meta_pressed()) {
- sc |= KEY_MASK_META;
- }
-
- return sc;
+ return physical_keycode | get_modifiers_mask();
}
String InputEventKey::as_text() const {
@@ -442,16 +431,14 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed
return match;
}
-bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
+bool InputEventKey::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
Ref<InputEventKey> key = p_event;
if (key.is_null()) {
return false;
}
- uint32_t code = get_keycode_with_modifiers();
- uint32_t event_code = key->get_keycode_with_modifiers();
-
- return code == event_code;
+ return keycode == key->keycode &&
+ (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask());
}
void InputEventKey::_bind_methods() {
@@ -599,6 +586,16 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p
return match;
}
+bool InputEventMouseButton::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_null()) {
+ return false;
+ }
+
+ return button_index == mb->button_index &&
+ (!p_exact_match || get_modifiers_mask() == mb->get_modifiers_mask());
+}
+
static const char *_mouse_button_descriptions[9] = {
TTRC("Left Mouse Button"),
TTRC("Right Mouse Button"),
@@ -904,6 +901,16 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
return match;
}
+bool InputEventJoypadMotion::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
+ Ref<InputEventJoypadMotion> jm = p_event;
+ if (jm.is_null()) {
+ return false;
+ }
+
+ return axis == jm->axis &&
+ (!p_exact_match || ((axis_value < 0) == (jm->axis_value < 0)));
+}
+
static const char *_joy_axis_descriptions[JOY_AXIS_MAX] = {
TTRC("Left Stick X-Axis, Joystick 0 X-Axis"),
TTRC("Left Stick Y-Axis, Joystick 0 Y-Axis"),
@@ -987,7 +994,7 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *
return match;
}
-bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
+bool InputEventJoypadButton::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
Ref<InputEventJoypadButton> button = p_event;
if (button.is_null()) {
return false;
@@ -1229,7 +1236,7 @@ float InputEventAction::get_strength() const {
return strength;
}
-bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
+bool InputEventAction::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) const {
if (p_event.is_null()) {
return false;
}
diff --git a/core/input/input_event.h b/core/input/input_event.h
index eed0d79326..3ef135221d 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -142,7 +142,8 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
+ virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
+
virtual bool is_action_type() const;
virtual bool accumulate(const Ref<InputEvent> &p_event) { return false; }
@@ -212,6 +213,8 @@ public:
void set_modifiers_from_event(const InputEventWithModifiers *event);
+ uint32_t get_modifiers_mask() const;
+
virtual String as_text() const override;
virtual String to_string() override;
@@ -252,7 +255,7 @@ public:
uint32_t get_physical_keycode_with_modifiers() const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
+ virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
@@ -313,7 +316,9 @@ public:
bool is_double_click() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
@@ -373,6 +378,7 @@ public:
virtual bool is_pressed() const override;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
virtual String as_text() const override;
@@ -401,9 +407,10 @@ public:
float get_pressure() const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
+ virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
+
virtual String as_text() const override;
virtual String to_string() override;
@@ -491,9 +498,10 @@ public:
virtual bool is_action(const StringName &p_action) const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
virtual bool is_action_type() const override { return true; }
+
virtual String as_text() const override;
virtual String to_string() override;
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index c43fd64561..52dc561546 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -130,12 +130,9 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
const Ref<InputEvent> e = E->get();
- //if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
- // continue;
-
int device = e->get_device();
if (device == ALL_DEVICES || device == p_event->get_device()) {
- if (p_exact_match && e->shortcut_match(p_event)) {
+ if (p_exact_match && e->is_match(p_event, true)) {
return E;
} else if (!p_exact_match && e->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) {
return E;
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 82ef2a6894..b3a2498212 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -45,7 +45,7 @@ const char *JSON::tk_name[TK_MAX] = {
"EOF",
};
-static String _make_indent(const String &p_indent, int p_size) {
+String JSON::_make_indent(const String &p_indent, int p_size) {
String indent_text = "";
if (!p_indent.is_empty()) {
for (int i = 0; i < p_size; i++) {
@@ -55,7 +55,7 @@ static String _make_indent(const String &p_indent, int p_size) {
return indent_text;
}
-String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision) {
+String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision) {
String colon = ":";
String end_statement = "";
@@ -100,7 +100,7 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
s += ",";
s += end_statement;
}
- s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(a[i], p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
+ s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(a[i], p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
}
s += end_statement + _make_indent(p_indent, p_cur_indent) + "]";
p_markers.erase(a.id());
@@ -126,9 +126,9 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
s += ",";
s += end_statement;
}
- s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
+ s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
s += colon;
- s += _print_var(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
+ s += _stringify(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
}
s += end_statement + _make_indent(p_indent, p_cur_indent) + "}";
@@ -140,11 +140,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
}
-String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) {
- Set<const void *> markers;
- return _print_var(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision);
-}
-
Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
while (p_len > 0) {
switch (p_str[index]) {
@@ -499,7 +494,7 @@ Error JSON::_parse_object(Dictionary &object, const char32_t *p_str, int &index,
return ERR_PARSE_ERROR;
}
-Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
+Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
const char32_t *str = p_json.ptr();
int idx = 0;
int len = p_json.length();
@@ -530,34 +525,24 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &
return err;
}
-Error JSONParser::parse_string(const String &p_json_string) {
- return JSON::parse(p_json_string, data, err_text, err_line);
-}
-String JSONParser::get_error_text() const {
- return err_text;
-}
-int JSONParser::get_error_line() const {
- return err_line;
-}
-Variant JSONParser::get_data() const {
- return data;
+String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) {
+ Set<const void *> markers;
+ return _stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision);
}
-Error JSONParser::decode_data(const Variant &p_data, const String &p_indent, bool p_sort_keys) {
- string = JSON::print(p_data, p_indent, p_sort_keys);
- data = p_data;
- return OK;
+Error JSON::parse(const String &p_json_string) {
+ Error err = _parse_string(p_json_string, data, err_str, err_line);
+ if (err == Error::OK) {
+ err_line = 0;
+ }
+ return err;
}
-String JSONParser::get_string() const {
- return string;
-}
+void JSON::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("parse", "json_string"), &JSON::parse);
-void JSONParser::_bind_methods() {
- ClassDB::bind_method(D_METHOD("parse_string", "json_string"), &JSONParser::parse_string);
- ClassDB::bind_method(D_METHOD("get_error_text"), &JSONParser::get_error_text);
- ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParser::get_error_line);
- ClassDB::bind_method(D_METHOD("get_data"), &JSONParser::get_data);
- ClassDB::bind_method(D_METHOD("decode_data", "data", "indent", "sort_keys"), &JSONParser::decode_data, DEFVAL(""), DEFVAL(true));
- ClassDB::bind_method(D_METHOD("get_string"), &JSONParser::get_string);
+ ClassDB::bind_method(D_METHOD("get_data"), &JSON::get_data);
+ ClassDB::bind_method(D_METHOD("get_error_line"), &JSON::get_error_line);
+ ClassDB::bind_method(D_METHOD("get_error_message"), &JSON::get_error_message);
}
diff --git a/core/io/json.h b/core/io/json.h
index 5be8cc1e86..f20c97f540 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -33,7 +33,10 @@
#include "core/object/ref_counted.h"
#include "core/variant/variant.h"
-class JSON {
+
+class JSON : public RefCounted {
+ GDCLASS(JSON, RefCounted);
+
enum TokenType {
TK_CURLY_BRACKET_OPEN,
TK_CURLY_BRACKET_CLOSE,
@@ -60,39 +63,30 @@ class JSON {
Variant value;
};
- static const char *tk_name[TK_MAX];
+ Variant data;
+ String err_str;
+ int err_line = 0;
- static String _print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision = false);
+ static const char *tk_name[];
+ static String _make_indent(const String &p_indent, int p_size);
+ static String _stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, Set<const void *> &p_markers, bool p_full_precision = false);
static Error _get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
static Error _parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
static Error _parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
static Error _parse_object(Dictionary &object, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
-
-public:
- static String print(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false);
- static Error parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line);
-};
-
-class JSONParser : public RefCounted {
- GDCLASS(JSONParser, RefCounted);
-
- Variant data;
- String string;
- String err_text;
- int err_line = 0;
+ static Error _parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line);
protected:
static void _bind_methods();
public:
- Error parse_string(const String &p_json_string);
- String get_error_text() const;
- int get_error_line() const;
- Variant get_data() const;
+ String stringify(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false);
+ Error parse(const String &p_json_string);
- Error decode_data(const Variant &p_data, const String &p_indent = "", bool p_sort_keys = true);
- String get_string() const;
+ inline Variant get_data() const { return data; }
+ inline int get_error_line() const { return err_line; }
+ inline String get_error_message() const { return err_str; }
};
#endif // JSON_H
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 4c58c84c14..c447e11ee7 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -111,6 +111,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
*r_len = 4;
}
+ // Note: We cannot use sizeof(real_t) for decoding, in case a different size is encoded.
+ // Decoding math types always checks for the encoded size, while encoding always uses compilation setting.
+ // This does lead to some code duplication for decoding, but compatibility is the priority.
switch (type & ENCODE_MASK) {
case Variant::NIL: {
r_variant = Variant();
@@ -144,18 +147,18 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::FLOAT: {
if (type & ENCODE_FLAG_64) {
- ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V((size_t)len < sizeof(double), ERR_INVALID_DATA);
double val = decode_double(buf);
r_variant = val;
if (r_len) {
- (*r_len) += 8;
+ (*r_len) += sizeof(double);
}
} else {
- ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V((size_t)len < sizeof(float), ERR_INVALID_DATA);
float val = decode_float(buf);
r_variant = val;
if (r_len) {
- (*r_len) += 4;
+ (*r_len) += sizeof(float);
}
}
@@ -172,15 +175,25 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
// math types
case Variant::VECTOR2: {
- ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
Vector2 val;
- val.x = decode_float(&buf[0]);
- val.y = decode_float(&buf[4]);
- r_variant = val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 2, ERR_INVALID_DATA);
+ val.x = decode_double(&buf[0]);
+ val.y = decode_double(&buf[sizeof(double)]);
- if (r_len) {
- (*r_len) += 4 * 2;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 2;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 2, ERR_INVALID_DATA);
+ val.x = decode_float(&buf[0]);
+ val.y = decode_float(&buf[sizeof(float)]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 2;
+ }
}
+ r_variant = val;
} break;
case Variant::VECTOR2I: {
@@ -196,17 +209,29 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::RECT2: {
- ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Rect2 val;
- val.position.x = decode_float(&buf[0]);
- val.position.y = decode_float(&buf[4]);
- val.size.x = decode_float(&buf[8]);
- val.size.y = decode_float(&buf[12]);
- r_variant = val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA);
+ val.position.x = decode_double(&buf[0]);
+ val.position.y = decode_double(&buf[sizeof(double)]);
+ val.size.x = decode_double(&buf[sizeof(double) * 2]);
+ val.size.y = decode_double(&buf[sizeof(double) * 3]);
- if (r_len) {
- (*r_len) += 4 * 4;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 4;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA);
+ val.position.x = decode_float(&buf[0]);
+ val.position.y = decode_float(&buf[sizeof(float)]);
+ val.size.x = decode_float(&buf[sizeof(float) * 2]);
+ val.size.y = decode_float(&buf[sizeof(float) * 3]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 4;
+ }
}
+ r_variant = val;
} break;
case Variant::RECT2I: {
@@ -224,16 +249,27 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::VECTOR3: {
- ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
Vector3 val;
- val.x = decode_float(&buf[0]);
- val.y = decode_float(&buf[4]);
- val.z = decode_float(&buf[8]);
- r_variant = val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 3, ERR_INVALID_DATA);
+ val.x = decode_double(&buf[0]);
+ val.y = decode_double(&buf[sizeof(double)]);
+ val.z = decode_double(&buf[sizeof(double) * 2]);
- if (r_len) {
- (*r_len) += 4 * 3;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 3;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 3, ERR_INVALID_DATA);
+ val.x = decode_float(&buf[0]);
+ val.y = decode_float(&buf[sizeof(float)]);
+ val.z = decode_float(&buf[sizeof(float) * 2]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 3;
+ }
}
+ r_variant = val;
} break;
case Variant::VECTOR3I: {
@@ -250,101 +286,177 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::TRANSFORM2D: {
- ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
Transform2D val;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 2; j++) {
- val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 6, ERR_INVALID_DATA);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 2; j++) {
+ val.elements[i][j] = decode_double(&buf[(i * 2 + j) * sizeof(double)]);
+ }
}
- }
- r_variant = val;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 6;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 6, ERR_INVALID_DATA);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 2; j++) {
+ val.elements[i][j] = decode_float(&buf[(i * 2 + j) * sizeof(float)]);
+ }
+ }
- if (r_len) {
- (*r_len) += 4 * 6;
+ if (r_len) {
+ (*r_len) += sizeof(float) * 6;
+ }
}
+ r_variant = val;
} break;
case Variant::PLANE: {
- ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Plane val;
- val.normal.x = decode_float(&buf[0]);
- val.normal.y = decode_float(&buf[4]);
- val.normal.z = decode_float(&buf[8]);
- val.d = decode_float(&buf[12]);
- r_variant = val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA);
+ val.normal.x = decode_double(&buf[0]);
+ val.normal.y = decode_double(&buf[sizeof(double)]);
+ val.normal.z = decode_double(&buf[sizeof(double) * 2]);
+ val.d = decode_double(&buf[sizeof(double) * 3]);
- if (r_len) {
- (*r_len) += 4 * 4;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 4;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA);
+ val.normal.x = decode_float(&buf[0]);
+ val.normal.y = decode_float(&buf[sizeof(float)]);
+ val.normal.z = decode_float(&buf[sizeof(float) * 2]);
+ val.d = decode_float(&buf[sizeof(float) * 3]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 4;
+ }
}
+ r_variant = val;
} break;
case Variant::QUATERNION: {
- ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Quaternion val;
- val.x = decode_float(&buf[0]);
- val.y = decode_float(&buf[4]);
- val.z = decode_float(&buf[8]);
- val.w = decode_float(&buf[12]);
- r_variant = val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 4, ERR_INVALID_DATA);
+ val.x = decode_double(&buf[0]);
+ val.y = decode_double(&buf[sizeof(double)]);
+ val.z = decode_double(&buf[sizeof(double) * 2]);
+ val.w = decode_double(&buf[sizeof(double) * 3]);
- if (r_len) {
- (*r_len) += 4 * 4;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 4;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 4, ERR_INVALID_DATA);
+ val.x = decode_float(&buf[0]);
+ val.y = decode_float(&buf[sizeof(float)]);
+ val.z = decode_float(&buf[sizeof(float) * 2]);
+ val.w = decode_float(&buf[sizeof(float) * 3]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 4;
+ }
}
+ r_variant = val;
} break;
case Variant::AABB: {
- ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
AABB val;
- val.position.x = decode_float(&buf[0]);
- val.position.y = decode_float(&buf[4]);
- val.position.z = decode_float(&buf[8]);
- val.size.x = decode_float(&buf[12]);
- val.size.y = decode_float(&buf[16]);
- val.size.z = decode_float(&buf[20]);
- r_variant = val;
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 6, ERR_INVALID_DATA);
+ val.position.x = decode_double(&buf[0]);
+ val.position.y = decode_double(&buf[sizeof(double)]);
+ val.position.z = decode_double(&buf[sizeof(double) * 2]);
+ val.size.x = decode_double(&buf[sizeof(double) * 3]);
+ val.size.y = decode_double(&buf[sizeof(double) * 4]);
+ val.size.z = decode_double(&buf[sizeof(double) * 5]);
- if (r_len) {
- (*r_len) += 4 * 6;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 6;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 6, ERR_INVALID_DATA);
+ val.position.x = decode_float(&buf[0]);
+ val.position.y = decode_float(&buf[sizeof(float)]);
+ val.position.z = decode_float(&buf[sizeof(float) * 2]);
+ val.size.x = decode_float(&buf[sizeof(float) * 3]);
+ val.size.y = decode_float(&buf[sizeof(float) * 4]);
+ val.size.z = decode_float(&buf[sizeof(float) * 5]);
+
+ if (r_len) {
+ (*r_len) += sizeof(float) * 6;
+ }
}
+ r_variant = val;
} break;
case Variant::BASIS: {
- ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA);
Basis val;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 9, ERR_INVALID_DATA);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ val.elements[i][j] = decode_double(&buf[(i * 3 + j) * sizeof(double)]);
+ }
}
- }
- r_variant = val;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 9;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 9, ERR_INVALID_DATA);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ val.elements[i][j] = decode_float(&buf[(i * 3 + j) * sizeof(float)]);
+ }
+ }
- if (r_len) {
- (*r_len) += 4 * 9;
+ if (r_len) {
+ (*r_len) += sizeof(float) * 9;
+ }
}
+ r_variant = val;
} break;
case Variant::TRANSFORM3D: {
- ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA);
Transform3D val;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_COND_V((size_t)len < sizeof(double) * 12, ERR_INVALID_DATA);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ val.basis.elements[i][j] = decode_double(&buf[(i * 3 + j) * sizeof(double)]);
+ }
}
- }
- val.origin[0] = decode_float(&buf[36]);
- val.origin[1] = decode_float(&buf[40]);
- val.origin[2] = decode_float(&buf[44]);
+ val.origin[0] = decode_double(&buf[sizeof(double) * 9]);
+ val.origin[1] = decode_double(&buf[sizeof(double) * 10]);
+ val.origin[2] = decode_double(&buf[sizeof(double) * 11]);
- r_variant = val;
+ if (r_len) {
+ (*r_len) += sizeof(double) * 12;
+ }
+ } else {
+ ERR_FAIL_COND_V((size_t)len < sizeof(float) * 12, ERR_INVALID_DATA);
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * sizeof(float)]);
+ }
+ }
+ val.origin[0] = decode_float(&buf[sizeof(float) * 9]);
+ val.origin[1] = decode_float(&buf[sizeof(float) * 10]);
+ val.origin[2] = decode_float(&buf[sizeof(float) * 11]);
- if (r_len) {
- (*r_len) += 4 * 12;
+ if (r_len) {
+ (*r_len) += sizeof(float) * 12;
+ }
}
+ r_variant = val;
} break;
-
// misc types
case Variant::COLOR: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
@@ -356,9 +468,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
if (r_len) {
- (*r_len) += 4 * 4;
+ (*r_len) += 4 * 4; // Colors should always be in single-precision.
}
-
} break;
case Variant::STRING_NAME: {
String str;
@@ -463,7 +574,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
if (r_len) {
- (*r_len) += 4;
+ (*r_len) += 4; // Size of count number.
}
for (int i = 0; i < count; i++) {
@@ -516,7 +627,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 4;
if (r_len) {
- (*r_len) += 4;
+ (*r_len) += 4; // Size of count number.
}
Dictionary d;
@@ -559,7 +670,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 4;
if (r_len) {
- (*r_len) += 4;
+ (*r_len) += 4; // Size of count number.
}
Array varr;
@@ -716,9 +827,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 4;
if (r_len) {
- (*r_len) += 4;
+ (*r_len) += 4; // Size of count number.
}
- //printf("string count: %i\n",count);
for (int32_t i = 0; i < count; i++) {
String str;
@@ -739,30 +849,57 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- ERR_FAIL_MUL_OF(count, 4 * 2, ERR_INVALID_DATA);
- ERR_FAIL_COND_V(count < 0 || count * 4 * 2 > len, ERR_INVALID_DATA);
Vector<Vector2> varray;
- if (r_len) {
- (*r_len) += 4;
- }
-
- if (count) {
- varray.resize(count);
- Vector2 *w = varray.ptrw();
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_MUL_OF(count, sizeof(double) * 2, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 2 > (size_t)len, ERR_INVALID_DATA);
- for (int32_t i = 0; i < count; i++) {
- w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0);
- w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1);
+ if (r_len) {
+ (*r_len) += 4; // Size of count number.
}
- int adv = 4 * 2 * count;
+ if (count) {
+ varray.resize(count);
+ Vector2 *w = varray.ptrw();
+
+ for (int32_t i = 0; i < count; i++) {
+ w[i].x = decode_double(buf + i * sizeof(double) * 2 + sizeof(double) * 0);
+ w[i].y = decode_double(buf + i * sizeof(double) * 2 + sizeof(double) * 1);
+ }
+
+ int adv = sizeof(double) * 2 * count;
+
+ if (r_len) {
+ (*r_len) += adv;
+ }
+ len -= adv;
+ buf += adv;
+ }
+ } else {
+ ERR_FAIL_MUL_OF(count, sizeof(float) * 2, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(count < 0 || count * sizeof(float) * 2 > (size_t)len, ERR_INVALID_DATA);
if (r_len) {
- (*r_len) += adv;
+ (*r_len) += 4; // Size of count number.
}
- }
+ if (count) {
+ varray.resize(count);
+ Vector2 *w = varray.ptrw();
+
+ for (int32_t i = 0; i < count; i++) {
+ w[i].x = decode_float(buf + i * sizeof(float) * 2 + sizeof(float) * 0);
+ w[i].y = decode_float(buf + i * sizeof(float) * 2 + sizeof(float) * 1);
+ }
+
+ int adv = sizeof(float) * 2 * count;
+
+ if (r_len) {
+ (*r_len) += adv;
+ }
+ }
+ }
r_variant = varray;
} break;
@@ -772,32 +909,61 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- ERR_FAIL_MUL_OF(count, 4 * 3, ERR_INVALID_DATA);
- ERR_FAIL_COND_V(count < 0 || count * 4 * 3 > len, ERR_INVALID_DATA);
-
Vector<Vector3> varray;
- if (r_len) {
- (*r_len) += 4;
- }
-
- if (count) {
- varray.resize(count);
- Vector3 *w = varray.ptrw();
+ if (type & ENCODE_FLAG_64) {
+ ERR_FAIL_MUL_OF(count, sizeof(double) * 3, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 3 > (size_t)len, ERR_INVALID_DATA);
- for (int32_t i = 0; i < count; i++) {
- w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0);
- w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1);
- w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2);
+ if (r_len) {
+ (*r_len) += 4; // Size of count number.
}
- int adv = 4 * 3 * count;
+ if (count) {
+ varray.resize(count);
+ Vector3 *w = varray.ptrw();
+
+ for (int32_t i = 0; i < count; i++) {
+ w[i].x = decode_double(buf + i * sizeof(double) * 3 + sizeof(double) * 0);
+ w[i].y = decode_double(buf + i * sizeof(double) * 3 + sizeof(double) * 1);
+ w[i].z = decode_double(buf + i * sizeof(double) * 3 + sizeof(double) * 2);
+ }
+
+ int adv = sizeof(double) * 3 * count;
+
+ if (r_len) {
+ (*r_len) += adv;
+ }
+ len -= adv;
+ buf += adv;
+ }
+ } else {
+ ERR_FAIL_MUL_OF(count, sizeof(float) * 3, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(count < 0 || count * sizeof(float) * 3 > (size_t)len, ERR_INVALID_DATA);
if (r_len) {
- (*r_len) += adv;
+ (*r_len) += 4; // Size of count number.
}
- }
+ if (count) {
+ varray.resize(count);
+ Vector3 *w = varray.ptrw();
+
+ for (int32_t i = 0; i < count; i++) {
+ w[i].x = decode_float(buf + i * sizeof(float) * 3 + sizeof(float) * 0);
+ w[i].y = decode_float(buf + i * sizeof(float) * 3 + sizeof(float) * 1);
+ w[i].z = decode_float(buf + i * sizeof(float) * 3 + sizeof(float) * 2);
+ }
+
+ int adv = sizeof(float) * 3 * count;
+
+ if (r_len) {
+ (*r_len) += adv;
+ }
+ len -= adv;
+ buf += adv;
+ }
+ }
r_variant = varray;
} break;
@@ -813,7 +979,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Vector<Color> carray;
if (r_len) {
- (*r_len) += 4;
+ (*r_len) += 4; // Size of count number.
}
if (count) {
@@ -821,6 +987,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Color *w = carray.ptrw();
for (int32_t i = 0; i < count; i++) {
+ // Colors should always be in single-precision.
w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0);
w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1);
w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2);
@@ -882,7 +1049,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
double d = p_variant;
float f = d;
if (double(f) != d) {
- flags |= ENCODE_FLAG_64; //always encode real as double
+ flags |= ENCODE_FLAG_64;
}
} break;
case Variant::OBJECT: {
@@ -1013,11 +1180,11 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
case Variant::VECTOR2: {
if (buf) {
Vector2 v2 = p_variant;
- encode_float(v2.x, &buf[0]);
- encode_float(v2.y, &buf[4]);
+ encode_real(v2.x, &buf[0]);
+ encode_real(v2.y, &buf[sizeof(real_t)]);
}
- r_len += 2 * 4;
+ r_len += 2 * sizeof(real_t);
} break;
case Variant::VECTOR2I: {
@@ -1033,12 +1200,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
case Variant::RECT2: {
if (buf) {
Rect2 r2 = p_variant;
- encode_float(r2.position.x, &buf[0]);
- encode_float(r2.position.y, &buf[4]);
- encode_float(r2.size.x, &buf[8]);
- encode_float(r2.size.y, &buf[12]);
+ encode_real(r2.position.x, &buf[0]);
+ encode_real(r2.position.y, &buf[sizeof(real_t)]);
+ encode_real(r2.size.x, &buf[sizeof(real_t) * 2]);
+ encode_real(r2.size.y, &buf[sizeof(real_t) * 3]);
}
- r_len += 4 * 4;
+ r_len += 4 * sizeof(real_t);
} break;
case Variant::RECT2I: {
@@ -1055,12 +1222,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
case Variant::VECTOR3: {
if (buf) {
Vector3 v3 = p_variant;
- encode_float(v3.x, &buf[0]);
- encode_float(v3.y, &buf[4]);
- encode_float(v3.z, &buf[8]);
+ encode_real(v3.x, &buf[0]);
+ encode_real(v3.y, &buf[sizeof(real_t)]);
+ encode_real(v3.z, &buf[sizeof(real_t) * 2]);
}
- r_len += 3 * 4;
+ r_len += 3 * sizeof(real_t);
} break;
case Variant::VECTOR3I: {
@@ -1079,50 +1246,50 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
Transform2D val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
- memcpy(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float));
+ memcpy(&buf[(i * 2 + j) * sizeof(real_t)], &val.elements[i][j], sizeof(real_t));
}
}
}
- r_len += 6 * 4;
+ r_len += 6 * sizeof(real_t);
} break;
case Variant::PLANE: {
if (buf) {
Plane p = p_variant;
- encode_float(p.normal.x, &buf[0]);
- encode_float(p.normal.y, &buf[4]);
- encode_float(p.normal.z, &buf[8]);
- encode_float(p.d, &buf[12]);
+ encode_real(p.normal.x, &buf[0]);
+ encode_real(p.normal.y, &buf[sizeof(real_t)]);
+ encode_real(p.normal.z, &buf[sizeof(real_t) * 2]);
+ encode_real(p.d, &buf[sizeof(real_t) * 3]);
}
- r_len += 4 * 4;
+ r_len += 4 * sizeof(real_t);
} break;
case Variant::QUATERNION: {
if (buf) {
Quaternion q = p_variant;
- encode_float(q.x, &buf[0]);
- encode_float(q.y, &buf[4]);
- encode_float(q.z, &buf[8]);
- encode_float(q.w, &buf[12]);
+ encode_real(q.x, &buf[0]);
+ encode_real(q.y, &buf[sizeof(real_t)]);
+ encode_real(q.z, &buf[sizeof(real_t) * 2]);
+ encode_real(q.w, &buf[sizeof(real_t) * 3]);
}
- r_len += 4 * 4;
+ r_len += 4 * sizeof(real_t);
} break;
case Variant::AABB: {
if (buf) {
AABB aabb = p_variant;
- encode_float(aabb.position.x, &buf[0]);
- encode_float(aabb.position.y, &buf[4]);
- encode_float(aabb.position.z, &buf[8]);
- encode_float(aabb.size.x, &buf[12]);
- encode_float(aabb.size.y, &buf[16]);
- encode_float(aabb.size.z, &buf[20]);
+ encode_real(aabb.position.x, &buf[0]);
+ encode_real(aabb.position.y, &buf[sizeof(real_t)]);
+ encode_real(aabb.position.z, &buf[sizeof(real_t) * 2]);
+ encode_real(aabb.size.x, &buf[sizeof(real_t) * 3]);
+ encode_real(aabb.size.y, &buf[sizeof(real_t) * 4]);
+ encode_real(aabb.size.z, &buf[sizeof(real_t) * 5]);
}
- r_len += 6 * 4;
+ r_len += 6 * sizeof(real_t);
} break;
case Variant::BASIS: {
@@ -1130,12 +1297,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
Basis val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float));
+ memcpy(&buf[(i * 3 + j) * sizeof(real_t)], &val.elements[i][j], sizeof(real_t));
}
}
}
- r_len += 9 * 4;
+ r_len += 9 * sizeof(real_t);
} break;
case Variant::TRANSFORM3D: {
@@ -1143,16 +1310,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
Transform3D val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float));
+ memcpy(&buf[(i * 3 + j) * sizeof(real_t)], &val.basis.elements[i][j], sizeof(real_t));
}
}
- encode_float(val.origin.x, &buf[36]);
- encode_float(val.origin.y, &buf[40]);
- encode_float(val.origin.z, &buf[44]);
+ encode_real(val.origin.x, &buf[sizeof(real_t) * 9]);
+ encode_real(val.origin.y, &buf[sizeof(real_t) * 10]);
+ encode_real(val.origin.z, &buf[sizeof(real_t) * 11]);
}
- r_len += 12 * 4;
+ r_len += 12 * sizeof(real_t);
} break;
@@ -1166,7 +1333,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_float(c.a, &buf[12]);
}
- r_len += 4 * 4;
+ r_len += 4 * 4; // Colors should always be in single-precision.
} break;
case Variant::RID: {
@@ -1441,13 +1608,13 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
for (int i = 0; i < len; i++) {
Vector2 v = data.get(i);
- encode_float(v.x, &buf[0]);
- encode_float(v.y, &buf[4]);
- buf += 4 * 2;
+ encode_real(v.x, &buf[0]);
+ encode_real(v.y, &buf[sizeof(real_t)]);
+ buf += sizeof(real_t) * 2;
}
}
- r_len += 4 * 2 * len;
+ r_len += sizeof(real_t) * 2 * len;
} break;
case Variant::PACKED_VECTOR3_ARRAY: {
@@ -1465,14 +1632,14 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
for (int i = 0; i < len; i++) {
Vector3 v = data.get(i);
- encode_float(v.x, &buf[0]);
- encode_float(v.y, &buf[4]);
- encode_float(v.z, &buf[8]);
- buf += 4 * 3;
+ encode_real(v.x, &buf[0]);
+ encode_real(v.y, &buf[sizeof(real_t)]);
+ encode_real(v.z, &buf[sizeof(real_t) * 2]);
+ buf += sizeof(real_t) * 3;
}
}
- r_len += 4 * 3 * len;
+ r_len += sizeof(real_t) * 3 * len;
} break;
case Variant::PACKED_COLOR_ARRAY: {
@@ -1494,7 +1661,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_float(c.g, &buf[4]);
encode_float(c.b, &buf[8]);
encode_float(c.a, &buf[12]);
- buf += 4 * 4;
+ buf += 4 * 4; // Colors should always be in single-precision.
}
}
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 7fac708f97..3ebed914a3 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -31,10 +31,18 @@
#ifndef MARSHALLS_H
#define MARSHALLS_H
+#include "core/math/math_defs.h"
#include "core/object/ref_counted.h"
#include "core/typedefs.h"
#include "core/variant/variant.h"
+// uintr_t is only for pairing with real_t, and we only need it in here.
+#ifdef REAL_T_IS_DOUBLE
+typedef uint64_t uintr_t;
+#else
+typedef uint32_t uintr_t;
+#endif
+
/**
* Miscellaneous helpers for marshalling data types, and encoding
* in an endian independent way
@@ -50,6 +58,12 @@ union MarshallDouble {
double d; ///< double
};
+// Behaves like one of the above, depending on compilation setting.
+union MarshallReal {
+ uintr_t i;
+ real_t r;
+};
+
static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
for (int i = 0; i < 2; i++) {
*p_arr = p_uint & 0xFF;
@@ -96,6 +110,24 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
return sizeof(uint64_t);
}
+static inline unsigned int encode_uintr(uintr_t p_uint, uint8_t *p_arr) {
+ for (size_t i = 0; i < sizeof(uintr_t); i++) {
+ *p_arr = p_uint & 0xFF;
+ p_arr++;
+ p_uint >>= 8;
+ }
+
+ return sizeof(uintr_t);
+}
+
+static inline unsigned int encode_real(real_t p_real, uint8_t *p_arr) {
+ MarshallReal mr;
+ mr.r = p_real;
+ encode_uintr(mr.i, p_arr);
+
+ return sizeof(uintr_t);
+}
+
static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
int len = 0;
diff --git a/core/object/script_language.h b/core/object/script_language.h
index a22e91870e..5d1f6a0deb 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -268,6 +268,12 @@ public:
String message;
};
+ struct ScriptError {
+ int line = -1;
+ int column = -1;
+ String message;
+ };
+
void get_core_type_words(List<String> *p_core_type_words) const;
virtual void get_reserved_words(List<String> *p_words) const = 0;
virtual bool is_control_flow_keyword(String p_string) const = 0;
@@ -276,7 +282,7 @@ public:
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const = 0;
virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {}
virtual bool is_using_templates() { return false; }
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const = 0;
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const = 0;
virtual String validate_path(const String &p_path) const { return ""; }
virtual Script *create_script() const = 0;
virtual bool has_named_classes() const = 0;
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index f67d615418..fc8ab72e1a 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -86,7 +86,6 @@ static _OS *_os = nullptr;
static _Engine *_engine = nullptr;
static _ClassDB *_classdb = nullptr;
static _Marshalls *_marshalls = nullptr;
-static _JSON *_json = nullptr;
static _EngineDebugger *_engine_debugger = nullptr;
static IP *ip = nullptr;
@@ -199,7 +198,7 @@ void register_core_types() {
ClassDB::register_class<_Semaphore>();
ClassDB::register_class<XMLParser>();
- ClassDB::register_class<JSONParser>();
+ ClassDB::register_class<JSON>();
ClassDB::register_class<ConfigFile>();
@@ -212,8 +211,6 @@ void register_core_types() {
ClassDB::register_class<EncodedObjectAsID>();
ClassDB::register_class<RandomNumberGenerator>();
- ClassDB::register_class<JSONParseResult>();
-
ClassDB::register_virtual_class<ResourceImporter>();
ip = IP::create();
@@ -227,7 +224,6 @@ void register_core_types() {
_engine = memnew(_Engine);
_classdb = memnew(_ClassDB);
_marshalls = memnew(_Marshalls);
- _json = memnew(_JSON);
_engine_debugger = memnew(_EngineDebugger);
}
@@ -256,7 +252,6 @@ void register_core_singletons() {
ClassDB::register_class<TranslationServer>();
ClassDB::register_virtual_class<Input>();
ClassDB::register_class<InputMap>();
- ClassDB::register_class<_JSON>();
ClassDB::register_class<Expression>();
ClassDB::register_class<_EngineDebugger>();
ClassDB::register_class<Time>();
@@ -274,7 +269,6 @@ void register_core_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("TranslationServer", TranslationServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Input", Input::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton()));
- Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("EngineDebugger", _EngineDebugger::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Time", Time::get_singleton()));
}
@@ -286,7 +280,6 @@ void unregister_core_types() {
memdelete(_engine);
memdelete(_classdb);
memdelete(_marshalls);
- memdelete(_json);
memdelete(_engine_debugger);
memdelete(_geometry_2d);
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index 4e45862fd3..badb5ba103 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -32,6 +32,7 @@
#include "core/core_string_names.h"
#include "core/debugger/engine_debugger.h"
+#include "core/io/json.h"
#include "core/io/marshalls.h"
#include "core/io/resource.h"
#include "core/math/math_funcs.h"
@@ -1838,6 +1839,11 @@ String Variant::stringify(List<const void *> &stack) const {
return "";
}
+String Variant::to_json_string() const {
+ JSON json;
+ return json.stringify(*this);
+}
+
Variant::operator Vector2() const {
if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 75316da63f..125173ea5c 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -645,6 +645,7 @@ public:
bool hash_compare(const Variant &p_variant) const;
bool booleanize() const;
String stringify(List<const void *> &stack) const;
+ String to_json_string() const;
void static_assign(const Variant &p_variant);
static void get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants);
diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml
index 552fc41318..fa118bec54 100644
--- a/doc/classes/@GlobalScope.xml
+++ b/doc/classes/@GlobalScope.xml
@@ -1066,11 +1066,13 @@
<description>
Returns the internal type of the given Variant object, using the [enum Variant.Type] values.
[codeblock]
- p = parse_json('["a", "b", "c"]')
- if typeof(p) == TYPE_ARRAY:
- print(p[0]) # Prints a
+ var json = JSON.new()
+ json.parse('["a", "b", "c"]')
+ var result = json.get_data()
+ if typeof(result) == TYPE_ARRAY:
+ print(result[0]) # Prints a
else:
- print("unexpected results")
+ print("Unexpected result")
[/codeblock]
</description>
</method>
@@ -1211,9 +1213,6 @@
<member name="InputMap" type="InputMap" setter="" getter="">
The [InputMap] singleton.
</member>
- <member name="JSON" type="JSON" setter="" getter="">
- The [JSON] singleton.
- </member>
<member name="JavaClassWrapper" type="JavaClassWrapper" setter="" getter="">
The [JavaClassWrapper] singleton.
[b]Note:[/b] Only implemented on Android.
diff --git a/doc/classes/CallbackTweener.xml b/doc/classes/CallbackTweener.xml
new file mode 100644
index 0000000000..8ac285c3df
--- /dev/null
+++ b/doc/classes/CallbackTweener.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="CallbackTweener" inherits="Tweener" version="4.0">
+ <brief_description>
+ Calls the specified method after optional delay.
+ </brief_description>
+ <description>
+ [CallbackTweener] is used to call a method in a tweening sequence. See [method Tween.tween_callback] for more usage information.
+ [b]Note:[/b] [method Tween.tween_callback] is the only correct way to create [CallbackTweener]. Any [CallbackTweener] created manually will not function correctly.
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="set_delay">
+ <return type="CallbackTweener">
+ </return>
+ <argument index="0" name="delay" type="float">
+ </argument>
+ <description>
+ Makes the callback call delayed by given time in seconds. Example:
+ [codeblock]
+ var tween = get_tree().create_tween()
+ tween.tween_callback(queue_free).set_delay(2) #this will call queue_free() after 2 seconds
+ [/codeblock]
+ </description>
+ </method>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/InputEvent.xml b/doc/classes/InputEvent.xml
index 0c8db0de73..c28c4c4282 100644
--- a/doc/classes/InputEvent.xml
+++ b/doc/classes/InputEvent.xml
@@ -90,20 +90,23 @@
Returns [code]true[/code] if this input event is an echo event (only for events of type [InputEventKey]).
</description>
</method>
- <method name="is_pressed" qualifiers="const">
+ <method name="is_match" qualifiers="const">
<return type="bool">
</return>
+ <argument index="0" name="event" type="InputEvent">
+ </argument>
+ <argument index="1" name="exact_match" type="bool" default="true">
+ </argument>
<description>
- Returns [code]true[/code] if this input event is pressed. Not relevant for events of type [InputEventMouseMotion] or [InputEventScreenDrag].
+ Returns [code]true[/code] if the specified [code]event[/code] matches this event. Only valid for action events i.e key ([InputEventKey]), button ([InputEventMouseButton] or [InputEventJoypadButton]), axis [InputEventJoypadMotion] or action ([InputEventAction]) events.
+ If [code]exact_match[/code] is [code]false[/code], it ignores the input modifiers for [InputEventKey] and [InputEventMouseButton] events, and the direction for [InputEventJoypadMotion] events.
</description>
</method>
- <method name="shortcut_match" qualifiers="const">
+ <method name="is_pressed" qualifiers="const">
<return type="bool">
</return>
- <argument index="0" name="event" type="InputEvent">
- </argument>
<description>
- Returns [code]true[/code] if the given input event is checking for the same key ([InputEventKey]), button ([InputEventJoypadButton]) or action ([InputEventAction]).
+ Returns [code]true[/code] if this input event is pressed. Not relevant for events of type [InputEventMouseMotion] or [InputEventScreenDrag].
</description>
</method>
<method name="xformed_by" qualifiers="const">
diff --git a/doc/classes/IntervalTweener.xml b/doc/classes/IntervalTweener.xml
new file mode 100644
index 0000000000..1c59003c70
--- /dev/null
+++ b/doc/classes/IntervalTweener.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="IntervalTweener" inherits="Tweener" version="4.0">
+ <brief_description>
+ Creates an idle interval in a [Tween] animation.
+ </brief_description>
+ <description>
+ [IntervalTweener] is used to make delays in a tweening sequence. See [method Tween.tween_interval] for more usage information.
+ [b]Note:[/b] [method Tween.tween_interval] is the only correct way to create [IntervalTweener]. Any [IntervalTweener] created manually will not function correctly.
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml
index 7baff7aa39..b95aaed143 100644
--- a/doc/classes/JSON.xml
+++ b/doc/classes/JSON.xml
@@ -1,45 +1,88 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="JSON" inherits="Object" version="4.0">
+<class name="JSON" inherits="RefCounted" version="4.0">
<brief_description>
- Helper class for parsing JSON data.
+ Helper class for creating and parsing JSON data.
</brief_description>
<description>
- Helper class for parsing JSON data. For usage example and other important hints, see [JSONParseResult].
+ The [JSON] enables all data types to be converted to and from a JSON string. This useful for serializing data to save to a file or send over the network.
+ [method stringify] is used to convert any data type into a JSON string.
+ [method parse] is used to convert any existing JSON data into a [Variant] that can be used within Godot. If successfully parsed, use [method get_data] to retrieve the [Variant], and use [code]typeof[/code] to check if the Variant's type is what you expect. JSON Objects are converted into a [Dictionary], but JSON data can be used to store [Array]s, numbers, [String]s and even just a boolean.
+ [b]Example[/b]
+ [codeblock]
+ var data_to_send = ["a", "b", "c"]
+ var json = JSON.new()
+ var json_string = json.stringify(data_to_send)
+ # Save data
+ # ...
+ # Retrieve data
+ var error = json.parse(json_string)
+ if error == OK:
+ var data_received = json.get_data()
+ if typeof(data_received) == TYPE_ARRAY:
+ print(data_received) # Prints array
+ else:
+ print("Unexpected data")
+ else:
+ print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
+ [/codeblock]
</description>
<tutorials>
</tutorials>
<methods>
+ <method name="get_data" qualifiers="const">
+ <return type="Variant">
+ </return>
+ <description>
+ Returns the [Variant] containing the data of a successful [method parse].
+ [b]Note:[/b] It will return [code]Null[/code] if the last call to parse was unsuccessful or [method parse] has not yet been called.
+ </description>
+ </method>
+ <method name="get_error_line" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns [code]0[/code] if the last call to [method parse] was successful, or the line number where the parse failed.
+ </description>
+ </method>
+ <method name="get_error_message" qualifiers="const">
+ <return type="String">
+ </return>
+ <description>
+ Returns an empty string if the last call to [method parse] was successful, or the error message if it failed.
+ </description>
+ </method>
<method name="parse">
- <return type="JSONParseResult">
+ <return type="int" enum="Error">
</return>
- <argument index="0" name="json" type="String">
+ <argument index="0" name="json_string" type="String">
</argument>
<description>
- Parses a JSON-encoded string and returns a [JSONParseResult] containing the result.
+ Attempts to parse the [code]json_string[/code] provided.
+ Returns an [enum Error]. If the parse was successful, it returns [code]OK[/code] and the result can be retrieved using [method get_data]. If unsuccessful, use [method get_error_line] and [method get_error_message] for identifying the source of the failure.
</description>
</method>
- <method name="print">
+ <method name="stringify">
<return type="String">
</return>
- <argument index="0" name="value" type="Variant">
+ <argument index="0" name="data" type="Variant">
</argument>
<argument index="1" name="indent" type="String" default="&quot;&quot;">
</argument>
- <argument index="2" name="sort_keys" type="bool" default="false">
+ <argument index="2" name="sort_keys" type="bool" default="true">
</argument>
<argument index="3" name="full_precision" type="bool" default="false">
</argument>
<description>
Converts a [Variant] var to JSON text and returns the result. Useful for serializing data to store or send over the network.
[b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, converting a Variant to JSON text will convert all numerical values to [float] types.
- [b]Note:[/b] If [code]full_precision[/code] is true, when printing floats, the unreliable digits are printed in addition to the reliable digits to guarantee exact decoding.
- Use [code]indent[/code] parameter to pretty print the output.
+ [b]Note:[/b] If [code]full_precision[/code] is true, when stringifying floats, the unreliable digits are stringified in addition to the reliable digits to guarantee exact decoding.
+ Use [code]indent[/code] parameter to pretty stringify the output.
[b]Example output:[/b]
[codeblock]
- ## JSON.print(my_dictionary)
+ ## JSON.stringify(my_dictionary)
{"name":"my_dictionary","version":"1.0.0","entities":[{"name":"entity_0","value":"value_0"},{"name":"entity_1","value":"value_1"}]}
- ## JSON.print(my_dictionary, "\t")
+ ## JSON.stringify(my_dictionary, "\t")
{
"name": "my_dictionary",
"version": "1.0.0",
diff --git a/doc/classes/JSONParseResult.xml b/doc/classes/JSONParseResult.xml
deleted file mode 100644
index 7311343b68..0000000000
--- a/doc/classes/JSONParseResult.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="JSONParseResult" inherits="RefCounted" version="4.0">
- <brief_description>
- Data class wrapper for decoded JSON.
- </brief_description>
- <description>
- Returned by [method JSON.parse], [JSONParseResult] contains the decoded JSON or error information if the JSON source wasn't successfully parsed. You can check if the JSON source was successfully parsed with [code]if json_result.error == OK[/code].
- </description>
- <tutorials>
- </tutorials>
- <methods>
- </methods>
- <members>
- <member name="error" type="int" setter="set_error" getter="get_error" enum="Error">
- The error type if the JSON source was not successfully parsed. See the [enum Error] constants.
- </member>
- <member name="error_line" type="int" setter="set_error_line" getter="get_error_line" default="-1">
- The line number where the error occurred if the JSON source was not successfully parsed.
- </member>
- <member name="error_string" type="String" setter="set_error_string" getter="get_error_string" default="&quot;&quot;">
- The error message if the JSON source was not successfully parsed. See the [enum Error] constants.
- </member>
- <member name="result" type="Variant" setter="set_result" getter="get_result">
- A [Variant] containing the parsed JSON. Use [method @GlobalScope.typeof] or the [code]is[/code] keyword to check if it is what you expect. For example, if the JSON source starts with curly braces ([code]{}[/code]), a [Dictionary] will be returned. If the JSON source starts with brackets ([code][][/code]), an [Array] will be returned.
- [b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, parsing a JSON text will convert all numerical values to [float] types.
- [b]Note:[/b] JSON objects do not preserve key order like Godot dictionaries, thus, you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements:
- [codeblocks]
- [gdscript]
- var p = JSON.parse('["hello", "world", "!"]')
- if typeof(p.result) == TYPE_ARRAY:
- print(p.result[0]) # Prints "hello"
- else:
- push_error("Unexpected results.")
- [/gdscript]
- [csharp]
- JSONParseResult p = JSON.Parse("[\"hello\"], \"world\", \"!\"]");
- if (p.Result is Godot.Collections.Array)
- {
- GD.Print((p.Result as Godot.Collections.Array)[0]); // Prints "hello"
- }
- else
- {
- GD.PushError("Unexpected results.");
- }
- [/csharp]
- [/codeblocks]
- </member>
- </members>
- <constants>
- </constants>
-</class>
diff --git a/doc/classes/JSONParser.xml b/doc/classes/JSONParser.xml
deleted file mode 100644
index 991629f255..0000000000
--- a/doc/classes/JSONParser.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<class name="JSONParser" inherits="RefCounted" version="4.0">
- <brief_description>
- </brief_description>
- <description>
- </description>
- <tutorials>
- </tutorials>
- <methods>
- <method name="decode_data">
- <return type="int" enum="Error">
- </return>
- <argument index="0" name="data" type="Variant">
- </argument>
- <argument index="1" name="indent" type="String" default="&quot;&quot;">
- </argument>
- <argument index="2" name="sort_keys" type="bool" default="true">
- </argument>
- <description>
- </description>
- </method>
- <method name="get_data" qualifiers="const">
- <return type="Variant">
- </return>
- <description>
- </description>
- </method>
- <method name="get_error_line" qualifiers="const">
- <return type="int">
- </return>
- <description>
- </description>
- </method>
- <method name="get_error_text" qualifiers="const">
- <return type="String">
- </return>
- <description>
- </description>
- </method>
- <method name="get_string" qualifiers="const">
- <return type="String">
- </return>
- <description>
- </description>
- </method>
- <method name="parse_string">
- <return type="int" enum="Error">
- </return>
- <argument index="0" name="json_string" type="String">
- </argument>
- <description>
- </description>
- </method>
- </methods>
- <constants>
- </constants>
-</class>
diff --git a/doc/classes/MethodTweener.xml b/doc/classes/MethodTweener.xml
new file mode 100644
index 0000000000..42b91abf93
--- /dev/null
+++ b/doc/classes/MethodTweener.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="MethodTweener" inherits="Tweener" version="4.0">
+ <brief_description>
+ Interpolates an abstract value and supplies it to a method called over time.
+ </brief_description>
+ <description>
+ [MethodTweener] is similar to a combination of [CallbackTweener] and [PropertyTweener]. It calls a method providing an interpolated value as a paramater. See [method Tween.tween_method] for more usage information.
+ [b]Note:[/b] [method Tween.tween_method] is the only correct way to create [MethodTweener]. Any [MethodTweener] created manually will not function correctly.
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="set_delay">
+ <return type="MethodTweener">
+ </return>
+ <argument index="0" name="delay" type="float">
+ </argument>
+ <description>
+ Sets the time in seconds after which the [MethodTweener] will start interpolating. By default there's no delay.
+ </description>
+ </method>
+ <method name="set_ease">
+ <return type="MethodTweener">
+ </return>
+ <argument index="0" name="ease" type="int" enum="Tween.EaseType">
+ </argument>
+ <description>
+ Sets the type of used easing from [enum Tween.EaseType]. If not set, the default easing is used from the [Tween] that contains this Tweener.
+ </description>
+ </method>
+ <method name="set_trans">
+ <return type="MethodTweener">
+ </return>
+ <argument index="0" name="trans" type="int" enum="Tween.TransitionType">
+ </argument>
+ <description>
+ Sets the type of used transition from [enum Tween.TransitionType]. If not set, the default transition is used from the [Tween] that contains this Tweener.
+ </description>
+ </method>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml
index a9c38e4d06..87dcfe18cf 100644
--- a/doc/classes/Node.xml
+++ b/doc/classes/Node.xml
@@ -182,6 +182,16 @@
Returns [code]true[/code] if the node can process while the scene tree is paused (see [member process_mode]). Always returns [code]true[/code] if the scene tree is not paused, and [code]false[/code] if the node is not in the tree.
</description>
</method>
+ <method name="create_tween">
+ <return type="Tween">
+ </return>
+ <description>
+ Creates a new [Tween] and binds it to this node. This is equivalent of doing:
+ [codeblock]
+ get_tree().create_tween().bind_node(self)
+ [/codeblock]
+ </description>
+ </method>
<method name="duplicate" qualifiers="const">
<return type="Node">
</return>
diff --git a/doc/classes/PropertyTweener.xml b/doc/classes/PropertyTweener.xml
new file mode 100644
index 0000000000..1e77bb33c6
--- /dev/null
+++ b/doc/classes/PropertyTweener.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="PropertyTweener" inherits="Tweener" version="4.0">
+ <brief_description>
+ Interpolates an [Object]'s property over time.
+ </brief_description>
+ <description>
+ [PropertyTweener] is used to interpolate a property in an object. See [method Tween.tween_property] for more usage information.
+ [b]Note:[/b] [method Tween.tween_property] is the only correct way to create [PropertyTweener]. Any [PropertyTweener] created manually will not function correctly.
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ <method name="as_relative">
+ <return type="PropertyTweener">
+ </return>
+ <description>
+ When called, the final value will be used as a relative value instead. Example:
+ [codeblock]
+ var tween = get_tree().create_tween()
+ tween.tween_property(self, "position", Vector2.RIGHT * 100, 1).as_relative() #the node will move by 100 pixels to the right
+ [/codeblock]
+ </description>
+ </method>
+ <method name="from">
+ <return type="PropertyTweener">
+ </return>
+ <argument index="0" name="value" type="Variant">
+ </argument>
+ <description>
+ Sets a custom initial value to the [PropertyTweener]. Example:
+ [codeblock]
+ var tween = get_tree().create_tween()
+ tween.tween_property(self, "position", Vector2(200, 100), 1).from(Vector2(100, 100) #this will move the node from position (100, 100) to (200, 100)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="from_current">
+ <return type="PropertyTweener">
+ </return>
+ <description>
+ Makes the [PropertyTweener] use the current property value (i.e. at the time of creating this [PropertyTweener]) as a starting point. This is equivalent of using [method from] with the current value. These two calls will do the same:
+ [codeblock]
+ tween.tween_property(self, "position", Vector2(200, 100), 1).from(position)
+ tween.tween_property(self, "position", Vector2(200, 100), 1).from_current()
+ [/codeblock]
+ </description>
+ </method>
+ <method name="set_delay">
+ <return type="PropertyTweener">
+ </return>
+ <argument index="0" name="delay" type="float">
+ </argument>
+ <description>
+ Sets the time in seconds after which the [PropertyTweener] will start interpolating. By default there's no delay.
+ </description>
+ </method>
+ <method name="set_ease">
+ <return type="PropertyTweener">
+ </return>
+ <argument index="0" name="ease" type="int" enum="Tween.EaseType">
+ </argument>
+ <description>
+ Sets the type of used easing from [enum Tween.EaseType]. If not set, the default easing is used from the [Tween] that contains this Tweener.
+ </description>
+ </method>
+ <method name="set_trans">
+ <return type="PropertyTweener">
+ </return>
+ <argument index="0" name="trans" type="int" enum="Tween.TransitionType">
+ </argument>
+ <description>
+ Sets the type of used transition from [enum Tween.TransitionType]. If not set, the default transition is used from the [Tween] that contains this Tweener.
+ </description>
+ </method>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/doc/classes/SceneTree.xml b/doc/classes/SceneTree.xml
index 7a15153fc2..d327e8cbca 100644
--- a/doc/classes/SceneTree.xml
+++ b/doc/classes/SceneTree.xml
@@ -90,6 +90,13 @@
The timer will be automatically freed after its time elapses.
</description>
</method>
+ <method name="create_tween">
+ <return type="Tween">
+ </return>
+ <description>
+ Creates and returns a new [Tween].
+ </description>
+ </method>
<method name="get_first_node_in_group">
<return type="Node">
</return>
@@ -135,6 +142,13 @@
Returns a list of all nodes assigned to the given group.
</description>
</method>
+ <method name="get_processed_tweens">
+ <return type="Array">
+ </return>
+ <description>
+ Returns an array of currently exising [Tween]s in the [SceneTree] (both running and paused).
+ </description>
+ </method>
<method name="get_rpc_sender_id" qualifiers="const">
<return type="int">
</return>
diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml
index 00cca40093..ed193b9f7e 100644
--- a/doc/classes/Tween.xml
+++ b/doc/classes/Tween.xml
@@ -1,453 +1,398 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="Tween" inherits="Node" version="4.0">
+<class name="Tween" inherits="RefCounted" version="4.0">
<brief_description>
- Smoothly animates a node's properties over time.
+ Lightweight object used for general-purpose animation via script, using [Tweener]s.
</brief_description>
<description>
- Tweens are useful for animations requiring a numerical property to be interpolated over a range of values. The name [i]tween[/i] comes from [i]in-betweening[/i], an animation technique where you specify [i]keyframes[/i] and the computer interpolates the frames that appear between them.
- [Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween] node; it would be difficult to do the same thing with an [AnimationPlayer] node.
- Here is a brief usage example that makes a 2D node move smoothly between two positions:
- [codeblocks]
- [gdscript]
- var tween = get_node("Tween")
- tween.interpolate_property($Node2D, "position",
- Vector2(0, 0), Vector2(100, 100), 1,
- Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
- tween.start()
- [/gdscript]
- [csharp]
- var tween = GetNode&lt;Tween&gt;("Tween");
- tween.InterpolateProperty(GetNode&lt;Node2D&gt;("Node2D"), "position",
- new Vector2(0, 0), new Vector2(100, 100), 1,
- Tween.TransitionType.Linear, Tween.EaseType.InOut);
- tween.Start();
- [/csharp]
- [/codeblocks]
- Many methods require a property name, such as [code]"position"[/code] above. You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using [code]"property:component"[/code] (e.g. [code]position:x[/code]), where it would only apply to that particular component.
- Many of the methods accept [code]trans_type[/code] and [code]ease_type[/code]. The first accepts an [enum TransitionType] constant, and refers to the way the timing of the animation is handled (see [url=https://easings.net/]easings.net[/url] for some examples). The second accepts an [enum EaseType] constant, and controls where the [code]trans_type[/code] is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different [enum TransitionType] constants with [constant EASE_IN_OUT], and use the one that looks best.
+ Tweens are mostly useful for animations requiring a numerical property to be interpolated over a range of values. The name [i]tween[/i] comes from [i]in-betweening[/i], an animation technique where you specify [i]keyframes[/i] and the computer interpolates the frames that appear between them.
+ [Tween] is more suited than [AnimationPlayer] for animations where you don't know the final values in advance. For example, interpolating a dynamically-chosen camera zoom value is best done with a [Tween]; it would be difficult to do the same thing with an [AnimationPlayer] node. Tweens are also more light-weight than [AnimationPlayer], so they are very much suited for simple animations or general tasks that don't require visual tweaking provided by the editor. They can be used in a fire-and-forget manner for some logic that normally would be done by code. You can e.g. make something shoot periodically by using a looped [CallbackTweener] with a delay.
+ A [Tween] can be created by using either [method SceneTree.create_tween] or [method Node.create_tween]. [Tween]s created manually (i.e. by using [code]Tween.new()[/code]) are invalid. They can't be used for tweening values, but you can do manual interpolation with [method interpolate_value].
+ A [Tween] animation is composed of a sequence of [Tweener]s, which by default are executed one after another. You can create a sequence by appending [Tweener]s to the [Tween]. Animating something with a [Tweener] is called tweening. Example tweening sequence looks like this:
+ [codeblock]
+ var tween = get_tree().create_tween()
+ tween.tween_property($Sprite, "modulate", Color.red, 1)
+ tween.tween_property($Sprite, "scale", Vector2(), 1)
+ tween.tween_callback($Sprite.queue_free)
+ [/codeblock]
+ This sequence will make the [code]$Sprite[/code] node turn red, then shrink and finally the [method Node.queue_free] is called to remove the sprite. See methods [method tween_property], [method tween_interval], [method tween_callback] and [method tween_method] for more usage information.
+ When a [Tweener] is created with one of the [code]tween_*[/code] methods, a chained method call can be used to tweak the properties of this [Tweener]. For example, if you want to set different transition type in the above example, you can do:
+ [codeblock]
+ var tween = get_tree().create_tween()
+ tween.tween_property($Sprite, "modulate", Color.red, 1).set_trans(Tween.TRANS_SINE)
+ tween.tween_property($Sprite, "scale", Vector2(), 1).set_trans(Tween.TRANS_BOUNCE)
+ tween.tween_callback($Sprite.queue_free)
+ [/codeblock]
+ Most of the [Tween] methods can be chained this way too. In this example the [Tween] is bound and have set a default transition:
+ [codeblock]
+ var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_ELASTIC)
+ tween.tween_property($Sprite, "modulate", Color.red, 1)
+ tween.tween_property($Sprite, "scale", Vector2(), 1)
+ tween.tween_callback($Sprite.queue_free)
+ [/codeblock]
+ Another interesting use for [Tween]s is animating arbitrary set of objects:
+ [codeblock]
+ var tween = create_tween()
+ for sprite in get_children():
+ tween.tween_property(sprite, "position", Vector2(), 1)
+ [/codeblock]
+ In the example above, all children of a node are moved one after another to position (0, 0).
+ Some [Tweener]s use transitions and eases. The first accepts an [enum TransitionType] constant, and refers to the way the timing of the animation is handled (see [url=https://easings.net/]easings.net[/url] for some examples). The second accepts an [enum EaseType] constant, and controls where the [code]trans_type[/code] is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different [enum TransitionType] constants with [constant EASE_IN_OUT], and use the one that looks best.
[url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/tween_cheatsheet.png]Tween easing and transition types cheatsheet[/url]
+ [b]Note:[/b] All [Tween]s will automatically start by default. To prevent a [Tween] from autostarting, you can call [method stop] immediately after it was created.
</description>
<tutorials>
</tutorials>
<methods>
- <method name="follow_method">
- <return type="void">
+ <method name="bind_node">
+ <return type="Tween">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="method" type="StringName">
- </argument>
- <argument index="2" name="initial_val" type="Variant">
- </argument>
- <argument index="3" name="target" type="Object">
- </argument>
- <argument index="4" name="target_method" type="StringName">
- </argument>
- <argument index="5" name="duration" type="float">
- </argument>
- <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0">
- </argument>
- <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2">
- </argument>
- <argument index="8" name="delay" type="float" default="0">
+ <argument index="0" name="node" type="Node">
</argument>
<description>
- Follows [code]method[/code] of [code]object[/code] and applies the returned value on [code]target_method[/code] of [code]target[/code], beginning from [code]initial_val[/code] for [code]duration[/code] seconds, [code]delay[/code] later. Methods are called with consecutive values.
- Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information.
+ Binds this [Tween] with the given [code]node[/code]. [Tween]s are processed directly by the [SceneTree], so they run independently of the animated nodes. When you bind a [Node] with the [Tween], the [Tween] will halt the animation when the object is not inside tree and the [Tween] will be automatically killed when the bound object is freed. Also [constant TWEEN_PAUSE_BOUND] will make the pausing behavior dependent on the bound node.
+ For a shorter way to create and bind a [Tween], you can use [method Node.create_tween].
</description>
</method>
- <method name="follow_property">
- <return type="void">
+ <method name="chain">
+ <return type="Tween">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="property" type="NodePath">
- </argument>
- <argument index="2" name="initial_val" type="Variant">
- </argument>
- <argument index="3" name="target" type="Object">
- </argument>
- <argument index="4" name="target_property" type="NodePath">
- </argument>
- <argument index="5" name="duration" type="float">
- </argument>
- <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0">
- </argument>
- <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2">
- </argument>
- <argument index="8" name="delay" type="float" default="0">
- </argument>
<description>
- Follows [code]property[/code] of [code]object[/code] and applies it on [code]target_property[/code] of [code]target[/code], beginning from [code]initial_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later.
- Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information.
+ Used to chain two [Tweener]s after [method set_parallel] is called with [code]true[/code].
+ [codeblock]
+ var tween = create_tween().set_parallel(true)
+ tween.tween_property(...)
+ tween.tween_property(...) #will run parallelly with above
+ tween.chain().tween_property(...) #will run after two above are finished
+ [/codeblock]
</description>
</method>
- <method name="get_runtime" qualifiers="const">
- <return type="float">
+ <method name="custom_step">
+ <return type="bool">
</return>
+ <argument index="0" name="delta" type="float">
+ </argument>
<description>
- Returns the total time needed for all tweens to end. If you have two tweens, one lasting 10 seconds and the other 20 seconds, it would return 20 seconds, as by that time all tweens would have finished.
+ Processes the [Tween] by given [code]delta[/code] value, in seconds. Mostly useful when the [Tween] is paused, for controlling it manually.
+ Returns [code]true[/code] if the [Tween] still has [Tweener]s that haven't finished.
+ [b]Note:[/b] The [Tween] will become invalid after finished, but you can call [method stop] after the step, to keep it and reset.
+ [b]Note:[/b] [method custom_step] will process only one step of the [Tween]. If the [code]delta[/code] is greater than the remaining time, the excessive time will not have any effect.
</description>
</method>
- <method name="interpolate_callback">
- <return type="void">
+ <method name="interpolate_value">
+ <return type="Variant">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="duration" type="float">
+ <argument index="0" name="trans_type" type="Variant">
</argument>
- <argument index="2" name="callback" type="String">
+ <argument index="1" name="ease_type" type="Variant">
</argument>
- <argument index="3" name="arg1" type="Variant" default="null">
+ <argument index="2" name="elapsed_time" type="float">
</argument>
- <argument index="4" name="arg2" type="Variant" default="null">
+ <argument index="3" name="initial_value" type="float">
</argument>
- <argument index="5" name="arg3" type="Variant" default="null">
+ <argument index="4" name="delta_value" type="int" enum="Tween.TransitionType">
</argument>
- <argument index="6" name="arg4" type="Variant" default="null">
- </argument>
- <argument index="7" name="arg5" type="Variant" default="null">
+ <argument index="5" name="duration" type="int" enum="Tween.EaseType">
</argument>
<description>
- Calls [code]callback[/code] of [code]object[/code] after [code]duration[/code]. [code]arg1[/code]-[code]arg5[/code] are arguments to be passed to the callback.
+ This method can be used for manual interpolation of a value, when you don't want [Tween] to do animating for you. It's similar to [method @GlobalScope.lerp], but with support for custom transition and easing.
+ [code]elapsed_time[/code] is the time in seconds that passed after the interping started and it's used to control the position of the interpolation. E.g. when it's equal to half of the [code]duration[/code], the interpolated value will be halfway between initial and final values. This value can also be greater than [code]duration[/code] or lower than 0, which will extrapolate the value.
+ [code]initial_value[/code] is the starting value of the interpolation.
+ [code]delta_value[/code] is the change of the value in the interpolation, i.e. it's equal to [code]final_value - initial_value[/code].
+ [code]duration[/code] is the total time of the interpolation.
</description>
</method>
- <method name="interpolate_deferred_callback">
- <return type="void">
+ <method name="is_running">
+ <return type="bool">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="duration" type="float">
- </argument>
- <argument index="2" name="callback" type="String">
- </argument>
- <argument index="3" name="arg1" type="Variant" default="null">
- </argument>
- <argument index="4" name="arg2" type="Variant" default="null">
- </argument>
- <argument index="5" name="arg3" type="Variant" default="null">
- </argument>
- <argument index="6" name="arg4" type="Variant" default="null">
- </argument>
- <argument index="7" name="arg5" type="Variant" default="null">
- </argument>
<description>
- Calls [code]callback[/code] of [code]object[/code] after [code]duration[/code] on the main thread (similar to [method Object.call_deferred]). [code]arg1[/code]-[code]arg5[/code] are arguments to be passed to the callback.
+ Returns whether the [Tween] is currently running, i.e. it wasn't paused and it's not finished.
</description>
</method>
- <method name="interpolate_method">
- <return type="void">
+ <method name="is_valid">
+ <return type="bool">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="method" type="StringName">
- </argument>
- <argument index="2" name="initial_val" type="Variant">
- </argument>
- <argument index="3" name="final_val" type="Variant">
- </argument>
- <argument index="4" name="duration" type="float">
- </argument>
- <argument index="5" name="trans_type" type="int" enum="Tween.TransitionType" default="0">
- </argument>
- <argument index="6" name="ease_type" type="int" enum="Tween.EaseType" default="2">
- </argument>
- <argument index="7" name="delay" type="float" default="0">
- </argument>
<description>
- Animates [code]method[/code] of [code]object[/code] from [code]initial_val[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. Methods are called with consecutive values.
- Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information.
+ Returns whether the [Tween] is valid. A valid [Tween] is a [Tween] contained by the scene tree (i.e. the array from [method SceneTree.get_processed_tweens] will contain this [Tween]). [Tween] might become invalid when it has finished tweening or was killed, also when created with [code]Tween.new()[/code]. Invalid [Tween] can't have [Tweener]s appended, because it can't animate them. You can however still use [method interpolate_value].
</description>
</method>
- <method name="interpolate_property">
+ <method name="kill">
<return type="void">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="property" type="NodePath">
- </argument>
- <argument index="2" name="initial_val" type="Variant">
- </argument>
- <argument index="3" name="final_val" type="Variant">
- </argument>
- <argument index="4" name="duration" type="float">
- </argument>
- <argument index="5" name="trans_type" type="int" enum="Tween.TransitionType" default="0">
- </argument>
- <argument index="6" name="ease_type" type="int" enum="Tween.EaseType" default="2">
- </argument>
- <argument index="7" name="delay" type="float" default="0">
- </argument>
<description>
- Animates [code]property[/code] of [code]object[/code] from [code]initial_val[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. Setting the initial value to [code]null[/code] uses the current value of the property.
- Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information.
+ Aborts all tweening operations and invalidates the [Tween].
</description>
</method>
- <method name="is_active" qualifiers="const">
- <return type="bool">
+ <method name="parallel">
+ <return type="Tween">
</return>
<description>
- Returns [code]true[/code] if any tweens are currently running.
- [b]Note:[/b] This method doesn't consider tweens that have ended.
+ Makes the next [Tweener] run parallely to the previous one. Example:
+ [codeblock]
+ var tween = create_tween()
+ tween.tween_property(...)
+ tween.parallel().tween_property(...)
+ tween.parallel().tween_property(...)
+ [/codeblock]
+ All [Tweener]s in the example will run at the same time.
+ You can make the [Tween] parallel by default by using [method set_parallel].
</description>
</method>
- <method name="remove">
+ <method name="pause">
<return type="void">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="StringName" default="&quot;&quot;">
- </argument>
<description>
- Stops animation and removes a tween, given its object and property/method pair. By default, all tweens are removed, unless [code]key[/code] is specified.
+ Pauses the tweening. The animation can be resumed by using [method play].
</description>
</method>
- <method name="remove_all">
+ <method name="play">
<return type="void">
</return>
<description>
- Stops animation and removes all tweens.
+ Resumes a paused or stopped [Tween].
</description>
</method>
- <method name="reset">
- <return type="void">
+ <method name="set_ease">
+ <return type="Tween">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="StringName" default="&quot;&quot;">
+ <argument index="0" name="ease" type="int" enum="Tween.EaseType">
</argument>
<description>
- Resets a tween to its initial value (the one given, not the one before the tween), given its object and property/method pair. By default, all tweens are removed, unless [code]key[/code] is specified.
+ Sets the default ease type for [PropertyTweener]s and [MethodTweener]s animated by this [Tween].
</description>
</method>
- <method name="reset_all">
- <return type="void">
+ <method name="set_loops">
+ <return type="Tween">
</return>
+ <argument index="0" name="loops" type="int" default="0">
+ </argument>
<description>
- Resets all tweens to their initial values (the ones given, not those before the tween).
+ Sets the number of times the tweening sequence will be repeated, i.e. [code]set_loops(2)[/code] will run the animation twice.
+ Calling this method without arguments will make the [Tween] run infinitely, until it is either killed by [method kill] or by freeing bound node, or all the animated objects have been freed (which makes further animation impossible).
</description>
</method>
- <method name="resume">
- <return type="void">
+ <method name="set_parallel">
+ <return type="Tween">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="StringName" default="&quot;&quot;">
+ <argument index="0" name="parallel" type="bool" default="true">
</argument>
<description>
- Continues animating a stopped tween, given its object and property/method pair. By default, all tweens are resumed, unless [code]key[/code] is specified.
+ If [code]parallel[/code] is [code]true[/code], the [Tweener]s appended after this method will by default run simultanously, as opposed to sequentially.
</description>
</method>
- <method name="resume_all">
- <return type="void">
+ <method name="set_pause_mode">
+ <return type="Tween">
</return>
+ <argument index="0" name="mode" type="int" enum="Tween.TweenPauseMode">
+ </argument>
<description>
- Continues animating all stopped tweens.
+ Determines the behavior of the [Tween] when the [SceneTree] is paused. Check [enum TweenPauseMode] for options.
+ Default value is [constant TWEEN_PAUSE_BOUND].
</description>
</method>
- <method name="seek">
- <return type="void">
+ <method name="set_process_mode">
+ <return type="Tween">
</return>
- <argument index="0" name="time" type="float">
+ <argument index="0" name="mode" type="int" enum="Tween.TweenProcessMode">
</argument>
<description>
- Sets the interpolation to the given [code]time[/code] in seconds.
+ Determines whether the [Tween] should run during idle frame (see [method Node._process]) or physics frame (see [method Node._physics_process].
+ Default value is [constant TWEEN_PROCESS_IDLE].
</description>
</method>
- <method name="set_active">
- <return type="void">
+ <method name="set_speed_scale">
+ <return type="Tween">
</return>
- <argument index="0" name="active" type="bool">
+ <argument index="0" name="speed" type="float">
</argument>
<description>
- Activates/deactivates the tween. See also [method stop_all] and [method resume_all].
+ Scales the speed of tweening. This affects all [Tweener]s and their delays.
</description>
</method>
- <method name="start">
- <return type="void">
+ <method name="set_trans">
+ <return type="Tween">
</return>
+ <argument index="0" name="trans" type="int" enum="Tween.TransitionType">
+ </argument>
<description>
- Starts the tween. You can define animations both before and after this.
+ Sets the default transition type for [PropertyTweener]s and [MethodTweener]s animated by this [Tween].
</description>
</method>
<method name="stop">
<return type="void">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="StringName" default="&quot;&quot;">
- </argument>
<description>
- Stops a tween, given its object and property/method pair. By default, all tweens are stopped, unless [code]key[/code] is specified.
+ Stops the tweening and resets the [Tween] to its initial state. This will not remove any appended [Tweener]s.
</description>
</method>
- <method name="stop_all">
- <return type="void">
+ <method name="tween_callback">
+ <return type="CallbackTweener">
</return>
+ <argument index="0" name="callback" type="Callable">
+ </argument>
<description>
- Stops animating all tweens.
+ Creates and appends a [CallbackTweener]. This method can be used to call an arbitrary method in any object. Use [method Callable.bind] to bind additional arguments for the call.
+ Example: object that keeps shooting every 1 second.
+ [codeblock]
+ var tween = get_tree().create_tween().set_loops()
+ tween.tween_callback(shoot).set_delay(1)
+ [/codeblock]
+ Example: turning a sprite red and then blue, with 2 second delay.
+ [codeblock]
+ var tween = get_tree().create_tween()
+ tween.tween_callback($Sprite.set_modulate.bind(Color.red)).set_delay(2)
+ tween.tween_callback($Sprite.set_modulate.bind(Color.blue)).set_delay(2)
+ [/codeblock]
</description>
</method>
- <method name="targeting_method">
- <return type="void">
+ <method name="tween_interval">
+ <return type="IntervalTweener">
</return>
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="method" type="StringName">
- </argument>
- <argument index="2" name="initial" type="Object">
- </argument>
- <argument index="3" name="initial_method" type="StringName">
- </argument>
- <argument index="4" name="final_val" type="Variant">
+ <argument index="0" name="time" type="float">
</argument>
- <argument index="5" name="duration" type="float">
+ <description>
+ Creates and appends an [IntervalTweener]. This method can be used to create delays in the tween animation, as an alternative for using the delay in other [Tweener]s or when there's no animation (in which case the [Tween] acts as a timer). [code]time[/code] is the length of the interval, in seconds.
+ Example: creating an interval in code execution.
+ [codeblock]
+ #... some code
+ var tween = create_tween()
+ tween.tween_interval(2)
+ await tween.finished
+ #... more code
+ [/codeblock]
+ Example: creating an object that moves back and forth and jumps every few seconds.
+ [codeblock]
+ var tween = create_tween().set_loops()
+ tween.tween_property("position:x", 200, 1).as_relative()
+ tween.tween_callback(jump)
+ tween.tween_interval(2)
+ tween.tween_property("position:x", -200, 1).as_relative()
+ tween.tween_callback(jump)
+ tween.tween_interval(2)
+ [/codeblock]
+ </description>
+ </method>
+ <method name="tween_method">
+ <return type="MethodTweener">
+ </return>
+ <argument index="0" name="method" type="Callable">
</argument>
- <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0">
+ <argument index="1" name="from" type="float">
</argument>
- <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2">
+ <argument index="2" name="to" type="float">
</argument>
- <argument index="8" name="delay" type="float" default="0">
+ <argument index="3" name="duration" type="float">
</argument>
<description>
- Animates [code]method[/code] of [code]object[/code] from the value returned by [code]initial_method[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later. Methods are animated by calling them with consecutive values.
- Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information.
+ Creates and appends a [MethodTweener]. This method is similar to a combination of [method tween_callback] and [method tween_property]. It calls a method over time with a tweened value provided as an argument. The value is tweened between [code]from[/code] and [code]to[/code] over the time specified by [code]duration[/code], in seconds. Use [method Callable.bind] to bind additional arguments for the call. You can use [method MethodTweener.set_ease] and [method MethodTweener.set_trans] to tweak the easing and transition of the value or [method MethodTweener.set_delay] to delay the tweening.
+ Example: making a 3D object look from one point to another point.
+ [codeblock]
+ var tween = create_tween()
+ tween.tween_method(look_at.bind(Vector3.UP), Vector3(-1, 0, -1), Vector3(1, 0, -1), 1) #the look_at() method takes up vector as second argument
+ [/codeblock]
+ Example: setting a text of a [Label], using an intermediate method and after a delay.
+ [codeblock]
+ func _ready():
+ var tween = create_tween()
+ tween.tween_method(set_label_text, 0, 10, 1).set_delay(1)
+
+ func set_label_text(value: int):
+ $Label.text = "Counting " + str(value)
+ [/codeblock]
</description>
</method>
- <method name="targeting_property">
- <return type="void">
+ <method name="tween_property">
+ <return type="PropertyTweener">
</return>
<argument index="0" name="object" type="Object">
</argument>
<argument index="1" name="property" type="NodePath">
</argument>
- <argument index="2" name="initial" type="Object">
- </argument>
- <argument index="3" name="initial_val" type="NodePath">
- </argument>
- <argument index="4" name="final_val" type="Variant">
+ <argument index="2" name="final_val" type="Variant">
</argument>
- <argument index="5" name="duration" type="float">
+ <argument index="3" name="duration" type="float">
</argument>
- <argument index="6" name="trans_type" type="int" enum="Tween.TransitionType" default="0">
- </argument>
- <argument index="7" name="ease_type" type="int" enum="Tween.EaseType" default="2">
- </argument>
- <argument index="8" name="delay" type="float" default="0">
- </argument>
- <description>
- Animates [code]property[/code] of [code]object[/code] from the current value of the [code]initial_val[/code] property of [code]initial[/code] to [code]final_val[/code] for [code]duration[/code] seconds, [code]delay[/code] seconds later.
- Use [enum TransitionType] for [code]trans_type[/code] and [enum EaseType] for [code]ease_type[/code] parameters. These values control the timing and direction of the interpolation. See the class description for more information.
- </description>
- </method>
- <method name="tell" qualifiers="const">
- <return type="float">
- </return>
<description>
- Returns the current time of the tween.
+ Creates and appends a [PropertyTweener]. This method tweens a [code]property[/code] of an [code]object[/code] between an initial value and [code]final_val[/code] in a span of time equal to [code]duration[/code], in seconds. The initial value by default is a value at the time the tweening of the [PropertyTweener] start. For example:
+ [codeblock]
+ var tween = create_tween()
+ tween.tween_property($Sprite, "position", Vector2(100, 200)
+ tween.tween_property($Sprite, "position", Vector2(200, 300)
+ [/codeblock]
+ will move the sprite to position (100, 200) and then to (200, 300). If you use [method PropertyTweener.from] or [method PropertyTweener.from_current], the starting position will be overwritten by the given value instead. See other methods in [PropertyTweener] to see how the tweening can be tweaked further.
+ [b]Note:[/b] You can find the correct property name by hovering over the property in the Inspector. You can also provide the components of a property directly by using [code]"property:component"[/code] (eg. [code]position:x[/code]), where it would only apply to that particular component.
+ Example: moving object twice from the same position, with different transition types.
+ [codeblock]
+ var tween = create_tween()
+ tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().set_trans(Tween.TRANS_SINE)
+ tween.tween_property($Sprite, "position", Vector2.RIGHT * 300).as_relative().from_current().set_trans(Tween.TRANS_EXPO)
+ [/codeblock]
</description>
</method>
</methods>
- <members>
- <member name="playback_process_mode" type="int" setter="set_tween_process_mode" getter="get_tween_process_mode" enum="Tween.TweenProcessMode" default="1">
- The tween's animation process thread. See [enum TweenProcessMode].
- </member>
- <member name="playback_speed" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0">
- The tween's speed multiplier. For example, set it to [code]1.0[/code] for normal speed, [code]2.0[/code] for two times normal speed, or [code]0.5[/code] for half of the normal speed. A value of [code]0[/code] pauses the animation, but see also [method set_active] or [method stop_all] for this.
- </member>
- <member name="repeat" type="bool" setter="set_repeat" getter="is_repeat" default="false">
- If [code]true[/code], the tween loops.
- </member>
- </members>
<signals>
- <signal name="tween_all_completed">
+ <signal name="finished">
<description>
- Emitted when all processes in a tween end.
+ Emitted when the [Tween] has finished all tweening. Never emitted when the [Tween] is set to infinite looping (see [method set_loops]).
+ [b]Note:[/b] The [Tween] is removed (invalidated) after this signal is emitted, but it doesn't happen immediately, but on the next processing frame. Calling [method stop] inside the signal callback will preserve the [Tween].
</description>
</signal>
- <signal name="tween_completed">
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="NodePath">
+ <signal name="loop_finished">
+ <argument index="0" name="loop_count" type="int">
</argument>
<description>
- Emitted when a tween ends.
+ Emitted when a full loop is complete (see [method set_loops]), providing the loop index. This signal is not emitted after final loop, use [signal finished] instead for this case.
</description>
</signal>
- <signal name="tween_started">
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="NodePath">
+ <signal name="step_finished">
+ <argument index="0" name="idx" type="int">
</argument>
<description>
- Emitted when a tween starts.
- </description>
- </signal>
- <signal name="tween_step">
- <argument index="0" name="object" type="Object">
- </argument>
- <argument index="1" name="key" type="NodePath">
- </argument>
- <argument index="2" name="elapsed" type="float">
- </argument>
- <argument index="3" name="value" type="Object">
- </argument>
- <description>
- Emitted at each step of the animation.
+ Emitted when one step of the [Tween] is complete, providing the step index. One step is either a single [Tweener] or a group of [Tweener]s running parallelly.
</description>
</signal>
</signals>
<constants>
<constant name="TWEEN_PROCESS_PHYSICS" value="0" enum="TweenProcessMode">
- The tween updates with the [code]_physics_process[/code] callback.
+ The [Tween] updates during physics frame.
</constant>
<constant name="TWEEN_PROCESS_IDLE" value="1" enum="TweenProcessMode">
- The tween updates with the [code]_process[/code] callback.
+ The [Tween] updates during idle
+ </constant>
+ <constant name="TWEEN_PAUSE_BOUND" value="0" enum="TweenPauseMode">
+ </constant>
+ <constant name="TWEEN_PAUSE_STOP" value="1" enum="TweenPauseMode">
+ </constant>
+ <constant name="TWEEN_PAUSE_PROCESS" value="2" enum="TweenPauseMode">
</constant>
<constant name="TRANS_LINEAR" value="0" enum="TransitionType">
- The animation is interpolated linearly.
</constant>
<constant name="TRANS_SINE" value="1" enum="TransitionType">
- The animation is interpolated using a sine function.
</constant>
<constant name="TRANS_QUINT" value="2" enum="TransitionType">
- The animation is interpolated with a quintic (to the power of 5) function.
</constant>
<constant name="TRANS_QUART" value="3" enum="TransitionType">
- The animation is interpolated with a quartic (to the power of 4) function.
</constant>
<constant name="TRANS_QUAD" value="4" enum="TransitionType">
- The animation is interpolated with a quadratic (to the power of 2) function.
</constant>
<constant name="TRANS_EXPO" value="5" enum="TransitionType">
- The animation is interpolated with an exponential (to the power of x) function.
</constant>
<constant name="TRANS_ELASTIC" value="6" enum="TransitionType">
- The animation is interpolated with elasticity, wiggling around the edges.
</constant>
<constant name="TRANS_CUBIC" value="7" enum="TransitionType">
- The animation is interpolated with a cubic (to the power of 3) function.
</constant>
<constant name="TRANS_CIRC" value="8" enum="TransitionType">
- The animation is interpolated with a function using square roots.
</constant>
<constant name="TRANS_BOUNCE" value="9" enum="TransitionType">
- The animation is interpolated by bouncing at the end.
</constant>
<constant name="TRANS_BACK" value="10" enum="TransitionType">
- The animation is interpolated backing out at ends.
</constant>
<constant name="EASE_IN" value="0" enum="EaseType">
- The interpolation starts slowly and speeds up towards the end.
</constant>
<constant name="EASE_OUT" value="1" enum="EaseType">
- The interpolation starts quickly and slows down towards the end.
</constant>
<constant name="EASE_IN_OUT" value="2" enum="EaseType">
- A combination of [constant EASE_IN] and [constant EASE_OUT]. The interpolation is slowest at both ends.
</constant>
<constant name="EASE_OUT_IN" value="3" enum="EaseType">
- A combination of [constant EASE_IN] and [constant EASE_OUT]. The interpolation is fastest at both ends.
</constant>
</constants>
</class>
diff --git a/doc/classes/Tweener.xml b/doc/classes/Tweener.xml
new file mode 100644
index 0000000000..5cd502ced9
--- /dev/null
+++ b/doc/classes/Tweener.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="Tweener" inherits="RefCounted" version="4.0">
+ <brief_description>
+ Abstract class for all Tweeners used by [Tween].
+ </brief_description>
+ <description>
+ Tweeners are objects that perform a specific animating task, e.g. interpolating a property or calling a method at a given time. A [Tweener] can't be created manually, you need to use a dedicated method from [Tween] or [Node].
+ </description>
+ <tutorials>
+ </tutorials>
+ <methods>
+ </methods>
+ <signals>
+ <signal name="finished">
+ <description>
+ Emited when the [Tweener] has just finished its job.
+ </description>
+ </signal>
+ </signals>
+ <constants>
+ </constants>
+</class>
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 807a45eb32..e0e9c6e2d1 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -1612,15 +1612,19 @@ void CodeTextEditor::validate_script() {
idle->start();
}
-void CodeTextEditor::_warning_label_gui_input(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
- _warning_button_pressed();
- }
+void CodeTextEditor::_error_button_pressed() {
+ _set_show_errors_panel(!is_errors_panel_opened);
+ _set_show_warnings_panel(false);
}
void CodeTextEditor::_warning_button_pressed() {
_set_show_warnings_panel(!is_warnings_panel_opened);
+ _set_show_errors_panel(false);
+}
+
+void CodeTextEditor::_set_show_errors_panel(bool p_show) {
+ is_errors_panel_opened = p_show;
+ emit_signal("show_errors_panel", p_show);
}
void CodeTextEditor::_set_show_warnings_panel(bool p_show) {
@@ -1653,6 +1657,7 @@ void CodeTextEditor::_notification(int p_what) {
_update_font();
} break;
case NOTIFICATION_ENTER_TREE: {
+ error_button->set_icon(get_theme_icon("StatusError", "EditorIcons"));
warning_button->set_icon(get_theme_icon("NodeWarning", "EditorIcons"));
add_theme_constant_override("separation", 4 * EDSCALE);
} break;
@@ -1667,11 +1672,18 @@ void CodeTextEditor::_notification(int p_what) {
}
}
-void CodeTextEditor::set_warning_nb(int p_warning_nb) {
- warning_count_label->set_text(itos(p_warning_nb));
- warning_count_label->set_visible(p_warning_nb > 0);
- warning_button->set_visible(p_warning_nb > 0);
- if (!p_warning_nb) {
+void CodeTextEditor::set_error_count(int p_error_count) {
+ error_button->set_text(itos(p_error_count));
+ error_button->set_visible(p_error_count > 0);
+ if (!p_error_count) {
+ _set_show_errors_panel(false);
+ }
+}
+
+void CodeTextEditor::set_warning_count(int p_warning_count) {
+ warning_button->set_text(itos(p_warning_count));
+ warning_button->set_visible(p_warning_count > 0);
+ if (!p_warning_count) {
_set_show_warnings_panel(false);
}
}
@@ -1738,6 +1750,7 @@ void CodeTextEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("validate_script"));
ADD_SIGNAL(MethodInfo("load_theme_settings"));
+ ADD_SIGNAL(MethodInfo("show_errors_panel"));
ADD_SIGNAL(MethodInfo("show_warnings_panel"));
}
@@ -1835,6 +1848,22 @@ CodeTextEditor::CodeTextEditor() {
error->set_mouse_filter(MOUSE_FILTER_STOP);
error->connect("gui_input", callable_mp(this, &CodeTextEditor::_error_pressed));
+ // Errors
+ error_button = memnew(Button);
+ error_button->set_flat(true);
+ status_bar->add_child(error_button);
+ error_button->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER);
+ error_button->set_default_cursor_shape(CURSOR_POINTING_HAND);
+ error_button->connect("pressed", callable_mp(this, &CodeTextEditor::_error_button_pressed));
+ error_button->set_tooltip(TTR("Errors"));
+
+ error_button->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor"));
+ error_button->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts"));
+ error_button->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
+
+ is_errors_panel_opened = false;
+ set_error_count(0);
+
// Warnings
warning_button = memnew(Button);
warning_button->set_flat(true);
@@ -1844,20 +1873,12 @@ CodeTextEditor::CodeTextEditor() {
warning_button->connect("pressed", callable_mp(this, &CodeTextEditor::_warning_button_pressed));
warning_button->set_tooltip(TTR("Warnings"));
- warning_count_label = memnew(Label);
- status_bar->add_child(warning_count_label);
- warning_count_label->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER);
- warning_count_label->set_align(Label::ALIGN_RIGHT);
- warning_count_label->set_default_cursor_shape(CURSOR_POINTING_HAND);
- warning_count_label->set_mouse_filter(MOUSE_FILTER_STOP);
- warning_count_label->set_tooltip(TTR("Warnings"));
- warning_count_label->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor"));
- warning_count_label->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts"));
- warning_count_label->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
- warning_count_label->connect("gui_input", callable_mp(this, &CodeTextEditor::_warning_label_gui_input));
+ warning_button->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor"));
+ warning_button->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("status_source", "EditorFonts"));
+ warning_button->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("status_source_size", "EditorFonts"));
is_warnings_panel_opened = false;
- set_warning_nb(0);
+ set_warning_count(0);
// Line and column
line_and_col_txt = memnew(Label);
diff --git a/editor/code_editor.h b/editor/code_editor.h
index f368305e85..28b09e0a5d 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -145,8 +145,8 @@ class CodeTextEditor : public VBoxContainer {
HBoxContainer *status_bar;
Button *toggle_scripts_button;
+ Button *error_button;
Button *warning_button;
- Label *warning_count_label;
Label *line_and_col_txt;
@@ -184,8 +184,9 @@ class CodeTextEditor : public VBoxContainer {
CodeTextEditorCodeCompleteFunc code_complete_func;
void *code_complete_ud;
- void _warning_label_gui_input(const Ref<InputEvent> &p_event);
+ void _error_button_pressed();
void _warning_button_pressed();
+ void _set_show_errors_panel(bool p_show);
void _set_show_warnings_panel(bool p_show);
void _error_pressed(const Ref<InputEvent> &p_event);
@@ -205,6 +206,7 @@ protected:
static void _bind_methods();
bool is_warnings_panel_opened;
+ bool is_errors_panel_opened;
public:
void trim_trailing_whitespace();
@@ -238,7 +240,8 @@ public:
Variant get_edit_state();
void set_edit_state(const Variant &p_state);
- void set_warning_nb(int p_warning_nb);
+ void set_error_count(int p_error_count);
+ void set_warning_count(int p_warning_count);
void update_editor_settings();
void set_error(const String &p_error);
diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp
index 51c6b473ad..4151c51b26 100644
--- a/editor/editor_feature_profile.cpp
+++ b/editor/editor_feature_profile.cpp
@@ -161,21 +161,21 @@ String EditorFeatureProfile::get_feature_description(Feature p_feature) {
}
Error EditorFeatureProfile::save_to_file(const String &p_path) {
- Dictionary json;
- json["type"] = "feature_profile";
+ Dictionary data;
+ data["type"] = "feature_profile";
Array dis_classes;
for (Set<StringName>::Element *E = disabled_classes.front(); E; E = E->next()) {
dis_classes.push_back(String(E->get()));
}
dis_classes.sort();
- json["disabled_classes"] = dis_classes;
+ data["disabled_classes"] = dis_classes;
Array dis_editors;
for (Set<StringName>::Element *E = disabled_editors.front(); E; E = E->next()) {
dis_editors.push_back(String(E->get()));
}
dis_editors.sort();
- json["disabled_editors"] = dis_editors;
+ data["disabled_editors"] = dis_editors;
Array dis_props;
@@ -185,7 +185,7 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) {
}
}
- json["disabled_properties"] = dis_props;
+ data["disabled_properties"] = dis_props;
Array dis_features;
for (int i = 0; i < FEATURE_MAX; i++) {
@@ -194,12 +194,13 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) {
}
}
- json["disabled_features"] = dis_features;
+ data["disabled_features"] = dis_features;
FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(!f, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");
- String text = JSON::print(json, "\t");
+ JSON json;
+ String text = json.stringify(data, "\t");
f->store_string(text);
f->close();
return OK;
@@ -212,26 +213,24 @@ Error EditorFeatureProfile::load_from_file(const String &p_path) {
return err;
}
- String err_str;
- int err_line;
- Variant v;
- err = JSON::parse(text, v, err_str, err_line);
+ JSON json;
+ err = json.parse(text);
if (err != OK) {
- ERR_PRINT("Error parsing '" + p_path + "' on line " + itos(err_line) + ": " + err_str);
+ ERR_PRINT("Error parsing '" + p_path + "' on line " + itos(json.get_error_line()) + ": " + json.get_error_message());
return ERR_PARSE_ERROR;
}
- Dictionary json = v;
+ Dictionary data = json.get_data();
- if (!json.has("type") || String(json["type"]) != "feature_profile") {
+ if (!data.has("type") || String(data["type"]) != "feature_profile") {
ERR_PRINT("Error parsing '" + p_path + "', it's not a feature profile.");
return ERR_PARSE_ERROR;
}
disabled_classes.clear();
- if (json.has("disabled_classes")) {
- Array disabled_classes_arr = json["disabled_classes"];
+ if (data.has("disabled_classes")) {
+ Array disabled_classes_arr = data["disabled_classes"];
for (int i = 0; i < disabled_classes_arr.size(); i++) {
disabled_classes.insert(disabled_classes_arr[i]);
}
@@ -239,8 +238,8 @@ Error EditorFeatureProfile::load_from_file(const String &p_path) {
disabled_editors.clear();
- if (json.has("disabled_editors")) {
- Array disabled_editors_arr = json["disabled_editors"];
+ if (data.has("disabled_editors")) {
+ Array disabled_editors_arr = data["disabled_editors"];
for (int i = 0; i < disabled_editors_arr.size(); i++) {
disabled_editors.insert(disabled_editors_arr[i]);
}
@@ -248,16 +247,16 @@ Error EditorFeatureProfile::load_from_file(const String &p_path) {
disabled_properties.clear();
- if (json.has("disabled_properties")) {
- Array disabled_properties_arr = json["disabled_properties"];
+ if (data.has("disabled_properties")) {
+ Array disabled_properties_arr = data["disabled_properties"];
for (int i = 0; i < disabled_properties_arr.size(); i++) {
String s = disabled_properties_arr[i];
set_disable_class_property(s.get_slice(":", 0), s.get_slice(":", 1), true);
}
}
- if (json.has("disabled_features")) {
- Array disabled_features_arr = json["disabled_features"];
+ if (data.has("disabled_features")) {
+ Array disabled_features_arr = data["disabled_features"];
for (int i = 0; i < FEATURE_MAX; i++) {
bool found = false;
String f = feature_identifiers[i];
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 657ec9d70b..719d3120da 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1625,15 +1625,6 @@ void EditorNode::_save_scene(String p_file, int idx) {
return;
}
- // force creation of node path cache
- // (hacky but needed for the tree to update properly)
- Node *dummy_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
- if (!dummy_scene) {
- show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK"));
- return;
- }
- memdelete(dummy_scene);
-
int flg = 0;
if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 3f66326b41..325e0173ab 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -1585,7 +1585,7 @@ void EditorSettings::set_builtin_action_override(const String &p_name, const Arr
// Check equality of each event.
for (List<Ref<InputEvent>>::Element *E = builtin_events.front(); E; E = E->next()) {
- if (!E->get()->shortcut_match(p_events[event_idx])) {
+ if (!E->get()->is_match(p_events[event_idx])) {
same_as_builtin = false;
break;
}
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index 76c6fcc3d3..dd4ce74406 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -242,10 +242,8 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code,
response_json.parse_utf8((const char *)r, p_data.size());
}
- Variant response;
- String errs;
- int errline;
- Error err = JSON::parse(response_json, response, errs, errline);
+ JSON json;
+ Error err = json.parse(response_json);
if (err != OK) {
EditorNode::get_singleton()->show_warning(TTR("Error parsing JSON with the list of mirrors. Please report this issue!"));
is_refreshing_mirrors = false;
@@ -260,7 +258,7 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code,
mirrors_available = false;
- Dictionary data = response;
+ Dictionary data = json.get_data();
if (data.has("mirrors")) {
Array mirrors = data["mirrors"];
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index 93bb170128..f0254e5639 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -1098,11 +1098,9 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const
Dictionary d;
{
- Variant js;
- String errs;
- int errl;
- JSON::parse(str, js, errs, errl);
- d = js;
+ JSON json;
+ json.parse(str);
+ d = json.get_data();
}
RequestType requested = requesting;
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index d3880ce12d..04d8c1d555 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -109,13 +109,11 @@ ConnectionInfoDialog::ConnectionInfoDialog() {
////////////////////////////////////////////////////////////////////////////////
Vector<String> ScriptTextEditor::get_functions() {
- String errortxt;
- int line = -1, col;
CodeEdit *te = code_editor->get_text_editor();
String text = te->get_text();
List<String> fnc;
- if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) {
+ if (script->get_language()->validate(text, script->get_path(), &fnc)) {
//if valid rewrite functions to latest
functions.clear();
for (List<String>::Element *E = fnc.front(); E; E = E->next()) {
@@ -223,6 +221,10 @@ void ScriptTextEditor::_set_theme_for_script() {
}
}
+void ScriptTextEditor::_show_errors_panel(bool p_show) {
+ errors_panel->set_visible(p_show);
+}
+
void ScriptTextEditor::_show_warnings_panel(bool p_show) {
warnings_panel->set_visible(p_show);
}
@@ -237,6 +239,12 @@ void ScriptTextEditor::_warning_clicked(Variant p_line) {
}
}
+void ScriptTextEditor::_error_clicked(Variant p_line) {
+ if (p_line.get_type() == Variant::INT) {
+ code_editor->get_text_editor()->cursor_set_line(p_line.operator int64_t());
+ }
+}
+
void ScriptTextEditor::reload_text() {
ERR_FAIL_COND(script.is_null());
@@ -387,23 +395,21 @@ Ref<Texture2D> ScriptTextEditor::get_theme_icon() {
}
void ScriptTextEditor::_validate_script() {
- String errortxt;
- int line = -1, col;
CodeEdit *te = code_editor->get_text_editor();
String text = te->get_text();
List<String> fnc;
Set<int> safe_lines;
List<ScriptLanguage::Warning> warnings;
+ List<ScriptLanguage::ScriptError> errors;
- if (!script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc, &warnings, &safe_lines)) {
- String error_text = "error(" + itos(line) + "," + itos(col) + "): " + errortxt;
+ if (!script->get_language()->validate(text, script->get_path(), &fnc, &errors, &warnings, &safe_lines)) {
+ String error_text = TTR("Error at ") + "(" + itos(errors[0].line) + "," + itos(errors[0].column) + "): " + errors[0].message;
code_editor->set_error(error_text);
- code_editor->set_error_pos(line - 1, col - 1);
+ code_editor->set_error_pos(errors[0].line - 1, errors[0].column - 1);
script_is_valid = false;
} else {
code_editor->set_error("");
- line = -1;
if (!script->is_tool()) {
script->set_source_code(text);
script->update_exports();
@@ -445,7 +451,8 @@ void ScriptTextEditor::_validate_script() {
}
}
- code_editor->set_warning_nb(warning_nb);
+ code_editor->set_error_count(errors.size());
+ code_editor->set_warning_count(warning_nb);
// Add script warnings.
warnings_panel->push_table(3);
@@ -479,11 +486,40 @@ void ScriptTextEditor::_validate_script() {
}
warnings_panel->pop(); // Table.
- line--;
+ errors_panel->clear();
+ errors_panel->push_table(2);
+ for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) {
+ ScriptLanguage::ScriptError err = E->get();
+
+ errors_panel->push_cell();
+ errors_panel->push_meta(err.line - 1);
+ errors_panel->push_color(warnings_panel->get_theme_color("error_color", "Editor"));
+ errors_panel->add_text(TTR("Line") + " " + itos(err.line) + ":");
+ errors_panel->pop(); // Color.
+ errors_panel->pop(); // Meta goto.
+ errors_panel->pop(); // Cell.
+
+ errors_panel->push_cell();
+ errors_panel->add_text(err.message);
+ errors_panel->pop(); // Cell.
+ }
+ errors_panel->pop(); // Table
+
bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true);
bool last_is_safe = false;
for (int i = 0; i < te->get_line_count(); i++) {
- te->set_line_background_color(i, (line == i) ? marked_line_color : Color(0, 0, 0, 0));
+ if (errors.is_empty()) {
+ te->set_line_background_color(i, Color(0, 0, 0, 0));
+ } else {
+ for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) {
+ bool error_line = i == E->get().line - 1;
+ te->set_line_background_color(i, error_line ? marked_line_color : Color(0, 0, 0, 0));
+ if (error_line) {
+ break;
+ }
+ }
+ }
+
if (highlight_safe) {
if (safe_lines.has(i + 1)) {
te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
@@ -495,7 +531,7 @@ void ScriptTextEditor::_validate_script() {
last_is_safe = false;
}
} else {
- te->set_line_gutter_item_color(line, 1, default_line_number_color);
+ te->set_line_gutter_item_color(i, 1, default_line_number_color);
}
}
@@ -1633,6 +1669,7 @@ void ScriptTextEditor::_enable_code_editor() {
editor_box->set_v_size_flags(SIZE_EXPAND_FILL);
editor_box->add_child(code_editor);
+ code_editor->connect("show_errors_panel", callable_mp(this, &ScriptTextEditor::_show_errors_panel));
code_editor->connect("show_warnings_panel", callable_mp(this, &ScriptTextEditor::_show_warnings_panel));
code_editor->connect("validate_script", callable_mp(this, &ScriptTextEditor::_validate_script));
code_editor->connect("load_theme_settings", callable_mp(this, &ScriptTextEditor::_load_theme_settings));
@@ -1653,6 +1690,13 @@ void ScriptTextEditor::_enable_code_editor() {
"normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts"));
warnings_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_warning_clicked));
+ editor_box->add_child(errors_panel);
+ errors_panel->add_theme_font_override(
+ "normal_font", EditorNode::get_singleton()->get_gui_base()->get_theme_font("main", "EditorFonts"));
+ errors_panel->add_theme_font_size_override(
+ "normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size("main_size", "EditorFonts"));
+ errors_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_error_clicked));
+
add_child(context_menu);
context_menu->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
@@ -1784,6 +1828,14 @@ ScriptTextEditor::ScriptTextEditor() {
warnings_panel->set_focus_mode(FOCUS_CLICK);
warnings_panel->hide();
+ errors_panel = memnew(RichTextLabel);
+ errors_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
+ errors_panel->set_h_size_flags(SIZE_EXPAND_FILL);
+ errors_panel->set_meta_underline(true);
+ errors_panel->set_selection_enabled(true);
+ errors_panel->set_focus_mode(FOCUS_CLICK);
+ errors_panel->hide();
+
update_settings();
code_editor->get_text_editor()->set_code_hint_draw_below(EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"));
@@ -1844,6 +1896,7 @@ ScriptTextEditor::~ScriptTextEditor() {
if (!editor_enabled) {
memdelete(code_editor);
memdelete(warnings_panel);
+ memdelete(errors_panel);
memdelete(context_menu);
memdelete(color_panel);
memdelete(edit_hb);
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 7bb961bf19..8a8e9aa737 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -55,6 +55,7 @@ class ScriptTextEditor : public ScriptEditorBase {
CodeTextEditor *code_editor = nullptr;
RichTextLabel *warnings_panel = nullptr;
+ RichTextLabel *errors_panel = nullptr;
Ref<Script> script;
bool script_is_valid = false;
@@ -161,7 +162,9 @@ protected:
void _load_theme_settings();
void _set_theme_for_script();
+ void _show_errors_panel(bool p_show);
void _show_warnings_panel(bool p_show);
+ void _error_clicked(Variant p_line);
void _warning_clicked(Variant p_line);
void _notification(int p_what);
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index e4a5a3796e..22d598d180 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -240,7 +240,7 @@ void ShaderTextEditor::_validate_script() {
warnings.sort_custom<WarningsComparator>();
_update_warning_panel();
} else {
- set_warning_nb(0);
+ set_warning_count(0);
}
emit_signal("script_changed");
}
@@ -280,7 +280,7 @@ void ShaderTextEditor::_update_warning_panel() {
}
warnings_panel->pop(); // Table.
- set_warning_nb(warning_count);
+ set_warning_count(warning_count);
}
void ShaderTextEditor::_bind_methods() {
diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp
index c05a3c2f89..c2c99ed17f 100644
--- a/editor/settings_config_dialog.cpp
+++ b/editor/settings_config_dialog.cpp
@@ -285,7 +285,7 @@ void EditorSettingsDialog::_update_shortcuts() {
event_strings.push_back(I->get()->as_text());
// Only check if the events have been the same so far - once one fails, we don't need to check any more.
- if (same_as_defaults && !key_default_events[count]->shortcut_match(I->get())) {
+ if (same_as_defaults && !key_default_events[count]->is_match(I->get())) {
same_as_defaults = false;
}
count++;
diff --git a/modules/fbx/tools/validation_tools.h b/modules/fbx/tools/validation_tools.h
index 6c15eb7e12..906a721045 100644
--- a/modules/fbx/tools/validation_tools.h
+++ b/modules/fbx/tools/validation_tools.h
@@ -34,8 +34,7 @@
#ifdef TOOLS_ENABLED
#include "core/io/file_access.h"
-#include "core/io/json.h"
-#include "core/string/ustring.h"
+#include "core/string/print_string.h"
#include "core/templates/local_vector.h"
#include "core/templates/map.h"
diff --git a/modules/gdnative/include/pluginscript/godot_pluginscript.h b/modules/gdnative/include/pluginscript/godot_pluginscript.h
index 34ed4f097d..02ee4066d0 100644
--- a/modules/gdnative/include/pluginscript/godot_pluginscript.h
+++ b/modules/gdnative/include/pluginscript/godot_pluginscript.h
@@ -132,7 +132,7 @@ typedef struct {
godot_bool can_inherit_from_file;
godot_string (*get_template_source_code)(godot_pluginscript_language_data *p_data, const godot_string *p_class_name, const godot_string *p_base_class_name);
- godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, int *r_line_error, int *r_col_error, godot_string *r_test_error, const godot_string *p_path, godot_packed_string_array *r_functions);
+ godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, const godot_string *p_path, godot_packed_string_array *r_functions, godot_array *r_errors); // errors = Array of Dictionary with "line", "column", "message" keys
int (*find_function)(godot_pluginscript_language_data *p_data, const godot_string *p_function, const godot_string *p_code); // Can be nullptr
godot_string (*make_function)(godot_pluginscript_language_data *p_data, const godot_string *p_class, const godot_string *p_name, const godot_packed_string_array *p_args);
godot_error (*complete_code)(godot_pluginscript_language_data *p_data, const godot_string *p_code, const godot_string *p_path, godot_object *p_owner, godot_array *r_options, godot_bool *r_force, godot_string *r_call_hint);
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 6c2d038654..0930302eb2 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -1035,7 +1035,7 @@ Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const
return Ref<NativeScript>(s);
}
-bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
+bool NativeScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
return true;
}
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index 1756321281..c53dc063b8 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -317,7 +317,7 @@ public:
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
+ virtual bool validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp
index 0291ae560b..79aba342c9 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_language.cpp
@@ -112,20 +112,29 @@ Ref<Script> PluginScriptLanguage::get_template(const String &p_class_name, const
return script;
}
-bool PluginScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
+bool PluginScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
PackedStringArray functions;
+ Array errors;
if (_desc.validate) {
bool ret = _desc.validate(
_data,
(godot_string *)&p_script,
- &r_line_error,
- &r_col_error,
- (godot_string *)&r_test_error,
(godot_string *)&p_path,
- (godot_packed_string_array *)&functions);
+ (godot_packed_string_array *)&functions,
+ (godot_array *)&errors);
for (int i = 0; i < functions.size(); i++) {
r_functions->push_back(functions[i]);
}
+ if (r_errors) {
+ for (int i = 0; i < errors.size(); i++) {
+ Dictionary error = errors[i];
+ ScriptLanguage::ScriptError e;
+ e.line = error["line"];
+ e.column = error["column"];
+ e.message = error["message"];
+ r_errors->push_back(e);
+ }
+ }
return ret;
}
return true;
diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h
index 957bf355ca..26ab4a95e3 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.h
+++ b/modules/gdnative/pluginscript/pluginscript_language.h
@@ -75,7 +75,7 @@ public:
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 602553bb1a..42019ae501 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -447,7 +447,7 @@ public:
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
virtual bool is_using_templates();
virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script);
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index 18b7810919..0e0b32b2a6 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -131,7 +131,7 @@ static void get_function_names_recursively(const GDScriptParser::ClassNode *p_cl
}
}
-bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
+bool GDScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
GDScriptParser parser;
GDScriptAnalyzer analyzer(&parser);
@@ -156,10 +156,16 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &
}
#endif
if (err) {
- GDScriptParser::ParserError parse_error = parser.get_errors().front()->get();
- r_line_error = parse_error.line;
- r_col_error = parse_error.column;
- r_test_error = parse_error.message;
+ if (r_errors) {
+ for (const List<GDScriptParser::ParserError>::Element *E = parser.get_errors().front(); E; E = E->next()) {
+ const GDScriptParser::ParserError &pe = E->get();
+ ScriptLanguage::ScriptError e;
+ e.line = pe.line;
+ e.column = pe.column;
+ e.message = pe.message;
+ r_errors->push_back(e);
+ }
+ }
return false;
} else {
const GDScriptParser::ClassNode *cl = parser.get_tree();
@@ -2378,7 +2384,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
r_forced = r_result.size() > 0;
}
-Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
+::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
GDScriptParser parser;
@@ -2929,7 +2935,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
return ERR_CANT_RESOLVE;
}
-Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) {
+::Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) {
//before parsing, try the usual stuff
if (ClassDB::class_exists(p_symbol)) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp
index 15236d900d..f817964a3c 100644
--- a/modules/gdscript/language_server/gdscript_extend_parser.cpp
+++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp
@@ -32,7 +32,6 @@
#include "../gdscript.h"
#include "../gdscript_analyzer.h"
-#include "core/io/json.h"
#include "gdscript_language_protocol.h"
#include "gdscript_workspace.h"
@@ -183,7 +182,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.detail += ": " + m.get_datatype().to_string();
}
if (m.variable->initializer != nullptr && m.variable->initializer->is_constant) {
- symbol.detail += " = " + JSON::print(m.variable->initializer->reduced_value);
+ symbol.detail += " = " + m.variable->initializer->reduced_value.to_json_string();
}
symbol.documentation = parse_documentation(LINE_NUMBER_TO_INDEX(m.variable->start_line));
@@ -224,10 +223,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
}
}
} else {
- value_text = JSON::print(default_value);
+ value_text = default_value.to_json_string();
}
} else {
- value_text = JSON::print(default_value);
+ value_text = default_value.to_json_string();
}
if (!value_text.is_empty()) {
symbol.detail += " = " + value_text;
@@ -353,8 +352,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
parameters += ": " + parameter->get_datatype().to_string();
}
if (parameter->default_value != nullptr) {
- String value = JSON::print(parameter->default_value->reduced_value);
- parameters += " = " + value;
+ parameters += " = " + parameter->default_value->reduced_value.to_json_string();
}
}
r_symbol.detail += parameters + ")";
diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp
index c16a7fa889..42ff8bb5b3 100644
--- a/modules/gdscript/language_server/gdscript_language_protocol.cpp
+++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp
@@ -31,7 +31,6 @@
#include "gdscript_language_protocol.h"
#include "core/config/project_settings.h"
-#include "core/io/json.h"
#include "editor/doc_tools.h"
#include "editor/editor_log.h"
#include "editor/editor_node.h"
@@ -194,7 +193,7 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) {
vformat("GDScriptLanguageProtocol: Can't initialize invalid peer '%d'.", latest_client_id));
Ref<LSPeer> peer = clients.get(latest_client_id);
if (peer != nullptr) {
- String msg = JSON::print(request);
+ String msg = Variant(request).to_json_string();
msg = format_output(msg);
(*peer)->res_queue.push_back(msg.utf8());
}
@@ -280,7 +279,7 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia
ERR_FAIL_COND(peer == nullptr);
Dictionary message = make_notification(p_method, p_params);
- String msg = JSON::print(message);
+ String msg = Variant(message).to_json_string();
msg = format_output(msg);
peer->res_queue.push_back(msg.utf8());
}
diff --git a/modules/gltf/editor_scene_importer_gltf.cpp b/modules/gltf/editor_scene_importer_gltf.cpp
index 21b4bb75fb..5f220a9e57 100644
--- a/modules/gltf/editor_scene_importer_gltf.cpp
+++ b/modules/gltf/editor_scene_importer_gltf.cpp
@@ -30,7 +30,6 @@
#include "core/crypto/crypto_core.h"
#include "core/io/file_access.h"
-#include "core/io/json.h"
#include "core/math/disjoint_set.h"
#include "core/math/math_defs.h"
#include "core/os/os.h"
diff --git a/modules/gltf/editor_scene_importer_gltf.h b/modules/gltf/editor_scene_importer_gltf.h
index af1a885f2b..566d5cfd34 100644
--- a/modules/gltf/editor_scene_importer_gltf.h
+++ b/modules/gltf/editor_scene_importer_gltf.h
@@ -32,7 +32,6 @@
#define EDITOR_SCENE_IMPORTER_GLTF_H
#include "core/config/project_settings.h"
-#include "core/io/json.h"
#include "core/object/object.h"
#include "core/templates/vector.h"
#include "editor/import/resource_importer_scene.h"
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index 988a75ac93..40f2116676 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -238,15 +238,13 @@ Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) {
String text;
text.parse_utf8((const char *)array.ptr(), array.size());
- String err_txt;
- int err_line;
- Variant v;
- err = JSON::parse(text, v, err_txt, err_line);
+ JSON json;
+ err = json.parse(text);
if (err != OK) {
- _err_print_error("", p_path.utf8().get_data(), err_line, err_txt.utf8().get_data(), ERR_HANDLER_SCRIPT);
+ _err_print_error("", p_path.utf8().get_data(), json.get_error_line(), json.get_error_message().utf8().get_data(), ERR_HANDLER_SCRIPT);
return err;
}
- state->json = v;
+ state->json = json.get_data();
return OK;
}
@@ -299,16 +297,14 @@ Error GLTFDocument::_parse_glb(const String &p_path, Ref<GLTFState> state) {
String text;
text.parse_utf8((const char *)json_data.ptr(), json_data.size());
- String err_txt;
- int err_line;
- Variant v;
- err = JSON::parse(text, v, err_txt, err_line);
+ JSON json;
+ err = json.parse(text);
if (err != OK) {
- _err_print_error("", p_path.utf8().get_data(), err_line, err_txt.utf8().get_data(), ERR_HANDLER_SCRIPT);
+ _err_print_error("", p_path.utf8().get_data(), json.get_error_line(), json.get_error_message().utf8().get_data(), ERR_HANDLER_SCRIPT);
return err;
}
- state->json = v;
+ state->json = json.get_data();
//data?
@@ -6584,7 +6580,7 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) {
FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V(!f, FAILED);
- String json = JSON::print(state->json);
+ String json = Variant(state->json).to_json_string();
const uint32_t magic = 0x46546C67; // GLTF
const int32_t header_size = 12;
@@ -6625,7 +6621,7 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) {
ERR_FAIL_COND_V(!f, FAILED);
f->create(FileAccess::ACCESS_RESOURCES);
- String json = JSON::print(state->json);
+ String json = Variant(state->json).to_json_string();
f->store_string(json);
f->close();
}
diff --git a/modules/jsonrpc/jsonrpc.cpp b/modules/jsonrpc/jsonrpc.cpp
index 306c0ff087..3d0759d83e 100644
--- a/modules/jsonrpc/jsonrpc.cpp
+++ b/modules/jsonrpc/jsonrpc.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "jsonrpc.h"
+
#include "core/io/json.h"
JSONRPC::JSONRPC() {
@@ -156,19 +157,17 @@ String JSONRPC::process_string(const String &p_input) {
}
Variant ret;
- Variant input;
- String err_message;
- int err_line;
- if (OK != JSON::parse(p_input, input, err_message, err_line)) {
- ret = make_response_error(JSONRPC::PARSE_ERROR, "Parse error");
+ JSON json;
+ if (json.parse(p_input) == OK) {
+ ret = process_action(json.get_data(), true);
} else {
- ret = process_action(input, true);
+ ret = make_response_error(JSONRPC::PARSE_ERROR, "Parse error");
}
if (ret.get_type() == Variant::NIL) {
return "";
}
- return JSON::print(ret);
+ return ret.to_json_string();
}
void JSONRPC::set_scope(const String &p_scope, Object *p_obj) {
diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp
index bd02ec0eac..25193a1352 100644
--- a/modules/mono/class_db_api_json.cpp
+++ b/modules/mono/class_db_api_json.cpp
@@ -240,7 +240,8 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) {
FileAccessRef f = FileAccess::open(p_output_file, FileAccess::WRITE);
ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_output_file + "'.");
- f->store_string(JSON::print(classes_dict, /*indent: */ "\t"));
+ JSON json;
+ f->store_string(json.stringify(classes_dict, "\t"));
f->close();
print_line(String() + "ClassDB API JSON written to: " + ProjectSettings::get_singleton()->globalize_path(p_output_file));
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 576256b6ec..b54340a7bc 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -38,7 +38,6 @@
#include "core/debugger/engine_debugger.h"
#include "core/debugger/script_debugger.h"
#include "core/io/file_access.h"
-#include "core/io/json.h"
#include "core/os/mutex.h"
#include "core/os/os.h"
#include "core/os/thread.h"
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index 965e882c5b..2f1ee6b123 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -455,9 +455,8 @@ public:
Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const override;
bool is_using_templates() override;
void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) override;
- /* TODO */ bool validate(const String &p_script, int &r_line_error, int &r_col_error,
- String &r_test_error, const String &p_path, List<String> *r_functions,
- List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const override {
+ /* TODO */ bool validate(const String &p_script, const String &p_path, List<String> *r_functions,
+ List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const override {
return true;
}
String validate_path(const String &p_path) const override;
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index 7badb1b717..1047a4d3a3 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -2276,7 +2276,7 @@ void VisualScriptLanguage::make_template(const String &p_class_name, const Strin
script->set_instance_base_type(p_base_class_name);
}
-bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
+bool VisualScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
return false;
}
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 438ec99a56..5e848dc6c7 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -571,7 +571,7 @@ public:
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
virtual bool is_using_templates();
virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script);
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
+ virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 1a0c206e28..4262cc1a50 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -1849,7 +1849,7 @@ public:
err = OS::get_singleton()->execute(adb, args, &output, &rv, true);
print_verbose(output);
if (err || rv != 0) {
- EditorNode::add_io_error("Could not install to device.");
+ EditorNode::add_io_error("Could not install to device: " + output);
CLEANUP_AND_RETURN(ERR_CANT_CREATE);
}
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index 7e49feee61..823f9b8281 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -29,7 +29,6 @@
/*************************************************************************/
#include "core/io/image_loader.h"
-#include "core/io/json.h"
#include "core/io/stream_peer_ssl.h"
#include "core/io/tcp_server.h"
#include "core/io/zip_io.h"
@@ -465,7 +464,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Re
}
// Replaces HTML string
- const String str_config = JSON::print(config);
+ const String str_config = Variant(config).to_json_string();
const String custom_head_include = p_preset->get("html/head_include");
Map<String, String> replaces;
replaces["$GODOT_URL"] = p_name + ".js";
@@ -518,7 +517,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &
replaces["@GODOT_NAME@"] = name;
replaces["@GODOT_OFFLINE_PAGE@"] = name + ".offline.html";
Array files;
- replaces["@GODOT_OPT_CACHE@"] = JSON::print(files);
+ replaces["@GODOT_OPT_CACHE@"] = Variant(files).to_json_string();
files.push_back(name + ".html");
files.push_back(name + ".js");
files.push_back(name + ".wasm");
@@ -537,7 +536,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &
files.push_back(p_shared_objects[i].path.get_file());
}
}
- replaces["@GODOT_CACHE@"] = JSON::print(files);
+ replaces["@GODOT_CACHE@"] = Variant(files).to_json_string();
const String sw_path = dir.plus_file(name + ".service.worker.js");
Vector<uint8_t> sw;
@@ -605,7 +604,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &
}
manifest["icons"] = icons_arr;
- CharString cs = JSON::print(manifest).utf8();
+ CharString cs = Variant(manifest).to_json_string().utf8();
err = _write_or_error((const uint8_t *)cs.get_data(), cs.length(), dir.plus_file(name + ".manifest.json"));
if (err != OK) {
return err;
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index b4e597f75e..7bf616e602 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -30,535 +30,407 @@
#include "tween.h"
-void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5, const Variant &p_arg6, const Variant &p_arg7, const Variant &p_arg8, const Variant &p_arg9, const Variant &p_arg10) {
- // Add a new pending command and reference it
- pending_commands.push_back(PendingCommand());
- PendingCommand &cmd = pending_commands.back()->get();
-
- // Update the command with the target key
- cmd.key = p_key;
-
- // Determine command argument count
- int &count = cmd.args;
- if (p_arg10.get_type() != Variant::NIL) {
- count = 10;
- } else if (p_arg9.get_type() != Variant::NIL) {
- count = 9;
- } else if (p_arg8.get_type() != Variant::NIL) {
- count = 8;
- } else if (p_arg7.get_type() != Variant::NIL) {
- count = 7;
- } else if (p_arg6.get_type() != Variant::NIL) {
- count = 6;
- } else if (p_arg5.get_type() != Variant::NIL) {
- count = 5;
- } else if (p_arg4.get_type() != Variant::NIL) {
- count = 4;
- } else if (p_arg3.get_type() != Variant::NIL) {
- count = 3;
- } else if (p_arg2.get_type() != Variant::NIL) {
- count = 2;
- } else if (p_arg1.get_type() != Variant::NIL) {
- count = 1;
- } else {
- count = 0;
- }
+#include "scene/main/node.h"
- // Add the specified arguments to the command
- if (count > 0) {
- cmd.arg[0] = p_arg1;
- }
- if (count > 1) {
- cmd.arg[1] = p_arg2;
- }
- if (count > 2) {
- cmd.arg[2] = p_arg3;
- }
- if (count > 3) {
- cmd.arg[3] = p_arg4;
- }
- if (count > 4) {
- cmd.arg[4] = p_arg5;
- }
- if (count > 5) {
- cmd.arg[5] = p_arg6;
- }
- if (count > 6) {
- cmd.arg[6] = p_arg7;
- }
- if (count > 7) {
- cmd.arg[7] = p_arg8;
- }
- if (count > 8) {
- cmd.arg[8] = p_arg9;
+void Tweener::set_tween(Ref<Tween> p_tween) {
+ tween = p_tween;
+}
+
+void Tweener::_bind_methods() {
+ ADD_SIGNAL(MethodInfo("finished"));
+}
+
+void Tween::start_tweeners() {
+ if (tweeners.is_empty()) {
+ dead = true;
+ ERR_FAIL_MSG("Tween without commands, aborting.");
}
- if (count > 9) {
- cmd.arg[9] = p_arg10;
+
+ for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) {
+ E->get()->start();
}
}
-void Tween::_process_pending_commands() {
- // For each pending command...
- for (List<PendingCommand>::Element *E = pending_commands.front(); E; E = E->next()) {
- // Get the command
- PendingCommand &cmd = E->get();
- Callable::CallError err;
-
- // Grab all of the arguments for the command
- Variant *arg[10] = {
- &cmd.arg[0],
- &cmd.arg[1],
- &cmd.arg[2],
- &cmd.arg[3],
- &cmd.arg[4],
- &cmd.arg[5],
- &cmd.arg[6],
- &cmd.arg[7],
- &cmd.arg[8],
- &cmd.arg[9],
- };
-
- // Execute the command (and retrieve any errors)
- this->call(cmd.key, (const Variant **)arg, cmd.args, err);
- }
+Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, float p_duration) {
+ ERR_FAIL_NULL_V(p_target, nullptr);
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
- // Clear the pending commands
- pending_commands.clear();
+ Ref<PropertyTweener> tweener = memnew(PropertyTweener(p_target, p_property, p_to, p_duration));
+ append(tweener);
+ return tweener;
}
-bool Tween::_set(const StringName &p_name, const Variant &p_value) {
- // Set the correct attribute based on the given name
- String name = p_name;
- if (name == "playback/speed" || name == "speed") { // Backwards compatibility
- set_speed_scale(p_value);
- return true;
+Ref<IntervalTweener> Tween::tween_interval(float p_time) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
- } else if (name == "playback/active") {
- set_active(p_value);
- return true;
+ Ref<IntervalTweener> tweener = memnew(IntervalTweener(p_time));
+ append(tweener);
+ return tweener;
+}
- } else if (name == "playback/repeat") {
- set_repeat(p_value);
- return true;
- }
- return false;
+Ref<CallbackTweener> Tween::tween_callback(Callable p_callback) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
+
+ Ref<CallbackTweener> tweener = memnew(CallbackTweener(p_callback));
+ append(tweener);
+ return tweener;
}
-bool Tween::_get(const StringName &p_name, Variant &r_ret) const {
- // Get the correct attribute based on the given name
- String name = p_name;
- if (name == "playback/speed") { // Backwards compatibility
- r_ret = speed_scale;
- return true;
+Ref<MethodTweener> Tween::tween_method(Callable p_callback, float p_from, float p_to, float p_duration) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
- } else if (name == "playback/active") {
- r_ret = is_active();
- return true;
+ Ref<MethodTweener> tweener = memnew(MethodTweener(p_callback, p_from, p_to, p_duration));
+ append(tweener);
+ return tweener;
+}
- } else if (name == "playback/repeat") {
- r_ret = is_repeat();
- return true;
+Ref<Tween> Tween::append(Ref<Tweener> p_tweener) {
+ ERR_FAIL_COND_V_MSG(invalid, nullptr, "Tween was created outside the scene tree, can't use Tweeners.");
+ ERR_FAIL_COND_V_MSG(started, nullptr, "Can't append to a Tween that has started. Use stop() first.");
+ p_tweener->set_tween(this);
+
+ if (parallel_enabled) {
+ current_step = MAX(current_step, 0);
+ } else {
+ current_step++;
}
- return false;
-}
-
-void Tween::_get_property_list(List<PropertyInfo> *p_list) const {
- // Add the property info for the Tween object
- p_list->push_back(PropertyInfo(Variant::BOOL, "playback/active", PROPERTY_HINT_NONE, ""));
- p_list->push_back(PropertyInfo(Variant::BOOL, "playback/repeat", PROPERTY_HINT_NONE, ""));
- p_list->push_back(PropertyInfo(Variant::FLOAT, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01"));
-}
-
-void Tween::_notification(int p_what) {
- // What notification did we receive?
- switch (p_what) {
- case NOTIFICATION_ENTER_TREE: {
- // Are we not already active?
- if (!is_active()) {
- // Make sure that a previous process state was not saved
- // Only process if "processing" is set
- set_physics_process_internal(false);
- set_process_internal(false);
- }
- } break;
+ parallel_enabled = default_parallel;
- case NOTIFICATION_READY: {
- // Do nothing
- } break;
+ tweeners.resize(current_step + 1);
+ tweeners.write[current_step].push_back(p_tweener);
- case NOTIFICATION_INTERNAL_PROCESS: {
- // Are we processing during physics time?
- if (tween_process_mode == TWEEN_PROCESS_PHYSICS) {
- // Do nothing since we aren't aligned with physics when we should be
- break;
- }
+ return this;
+}
- // Should we update?
- if (is_active()) {
- // Update the tweens
- _tween_process(get_process_delta_time());
- }
- } break;
+void Tween::stop() {
+ started = false;
+ running = false;
+ dead = false;
+}
- case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- // Are we processing during 'regular' time?
- if (tween_process_mode == TWEEN_PROCESS_IDLE) {
- // Do nothing since we would only process during idle time
- break;
- }
+void Tween::pause() {
+ running = false;
+}
- // Should we update?
- if (is_active()) {
- // Update the tweens
- _tween_process(get_physics_process_delta_time());
- }
- } break;
+void Tween::play() {
+ ERR_FAIL_COND_MSG(invalid, "Tween invalid, can't play.");
+ ERR_FAIL_COND_MSG(dead, "Can't play finished Tween, use stop() first to reset its state.");
+ running = true;
+}
- case NOTIFICATION_EXIT_TREE: {
- // We've left the tree. Stop all tweens
- stop_all();
- } break;
- }
+void Tween::kill() {
+ running = false; // For the sake of is_running().
+ dead = true;
}
-void Tween::_bind_methods() {
- // Bind getters and setters
- ClassDB::bind_method(D_METHOD("is_active"), &Tween::is_active);
- ClassDB::bind_method(D_METHOD("set_active", "active"), &Tween::set_active);
+bool Tween::is_running() {
+ return running;
+}
- ClassDB::bind_method(D_METHOD("is_repeat"), &Tween::is_repeat);
- ClassDB::bind_method(D_METHOD("set_repeat", "repeat"), &Tween::set_repeat);
+void Tween::set_valid(bool p_valid) {
+ invalid = !p_valid;
+}
- ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale);
- ClassDB::bind_method(D_METHOD("get_speed_scale"), &Tween::get_speed_scale);
-
- ClassDB::bind_method(D_METHOD("set_tween_process_mode", "mode"), &Tween::set_tween_process_mode);
- ClassDB::bind_method(D_METHOD("get_tween_process_mode"), &Tween::get_tween_process_mode);
-
- // Bind the various Tween control methods
- ClassDB::bind_method(D_METHOD("start"), &Tween::start);
- ClassDB::bind_method(D_METHOD("reset", "object", "key"), &Tween::reset, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("reset_all"), &Tween::reset_all);
- ClassDB::bind_method(D_METHOD("stop", "object", "key"), &Tween::stop, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("stop_all"), &Tween::stop_all);
- ClassDB::bind_method(D_METHOD("resume", "object", "key"), &Tween::resume, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("resume_all"), &Tween::resume_all);
- ClassDB::bind_method(D_METHOD("remove", "object", "key"), &Tween::remove, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("_remove_by_uid", "uid"), &Tween::_remove_by_uid);
- ClassDB::bind_method(D_METHOD("remove_all"), &Tween::remove_all);
- ClassDB::bind_method(D_METHOD("seek", "time"), &Tween::seek);
- ClassDB::bind_method(D_METHOD("tell"), &Tween::tell);
- ClassDB::bind_method(D_METHOD("get_runtime"), &Tween::get_runtime);
-
- // Bind interpolation and follow methods
- ClassDB::bind_method(D_METHOD("interpolate_property", "object", "property", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
- ClassDB::bind_method(D_METHOD("interpolate_method", "object", "method", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::interpolate_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
- ClassDB::bind_method(D_METHOD("interpolate_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5"), &Tween::interpolate_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("interpolate_deferred_callback", "object", "duration", "callback", "arg1", "arg2", "arg3", "arg4", "arg5"), &Tween::interpolate_deferred_callback, DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("follow_property", "object", "property", "initial_val", "target", "target_property", "duration", "trans_type", "ease_type", "delay"), &Tween::follow_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
- ClassDB::bind_method(D_METHOD("follow_method", "object", "method", "initial_val", "target", "target_method", "duration", "trans_type", "ease_type", "delay"), &Tween::follow_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
- ClassDB::bind_method(D_METHOD("targeting_property", "object", "property", "initial", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_property, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
- ClassDB::bind_method(D_METHOD("targeting_method", "object", "method", "initial", "initial_method", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_method, DEFVAL(TRANS_LINEAR), DEFVAL(EASE_IN_OUT), DEFVAL(0));
-
- // Add the Tween signals
- ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key")));
- ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"), PropertyInfo(Variant::FLOAT, "elapsed"), PropertyInfo(Variant::OBJECT, "value")));
- ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key")));
- ADD_SIGNAL(MethodInfo("tween_all_completed"));
-
- // Add the properties and tie them to the getters and setters
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "repeat"), "set_repeat", "is_repeat");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_tween_process_mode", "get_tween_process_mode");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale");
-
- // Bind Idle vs Physics process
- BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS);
- BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE);
+bool Tween::is_valid() {
+ return invalid;
+}
- // Bind the Transition type constants
- BIND_ENUM_CONSTANT(TRANS_LINEAR);
- BIND_ENUM_CONSTANT(TRANS_SINE);
- BIND_ENUM_CONSTANT(TRANS_QUINT);
- BIND_ENUM_CONSTANT(TRANS_QUART);
- BIND_ENUM_CONSTANT(TRANS_QUAD);
- BIND_ENUM_CONSTANT(TRANS_EXPO);
- BIND_ENUM_CONSTANT(TRANS_ELASTIC);
- BIND_ENUM_CONSTANT(TRANS_CUBIC);
- BIND_ENUM_CONSTANT(TRANS_CIRC);
- BIND_ENUM_CONSTANT(TRANS_BOUNCE);
- BIND_ENUM_CONSTANT(TRANS_BACK);
+Ref<Tween> Tween::bind_node(Node *p_node) {
+ bound_node = p_node->get_instance_id();
+ is_bound = true;
+ return this;
+}
- // Bind the easing constants
- BIND_ENUM_CONSTANT(EASE_IN);
- BIND_ENUM_CONSTANT(EASE_OUT);
- BIND_ENUM_CONSTANT(EASE_IN_OUT);
- BIND_ENUM_CONSTANT(EASE_OUT_IN);
+Ref<Tween> Tween::set_process_mode(TweenProcessMode p_mode) {
+ process_mode = p_mode;
+ return this;
}
-Variant Tween::_get_initial_val(const InterpolateData &p_data) const {
- // What type of data are we interpolating?
- switch (p_data.type) {
- case INTER_PROPERTY:
- case INTER_METHOD:
- case FOLLOW_PROPERTY:
- case FOLLOW_METHOD:
- // Simply use the given initial value
- return p_data.initial_val;
-
- case TARGETING_PROPERTY:
- case TARGETING_METHOD: {
- // Get the object that is being targeted
- Object *object = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(object == nullptr, p_data.initial_val);
-
- // Are we targeting a property or a method?
- Variant initial_val;
- if (p_data.type == TARGETING_PROPERTY) {
- // Get the property from the target object
- bool valid = false;
- initial_val = object->get_indexed(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid, p_data.initial_val);
- } else {
- // Call the method and get the initial value from it
- Callable::CallError error;
- initial_val = object->call(p_data.target_key[0], nullptr, 0, error);
- ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val);
- }
- return initial_val;
- }
+Tween::TweenProcessMode Tween::get_process_mode() {
+ return process_mode;
+}
+
+Ref<Tween> Tween::set_pause_mode(TweenPauseMode p_mode) {
+ pause_mode = p_mode;
+ return this;
+}
+
+Tween::TweenPauseMode Tween::get_pause_mode() {
+ return pause_mode;
+}
+
+Ref<Tween> Tween::set_parallel(bool p_parallel) {
+ default_parallel = p_parallel;
+ parallel_enabled = p_parallel;
+ return this;
+}
+
+Ref<Tween> Tween::set_loops(int p_loops) {
+ loops = p_loops;
+ return this;
+}
+
+Ref<Tween> Tween::set_speed_scale(float p_speed) {
+ speed_scale = p_speed;
+ return this;
+}
+
+Ref<Tween> Tween::set_trans(TransitionType p_trans) {
+ default_transition = p_trans;
+ return this;
+}
- case INTER_CALLBACK:
- // Callback does not have a special initial value
- break;
+Tween::TransitionType Tween::get_trans() {
+ return default_transition;
+}
+
+Ref<Tween> Tween::set_ease(EaseType p_ease) {
+ default_ease = p_ease;
+ return this;
+}
+
+Tween::EaseType Tween::get_ease() {
+ return default_ease;
+}
+
+Ref<Tween> Tween::parallel() {
+ parallel_enabled = true;
+ return this;
+}
+
+Ref<Tween> Tween::chain() {
+ parallel_enabled = false;
+ return this;
+}
+
+bool Tween::custom_step(float p_delta) {
+ bool r = running;
+ running = true;
+ bool ret = step(p_delta);
+ running = running && r; // Running might turn false when Tween finished.
+ return ret;
+}
+
+bool Tween::step(float p_delta) {
+ ERR_FAIL_COND_V_MSG(tweeners.is_empty(), false, "Tween started, but has no Tweeners.");
+
+ if (dead) {
+ return false;
}
- // If we've made it here, just return the delta value as the initial value
- return p_data.delta_val;
-}
-
-Variant Tween::_get_final_val(const InterpolateData &p_data) const {
- switch (p_data.type) {
- case FOLLOW_PROPERTY:
- case FOLLOW_METHOD: {
- // Get the object that is being followed
- Object *target = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(target == nullptr, p_data.initial_val);
-
- // We want to figure out the final value
- Variant final_val;
- if (p_data.type == FOLLOW_PROPERTY) {
- // Read the property as-is
- bool valid = false;
- final_val = target->get_indexed(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid, p_data.initial_val);
- } else {
- // We're looking at a method. Call the method on the target object
- Callable::CallError error;
- final_val = target->call(p_data.target_key[0], nullptr, 0, error);
- ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val);
- }
- // If we're looking at an INT value, instead convert it to a FLOAT
- // This is better for interpolation
- if (final_val.get_type() == Variant::INT) {
- final_val = final_val.operator real_t();
- }
+ if (!running) {
+ return true;
+ }
- return final_val;
- }
- default: {
- // If we're not following a final value/method, use the final value from the data
- return p_data.final_val;
+ if (is_bound) {
+ Object *bound_instance = ObjectDB::get_instance(bound_node);
+ if (bound_instance) {
+ Node *bound_node = Object::cast_to<Node>(bound_instance);
+ // This can't by anything else than Node, so we can omit checking if casting succeeded.
+ if (!bound_node->is_inside_tree()) {
+ return true;
+ }
+ } else {
+ return false;
}
}
-}
-Variant &Tween::_get_delta_val(InterpolateData &p_data) {
- // What kind of data are we interpolating?
- switch (p_data.type) {
- case INTER_PROPERTY:
- case INTER_METHOD:
- // Simply return the given delta value
- return p_data.delta_val;
-
- case FOLLOW_PROPERTY:
- case FOLLOW_METHOD: {
- // We're following an object, so grab that instance
- Object *target = ObjectDB::get_instance(p_data.target_id);
- ERR_FAIL_COND_V(target == nullptr, p_data.initial_val);
-
- // We want to figure out the final value
- Variant final_val;
- if (p_data.type == FOLLOW_PROPERTY) {
- // Read the property as-is
- bool valid = false;
- final_val = target->get_indexed(p_data.target_key, &valid);
- ERR_FAIL_COND_V(!valid, p_data.initial_val);
- } else {
- // We're looking at a method. Call the method on the target object
- Callable::CallError error;
- final_val = target->call(p_data.target_key[0], nullptr, 0, error);
- ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val);
- }
+ if (!started) {
+ current_step = 0;
+ loops_done = 0;
+ start_tweeners();
+ started = true;
+ }
- // If we're looking at an INT value, instead convert it to a FLOAT
- // This is better for interpolation
- if (final_val.get_type() == Variant::INT) {
- final_val = final_val.operator real_t();
- }
+ float rem_delta = p_delta * speed_scale;
+ bool step_active = false;
- // Calculate the delta based on the initial value and the final value
- _calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
- return p_data.delta_val;
+ while (rem_delta > 0 && running) {
+ float step_delta = rem_delta;
+ step_active = false;
+
+ for (List<Ref<Tweener>>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) {
+ // Modified inside Tweener.step().
+ float temp_delta = rem_delta;
+ // Turns to true if any Tweener returns true (i.e. is still not finished).
+ step_active = E->get()->step(temp_delta) || step_active;
+ step_delta = MIN(temp_delta, rem_delta);
}
- case TARGETING_PROPERTY:
- case TARGETING_METHOD: {
- // Grab the initial value from the data to calculate delta
- Variant initial_val = _get_initial_val(p_data);
+ rem_delta = step_delta;
- // If we're looking at an INT value, instead convert it to a FLOAT
- // This is better for interpolation
- if (initial_val.get_type() == Variant::INT) {
- initial_val = initial_val.operator real_t();
- }
+ if (!step_active) {
+ emit_signal("step_finished", current_step);
+ current_step++;
- // Calculate the delta based on the initial value and the final value
- _calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
- return p_data.delta_val;
+ if (current_step == tweeners.size()) {
+ loops_done++;
+ if (loops_done == loops) {
+ running = false;
+ dead = true;
+ emit_signal("finished");
+ } else {
+ emit_signal("loop_finished", loops_done);
+ current_step = 0;
+ start_tweeners();
+ }
+ } else {
+ start_tweeners();
+ }
}
+ }
+
+ return true;
+}
- case INTER_CALLBACK:
- // Callbacks have no special delta
- break;
+bool Tween::should_pause() {
+ if (is_bound && pause_mode == TWEEN_PAUSE_BOUND) {
+ Object *bound_instance = ObjectDB::get_instance(bound_node);
+ if (bound_instance) {
+ Node *bound_node = Object::cast_to<Node>(bound_instance);
+ return !bound_node->can_process();
+ }
}
- // If we've made it here, use the initial value as the delta
- return p_data.initial_val;
+
+ return pause_mode != TWEEN_PAUSE_PROCESS;
}
-Variant Tween::_run_equation(InterpolateData &p_data) {
- // Get the initial and delta values from the data
- Variant initial_val = _get_initial_val(p_data);
- Variant &delta_val = _get_delta_val(p_data);
- Variant result;
+Variant Tween::interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, TransitionType p_trans, EaseType p_ease) {
+ ERR_FAIL_INDEX_V(p_trans, TransitionType::TRANS_MAX, Variant());
+ ERR_FAIL_INDEX_V(p_ease, EaseType::EASE_MAX, Variant());
+// Helper macro to run equation on sub-elements of the value (e.g. x and y of Vector2).
#define APPLY_EQUATION(element) \
- r.element = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, i.element, d.element, p_data.duration);
+ r.element = run_equation(p_trans, p_ease, p_time, i.element, d.element, p_duration);
- // What type of data are we interpolating?
- switch (initial_val.get_type()) {
- case Variant::BOOL:
- // Run the boolean specific equation (checking if it is at least 0.5)
- result = (_run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, initial_val, delta_val, p_data.duration)) >= 0.5;
- break;
+ switch (p_initial_val.get_type()) {
+ case Variant::BOOL: {
+ return (run_equation(p_trans, p_ease, p_time, p_initial_val, p_delta_val, p_duration)) >= 0.5;
+ }
- case Variant::INT:
- // Run the integer specific equation
- result = (int)_run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (int)initial_val, (int)delta_val, p_data.duration);
- break;
+ case Variant::INT: {
+ return (int)run_equation(p_trans, p_ease, p_time, (int)p_initial_val, (int)p_delta_val, p_duration);
+ }
- case Variant::FLOAT:
- // Run the FLOAT specific equation
- result = _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (real_t)initial_val, (real_t)delta_val, p_data.duration);
- break;
+ case Variant::FLOAT: {
+ return run_equation(p_trans, p_ease, p_time, (real_t)p_initial_val, (real_t)p_delta_val, p_duration);
+ }
case Variant::VECTOR2: {
- // Get vectors for initial and delta values
- Vector2 i = initial_val;
- Vector2 d = delta_val;
+ Vector2 i = p_initial_val;
+ Vector2 d = p_delta_val;
Vector2 r;
- // Execute the equation and mutate the r vector
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(x);
APPLY_EQUATION(y);
- result = r;
- } break;
+ return r;
+ }
+
+ case Variant::VECTOR2I: {
+ Vector2i i = p_initial_val;
+ Vector2i d = p_delta_val;
+ Vector2i r;
+
+ APPLY_EQUATION(x);
+ APPLY_EQUATION(y);
+ return r;
+ }
case Variant::RECT2: {
- // Get the Rect2 for initial and delta value
- Rect2 i = initial_val;
- Rect2 d = delta_val;
+ Rect2 i = p_initial_val;
+ Rect2 d = p_delta_val;
Rect2 r;
- // Execute the equation for the position and size of Rect2
APPLY_EQUATION(position.x);
APPLY_EQUATION(position.y);
APPLY_EQUATION(size.x);
APPLY_EQUATION(size.y);
- result = r;
- } break;
+ return r;
+ }
+
+ case Variant::RECT2I: {
+ Rect2i i = p_initial_val;
+ Rect2i d = p_delta_val;
+ Rect2i r;
+
+ APPLY_EQUATION(position.x);
+ APPLY_EQUATION(position.y);
+ APPLY_EQUATION(size.x);
+ APPLY_EQUATION(size.y);
+ return r;
+ }
case Variant::VECTOR3: {
- // Get vectors for initial and delta values
- Vector3 i = initial_val;
- Vector3 d = delta_val;
+ Vector3 i = p_initial_val;
+ Vector3 d = p_delta_val;
Vector3 r;
- // Execute the equation and mutate the r vector
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(x);
APPLY_EQUATION(y);
APPLY_EQUATION(z);
- result = r;
- } break;
+ return r;
+ }
+
+ case Variant::VECTOR3I: {
+ Vector3i i = p_initial_val;
+ Vector3i d = p_delta_val;
+ Vector3i r;
+
+ APPLY_EQUATION(x);
+ APPLY_EQUATION(y);
+ APPLY_EQUATION(z);
+ return r;
+ }
case Variant::TRANSFORM2D: {
- // Get the transforms for initial and delta values
- Transform2D i = initial_val;
- Transform2D d = delta_val;
+ Transform2D i = p_initial_val;
+ Transform2D d = p_delta_val;
Transform2D r;
- // Execute the equation on the transforms and mutate the r transform
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(elements[0][0]);
APPLY_EQUATION(elements[0][1]);
APPLY_EQUATION(elements[1][0]);
APPLY_EQUATION(elements[1][1]);
APPLY_EQUATION(elements[2][0]);
APPLY_EQUATION(elements[2][1]);
- result = r;
- } break;
+ return r;
+ }
case Variant::QUATERNION: {
- // Get the quaternian for the initial and delta values
- Quaternion i = initial_val;
- Quaternion d = delta_val;
+ Quaternion i = p_initial_val;
+ Quaternion d = p_delta_val;
Quaternion r;
- // Execute the equation on the quaternian values and mutate the r quaternian
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(x);
APPLY_EQUATION(y);
APPLY_EQUATION(z);
APPLY_EQUATION(w);
- result = r;
- } break;
+ return r;
+ }
case Variant::AABB: {
- // Get the AABB's for the initial and delta values
- AABB i = initial_val;
- AABB d = delta_val;
+ AABB i = p_initial_val;
+ AABB d = p_delta_val;
AABB r;
- // Execute the equation for the position and size of the AABB's and mutate the r AABB
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(position.x);
APPLY_EQUATION(position.y);
APPLY_EQUATION(position.z);
APPLY_EQUATION(size.x);
APPLY_EQUATION(size.y);
APPLY_EQUATION(size.z);
- result = r;
- } break;
+ return r;
+ }
case Variant::BASIS: {
- // Get the basis for initial and delta values
- Basis i = initial_val;
- Basis d = delta_val;
+ Basis i = p_initial_val;
+ Basis d = p_delta_val;
Basis r;
- // Execute the equation on all the basis and mutate the r basis
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(elements[0][0]);
APPLY_EQUATION(elements[0][1]);
APPLY_EQUATION(elements[0][2]);
@@ -568,17 +440,14 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
APPLY_EQUATION(elements[2][0]);
APPLY_EQUATION(elements[2][1]);
APPLY_EQUATION(elements[2][2]);
- result = r;
- } break;
+ return r;
+ }
case Variant::TRANSFORM3D: {
- // Get the transforms for the initial and delta values
- Transform3D i = initial_val;
- Transform3D d = delta_val;
+ Transform3D i = p_initial_val;
+ Transform3D d = p_delta_val;
Transform3D r;
- // Execute the equation for each of the transforms and their origin and mutate the r transform
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(basis.elements[0][0]);
APPLY_EQUATION(basis.elements[0][1]);
APPLY_EQUATION(basis.elements[0][2]);
@@ -591,634 +460,67 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
APPLY_EQUATION(origin.x);
APPLY_EQUATION(origin.y);
APPLY_EQUATION(origin.z);
- result = r;
- } break;
+ return r;
+ }
case Variant::COLOR: {
- // Get the Color for initial and delta value
- Color i = initial_val;
- Color d = delta_val;
+ Color i = p_initial_val;
+ Color d = p_delta_val;
Color r;
- // Apply the equation on the Color RGBA, and mutate the r color
- // This uses the custom APPLY_EQUATION macro defined above
APPLY_EQUATION(r);
APPLY_EQUATION(g);
APPLY_EQUATION(b);
APPLY_EQUATION(a);
- result = r;
- } break;
-
- default: {
- // If unknown, just return the initial value
- result = initial_val;
- } break;
- };
-#undef APPLY_EQUATION
- // Return the result that was computed
- return result;
-}
-
-bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) {
- // Get the object we want to apply the new value to
- Object *object = ObjectDB::get_instance(p_data.id);
- ERR_FAIL_COND_V(object == nullptr, false);
-
- // What kind of data are we mutating?
- switch (p_data.type) {
- case INTER_PROPERTY:
- case FOLLOW_PROPERTY:
- case TARGETING_PROPERTY: {
- // Simply set the property on the object
- bool valid = false;
- object->set_indexed(p_data.key, value, &valid);
- return valid;
+ return r;
}
- case INTER_METHOD:
- case FOLLOW_METHOD:
- case TARGETING_METHOD: {
- // We want to call the method on the target object
- Callable::CallError error;
-
- // Do we have a non-nil value passed in?
- if (value.get_type() != Variant::NIL) {
- // Pass it as an argument to the function call
- Variant *arg[1] = { &value };
- object->call(p_data.key[0], (const Variant **)arg, 1, error);
- } else {
- // Don't pass any argument
- object->call(p_data.key[0], nullptr, 0, error);
- }
-
- // Did we get an error from the function call?
- return error.error == Callable::CallError::CALL_OK;
+ default: {
+ return p_initial_val;
}
-
- case INTER_CALLBACK:
- // Nothing to apply for a callback
- break;
};
- // No issues found!
- return true;
-}
-
-void Tween::_tween_process(float p_delta) {
- // Process all of the pending commands
- _process_pending_commands();
-
- // If the scale is 0, make no progress on the tweens
- if (speed_scale == 0) {
- return;
- }
-
- // Update the delta and whether we are pending an update
- p_delta *= speed_scale;
- pending_update++;
-
- // Are we repeating the interpolations?
- if (repeat) {
- // For each interpolation...
- bool repeats_finished = true;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the data from it
- InterpolateData &data = E->get();
-
- // Is not finished?
- if (!data.finish) {
- // We aren't finished yet, no need to check the rest
- repeats_finished = false;
- break;
- }
- }
-
- // If we are all finished, we can reset all of the tweens
- if (repeats_finished) {
- reset_all();
- }
- }
-
- // Are all of the tweens complete?
- int any_unfinished = 0;
-
- // For each tween we wish to interpolate...
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the data from it
- InterpolateData &data = E->get();
-
- // Is the data not active or already finished? No need to go any further
- if (!data.active || data.finish) {
- continue;
- }
-
- // Track if we hit one that isn't finished yet
- any_unfinished++;
-
- // Get the target object for this interpolation
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // Are we still delaying this tween?
- bool prev_delaying = data.elapsed <= data.delay;
- data.elapsed += p_delta;
- if (data.elapsed < data.delay) {
- continue;
- } else if (prev_delaying) {
- // We can apply the tween's value to the data and emit that the tween has started
- _apply_tween_value(data, data.initial_val);
- emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false));
- }
-
- // Are we at the end of the tween?
- if (data.elapsed > (data.delay + data.duration)) {
- // Set the elapsed time to the end and mark this one as finished
- data.elapsed = data.delay + data.duration;
- data.finish = true;
- }
-
- // Are we interpolating a callback?
- if (data.type == INTER_CALLBACK) {
- // Is the tween completed?
- if (data.finish) {
- // Are we calling this callback deferred or immediately?
- if (data.call_deferred) {
- // Run the deferred function callback, applying the correct number of arguments
- switch (data.args) {
- case 0:
- object->call_deferred(data.key[0]);
- break;
- case 1:
- object->call_deferred(data.key[0], data.arg[0]);
- break;
- case 2:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1]);
- break;
- case 3:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]);
- break;
- case 4:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]);
- break;
- case 5:
- object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]);
- break;
- }
- } else {
- // Call the function directly with the arguments
- Callable::CallError error;
- Variant *arg[5] = {
- &data.arg[0],
- &data.arg[1],
- &data.arg[2],
- &data.arg[3],
- &data.arg[4],
- };
- object->call(data.key[0], (const Variant **)arg, data.args, error);
- }
- }
- } else {
- // We can apply the value directly
- Variant result = _run_equation(data);
- _apply_tween_value(data, result);
-
- // Emit that the tween has taken a step
- emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result);
- }
-
- // Is the tween now finished?
- if (data.finish) {
- // Set it to the final value directly
- Variant final_val = _get_final_val(data);
- _apply_tween_value(data, final_val);
-
- // Mark the tween as completed and emit the signal
- data.elapsed = 0;
- emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false));
-
- // If we are not repeating the tween, remove it
- if (!repeat) {
- call_deferred("_remove_by_uid", data.uid);
- any_unfinished--;
- }
- }
- }
- // One less update left to go
- pending_update--;
-
- // If all tweens are completed, we no longer need to be active
- if (any_unfinished == 0) {
- set_active(false);
- emit_signal("tween_all_completed");
- }
-}
-
-void Tween::set_tween_process_mode(TweenProcessMode p_mode) {
- tween_process_mode = p_mode;
-}
-
-Tween::TweenProcessMode Tween::get_tween_process_mode() const {
- return tween_process_mode;
-}
-
-bool Tween::is_active() const {
- return is_processing_internal() || is_physics_processing_internal();
-}
-
-void Tween::set_active(bool p_active) {
- // Do nothing if it's the same active mode that we currently are
- if (is_active() == p_active) {
- return;
- }
-
- // Depending on physics or idle, set processing
- switch (tween_process_mode) {
- case TWEEN_PROCESS_IDLE:
- set_process_internal(p_active);
- break;
- case TWEEN_PROCESS_PHYSICS:
- set_physics_process_internal(p_active);
- break;
- }
-}
-
-bool Tween::is_repeat() const {
- return repeat;
-}
-
-void Tween::set_repeat(bool p_repeat) {
- repeat = p_repeat;
-}
-
-void Tween::set_speed_scale(float p_speed) {
- speed_scale = p_speed;
-}
-
-float Tween::get_speed_scale() const {
- return speed_scale;
-}
-
-void Tween::start() {
- ERR_FAIL_COND_MSG(!is_inside_tree(), "Tween was not added to the SceneTree!");
-
- // Are there any pending updates?
- if (pending_update != 0) {
- // Start the tweens after deferring
- call_deferred("start");
- return;
- }
-
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- InterpolateData &data = E->get();
- data.active = true;
- }
- pending_update--;
-
- // We want to be activated
- set_active(true);
-
- // Don't resume from current position if stop_all() function has been used
- if (was_stopped) {
- seek(0);
- }
- was_stopped = false;
-}
-
-void Tween::reset(Object *p_object, StringName p_key) {
- // Find all interpolations that use the same object and target string
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target object
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // Do we have the correct object and key?
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- // Reset the tween to the initial state
- data.elapsed = 0;
- data.finish = false;
-
- // Also apply the initial state if there isn't a delay
- if (data.delay == 0) {
- _apply_tween_value(data, data.initial_val);
- }
- }
- }
- pending_update--;
-}
-
-void Tween::reset_all() {
- // Go through all interpolations
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target data and set it back to the initial state
- InterpolateData &data = E->get();
- data.elapsed = 0;
- data.finish = false;
-
- // If there isn't a delay, apply the value to the object
- if (data.delay == 0) {
- _apply_tween_value(data, data.initial_val);
- }
- }
- pending_update--;
-}
-
-void Tween::stop(Object *p_object, StringName p_key) {
- // Find the tween that has the given target object and string key
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the object the tween is targeting
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // Is this the correct object and does it have the given key?
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- // Disable the tween
- data.active = false;
- }
- }
- pending_update--;
-}
-
-void Tween::stop_all() {
- // We no longer need to be active since all tweens have been stopped
- set_active(false);
- was_stopped = true;
- // For each interpolation...
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Simply set it inactive
- InterpolateData &data = E->get();
- data.active = false;
- }
- pending_update--;
-}
-
-void Tween::resume(Object *p_object, StringName p_key) {
- // We need to be activated
- // TODO: What if no tween is found??
- set_active(true);
-
- // Find the tween that uses the given target object and string key
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Grab the object
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // If the object and string key match, activate it
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- data.active = true;
- }
- }
- pending_update--;
-}
-
-void Tween::resume_all() {
- // Set ourselves active so we can process tweens
- // TODO: What if there are no tweens? We get set to active for no reason!
- set_active(true);
-
- // For each interpolation...
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Simply grab it and set it to active
- InterpolateData &data = E->get();
- data.active = true;
- }
- pending_update--;
-}
-
-void Tween::remove(Object *p_object, StringName p_key) {
- // If we are still updating, call this function again later
- if (pending_update != 0) {
- call_deferred("remove", p_object, p_key);
- return;
- }
-
- // For each interpolation...
- List<List<InterpolateData>::Element *> for_removal;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target object
- InterpolateData &data = E->get();
- Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr) {
- continue;
- }
-
- // If the target object and string key match, queue it for removal
- if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
- for_removal.push_back(E);
- }
- }
-
- // For each interpolation we wish to remove...
- for (List<List<InterpolateData>::Element *>::Element *E = for_removal.front(); E; E = E->next()) {
- // Erase it
- interpolates.erase(E->get());
- }
-}
-
-void Tween::_remove_by_uid(int uid) {
- // If we are still updating, call this function again later
- if (pending_update != 0) {
- call_deferred("_remove_by_uid", uid);
- return;
- }
-
- // Find the interpolation that matches the given UID
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- if (uid == E->get().uid) {
- // It matches, erase it and stop looking
- E->erase();
- break;
- }
- }
-}
-
-void Tween::_push_interpolate_data(InterpolateData &p_data) {
- pending_update++;
-
- // Add the new interpolation
- p_data.uid = ++uid;
- interpolates.push_back(p_data);
-
- pending_update--;
+#undef APPLY_EQUATION
}
-void Tween::remove_all() {
- // If we are still updating, call this function again later
- if (pending_update != 0) {
- call_deferred("remove_all");
- return;
- }
- // We no longer need to be active
- set_active(false);
-
- // Clear out all interpolations and reset the uid
- interpolates.clear();
- uid = 0;
-}
-
-void Tween::seek(real_t p_time) {
- // Go through each interpolation...
- pending_update++;
- for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the target data
- InterpolateData &data = E->get();
-
- // Update the elapsed data to be set to the target time
- data.elapsed = p_time;
-
- // Are we at the end?
- if (data.elapsed < data.delay) {
- // There is still time left to go
- data.finish = false;
- continue;
- } else if (data.elapsed >= (data.delay + data.duration)) {
- // We are past the end of it, set the elapsed time to the end and mark as finished
- data.elapsed = (data.delay + data.duration);
- data.finish = true;
- } else {
- // We are not finished with this interpolation yet
- data.finish = false;
+Variant Tween::calculate_delta_value(Variant p_intial_val, Variant p_final_val) {
+ switch (p_intial_val.get_type()) {
+ case Variant::BOOL: {
+ return (int)p_final_val - (int)p_intial_val;
}
- // If we are a callback, do nothing special
- if (data.type == INTER_CALLBACK) {
- continue;
+ case Variant::RECT2: {
+ Rect2 i = p_intial_val;
+ Rect2 f = p_final_val;
+ return Rect2(f.position - i.position, f.size - i.size);
}
- // Run the equation on the data and apply the value
- Variant result = _run_equation(data);
- _apply_tween_value(data, result);
- }
- pending_update--;
-}
-
-real_t Tween::tell() const {
- // We want to grab the position of the furthest along tween
- pending_update++;
- real_t pos = 0.0;
-
- // For each interpolation...
- for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the data and figure out if its position is further along than the previous ones
- const InterpolateData &data = E->get();
- if (data.elapsed > pos) {
- // Save it if so
- pos = data.elapsed;
+ case Variant::RECT2I: {
+ Rect2i i = p_intial_val;
+ Rect2i f = p_final_val;
+ return Rect2i(f.position - i.position, f.size - i.size);
}
- }
- pending_update--;
- return pos;
-}
-
-real_t Tween::get_runtime() const {
- // If the tween isn't moving, it'll last forever
- if (speed_scale == 0) {
- return INFINITY;
- }
-
- pending_update++;
-
- // For each interpolation...
- real_t runtime = 0.0;
- for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
- // Get the tween data and see if it's runtime is greater than the previous tweens
- const InterpolateData &data = E->get();
- real_t t = data.delay + data.duration;
- if (t > runtime) {
- // This is the longest running tween
- runtime = t;
- }
- }
- pending_update--;
-
- // Adjust the runtime for the current speed scale
- return runtime / speed_scale;
-}
-
-bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val) {
- // Get the initial, final, and delta values
- const Variant &initial_val = p_initial_val;
- const Variant &final_val = p_final_val;
- Variant &delta_val = p_delta_val;
-
- // What kind of data are we interpolating?
- switch (initial_val.get_type()) {
- case Variant::BOOL:
- // We'll treat booleans just like integers
- case Variant::INT:
- // Compute the integer delta
- delta_val = (int)final_val - (int)initial_val;
- break;
-
- case Variant::FLOAT:
- // Convert to FLOAT and find the delta
- delta_val = (real_t)final_val - (real_t)initial_val;
- break;
-
- case Variant::VECTOR2:
- // Convert to Vectors and find the delta
- delta_val = final_val.operator Vector2() - initial_val.operator Vector2();
- break;
-
- case Variant::RECT2: {
- // Build a new Rect2 and use the new position and sizes to make a delta
- Rect2 i = initial_val;
- Rect2 f = final_val;
- delta_val = Rect2(f.position - i.position, f.size - i.size);
- } break;
-
- case Variant::VECTOR3:
- // Convert to Vectors and find the delta
- delta_val = final_val.operator Vector3() - initial_val.operator Vector3();
- break;
case Variant::TRANSFORM2D: {
- // Build a new transform which is the difference between the initial and final values
- Transform2D i = initial_val;
- Transform2D f = final_val;
- Transform2D d = Transform2D();
- d[0][0] = f.elements[0][0] - i.elements[0][0];
- d[0][1] = f.elements[0][1] - i.elements[0][1];
- d[1][0] = f.elements[1][0] - i.elements[1][0];
- d[1][1] = f.elements[1][1] - i.elements[1][1];
- d[2][0] = f.elements[2][0] - i.elements[2][0];
- d[2][1] = f.elements[2][1] - i.elements[2][1];
- delta_val = d;
- } break;
-
- case Variant::QUATERNION:
- // Convert to quaternianls and find the delta
- delta_val = final_val.operator Quaternion() - initial_val.operator Quaternion();
- break;
+ Transform2D i = p_intial_val;
+ Transform2D f = p_final_val;
+ return Transform2D(f.elements[0][0] - i.elements[0][0],
+ f.elements[0][1] - i.elements[0][1],
+ f.elements[1][0] - i.elements[1][0],
+ f.elements[1][1] - i.elements[1][1],
+ f.elements[2][0] - i.elements[2][0],
+ f.elements[2][1] - i.elements[2][1]);
+ }
case Variant::AABB: {
- // Build a new AABB and use the new position and sizes to make a delta
- AABB i = initial_val;
- AABB f = final_val;
- delta_val = AABB(f.position - i.position, f.size - i.size);
- } break;
+ AABB i = p_intial_val;
+ AABB f = p_final_val;
+ return AABB(f.position - i.position, f.size - i.size);
+ }
case Variant::BASIS: {
- // Build a new basis which is the delta between the initial and final values
- Basis i = initial_val;
- Basis f = final_val;
- delta_val = Basis(f.elements[0][0] - i.elements[0][0],
+ Basis i = p_intial_val;
+ Basis f = p_final_val;
+ return Basis(f.elements[0][0] - i.elements[0][0],
f.elements[0][1] - i.elements[0][1],
f.elements[0][2] - i.elements[0][2],
f.elements[1][0] - i.elements[1][0],
@@ -1227,14 +529,12 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
f.elements[2][0] - i.elements[2][0],
f.elements[2][1] - i.elements[2][1],
f.elements[2][2] - i.elements[2][2]);
- } break;
+ }
case Variant::TRANSFORM3D: {
- // Build a new transform which is the difference between the initial and final values
- Transform3D i = initial_val;
- Transform3D f = final_val;
- Transform3D d;
- d.set(f.basis.elements[0][0] - i.basis.elements[0][0],
+ Transform3D i = p_intial_val;
+ Transform3D f = p_final_val;
+ return Transform3D(f.basis.elements[0][0] - i.basis.elements[0][0],
f.basis.elements[0][1] - i.basis.elements[0][1],
f.basis.elements[0][2] - i.basis.elements[0][2],
f.basis.elements[1][0] - i.basis.elements[1][0],
@@ -1246,569 +546,342 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
f.origin.x - i.origin.x,
f.origin.y - i.origin.y,
f.origin.z - i.origin.z);
-
- delta_val = d;
- } break;
-
- case Variant::COLOR: {
- // Make a new color which is the difference between each the color's RGBA attributes
- Color i = initial_val;
- Color f = final_val;
- delta_val = Color(f.r - i.r, f.g - i.g, f.b - i.b, f.a - i.a);
- } break;
+ }
default: {
- static Variant::Type supported_types[] = {
- Variant::BOOL,
- Variant::INT,
- Variant::FLOAT,
- Variant::VECTOR2,
- Variant::RECT2,
- Variant::VECTOR3,
- Variant::TRANSFORM2D,
- Variant::QUATERNION,
- Variant::AABB,
- Variant::BASIS,
- Variant::TRANSFORM3D,
- Variant::COLOR,
- };
-
- int length = *(&supported_types + 1) - supported_types;
- String error_msg = "Invalid parameter type. Supported types are: ";
- for (int i = 0; i < length; i++) {
- if (i != 0) {
- error_msg += ", ";
- }
- error_msg += Variant::get_type_name(supported_types[i]);
- }
- error_msg += ".";
- ERR_PRINT(error_msg);
- return false;
+ return Variant::evaluate(Variant::OP_SUBTRACT, p_final_val, p_intial_val);
}
};
- return true;
}
-void Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // TODO: Add initialization+implementation for remaining interpolation types
- // TODO: Fix this method's organization to take advantage of the type
-
- // Make a new interpolation data
- InterpolateData data;
- data.active = true;
- data.type = p_interpolation_type;
- data.finish = false;
- data.elapsed = 0;
+void Tween::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("tween_property", "object", "property", "final_val", "duration"), &Tween::tween_property);
+ ClassDB::bind_method(D_METHOD("tween_interval", "time"), &Tween::tween_interval);
+ ClassDB::bind_method(D_METHOD("tween_callback", "callback"), &Tween::tween_callback);
+ ClassDB::bind_method(D_METHOD("tween_method", "method", "from", "to", "duration"), &Tween::tween_method);
+
+ ClassDB::bind_method(D_METHOD("custom_step", "delta"), &Tween::custom_step);
+ ClassDB::bind_method(D_METHOD("stop"), &Tween::stop);
+ ClassDB::bind_method(D_METHOD("pause"), &Tween::pause);
+ ClassDB::bind_method(D_METHOD("play"), &Tween::play);
+ ClassDB::bind_method(D_METHOD("kill"), &Tween::kill);
+
+ ClassDB::bind_method(D_METHOD("is_running"), &Tween::is_running);
+ ClassDB::bind_method(D_METHOD("is_valid"), &Tween::is_valid);
+ ClassDB::bind_method(D_METHOD("bind_node", "node"), &Tween::bind_node);
+ ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Tween::set_process_mode);
+ ClassDB::bind_method(D_METHOD("set_pause_mode", "mode"), &Tween::set_pause_mode);
+
+ ClassDB::bind_method(D_METHOD("set_parallel", "parallel"), &Tween::set_parallel, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("set_loops", "loops"), &Tween::set_loops, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &Tween::set_speed_scale);
+ ClassDB::bind_method(D_METHOD("set_trans", "trans"), &Tween::set_trans);
+ ClassDB::bind_method(D_METHOD("set_ease", "ease"), &Tween::set_ease);
- // Validate and apply interpolation data
+ ClassDB::bind_method(D_METHOD("parallel"), &Tween::parallel);
+ ClassDB::bind_method(D_METHOD("chain"), &Tween::chain);
- // Give it the object
- ERR_FAIL_COND_MSG(p_object == nullptr, "Invalid object provided to Tween.");
- data.id = p_object->get_instance_id();
+ ClassDB::bind_method(D_METHOD("interpolate_value", "trans_type", "ease_type", "elapsed_time", "initial_value", "delta_value", "duration"), &Tween::interpolate_variant);
- // Validate the initial and final values
- ERR_FAIL_COND_MSG(p_initial_val.get_type() != p_final_val.get_type(), "Initial value type '" + Variant::get_type_name(p_initial_val.get_type()) + "' does not match final value type '" + Variant::get_type_name(p_final_val.get_type()) + "'.");
- data.initial_val = p_initial_val;
- data.final_val = p_final_val;
+ ADD_SIGNAL(MethodInfo("step_finished", PropertyInfo(Variant::INT, "idx")));
+ ADD_SIGNAL(MethodInfo("loop_finished", PropertyInfo(Variant::INT, "loop_count")));
+ ADD_SIGNAL(MethodInfo("finished"));
- // Check the Duration
- ERR_FAIL_COND_MSG(p_duration < 0, "Only non-negative duration values allowed in Tweens.");
- data.duration = p_duration;
+ BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS);
+ BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE);
- // Tween Delay
- ERR_FAIL_COND_MSG(p_delay < 0, "Only non-negative delay values allowed in Tweens.");
- data.delay = p_delay;
+ BIND_ENUM_CONSTANT(TWEEN_PAUSE_BOUND);
+ BIND_ENUM_CONSTANT(TWEEN_PAUSE_STOP);
+ BIND_ENUM_CONSTANT(TWEEN_PAUSE_PROCESS);
- // Transition type
- ERR_FAIL_COND_MSG(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, "Invalid transition type provided to Tween.");
- data.trans_type = p_trans_type;
+ BIND_ENUM_CONSTANT(TRANS_LINEAR);
+ BIND_ENUM_CONSTANT(TRANS_SINE);
+ BIND_ENUM_CONSTANT(TRANS_QUINT);
+ BIND_ENUM_CONSTANT(TRANS_QUART);
+ BIND_ENUM_CONSTANT(TRANS_QUAD);
+ BIND_ENUM_CONSTANT(TRANS_EXPO);
+ BIND_ENUM_CONSTANT(TRANS_ELASTIC);
+ BIND_ENUM_CONSTANT(TRANS_CUBIC);
+ BIND_ENUM_CONSTANT(TRANS_CIRC);
+ BIND_ENUM_CONSTANT(TRANS_BOUNCE);
+ BIND_ENUM_CONSTANT(TRANS_BACK);
- // Easing type
- ERR_FAIL_COND_MSG(p_ease_type < 0 || p_ease_type >= EASE_COUNT, "Invalid easing type provided to Tween.");
- data.ease_type = p_ease_type;
+ BIND_ENUM_CONSTANT(EASE_IN);
+ BIND_ENUM_CONSTANT(EASE_OUT);
+ BIND_ENUM_CONSTANT(EASE_IN_OUT);
+ BIND_ENUM_CONSTANT(EASE_OUT_IN);
+}
- // Is the property defined?
- if (p_property) {
- // Check that the object actually contains the given property
- bool prop_valid = false;
- p_object->get_indexed(p_property->get_subnames(), &prop_valid);
- ERR_FAIL_COND_MSG(!prop_valid, "Tween target object has no property named: " + p_property->get_concatenated_subnames() + ".");
+Ref<PropertyTweener> PropertyTweener::from(Variant p_value) {
+ initial_val = p_value;
+ do_continue = false;
+ return this;
+}
- data.key = p_property->get_subnames();
- data.concatenated_key = p_property->get_concatenated_subnames();
- }
+Ref<PropertyTweener> PropertyTweener::from_current() {
+ do_continue = false;
+ return this;
+}
- // Is the method defined?
- if (p_method) {
- // Does the object even have the requested method?
- ERR_FAIL_COND_MSG(!p_object->has_method(*p_method), "Tween target object has no method named: " + *p_method + ".");
+Ref<PropertyTweener> PropertyTweener::as_relative() {
+ relative = true;
+ return this;
+}
- data.key.push_back(*p_method);
- data.concatenated_key = *p_method;
- }
+Ref<PropertyTweener> PropertyTweener::set_trans(Tween::TransitionType p_trans) {
+ trans_type = p_trans;
+ return this;
+}
- // Is there not a valid delta?
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
- return;
- }
+Ref<PropertyTweener> PropertyTweener::set_ease(Tween::EaseType p_ease) {
+ ease_type = p_ease;
+ return this;
+}
- // Add this interpolation to the total
- _push_interpolate_data(data);
+Ref<PropertyTweener> PropertyTweener::set_delay(float p_delay) {
+ delay = p_delay;
+ return this;
}
-void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are busy updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_property", p_object, p_property, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
+void PropertyTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+
+ Object *target_instance = ObjectDB::get_instance(target);
+ if (!target_instance) {
+ WARN_PRINT("Target object freed before starting, aborting Tweener.");
return;
}
- // Check that the target object is valid
- ERR_FAIL_COND_MSG(p_object == nullptr, vformat("The Tween \"%s\"'s target node is `null`. Is the node reference correct?", get_name()));
-
- // Get the property from the node path
- p_property = p_property.get_as_property_path();
-
- // If no initial value given, grab the initial value from the object
- // TODO: Is this documented? This is very useful and removes a lot of clutter from tweens!
- if (p_initial_val.get_type() == Variant::NIL) {
- p_initial_val = p_object->get_indexed(p_property.get_subnames());
+ if (do_continue) {
+ initial_val = target_instance->get_indexed(property);
}
- // Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
- }
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+ if (relative) {
+ final_val = Variant::evaluate(Variant::Operator::OP_ADD, initial_val, base_final_val);
}
- // Build the interpolation data
- _build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
+ delta_val = tween->calculate_delta_value(initial_val, final_val);
}
-void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are busy updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_method", p_object, p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
+bool PropertyTweener::step(float &r_delta) {
+ if (finished) {
+ // This is needed in case there's a parallel Tweener with longer duration.
+ return false;
}
- // Check that the target object is valid
- ERR_FAIL_COND_MSG(p_object == nullptr, vformat("The Tween \"%s\"'s target node is `null`. Is the node reference correct?", get_name()));
-
- // Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
- }
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+ Object *target_instance = ObjectDB::get_instance(target);
+ if (!target_instance) {
+ return false;
}
+ elapsed_time += r_delta;
- // Build the interpolation data
- _build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
-}
-
-void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) {
- // If we are already updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_callback", p_object, p_duration, p_callback, p_arg1, p_arg2, p_arg3, p_arg4, p_arg5);
- return;
+ if (elapsed_time < delay) {
+ r_delta = 0;
+ return true;
}
- // Check that the target object is valid
- ERR_FAIL_COND(p_object == nullptr);
-
- // Duration cannot be negative
- ERR_FAIL_COND(p_duration < 0);
-
- // Check whether the object even has the callback
- ERR_FAIL_COND_MSG(!p_object->has_method(p_callback), "Object has no callback named: " + p_callback + ".");
-
- // Build a new InterpolationData
- InterpolateData data;
- data.active = true;
- data.type = INTER_CALLBACK;
- data.finish = false;
- data.call_deferred = false;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key.push_back(p_callback);
- data.concatenated_key = p_callback;
- data.duration = p_duration;
- data.delay = 0;
-
- // Add arguments to the interpolation
- int args = 0;
- if (p_arg5.get_type() != Variant::NIL) {
- args = 5;
- } else if (p_arg4.get_type() != Variant::NIL) {
- args = 4;
- } else if (p_arg3.get_type() != Variant::NIL) {
- args = 3;
- } else if (p_arg2.get_type() != Variant::NIL) {
- args = 2;
- } else if (p_arg1.get_type() != Variant::NIL) {
- args = 1;
+ float time = MIN(elapsed_time - delay, duration);
+ target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type));
+
+ if (time < duration) {
+ r_delta = 0;
+ return true;
} else {
- args = 0;
+ finished = true;
+ r_delta = elapsed_time - delay - duration;
+ emit_signal("finished");
+ return false;
}
-
- data.args = args;
- data.arg[0] = p_arg1;
- data.arg[1] = p_arg2;
- data.arg[2] = p_arg3;
- data.arg[3] = p_arg4;
- data.arg[4] = p_arg5;
-
- // Add the new interpolation
- _push_interpolate_data(data);
}
-void Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) {
- // If we are already updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("interpolate_deferred_callback", p_object, p_duration, p_callback, p_arg1, p_arg2, p_arg3, p_arg4, p_arg5);
- return;
+void PropertyTweener::set_tween(Ref<Tween> p_tween) {
+ tween = p_tween;
+ if (trans_type == Tween::TRANS_MAX) {
+ trans_type = tween->get_trans();
}
-
- // Check that the target object is valid
- ERR_FAIL_COND(p_object == nullptr);
-
- // No negative durations allowed
- ERR_FAIL_COND(p_duration < 0);
-
- // Confirm the callback exists on the object
- ERR_FAIL_COND_MSG(!p_object->has_method(p_callback), "Object has no callback named: " + p_callback + ".");
-
- // Create a new InterpolateData for the callback
- InterpolateData data;
- data.active = true;
- data.type = INTER_CALLBACK;
- data.finish = false;
- data.call_deferred = true;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key.push_back(p_callback);
- data.concatenated_key = p_callback;
- data.duration = p_duration;
- data.delay = 0;
-
- // Collect arguments for the callback
- int args = 0;
- if (p_arg5.get_type() != Variant::NIL) {
- args = 5;
- } else if (p_arg4.get_type() != Variant::NIL) {
- args = 4;
- } else if (p_arg3.get_type() != Variant::NIL) {
- args = 3;
- } else if (p_arg2.get_type() != Variant::NIL) {
- args = 2;
- } else if (p_arg1.get_type() != Variant::NIL) {
- args = 1;
- } else {
- args = 0;
+ if (ease_type == Tween::EASE_MAX) {
+ ease_type = tween->get_ease();
}
+}
- data.args = args;
- data.arg[0] = p_arg1;
- data.arg[1] = p_arg2;
- data.arg[2] = p_arg3;
- data.arg[3] = p_arg4;
- data.arg[4] = p_arg5;
+void PropertyTweener::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("from", "value"), &PropertyTweener::from);
+ ClassDB::bind_method(D_METHOD("from_current"), &PropertyTweener::from_current);
+ ClassDB::bind_method(D_METHOD("as_relative"), &PropertyTweener::as_relative);
+ ClassDB::bind_method(D_METHOD("set_trans", "trans"), &PropertyTweener::set_trans);
+ ClassDB::bind_method(D_METHOD("set_ease", "ease"), &PropertyTweener::set_ease);
+ ClassDB::bind_method(D_METHOD("set_delay", "delay"), &PropertyTweener::set_delay);
+}
- // Add the new interpolation
- _push_interpolate_data(data);
+PropertyTweener::PropertyTweener(Object *p_target, NodePath p_property, Variant p_to, float p_duration) {
+ target = p_target->get_instance_id();
+ property = p_property.get_as_property_path().get_subnames();
+ initial_val = p_target->get_indexed(property);
+ base_final_val = p_to;
+ final_val = base_final_val;
+ duration = p_duration;
}
-void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are already updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("follow_property", p_object, p_property, p_initial_val, p_target, p_target_property, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
- }
+PropertyTweener::PropertyTweener() {
+ ERR_FAIL_MSG("Can't create empty PropertyTweener. Use get_tree().tween_property() or tween_property() instead.");
+}
- // Get the two properties from their paths
- p_property = p_property.get_as_property_path();
- p_target_property = p_target_property.get_as_property_path();
+void IntervalTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+}
- // If no initial value is given, grab it from the source object
- // TODO: Is this documented? It's really helpful for decluttering tweens
- if (p_initial_val.get_type() == Variant::NIL) {
- p_initial_val = p_object->get_indexed(p_property.get_subnames());
+bool IntervalTweener::step(float &r_delta) {
+ if (finished) {
+ return false;
}
- // Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
+ elapsed_time += r_delta;
+
+ if (elapsed_time < duration) {
+ r_delta = 0;
+ return true;
+ } else {
+ finished = true;
+ r_delta = elapsed_time - duration;
+ emit_signal("finished");
+ return false;
}
+}
- // Confirm the source and target objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_target == nullptr);
+IntervalTweener::IntervalTweener(float p_time) {
+ duration = p_time;
+}
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
+IntervalTweener::IntervalTweener() {
+ ERR_FAIL_MSG("Can't create empty IntervalTweener. Use get_tree().tween_interval() instead.");
+}
- // Ensure transition and easing types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
+Ref<CallbackTweener> CallbackTweener::set_delay(float p_delay) {
+ delay = p_delay;
+ return this;
+}
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
+void CallbackTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+}
- // Confirm the source and target objects have the desired properties
- bool prop_valid = false;
- p_object->get_indexed(p_property.get_subnames(), &prop_valid);
- ERR_FAIL_COND(!prop_valid);
+bool CallbackTweener::step(float &r_delta) {
+ if (finished) {
+ return false;
+ }
- bool target_prop_valid = false;
- Variant target_val = p_target->get_indexed(p_target_property.get_subnames(), &target_prop_valid);
- ERR_FAIL_COND(!target_prop_valid);
+ elapsed_time += r_delta;
+ if (elapsed_time >= delay) {
+ Variant result;
+ Callable::CallError ce;
+ callback.call(nullptr, 0, result, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ ERR_FAIL_V_MSG(false, "Error calling method from CallbackTweener: " + Variant::get_call_error_text(this, callback.get_method(), nullptr, 0, ce));
+ }
- // Convert target INT to FLOAT since it is better for interpolation
- if (target_val.get_type() == Variant::INT) {
- target_val = target_val.operator real_t();
+ finished = true;
+ r_delta = elapsed_time - delay;
+ emit_signal("finished");
+ return false;
}
- // Verify that the target value and initial value are the same type
- ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
-
- // Create a new InterpolateData
- InterpolateData data;
- data.active = true;
- data.type = FOLLOW_PROPERTY;
- data.finish = false;
- data.elapsed = 0;
-
- // Give the InterpolateData it's configuration
- data.id = p_object->get_instance_id();
- data.key = p_property.get_subnames();
- data.concatenated_key = p_property.get_concatenated_subnames();
- data.initial_val = p_initial_val;
- data.target_id = p_target->get_instance_id();
- data.target_key = p_target_property.get_subnames();
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Add the interpolation
- _push_interpolate_data(data);
-}
-
-void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are currently updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("follow_method", p_object, p_method, p_initial_val, p_target, p_target_method, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
- }
- // Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT) {
- p_initial_val = p_initial_val.operator real_t();
- }
+ r_delta = 0;
+ return true;
+}
- // Verify the source and target objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_target == nullptr);
+void CallbackTweener::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_delay", "delay"), &CallbackTweener::set_delay);
+}
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
+CallbackTweener::CallbackTweener(Callable p_callback) {
+ callback = p_callback;
+}
- // Ensure that the transition and ease types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
+CallbackTweener::CallbackTweener() {
+ ERR_FAIL_MSG("Can't create empty CallbackTweener. Use get_tree().tween_callback() instead.");
+}
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
+Ref<MethodTweener> MethodTweener::set_delay(float p_delay) {
+ delay = p_delay;
+ return this;
+}
- // Confirm both objects have the target methods
- ERR_FAIL_COND_MSG(!p_object->has_method(p_method), "Object has no method named: " + p_method + ".");
- ERR_FAIL_COND_MSG(!p_target->has_method(p_target_method), "Target has no method named: " + p_target_method + ".");
+Ref<MethodTweener> MethodTweener::set_trans(Tween::TransitionType p_trans) {
+ trans_type = p_trans;
+ return this;
+}
- // Call the method to get the target value
- Callable::CallError error;
- Variant target_val = p_target->call(p_target_method, nullptr, 0, error);
- ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
+Ref<MethodTweener> MethodTweener::set_ease(Tween::EaseType p_ease) {
+ ease_type = p_ease;
+ return this;
+}
- // Convert target INT values to FLOAT as they are better for interpolation
- if (target_val.get_type() == Variant::INT) {
- target_val = target_val.operator real_t();
- }
- ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
-
- // Make the new InterpolateData for the method follow
- InterpolateData data;
- data.active = true;
- data.type = FOLLOW_METHOD;
- data.finish = false;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key.push_back(p_method);
- data.concatenated_key = p_method;
- data.initial_val = p_initial_val;
- data.target_id = p_target->get_instance_id();
- data.target_key.push_back(p_target_method);
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Add the new interpolation
- _push_interpolate_data(data);
-}
-
-void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are currently updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("targeting_property", p_object, p_property, p_initial, p_initial_property, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
- }
- // Grab the target property and the target property
- p_property = p_property.get_as_property_path();
- p_initial_property = p_initial_property.get_as_property_path();
+void MethodTweener::start() {
+ elapsed_time = 0;
+ finished = false;
+}
- // Convert the initial INT values to FLOAT as they are better for Interpolation
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+bool MethodTweener::step(float &r_delta) {
+ if (finished) {
+ return false;
}
- // Verify both objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_initial == nullptr);
-
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
-
- // Ensure transition and easing types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
-
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
-
- // Ensure the initial and target properties exist on their objects
- bool prop_valid = false;
- p_object->get_indexed(p_property.get_subnames(), &prop_valid);
- ERR_FAIL_COND(!prop_valid);
+ elapsed_time += r_delta;
- bool initial_prop_valid = false;
- Variant initial_val = p_initial->get_indexed(p_initial_property.get_subnames(), &initial_prop_valid);
- ERR_FAIL_COND(!initial_prop_valid);
-
- // Convert the initial INT value to FLOAT as it is better for interpolation
- if (initial_val.get_type() == Variant::INT) {
- initial_val = initial_val.operator real_t();
- }
- ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
-
- // Build the InterpolateData object
- InterpolateData data;
- data.active = true;
- data.type = TARGETING_PROPERTY;
- data.finish = false;
- data.elapsed = 0;
-
- // Give the data it's configuration
- data.id = p_object->get_instance_id();
- data.key = p_property.get_subnames();
- data.concatenated_key = p_property.get_concatenated_subnames();
- data.target_id = p_initial->get_instance_id();
- data.target_key = p_initial_property.get_subnames();
- data.initial_val = initial_val;
- data.final_val = p_final_val;
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Ensure there is a valid delta
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
- return;
+ if (elapsed_time < delay) {
+ r_delta = 0;
+ return true;
}
- // Add the interpolation
- _push_interpolate_data(data);
-}
+ float time = MIN(elapsed_time - delay, duration);
+ Variant current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type);
+ const Variant **argptr = (const Variant **)alloca(sizeof(Variant *));
+ argptr[0] = &current_val;
-void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) {
- // If we are currently updating, call this function again later
- if (pending_update != 0) {
- _add_pending_command("targeting_method", p_object, p_method, p_initial, p_initial_method, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
- return;
+ Variant result;
+ Callable::CallError ce;
+ callback.call(argptr, 1, result, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ ERR_FAIL_V_MSG(false, "Error calling method from MethodTweener: " + Variant::get_call_error_text(this, callback.get_method(), argptr, 1, ce));
}
- // Convert final INT values to FLOAT as they are better for interpolation
- if (p_final_val.get_type() == Variant::INT) {
- p_final_val = p_final_val.operator real_t();
+ if (time < duration) {
+ r_delta = 0;
+ return true;
+ } else {
+ finished = true;
+ r_delta = elapsed_time - delay - duration;
+ emit_signal("finished");
+ return false;
}
+}
- // Make sure the given objects are valid
- ERR_FAIL_COND(p_object == nullptr);
- ERR_FAIL_COND(p_initial == nullptr);
-
- // No negative durations
- ERR_FAIL_COND(p_duration < 0);
-
- // Ensure transition and easing types are valid
- ERR_FAIL_COND(p_trans_type < 0 || p_trans_type >= TRANS_COUNT);
- ERR_FAIL_COND(p_ease_type < 0 || p_ease_type >= EASE_COUNT);
-
- // No negative delays
- ERR_FAIL_COND(p_delay < 0);
-
- // Make sure both objects have the given method
- ERR_FAIL_COND_MSG(!p_object->has_method(p_method), "Object has no method named: " + p_method + ".");
- ERR_FAIL_COND_MSG(!p_initial->has_method(p_initial_method), "Initial Object has no method named: " + p_initial_method + ".");
-
- // Call the method to get the initial value
- Callable::CallError error;
- Variant initial_val = p_initial->call(p_initial_method, nullptr, 0, error);
- ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
-
- // Convert initial INT values to FLOAT as they aer better for interpolation
- if (initial_val.get_type() == Variant::INT) {
- initial_val = initial_val.operator real_t();
+void MethodTweener::set_tween(Ref<Tween> p_tween) {
+ tween = p_tween;
+ if (trans_type == Tween::TRANS_MAX) {
+ trans_type = tween->get_trans();
}
- ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
-
- // Build the new InterpolateData object
- InterpolateData data;
- data.active = true;
- data.type = TARGETING_METHOD;
- data.finish = false;
- data.elapsed = 0;
-
- // Configure the data
- data.id = p_object->get_instance_id();
- data.key.push_back(p_method);
- data.concatenated_key = p_method;
- data.target_id = p_initial->get_instance_id();
- data.target_key.push_back(p_initial_method);
- data.initial_val = initial_val;
- data.final_val = p_final_val;
- data.duration = p_duration;
- data.trans_type = p_trans_type;
- data.ease_type = p_ease_type;
- data.delay = p_delay;
-
- // Ensure there is a valid delta
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
- return;
+ if (ease_type == Tween::EASE_MAX) {
+ ease_type = tween->get_ease();
}
+}
- // Add the interpolation
- _push_interpolate_data(data);
+void MethodTweener::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_delay", "delay"), &MethodTweener::set_delay);
+ ClassDB::bind_method(D_METHOD("set_trans", "trans"), &MethodTweener::set_trans);
+ ClassDB::bind_method(D_METHOD("set_ease", "ease"), &MethodTweener::set_ease);
}
-Tween::Tween() {
+MethodTweener::MethodTweener(Callable p_callback, float p_from, float p_to, float p_duration) {
+ callback = p_callback;
+ initial_val = p_from;
+ delta_val = tween->calculate_delta_value(p_from, p_to);
+ duration = p_duration;
}
-Tween::~Tween() {
+MethodTweener::MethodTweener() {
+ ERR_FAIL_MSG("Can't create empty MethodTweener. Use get_tree().tween_method() instead.");
}
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index 142c0c65e0..947cdb7c2d 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -31,10 +31,33 @@
#ifndef TWEEN_H
#define TWEEN_H
-#include "scene/main/node.h"
+#include "core/object/ref_counted.h"
-class Tween : public Node {
- GDCLASS(Tween, Node);
+class Tween;
+class Node;
+
+class Tweener : public RefCounted {
+ GDCLASS(Tweener, RefCounted);
+
+public:
+ virtual void set_tween(Ref<Tween> p_tween);
+ virtual void start() = 0;
+ virtual bool step(float &r_delta) = 0;
+
+protected:
+ static void _bind_methods();
+ Ref<Tween> tween;
+ float elapsed_time = 0;
+ bool finished = false;
+};
+
+class PropertyTweener;
+class IntervalTweener;
+class CallbackTweener;
+class MethodTweener;
+
+class Tween : public RefCounted {
+ GDCLASS(Tween, RefCounted);
public:
enum TweenProcessMode {
@@ -42,6 +65,12 @@ public:
TWEEN_PROCESS_IDLE,
};
+ enum TweenPauseMode {
+ TWEEN_PAUSE_BOUND,
+ TWEEN_PAUSE_STOP,
+ TWEEN_PAUSE_PROCESS,
+ };
+
enum TransitionType {
TRANS_LINEAR,
TRANS_SINE,
@@ -54,8 +83,7 @@ public:
TRANS_CIRC,
TRANS_BOUNCE,
TRANS_BACK,
-
- TRANS_COUNT,
+ TRANS_MAX
};
enum EaseType {
@@ -63,130 +91,187 @@ public:
EASE_OUT,
EASE_IN_OUT,
EASE_OUT_IN,
-
- EASE_COUNT,
+ EASE_MAX
};
private:
- enum InterpolateType {
- INTER_PROPERTY,
- INTER_METHOD,
- FOLLOW_PROPERTY,
- FOLLOW_METHOD,
- TARGETING_PROPERTY,
- TARGETING_METHOD,
- INTER_CALLBACK,
- };
+ TweenProcessMode process_mode = TweenProcessMode::TWEEN_PROCESS_IDLE;
+ TweenPauseMode pause_mode = TweenPauseMode::TWEEN_PAUSE_STOP;
+ TransitionType default_transition = TransitionType::TRANS_LINEAR;
+ EaseType default_ease = EaseType::EASE_IN_OUT;
+ ObjectID bound_node;
- struct InterpolateData {
- bool active = false;
- InterpolateType type = INTER_CALLBACK;
- bool finish = false;
- bool call_deferred = false;
- real_t elapsed = 0.0;
- ObjectID id;
- Vector<StringName> key;
- StringName concatenated_key;
- Variant initial_val;
- Variant delta_val;
- Variant final_val;
- ObjectID target_id;
- Vector<StringName> target_key;
- real_t duration = 0.0;
- TransitionType trans_type = TransitionType::TRANS_BACK;
- EaseType ease_type = EaseType::EASE_COUNT;
- real_t delay = 0.0;
- int args = 0;
- Variant arg[5];
- int uid = 0;
- };
+ Vector<List<Ref<Tweener>>> tweeners;
+ int current_step = -1;
+ int loops = 1;
+ int loops_done = 0;
+ float speed_scale = 1;
- String autoplay;
- TweenProcessMode tween_process_mode = TWEEN_PROCESS_IDLE;
- bool repeat = false;
- float speed_scale = 1.0;
- mutable int pending_update = 0;
- int uid = 0;
- bool was_stopped = false;
+ bool is_bound = false;
+ bool started = false;
+ bool running = true;
+ bool dead = false;
+ bool invalid = true;
+ bool default_parallel = false;
+ bool parallel_enabled = false;
- List<InterpolateData> interpolates;
+ typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
+ static interpolater interpolaters[TRANS_MAX][EASE_MAX];
- struct PendingCommand {
- StringName key;
- int args = 0;
- Variant arg[10];
- };
- List<PendingCommand> pending_commands;
+ void start_tweeners();
- void _add_pending_command(StringName p_key, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant(), const Variant &p_arg6 = Variant(), const Variant &p_arg7 = Variant(), const Variant &p_arg8 = Variant(), const Variant &p_arg9 = Variant(), const Variant &p_arg10 = Variant());
- void _process_pending_commands();
+protected:
+ static void _bind_methods();
- typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
- static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
+public:
+ Ref<PropertyTweener> tween_property(Object *p_target, NodePath p_property, Variant p_to, float p_duration);
+ Ref<IntervalTweener> tween_interval(float p_time);
+ Ref<CallbackTweener> tween_callback(Callable p_callback);
+ Ref<MethodTweener> tween_method(Callable p_callback, float p_from, float p_to, float p_duration);
+ Ref<Tween> append(Ref<Tweener> p_tweener);
- real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
- Variant &_get_delta_val(InterpolateData &p_data);
- Variant _get_initial_val(const InterpolateData &p_data) const;
- Variant _get_final_val(const InterpolateData &p_data) const;
- Variant _run_equation(InterpolateData &p_data);
- bool _calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val);
- bool _apply_tween_value(InterpolateData &p_data, Variant &value);
+ bool custom_step(float p_delta);
+ void stop();
+ void pause();
+ void play();
+ void kill();
- void _tween_process(float p_delta);
- void _remove_by_uid(int uid);
- void _push_interpolate_data(InterpolateData &p_data);
- void _build_interpolation(InterpolateType p_interpolation_type, Object *p_object, NodePath *p_property, StringName *p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay);
+ bool is_running();
+ void set_valid(bool p_valid);
+ bool is_valid();
-protected:
- bool _set(const StringName &p_name, const Variant &p_value);
- bool _get(const StringName &p_name, Variant &r_ret) const;
- void _get_property_list(List<PropertyInfo> *p_list) const;
- void _notification(int p_what);
+ Ref<Tween> bind_node(Node *p_node);
+ Ref<Tween> set_process_mode(TweenProcessMode p_mode);
+ TweenProcessMode get_process_mode();
+ Ref<Tween> set_pause_mode(TweenPauseMode p_mode);
+ TweenPauseMode get_pause_mode();
- static void _bind_methods();
+ Ref<Tween> set_parallel(bool p_parallel);
+ Ref<Tween> set_loops(int p_loops);
+ Ref<Tween> set_speed_scale(float p_speed);
+ Ref<Tween> set_trans(TransitionType p_trans);
+ TransitionType get_trans();
+ Ref<Tween> set_ease(EaseType p_ease);
+ EaseType get_ease();
-public:
- bool is_active() const;
- void set_active(bool p_active);
-
- bool is_repeat() const;
- void set_repeat(bool p_repeat);
-
- void set_tween_process_mode(TweenProcessMode p_mode);
- TweenProcessMode get_tween_process_mode() const;
-
- void set_speed_scale(float p_speed);
- float get_speed_scale() const;
-
- void start();
- void reset(Object *p_object, StringName p_key);
- void reset_all();
- void stop(Object *p_object, StringName p_key);
- void stop_all();
- void resume(Object *p_object, StringName p_key);
- void resume_all();
- void remove(Object *p_object, StringName p_key);
- void remove_all();
-
- void seek(real_t p_time);
- real_t tell() const;
- real_t get_runtime() const;
-
- void interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
- void interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE);
- void follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
- void targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type = TRANS_LINEAR, EaseType p_ease_type = EASE_IN_OUT, real_t p_delay = 0);
-
- Tween();
- ~Tween();
+ Ref<Tween> parallel();
+ Ref<Tween> chain();
+
+ real_t run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
+ Variant interpolate_variant(Variant p_initial_val, Variant p_delta_val, float p_time, float p_duration, Tween::TransitionType p_trans, Tween::EaseType p_ease);
+ Variant calculate_delta_value(Variant p_intial_val, Variant p_final_val);
+
+ bool step(float p_delta);
+ bool should_pause();
+
+ Tween() {}
};
+VARIANT_ENUM_CAST(Tween::TweenPauseMode);
VARIANT_ENUM_CAST(Tween::TweenProcessMode);
VARIANT_ENUM_CAST(Tween::TransitionType);
VARIANT_ENUM_CAST(Tween::EaseType);
+class PropertyTweener : public Tweener {
+ GDCLASS(PropertyTweener, Tweener);
+
+public:
+ Ref<PropertyTweener> from(Variant p_value);
+ Ref<PropertyTweener> from_current();
+ Ref<PropertyTweener> as_relative();
+ Ref<PropertyTweener> set_trans(Tween::TransitionType p_trans);
+ Ref<PropertyTweener> set_ease(Tween::EaseType p_ease);
+ Ref<PropertyTweener> set_delay(float p_delay);
+
+ void set_tween(Ref<Tween> p_tween) override;
+ void start() override;
+ bool step(float &r_delta) override;
+
+ PropertyTweener(Object *p_target, NodePath p_property, Variant p_to, float p_duration);
+ PropertyTweener();
+
+protected:
+ static void _bind_methods();
+
+private:
+ ObjectID target;
+ Vector<StringName> property;
+ Variant initial_val;
+ Variant base_final_val;
+ Variant final_val;
+ Variant delta_val;
+
+ float duration = 0;
+ Tween::TransitionType trans_type = Tween::TRANS_MAX; // This is set inside set_tween();
+ Tween::EaseType ease_type = Tween::EASE_MAX;
+
+ float delay = 0;
+ bool do_continue = true;
+ bool relative = false;
+};
+
+class IntervalTweener : public Tweener {
+ GDCLASS(IntervalTweener, Tweener);
+
+public:
+ void start() override;
+ bool step(float &r_delta) override;
+
+ IntervalTweener(float p_time);
+ IntervalTweener();
+
+private:
+ float duration = 0;
+};
+
+class CallbackTweener : public Tweener {
+ GDCLASS(CallbackTweener, Tweener);
+
+public:
+ Ref<CallbackTweener> set_delay(float p_delay);
+
+ void start() override;
+ bool step(float &r_delta) override;
+
+ CallbackTweener(Callable p_callback);
+ CallbackTweener();
+
+protected:
+ static void _bind_methods();
+
+private:
+ Callable callback;
+ float delay = 0;
+};
+
+class MethodTweener : public Tweener {
+ GDCLASS(MethodTweener, Tweener);
+
+public:
+ Ref<MethodTweener> set_trans(Tween::TransitionType p_trans);
+ Ref<MethodTweener> set_ease(Tween::EaseType p_ease);
+ Ref<MethodTweener> set_delay(float p_delay);
+
+ void set_tween(Ref<Tween> p_tween) override;
+ void start() override;
+ bool step(float &r_delta) override;
+
+ MethodTweener(Callable p_callback, float p_from, float p_to, float p_duration);
+ MethodTweener();
+
+protected:
+ static void _bind_methods();
+
+private:
+ float duration = 0;
+ float delay = 0;
+ Tween::TransitionType trans_type = Tween::TRANS_MAX;
+ Tween::EaseType ease_type = Tween::EASE_MAX;
+
+ Ref<Tween> tween;
+ Variant initial_val;
+ Variant delta_val;
+ Callable callback;
+};
+
#endif
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index cbbcf9e069..962c6dcc60 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -42,7 +42,7 @@ Ref<InputEvent> Shortcut::get_shortcut() const {
}
bool Shortcut::is_shortcut(const Ref<InputEvent> &p_event) const {
- return shortcut.is_valid() && shortcut->shortcut_match(p_event);
+ return shortcut.is_valid() && shortcut->is_match(p_event, true);
}
String Shortcut::get_as_text() const {
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index e1abea81ef..679fca0217 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -35,6 +35,7 @@
#include "core/object/message_queue.h"
#include "core/string/print_string.h"
#include "instance_placeholder.h"
+#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
#include "scene/resources/packed_scene.h"
#include "scene/scene_string_names.h"
@@ -1686,6 +1687,13 @@ int Node::get_index() const {
return data.pos;
}
+Ref<Tween> Node::create_tween() {
+ ERR_FAIL_COND_V_MSG(!data.tree, nullptr, "Can't create Tween when not inside scene tree.");
+ Ref<Tween> tween = get_tree()->create_tween();
+ tween->bind_node(this);
+ return tween;
+}
+
void Node::remove_and_skip() {
ERR_FAIL_COND(!data.parent);
@@ -2555,6 +2563,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_physics_processing_internal"), &Node::is_physics_processing_internal);
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
+ ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);
ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANCING | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups"), &Node::replace_by, DEFVAL(false));
diff --git a/scene/main/node.h b/scene/main/node.h
index e7b36f351b..0d1685a2be 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -41,6 +41,9 @@
class Viewport;
class SceneState;
+class Tween;
+class PropertyTweener;
+
class Node : public Object {
GDCLASS(Node, Object);
OBJ_CATEGORY("Nodes");
@@ -308,6 +311,8 @@ public:
void remove_and_skip();
int get_index() const;
+ Ref<Tween> create_tween();
+
void print_tree();
void print_tree_pretty();
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 001c857d4c..918eca7def 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -41,6 +41,7 @@
#include "core/os/os.h"
#include "core/string/print_string.h"
#include "node.h"
+#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
#include "scene/resources/font.h"
#include "scene/resources/material.h"
@@ -412,6 +413,9 @@ bool SceneTree::physics_process(float p_time) {
_notify_group_pause("physics_process", Node::NOTIFICATION_PHYSICS_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
+
+ process_tweens(p_time, true);
+
flush_transform_notifications();
root_lock--;
@@ -476,6 +480,8 @@ bool SceneTree::process(float p_time) {
E = N;
}
+ process_tweens(p_time, false);
+
flush_transform_notifications(); //additional transforms after timers update
_call_idle_callbacks();
@@ -510,6 +516,32 @@ bool SceneTree::process(float p_time) {
return _quit;
}
+void SceneTree::process_tweens(float p_delta, bool p_physics) {
+ // This methods works similarly to how SceneTreeTimers are handled.
+ List<Ref<Tween>>::Element *L = tweens.back();
+
+ for (List<Ref<Tween>>::Element *E = tweens.front(); E;) {
+ List<Ref<Tween>>::Element *N = E->next();
+ // Don't process if paused or process mode doesn't match.
+ if ((paused && E->get()->should_pause()) || (p_physics == (E->get()->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) {
+ if (E == L) {
+ break;
+ }
+ E = N;
+ continue;
+ }
+
+ if (!E->get()->step(p_delta)) {
+ E->get()->set_valid(false);
+ tweens.erase(E);
+ }
+ if (E == L) {
+ break;
+ }
+ E = N;
+ }
+}
+
void SceneTree::finalize() {
_flush_delete_queue();
@@ -1089,6 +1121,27 @@ Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_al
return stt;
}
+Ref<Tween> SceneTree::create_tween() {
+ Ref<Tween> tween;
+ tween.instance();
+ tween->set_valid(true);
+ tweens.push_back(tween);
+ return tween;
+}
+
+Array SceneTree::get_processed_tweens() {
+ Array ret;
+ ret.resize(tweens.size());
+
+ int i = 0;
+ for (List<Ref<Tween>>::Element *E = tweens.front(); E; E = E->next()) {
+ ret[i] = E->get();
+ i++;
+ }
+
+ return ret;
+}
+
void SceneTree::_network_peer_connected(int p_id) {
emit_signal("network_peer_connected", p_id);
}
@@ -1197,6 +1250,8 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_paused"), &SceneTree::is_paused);
ClassDB::bind_method(D_METHOD("create_timer", "time_sec", "process_always"), &SceneTree::create_timer, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("create_tween"), &SceneTree::create_tween);
+ ClassDB::bind_method(D_METHOD("get_processed_tweens"), &SceneTree::get_processed_tweens);
ClassDB::bind_method(D_METHOD("get_node_count"), &SceneTree::get_node_count);
ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame);
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 78c4c14e97..0e9ffb0f5f 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -47,6 +47,7 @@ class Window;
class Material;
class Mesh;
class SceneDebugger;
+class Tween;
class SceneTreeTimer : public RefCounted {
GDCLASS(SceneTreeTimer, RefCounted);
@@ -151,6 +152,7 @@ private:
//void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2);
List<Ref<SceneTreeTimer>> timers;
+ List<Ref<Tween>> tweens;
///network///
@@ -171,6 +173,7 @@ private:
void node_added(Node *p_node);
void node_removed(Node *p_node);
void node_renamed(Node *p_node);
+ void process_tweens(float p_delta, bool p_physics_frame);
Group *add_to_group(const StringName &p_group, Node *p_node);
void remove_from_group(const StringName &p_group, Node *p_node);
@@ -318,6 +321,8 @@ public:
Error reload_current_scene();
Ref<SceneTreeTimer> create_timer(float p_delay_sec, bool p_process_always = true);
+ Ref<Tween> create_tween();
+ Array get_processed_tweens();
//used by Main::start, don't use otherwise
void add_current_scene(Node *p_current);
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 2a97ae3acf..931c81ad65 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -407,6 +407,11 @@ void register_scene_types() {
ClassDB::register_class<AnimationPlayer>();
ClassDB::register_class<Tween>();
+ ClassDB::register_virtual_class<Tweener>();
+ ClassDB::register_class<PropertyTweener>();
+ ClassDB::register_class<IntervalTweener>();
+ ClassDB::register_class<CallbackTweener>();
+ ClassDB::register_class<MethodTweener>();
ClassDB::register_class<AnimationTree>();
ClassDB::register_class<AnimationNode>();
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index ab8a4b7934..e93c005779 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -893,6 +893,13 @@ Error SceneState::pack(Node *p_scene) {
node_paths.write[E->get()] = scene->get_path_to(E->key());
}
+ if (Engine::get_singleton()->is_editor_hint()) {
+ // Build node path cache
+ for (Map<Node *, int>::Element *E = node_map.front(); E; E = E->next()) {
+ node_path_cache[scene->get_path_to(E->key())] = E->get();
+ }
+ }
+
return OK;
}
@@ -927,10 +934,12 @@ Ref<SceneState> SceneState::_get_base_scene_state() const {
}
int SceneState::find_node_by_path(const NodePath &p_node) const {
+ ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built.");
+
if (!node_path_cache.has(p_node)) {
if (_get_base_scene_state().is_valid()) {
int idx = _get_base_scene_state()->find_node_by_path(p_node);
- if (idx >= 0) {
+ if (idx != -1) {
int rkey = _find_base_scene_node_remap_key(idx);
if (rkey == -1) {
rkey = nodes.size() + base_scene_node_remap.size();
diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp
index efaf77f30b..e0d0ce76be 100644
--- a/servers/rendering/renderer_scene_cull.cpp
+++ b/servers/rendering/renderer_scene_cull.cpp
@@ -2578,7 +2578,7 @@ void RendererSceneCull::_scene_cull(CullData &cull_data, InstanceCullResult &cul
#define HIDDEN_BY_VISIBILITY_CHECKS (visibility_flags == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE || visibility_flags == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN)
#define LAYER_CHECK (cull_data.visible_layers & idata.layer_mask)
#define IN_FRUSTUM(f) (cull_data.scenario->instance_aabbs[i].in_frustum(f))
-#define VIS_RANGE_CHECK ((idata.visibility_index == -1) || _visibility_range_check(cull_data.scenario->instance_visibility[idata.visibility_index], cull_data.cam_transform.origin, cull_data.visibility_cull_data->viewport_mask) == 0)
+#define VIS_RANGE_CHECK ((idata.visibility_index == -1) || _visibility_range_check(cull_data.scenario->instance_visibility[idata.visibility_index], cull_data.cam_transform.origin, cull_data.visibility_viewport_mask) == 0)
#define VIS_PARENT_CHECK ((idata.parent_array_index == -1) || ((cull_data.scenario->instance_data[idata.parent_array_index].flags & InstanceData::FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK) == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE))
#define VIS_CHECK (visibility_check < 0 ? (visibility_check = (visibility_flags != InstanceData::FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK || (VIS_RANGE_CHECK && VIS_PARENT_CHECK))) : visibility_check)
#define OCCLUSION_CULLED (cull_data.occlusion_buffer != nullptr && (cull_data.scenario->instance_data[i].flags & InstanceData::FLAG_IGNORE_OCCLUSION_CULLING) == 0 && cull_data.occlusion_buffer->is_occluded(cull_data.scenario->instance_aabbs[i].bounds, cull_data.cam_transform.origin, inv_cam_transform, *cull_data.camera_matrix, z_near))
@@ -2808,12 +2808,12 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c
RENDER_TIMESTAMP("Visibility Dependencies");
- VisibilityCullData visibility_cull_data;
if (scenario->instance_visibility.get_bin_count() > 0) {
if (!scenario->viewport_visibility_masks.has(p_viewport)) {
scenario_add_viewport_visibility_mask(scenario->self, p_viewport);
}
+ VisibilityCullData visibility_cull_data;
visibility_cull_data.scenario = scenario;
visibility_cull_data.viewport_mask = scenario->viewport_visibility_masks[p_viewport];
visibility_cull_data.camera_position = p_camera_data->main_transform.origin;
@@ -2924,6 +2924,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c
cull_data.render_reflection_probe = render_reflection_probe;
cull_data.occlusion_buffer = RendererSceneOcclusionCull::get_singleton()->buffer_get_ptr(p_viewport);
cull_data.camera_matrix = &p_camera_data->main_projection;
+ cull_data.visibility_viewport_mask = scenario->viewport_visibility_masks.has(p_viewport) ? scenario->viewport_visibility_masks[p_viewport] : 0;
//#define DEBUG_CULL_TIME
#ifdef DEBUG_CULL_TIME
uint64_t time_from = OS::get_singleton()->get_ticks_usec();
diff --git a/servers/rendering/renderer_scene_cull.h b/servers/rendering/renderer_scene_cull.h
index d9466d8b04..652d322731 100644
--- a/servers/rendering/renderer_scene_cull.h
+++ b/servers/rendering/renderer_scene_cull.h
@@ -1016,7 +1016,7 @@ public:
Instance *render_reflection_probe;
const RendererSceneOcclusionCull::HZBuffer *occlusion_buffer;
const CameraMatrix *camera_matrix;
- const VisibilityCullData *visibility_cull_data;
+ uint64_t visibility_viewport_mask;
};
void _scene_cull_threaded(uint32_t p_thread, CullData *cull_data);
diff --git a/tests/test_json.h b/tests/test_json.h
index f1cb4799dc..60c4991a57 100644
--- a/tests/test_json.h
+++ b/tests/test_json.h
@@ -45,75 +45,65 @@ TEST_CASE("[JSON] Parsing single data types") {
// Parsing a single data type as JSON is valid per the JSON specification.
JSON json;
- Variant result;
- String err_str;
- int err_line;
- json.parse("null", result, err_str, err_line);
+ json.parse("null");
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing `null` as JSON should parse successfully.");
CHECK_MESSAGE(
- result == Variant(),
+ json.get_data() == Variant(),
"Parsing a double quoted string as JSON should return the expected value.");
- json.parse("true", result, err_str, err_line);
+ json.parse("true");
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing boolean `true` as JSON should parse successfully.");
CHECK_MESSAGE(
- result,
+ json.get_data(),
"Parsing boolean `true` as JSON should return the expected value.");
- json.parse("false", result, err_str, err_line);
+ json.parse("false");
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing boolean `false` as JSON should parse successfully.");
CHECK_MESSAGE(
- !result,
+ !json.get_data(),
"Parsing boolean `false` as JSON should return the expected value.");
- // JSON only has a floating-point number type, no integer type.
- // This is why we use `is_equal_approx()` for the comparison.
- json.parse("123456", result, err_str, err_line);
+ json.parse("123456");
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing an integer number as JSON should parse successfully.");
CHECK_MESSAGE(
- (int)result == 123'456,
+ (int)(json.get_data()) == 123456,
"Parsing an integer number as JSON should return the expected value.");
- json.parse("0.123456", result, err_str, err_line);
+ json.parse("0.123456");
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing a floating-point number as JSON should parse successfully.");
CHECK_MESSAGE(
- Math::is_equal_approx(result, 0.123456),
+ Math::is_equal_approx(json.get_data(), 0.123456),
"Parsing a floating-point number as JSON should return the expected value.");
- json.parse("\"hello\"", result, err_str, err_line);
+ json.parse("\"hello\"");
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing a double quoted string as JSON should parse successfully.");
CHECK_MESSAGE(
- result == "hello",
+ json.get_data() == "hello",
"Parsing a double quoted string as JSON should return the expected value.");
}
TEST_CASE("[JSON] Parsing arrays") {
JSON json;
- Variant result;
- String err_str;
- int err_line;
// JSON parsing fails if it's split over several lines (even if leading indentation is removed).
- json.parse(
- R"(["Hello", "world.", "This is",["a","json","array.",[]], "Empty arrays ahoy:", [[["Gotcha!"]]]])",
- result, err_str, err_line);
+ json.parse(R"(["Hello", "world.", "This is",["a","json","array.",[]], "Empty arrays ahoy:", [[["Gotcha!"]]]])");
- const Array array = result;
+ const Array array = json.get_data();
CHECK_MESSAGE(
- err_line == 0,
+ json.get_error_line() == 0,
"Parsing a JSON array should parse successfully.");
CHECK_MESSAGE(
array[0] == "Hello",
@@ -136,15 +126,10 @@ TEST_CASE("[JSON] Parsing arrays") {
TEST_CASE("[JSON] Parsing objects (dictionaries)") {
JSON json;
- Variant result;
- String err_str;
- int err_line;
- json.parse(
- R"({"name": "Godot Engine", "is_free": true, "bugs": null, "apples": {"red": 500, "green": 0, "blue": -20}, "empty_object": {}})",
- result, err_str, err_line);
+ json.parse(R"({"name": "Godot Engine", "is_free": true, "bugs": null, "apples": {"red": 500, "green": 0, "blue": -20}, "empty_object": {}})");
- const Dictionary dictionary = result;
+ const Dictionary dictionary = json.get_data();
CHECK_MESSAGE(
dictionary["name"] == "Godot Engine",
"The parsed JSON should contain the expected values.");
diff --git a/thirdparty/misc/easing_equations.cpp b/thirdparty/misc/easing_equations.cpp
index af48aaf079..ce32c1a362 100644
--- a/thirdparty/misc/easing_equations.cpp
+++ b/thirdparty/misc/easing_equations.cpp
@@ -297,7 +297,7 @@ static real_t out_in(real_t t, real_t b, real_t c, real_t d) {
}
}; // namespace back
-Tween::interpolater Tween::interpolaters[Tween::TRANS_COUNT][Tween::EASE_COUNT] = {
+Tween::interpolater Tween::interpolaters[Tween::TRANS_MAX][Tween::EASE_MAX] = {
{ &linear::in, &linear::out, &linear::in_out, &linear::out_in },
{ &sine::in, &sine::out, &sine::in_out, &sine::out_in },
{ &quint::in, &quint::out, &quint::in_out, &quint::out_in },
@@ -311,7 +311,7 @@ Tween::interpolater Tween::interpolaters[Tween::TRANS_COUNT][Tween::EASE_COUNT]
{ &back::in, &back::out, &back::in_out, &back::out_in },
};
-real_t Tween::_run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) {
+real_t Tween::run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) {
interpolater cb = interpolaters[p_trans_type][p_ease_type];
ERR_FAIL_COND_V(cb == NULL, b);