Skip to content

Commit

Permalink
Merge pull request #15611 from bojidar-bg/x-bind-more-properties
Browse files Browse the repository at this point in the history
Bind many more properties to scripts
  • Loading branch information
akien-mga committed Jan 12, 2018
2 parents 0063047 + ad79c70 commit e24f2c6
Show file tree
Hide file tree
Showing 169 changed files with 1,261 additions and 3,567 deletions.
23 changes: 23 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,22 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_power_seconds_left"), &_OS::get_power_seconds_left);
ClassDB::bind_method(D_METHOD("get_power_percent_left"), &_OS::get_power_percent_left);

ADD_PROPERTY(PropertyInfo(Variant::STRING, "clipboard"), "set_clipboard", "get_clipboard");
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen"), "set_current_screen", "get_current_screen");
ADD_PROPERTY(PropertyInfo(Variant::INT, "exit_code"), "set_exit_code", "get_exit_code");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_enabled"), "set_use_vsync", "is_vsync_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_screen_on"), "set_keep_screen_on", "is_keep_screen_on");
ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation");
ADD_GROUP("Window", "window_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_fullscreen"), "set_window_fullscreen", "is_window_fullscreen");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_maximized"), "set_window_maximized", "is_window_maximized");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_minimized"), "set_window_minimized", "is_window_minimized");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_resizable"), "set_window_resizable", "is_window_resizable");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_position"), "set_window_position", "get_window_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_size"), "set_window_size", "get_window_size");

BIND_ENUM_CONSTANT(DAY_SUNDAY);
BIND_ENUM_CONSTANT(DAY_MONDAY);
BIND_ENUM_CONSTANT(DAY_TUESDAY);
Expand Down Expand Up @@ -1808,6 +1824,8 @@ void _File::_bind_methods() {
ClassDB::bind_method(D_METHOD("file_exists", "path"), &_File::file_exists);
ClassDB::bind_method(D_METHOD("get_modified_time", "file"), &_File::get_modified_time);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "endian_swap"), "set_endian_swap", "get_endian_swap");

BIND_ENUM_CONSTANT(READ);
BIND_ENUM_CONSTANT(WRITE);
BIND_ENUM_CONSTANT(READ_WRITE);
Expand Down Expand Up @@ -2649,6 +2667,11 @@ void _Engine::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_editor_hint", "enabled"), &_Engine::set_editor_hint);
ClassDB::bind_method(D_METHOD("is_editor_hint"), &_Engine::is_editor_hint);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_hint"), "set_editor_hint", "is_editor_hint");
ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_second"), "set_iterations_per_second", "get_iterations_per_second");
ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_scale"), "set_time_scale", "get_time_scale");
}

_Engine *_Engine::singleton = NULL;
Expand Down
3 changes: 3 additions & 0 deletions core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ void HTTPClient::_bind_methods() {

ClassDB::bind_method(D_METHOD("query_string_from_dict", "fields"), &HTTPClient::query_string_from_dict);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_mode_enabled"), "set_blocking_mode", "is_blocking_mode_enabled");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "connection", PROPERTY_HINT_RESOURCE_TYPE, "StreamPeer", 0), "set_connection", "get_connection");

BIND_ENUM_CONSTANT(METHOD_GET);
BIND_ENUM_CONSTANT(METHOD_HEAD);
BIND_ENUM_CONSTANT(METHOD_POST);
Expand Down
4 changes: 4 additions & 0 deletions core/io/networked_multiplayer_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
void NetworkedMultiplayerPeer::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode);
ClassDB::bind_method(D_METHOD("get_transfer_mode"), &NetworkedMultiplayerPeer::get_transfer_mode);
ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &NetworkedMultiplayerPeer::set_target_peer);

ClassDB::bind_method(D_METHOD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer);
Expand All @@ -45,6 +46,9 @@ void NetworkedMultiplayerPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_refuse_new_connections", "enable"), &NetworkedMultiplayerPeer::set_refuse_new_connections);
ClassDB::bind_method(D_METHOD("is_refusing_new_connections"), &NetworkedMultiplayerPeer::is_refusing_new_connections);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_connections"), "set_refuse_new_connections", "is_refusing_new_connections");
ADD_PROPERTY(PropertyInfo(Variant::INT, "transfer_mode", PROPERTY_HINT_ENUM, "Unreliable,Unreliable Ordered,Reliable"), "set_transfer_mode", "get_transfer_mode");

