mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Create SummoningRecipe
This commit is contained in:
parent
872ff3c6b6
commit
8ca2325f22
4 changed files with 149 additions and 0 deletions
63
behaviours/summoning_recipe.gd
Normal file
63
behaviours/summoning_recipe.gd
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
@icon("res://behaviours/summoning_recipe.svg")
|
||||||
|
extends Node2D
|
||||||
|
class_name SummoningRecipe
|
||||||
|
|
||||||
|
|
||||||
|
## A [Node2D] describing a possible recipe that can be performed with the [SummoningCircle].
|
||||||
|
##
|
||||||
|
## [Node2D] is required instead of [Node] as otherwise the child [Spawner] would lose its relative [field position].
|
||||||
|
|
||||||
|
|
||||||
|
## 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,
|
||||||
|
}
|
43
behaviours/summoning_recipe.svg
Normal file
43
behaviours/summoning_recipe.svg
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
viewBox="0 0 512 512"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
sodipodi:docname="summoning_recipe.svg"
|
||||||
|
width="16"
|
||||||
|
height="16"
|
||||||
|
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs1" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#000000"
|
||||||
|
borderopacity="0.25"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:zoom="13.171875"
|
||||||
|
inkscape:cx="5.5421115"
|
||||||
|
inkscape:cy="7.0225386"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1020"
|
||||||
|
inkscape:window-x="1280"
|
||||||
|
inkscape:window-y="32"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg1" />
|
||||||
|
<!--! Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. -->
|
||||||
|
<path
|
||||||
|
d="m 137.3,502.65 c 12.5,12.5 32.8,12.5 45.3,0 12.5,-12.5 12.5,-32.8 0,-45.3 l -41.3,-41.3 H 448 c 17.7,0 32,-14.3 32,-32 0,-17.7 -14.3,-32 -32,-32 H 141.3 l 41.4,-41.4 c 12.5,-12.5 12.5,-32.8 0,-45.3 -12.5,-12.5 -32.8,-12.5 -45.3,0 l -96,96 c -12.5,12.5 -12.5,32.8 0,45.3 l 96,96 z"
|
||||||
|
id="path2"
|
||||||
|
style="fill:#8da5f3" />
|
||||||
|
<path
|
||||||
|
d="m 470.6,150.65 c 12.5,-12.5 12.5,-32.8 0,-45.3 l -96,-96 c -12.5,-12.5 -32.8,-12.5 -45.3,0 -12.5,12.5 -12.5,32.8 0,45.3 l 41.4,41.4 H 64 c -17.7,0 -32,14.3 -32,32 0,17.7 14.3,32 32,32 h 306.7 l -41.4,41.4 c -12.5,12.5 -12.5,32.8 0,45.3 12.5,12.5 32.8,12.5 45.3,0 l 96,-96 z"
|
||||||
|
id="path1"
|
||||||
|
style="fill:#e0e0e0" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
37
behaviours/summoning_recipe.svg.import
Normal file
37
behaviours/summoning_recipe.svg.import
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cwcq7xmmgohwp"
|
||||||
|
path="res://.godot/imported/summoning_recipe.svg-ef125a879691beaa95aba644389f31da.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://behaviours/summoning_recipe.svg"
|
||||||
|
dest_files=["res://.godot/imported/summoning_recipe.svg-ef125a879691beaa95aba644389f31da.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=false
|
||||||
|
editor/convert_colors_with_editor_theme=false
|
6
behaviours/summoning_recipe.tscn
Normal file
6
behaviours/summoning_recipe.tscn
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://ufjnfj3itypj"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://behaviours/summoning_recipe.gd" id="1_ek58s"]
|
||||||
|
|
||||||
|
[node name="SummoningRecipe" type="Node2D"]
|
||||||
|
script = ExtResource("1_ek58s")
|
Loading…
Reference in a new issue