This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name Serializable | |
extends Object | |
# Serializable classes cannot have a constructor as an empty one is needed. Resort to static | |
# create function for easier object creation. | |
# Convert instance to a dictionary. | |
func to_dict() -> Dictionary: | |
var result = { | |
"_type": get_script().get_path() # This is a reference to the class/script type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T, K> Iterable<T>.multiDistinctBy(vararg selectors: (T) -> K): List<T> { | |
require(selectors.isNotEmpty()) | |
val set = HashSet<Int>() | |
val distinct = ArrayList<T>() | |
for (element in this) { | |
val key = selectors.fold(0) { sum, selector -> | |
sum.plus(selector(element)?.hashCode() ?: 0) } | |
if (set.add(key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun View.visible() { | |
visibility = View.VISIBLE | |
} | |
fun View.invisible() { | |
visibility = View.INVISIBLE | |
} | |
fun View.gone() { | |
visibility = View.GONE |