53 lines
848 B
GDScript
53 lines
848 B
GDScript
extends Object
|
|
|
|
var _values: Dictionary
|
|
|
|
func _init():
|
|
_values = Dictionary()
|
|
|
|
func size() -> int:
|
|
return _values.size()
|
|
|
|
func empty() -> bool:
|
|
return _values.size() == 0
|
|
|
|
func add(value):
|
|
_values[value] = true
|
|
|
|
func add_all(values):
|
|
for value in values:
|
|
add(value)
|
|
|
|
func remove(value):
|
|
_values.erase(value)
|
|
|
|
func remove_all(values):
|
|
for value in values:
|
|
remove(value)
|
|
|
|
func get_random():
|
|
return _values.keys()[randi() % _values.size()]
|
|
|
|
func pop_random():
|
|
assert(size() > 0)
|
|
var value = get_random()
|
|
remove(value)
|
|
return value
|
|
|
|
func values() -> Array:
|
|
return _values.keys()
|
|
|
|
func has(value) -> bool:
|
|
return _values.has(value)
|
|
|
|
func has_all(values) -> bool:
|
|
return _values.has_all(values)
|
|
|
|
func duplicate():
|
|
var new_set = get_script().new()
|
|
new_set._values = _values.duplicate()
|
|
return new_set
|
|
|
|
func clear():
|
|
_values.clear()
|