BIND_ENUM_CONSTANT(TRANSFER_MODE_UNRELIABLE);
BIND_ENUM_CONSTANT(TRANSFER_MODE_UNRELIABLE_ORDERED);
BIND_ENUM_CONSTANT(TRANSFER_MODE_RELIABLE);
Expand Down
1 change: 1 addition & 0 deletions core/io/networked_multiplayer_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class NetworkedMultiplayerPeer : public PacketPeer {
};

virtual void set_transfer_mode(TransferMode p_mode) = 0;
virtual TransferMode get_transfer_mode() const = 0;
virtual void set_target_peer(int p_peer_id) = 0;

virtual int get_packet_peer() const = 0;
Expand Down
12 changes: 12 additions & 0 deletions core/io/packet_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ void PacketPeer::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_allow_object_decoding", "enable"), &PacketPeer::set_allow_object_decoding);
ClassDB::bind_method(D_METHOD("is_object_decoding_allowed"), &PacketPeer::is_object_decoding_allowed);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_object_decoding"), "set_allow_object_decoding", "is_object_decoding_allowed");
};

/***************/
Expand All @@ -154,10 +156,15 @@ void PacketPeerStream::_set_stream_peer(REF p_peer) {
void PacketPeerStream::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::_set_stream_peer);
ClassDB::bind_method(D_METHOD("get_stream_peer"), &PacketPeerStream::get_stream_peer);
ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size);
ClassDB::bind_method(D_METHOD("set_output_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_output_buffer_max_size);
ClassDB::bind_method(D_METHOD("get_input_buffer_max_size"), &PacketPeerStream::get_input_buffer_max_size);
ClassDB::bind_method(D_METHOD("get_output_buffer_max_size"), &PacketPeerStream::get_output_buffer_max_size);

ADD_PROPERTY(PropertyInfo(Variant::INT, "input_buffer_max_size"), "set_input_buffer_max_size", "get_input_buffer_max_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "output_buffer_max_size"), "set_output_buffer_max_size", "get_output_buffer_max_size");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream_peer", PROPERTY_HINT_RESOURCE_TYPE, "StreamPeer", 0), "set_stream_peer", "get_stream_peer");
}

Error PacketPeerStream::_poll_buffer() const {
Expand Down Expand Up @@ -262,6 +269,11 @@ void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
peer = p_peer;
}

Ref<StreamPeer> PacketPeerStream::get_stream_peer() const {

return peer;
}

void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {

//warning may lose packets
Expand Down
1 change: 1 addition & 0 deletions core/io/packet_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class PacketPeerStream : public PacketPeer {
virtual int get_max_packet_size() const;

void set_stream_peer(const Ref<StreamPeer> &p_peer);
Ref<StreamPeer> get_stream_peer() const;
void set_input_buffer_max_size(int p_max_size);
int get_input_buffer_max_size() const;
void set_output_buffer_max_size(int p_max_size);
Expand Down
5 changes: 5 additions & 0 deletions core/io/stream_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ void StreamPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_string", "bytes"), &StreamPeer::get_string);
ClassDB::bind_method(D_METHOD("get_utf8_string", "bytes"), &StreamPeer::get_utf8_string);
ClassDB::bind_method(D_METHOD("get_var"), &StreamPeer::get_var);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "big_endian"), "set_big_endian", "is_big_endian_enabled");
}
////////////////////////////////

Expand All @@ -414,6 +416,9 @@ void StreamPeerBuffer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_data_array"), &StreamPeerBuffer::get_data_array);
ClassDB::bind_method(D_METHOD("clear"), &StreamPeerBuffer::clear);
ClassDB::bind_method(D_METHOD("duplicate"), &StreamPeerBuffer::duplicate);

ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_array"), "set_data_array", "get_data_array");

}

Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
Expand Down
4 changes: 2 additions & 2 deletions core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NONZERO));
#ifdef TOOLS_ENABLED
if (editor_section_folding.size()) {
p_list->push_back(PropertyInfo(Variant::ARRAY, CoreStringNames::get_singleton()->_sections_unfolded, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::ARRAY, CoreStringNames::get_singleton()->_sections_unfolded, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
}
#endif
if (!metadata.empty())
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "__meta__", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_STORE_IF_NONZERO));
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "__meta__", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORE_IF_NONZERO));
if (script_instance && !p_reversed) {
p_list->push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY));
script_instance->get_property_list(p_list);
Expand Down
2 changes: 1 addition & 1 deletion core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ enum PropertyUsageFlags {

PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED,
PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNAL,
PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK,
};

