mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 23:54:23 +00:00
Start refactoring SummoningCircle
This commit is contained in:
parent
948234d7f3
commit
8fb258b493
4 changed files with 29 additions and 39 deletions
|
@ -12,6 +12,7 @@ radius = 4.0
|
||||||
script = ExtResource("1_sgl1t")
|
script = ExtResource("1_sgl1t")
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite2D" parent="."]
|
[node name="Sprite" type="Sprite2D" parent="."]
|
||||||
|
z_index = 5
|
||||||
position = Vector2(0, 32)
|
position = Vector2(0, 32)
|
||||||
scale = Vector2(2, 2)
|
scale = Vector2(2, 2)
|
||||||
texture = ExtResource("2_rbklw")
|
texture = ExtResource("2_rbklw")
|
||||||
|
|
|
@ -1,42 +1,29 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
class_name SummoningCircle
|
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.
|
## The [SacrificeStone]s part of this summoning circle.
|
||||||
var stones: Array[SacrificeStone] = []
|
var stones: Array[SacrificeStone] = []
|
||||||
|
|
||||||
|
|
||||||
## Refresh the value of [field stones].
|
## Refresh the value of [field stones], and reconnect signals accordingly.
|
||||||
func refresh_stones() -> void:
|
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(
|
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:
|
func _ready() -> void:
|
||||||
spawn(scene_imp)
|
refresh_stones()
|
||||||
|
|
||||||
func spawn(type: PackedScene) -> void:
|
func _on_sacrifice_changed(_entity: Node2D) -> void:
|
||||||
spawner.scene = type
|
Log.w(self, "Sacrifice has changed, but no summoning function is implemented.")
|
||||||
spawner.spawn()
|
|
||||||
|
|
||||||
for s in stones:
|
|
||||||
s.entity.queue_free()
|
|
||||||
|
|
||||||
func _on_sacrifice_changed(_entity: Node2D, _type: Enums.MonsterType):
|
|
||||||
refresh_sacrifices()
|
|
||||||
try_sacrifice()
|
|
||||||
|
|
|
@ -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="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="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://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"]
|
[ext_resource type="PackedScene" uid="uid://tx1qi6ahlxjp" path="res://behaviours/spawner.tscn" id="3_p6s0q"]
|
||||||
|
|
||||||
[node name="SummoningCircle" type="Node2D"]
|
[node name="SummoningCircle" type="Node2D"]
|
||||||
script = ExtResource("1_x3bxd")
|
script = ExtResource("1_x3bxd")
|
||||||
scene_imp = ExtResource("2_48rxv")
|
|
||||||
|
|
||||||
[node name="Spawner" parent="." instance=ExtResource("3_p6s0q")]
|
[node name="Spawner" parent="." instance=ExtResource("3_p6s0q")]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite2D" parent="."]
|
[node name="Sprite" type="Sprite2D" parent="."]
|
||||||
position = Vector2(2, 4)
|
position = Vector2(2, 4)
|
||||||
scale = Vector2(2, 2)
|
scale = Vector2(2, 2)
|
||||||
texture = ExtResource("1_c6jmb")
|
texture = ExtResource("1_c6jmb")
|
||||||
|
|
||||||
[node name="S1" parent="." instance=ExtResource("2_dwkfn")]
|
[node name="SacrificeStones" type="Node2D" parent="."]
|
||||||
position = Vector2(-92, -64)
|
|
||||||
|
|
||||||
[node name="S2" parent="." instance=ExtResource("2_dwkfn")]
|
[node name="StoneUp" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
|
||||||
position = Vector2(0, -108)
|
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)
|
position = Vector2(92, -64)
|
||||||
|
|
||||||
[node name="S4" parent="." instance=ExtResource("2_dwkfn")]
|
[node name="StoneBottomLeft" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
|
||||||
position = Vector2(75, 30)
|
|
||||||
|
|
||||||
[node name="S5" parent="." instance=ExtResource("2_dwkfn")]
|
|
||||||
position = Vector2(-75, 30)
|
position = Vector2(-75, 30)
|
||||||
|
|
||||||
|
[node name="StoneBottomRight" parent="SacrificeStones" instance=ExtResource("2_dwkfn")]
|
||||||
|
position = Vector2(75, 30)
|
||||||
|
|
1
enums.gd
1
enums.gd
|
@ -4,6 +4,7 @@ class_name Enums
|
||||||
enum ZIndex {
|
enum ZIndex {
|
||||||
EntityAir = 20,
|
EntityAir = 20,
|
||||||
EntityGround = 10,
|
EntityGround = 10,
|
||||||
|
SacrificeStone = 5,
|
||||||
Props = 0,
|
Props = 0,
|
||||||
Terrain = -10,
|
Terrain = -10,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue