Wanna jump into it? See the api docs
Visit it in the asset library
GD_ is an effort to bring Lodash into Godot. This will attempt to replicate Lodash's behavior as close as possible (even if the implementation becomes round about).
# Map Example
var users = [
{ 'user': 'barney' },
{ 'user': 'fred' }
];
GD_.map(users, 'user');
# => ['barney', 'fred']
# Get Example
var node = Node2D.new()
node.global_position = Vector2(999,123)
var everything_everywhere_all_at_once = {
"array": ["hello", node, "world"]
}
GD_.get_prop(everything_everywhere_all_at_once, "array:1:global_position:y")
# => 123
- Install it through the asset library
- Copy
addons\gd_\src
folder into your project and it must contain the following files- GD_.gd
- GD_array.gd
- GD_collection.gd
- GD_object.gd
- GD_function.gd
- GD_math.gd
- GD_number.gd
- GD_util.gd
- GD_date.gd
- GD_string.gd
- GD_lang.gd
- GD_base.gd
In version 4.2 and below
all Callables supplied should always be constructed with 2 arguments. This means that if in lodash you have a callback like in
_.drop_right_while
which is invoked with 3 arguments (value,index,array). We drop the 3rd arguments.
# Version 4.2, only the callable below with 2 args works
GD_.drop_right_while(..., func(value,index): return true)
# the rest of these will not work
GD_.drop_right_while(..., func(): return true)
GD_.drop_right_while(..., func(value): return true)
GD_.drop_right_while(..., func(value,index,array): return true)
This also means that if in lodash a callback is invoked with only 1 argument like in _.differenceBy
, we must supply a dummy arg.
var callback_1_arg = func (value, _unused):
return value
GD_.difference_by(..., callback_1_arg)
In version 4.3 and above
callbacks can be of variable length, and GD_ ensures that all Callables will be called irregardless of how many arguments are actually needed
# Version 4.3 and above, all of these work
GD_.drop_right_while(..., func(): return true)
GD_.drop_right_while(..., func(value): return true)
GD_.drop_right_while(..., func(value,index): return true)
GD_.drop_right_while(..., func(value,index,array): return true)
Some functions specifically use SameValueZero specification for equality.
For GD_ we just use Godot's ==
operator which for the most part behaves like the SameValueZero.
@TODO tabulate differences
This project is very much in its early stages, so it's very likely for the function you need to not exist yet. If that happens, please leave an issue for a specific function to be prioritized.
Wanna jump into it? See the api docs
Contributing
Just do a pull request against develop
with the following requirements
- Determine what category the function belongs to (array, collection, etc).
- Then add your code to the corresponding category file (GD_array.gd, GD_collection.gd, etc)
- Add a unit test node for it at
res://tests/unit_tests.tscn
scene- For unit tests I suggest checking the test cases over at Lodash's repo
- Update the comments, it should match how the other comments are written because 👇
- Run the auto-markdown generator at
scripts/rebuild_webdocs.gd
which autogenerates index.html - Once your PR is merged into develop, I will bump up the plugin version and deploy to the asset library