1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 01:24:23 +00:00
hella-farm/behaviours/summoning_recipe.gd

62 lines
1.6 KiB
GDScript3
Raw Normal View History

2024-04-28 21:41:01 +00:00
@icon("res://behaviours/summoning_recipe.svg")
2024-04-28 21:46:36 +00:00
extends Node
2024-04-28 21:41:01 +00:00
class_name SummoningRecipe
2024-04-28 21:46:36 +00:00
## A [Node] describing a possible recipe that can be performed with the [SummoningCircle].
2024-04-28 21:41:01 +00:00
## Emitted when [method do_match] is called, and the [field recipe] is successfully matched.
signal matched
## How [Sacrificable]s should be matched.
@export var mode := Mode.NONE
## Which [Sacrificable]s should be matched.
@export var recipe: Array[StringName] = []
func check_match(inputs: Array[StringName]) -> bool:
var matching: Array[bool] = recipe.map(func(): return false)
# This is awful, but I am too lazy to implement something better
# why is there no enumerate Q_Q
for input in inputs:
var idx = 0
for matchable in recipe:
if input == matchable and not matching[idx]:
matching[idx] = true
continue
idx += 1
# Use one of the various modes
# why do i have to do this
match mode:
Mode.NONE:
return false
Mode.ANY:
return matching.any(func(value): return value)
Mode.ALL:
return matching.all(func(value): return value)
Mode.EXACT:
return matching.all(func(value): return value) and len(inputs) == len(recipe)
_:
# Static analysis go home you're drunk
return false
func do_match(inputs: Array[StringName]) -> void:
if check_match(inputs):
matched.emit()
enum Mode {
## Never match the recipe.
NONE = 0,
## Match the recipe if a single one of the sacrificables is matched.
ANY = 1,
## Match the recipe if all the sacrificables are matched, even if more are present.
ALL = 2,
## Match the recipe if all the sacrificables are matched AND there are no other sacrificables present.
EXACT = 3,
}