1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 15:44:23 +00:00

Start refactoring SummoningCircle

This commit is contained in:
Steffo 2024-04-28 19:21:22 +02:00
parent 948234d7f3
commit 8fb258b493
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
4 changed files with 29 additions and 39 deletions

View file

@ -12,6 +12,7 @@ radius = 4.0
script = ExtResource("1_sgl1t")
[node name="Sprite" type="Sprite2D" parent="."]
z_index = 5
position = Vector2(0, 32)
scale = Vector2(2, 2)
texture = ExtResource("2_rbklw")

View file

@ -1,42 +1,29 @@
extends Node2D
class_name SummoningCircle
@onready var spawner: Spawner = %"Spawner"
## The scene to spawn.
@export var scene_imp: PackedScene
## The [SacrificeStone]s part of this summoning circle.
var stones: Array[SacrificeStone] = []
## Refresh the value of [field stones].
## Refresh the value of [field stones], and reconnect signals accordingly.
func refresh_stones() -> void:
stones.map(func(stone: SacrificeStone):
if stone == null:
return
if stone.sacrifice_changed.is_connected(self._on_sacrifice_changed):
stone.sacrifice_changed.disconnect(self._on_sacrifice_changed)
)
stones.assign(
find_children("*", "SacrificeStone", false, false)
find_children("*", "SacrificeStone", true, false)
)
stones.map(func(stone: SacrificeStone):
stone.sacrifice_changed.connect(self._on_sacrifice_changed)
)
func try_sacrifice() -> void:
var first_monster = sacrifices[0]
var all_same = true
for m in sacrifices:
if m != first_monster:
all_same = false
break
if not all_same:
return
if first_monster == Enums.MonsterType.Sheep:
spawn(scene_imp)
func _ready() -> void:
refresh_stones()
func spawn(type: PackedScene) -> void:
spawner.scene = type
spawner.spawn()
for s in stones:
s.entity.queue_free()
func _on_sacrifice_changed(_entity: Node2D, _type: Enums.MonsterType):
refresh_sacrifices()
try_sacrifice()
func _on_sacrifice_changed(_entity: Node2D) -> void:
Log.w(self, "Sacrifice has changed, but no summoning function is implemented.")

View file

@ -1,33 +1,34 @@
[gd_scene load_steps=6 format=3 uid="uid://xj0pa287n1wo"]
[gd_scene load_steps=5 format=3 uid="uid://xj0pa287n1wo"]
[ext_resource type="Texture2D" uid="uid://n0wj20mduwy8" path="res://entities/summoning_circle.png" id="1_c6jmb"]
[ext_resource type="Script" path="res://entities/summoning_circle.gd" id="1_x3bxd"]
[ext_resource type="PackedScene" uid="uid://4d3ksr3171x4" path="res://entities/imp.tscn" id="2_48rxv"]
[ext_resource type="PackedScene" uid="uid://ddpo03rb6068c" path="res://entities/sacrifice_stone.tscn" id="2_dwkfn"]
[ext_resource type="PackedScene" uid="uid://tx1qi6ahlxjp" path="res://behaviours/spawner.tscn" id="3_p6s0q"]
[node name="SummoningCircle" type="Node2D"]
script = ExtResource("1_x3bxd")
scene_imp = ExtResource("2_48rxv")
[node name="Spawner" parent="." instance=ExtResource("3_p6s0q")]
unique_name_in_owner = true
[node name="Sprite" type="Sprite2D" parent="."]
position = Vector2(2, 4)
scale = Vector2(2, 2)
texture = ExtResource("1_c6jmb")
[node name="S1" parent="." instance=ExtResource("2_dwkfn")]
position = Vector2(-92, -64)
[node name="SacrificeStones" type="Node2D" parent="."]
[node name="S2" parent="." instance=ExtResource("2_dwkfn")]
[node name="StoneUp" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
position = Vector2(0, -108)
[node name="S3" parent="." instance=ExtResource("2_dwkfn")]
[node name="StoneTopLeft" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
position = Vector2(-92, -64)
[node name="StoneTopRight" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
position = Vector2(92, -64)
[node name="S4" parent="." instance=ExtResource("2_dwkfn")]
position = Vector2(75, 30)
[node name="S5" parent="." instance=ExtResource("2_dwkfn")]
[node name="StoneBottomLeft" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
position = Vector2(-75, 30)
[node name="StoneBottomRight" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
position = Vector2(75, 30)

View file

@ -4,6 +4,7 @@ class_name Enums
enum ZIndex {
EntityAir = 20,
EntityGround = 10,
SacrificeStone = 5,
Props = 0,
Terrain = -10,
}