#define ADD_SIGNAL(m_signal) ClassDB::add_signal(get_class_static(), m_signal)
Expand Down
2 changes: 2 additions & 0 deletions core/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void Script::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_script_signal", "signal_name"), &Script::has_script_signal);

ClassDB::bind_method(D_METHOD("is_tool"), &Script::is_tool);

ADD_PROPERTY(PropertyInfo(Variant::STRING, "source_code", PROPERTY_HINT_NONE, "", 0), "set_source_code", "get_source_code");
}

void ScriptServer::set_scripting_enabled(bool p_enabled) {
Expand Down
2 changes: 1 addition & 1 deletion core/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ void Translation::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_messages"), &Translation::_set_messages);
ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages);

ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "messages", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_messages", "_get_messages");
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "messages", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_messages", "_get_messages");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale");
}

Expand Down
5 changes: 1 addition & 4 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
<member name="Geometry" type="Geometry" setter="" getter="">
[Geometry] singleton
</member>
<member name="GodotSharp" type="GodotSharp" setter="" getter="">
[GodotSharp] singleton
</member>
<member name="IP" type="IP" setter="" getter="">
[IP] singleton
</member>
Expand Down Expand Up @@ -1285,7 +1282,7 @@
</constant>
<constant name="PROPERTY_USAGE_DEFAULT_INTL" value="71" enum="PropertyUsageFlags">
</constant>
<constant name="PROPERTY_USAGE_NOEDITOR" value="1048581" enum="PropertyUsageFlags">
<constant name="PROPERTY_USAGE_NOEDITOR" value="5" enum="PropertyUsageFlags">
</constant>
<constant name="METHOD_FLAG_NORMAL" value="1" enum="MethodFlags">
Flag for normal method
Expand Down
59 changes: 11 additions & 48 deletions doc/classes/Animation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,13 @@
Return the index of the specified track. If the track is not found, return -1.
</description>
</method>
<method name="get_length" qualifiers="const">
<return type="float">
</return>
<description>
Return the total length of the animation (in seconds).
</description>
</method>
<method name="get_step" qualifiers="const">
<return type="float">
</return>
<description>
Get the animation step value.
</description>
</method>
<method name="get_track_count" qualifiers="const">
<return type="int">
</return>
<description>
Return the amount of tracks in the animation.
</description>
</method>
<method name="has_loop" qualifiers="const">
<return type="bool">
</return>
<description>
Return whether the animation has the loop flag set.
</description>
</method>
<method name="method_track_get_key_indices" qualifiers="const">
<return type="PoolIntArray">
</return>
Expand Down Expand Up @@ -122,33 +101,6 @@
Remove a track by specifying the track index.
</description>
</method>
<method name="set_length">
<return type="void">
</return>
<argument index="0" name="time_sec" type="float">
</argument>
<description>
Set the total length of the animation (in seconds). Note that length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.
</description>
</method>
<method name="set_loop">
<return type="void">
</return>
<argument index="0" name="enabled" type="bool">
</argument>
<description>
Set a flag indicating that the animation must loop. This is uses for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
</description>
</method>
<method name="set_step">
<return type="void">
</return>
<argument index="0" name="size_sec" type="float">
</argument>
<description>
Set the animation step value.
</description>
</method>
<method name="track_find_key" qualifiers="const">
<return type="int">
</return>
Expand Down Expand Up @@ -456,6 +408,17 @@
</description>
</method>
</methods>
<members>
<member name="length" type="float" setter="set_length" getter="get_length">
The total length of the animation (in seconds). Note that length is not delimited by the last key, as this one may be before or after the end to ensure correct interpolation and looping.
</member>
<member name="loop" type="bool" setter="set_loop" getter="has_loop">
A flag indicating that the animation must loop. This is uses for correct interpolation of animation cycles, and for hinting the player that it must restart the animation.
</member>
<member name="step" type="float" setter="set_step" getter="get_step">
The animation step value.
</member>
</members>
<constants>
<constant name="TYPE_VALUE" value="0" enum="TrackType">
Value tracks set values in node properties, but only those which can be Interpolated.
Expand Down

0 comments on commit e24f2c6

Please sign in to comment.