LokUtil

Inherits:

The LokUtil class is a utility class that brings random useful static methods that can be used wherever convenient.

Description

The purpose of this class is helping with common repetitive code that is needed in multiple places. Since the methods of this class are static it doesn’t need to be instantiated.

Version: 1.0.0 Author: Daniel Sousa (github.com/nadjiel <github.com/nadjiel>_)

Method Index

Method Descriptions

bool filter_value(Array filter, Variant value)

The filter_value method is a helper function that takes a filter Array and a value to be filtered. This function, then, tests if the value is present in the filter Array (using the in operator). If present, true is returned to indicate the filtering passed, if absent, false is returned to indicate the filtering didn’t pass. If the received filter is an empty Array, this function considers the filtering as passed.

Dictionary filter_dictionary(Dictionary dict, Callable filter)

The filter_dictionary method takes a dict (Dictionary) and a filter Callable and uses that Callable to test for each key/ value pair of that dict if such entry should be kept or not in the resultant Dictionary. In order to realize the tests, the filter Callable should accept two values: a key and a value. That Callable should then return a bool indicating if that pair should be kept in the result.

Dictionary dict, Callable spliter)

The split_dictionary method works similarly to the filter_dictionary method, but instead of returning only a Dictionary with the values that passed the filtering, this method returns an Array with two :ref:`Dictionary <Dictionary>`s: one with the entries that passed the filtering, and the one with the entries that didn’t.

Dictionary map_dictionary(Dictionary dict, Callable mapper)

The map_dictionary method takes a dict (Dictionary) and a mapper Callable and uses that Callable to transform each key/ value pair of the original Dictionary into a new value in a new Dictionary. In order to realize that mapping, the mapper Callable should accept two values: a key and a value. That Callable should then return a value that will occupy the place of the received value in the new Dictionary.

bool check_and_disconnect_signal(Object object, StringName signal_name, Callable callable)

The check_and_disconnect_signal method tries to disconnect a callable from a signal in an object if they are connected. If they aren’t, this method returns false to indicate that nothing was done. If the object is null false is also returned, and nothing is done. If the disconection is successful, true is returned.

void check_and_disconnect_signals(Object object, :ref:`Dictionary <Dictionary>`[] signals)

The check_and_disconnect_signals method tries to disconnect all the callables and signals passed in the signals Array. The signals parameter must be passed as an Array which elements must be in the following format: { "name": <signal_name>, "callable": <callable_reference> } In the object parameter is null, this method won’t do nothing.

bool check_and_connect_signal(Object object, StringName signal_name, Callable callable, int flags = 0)

The check_and_connect_signal method tries to connect a callable to a signal in an object. If the object is null, false is returned and nothing is done. If the connection is successful, true is returned.

void check_and_connect_signals(Object object, :ref:`Dictionary <Dictionary>`[] signals)

The check_and_connect_signals method tries to connect all the callables and signals passed in the signals Array. The signals parameter must be passed as an Array which elements must be in the following format: { "name": <signal_name>, "callable": <callable_reference>, "flags": <optional_flags> } If the object parameter is null, this method won’t do nothing.