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

Refactor Spawner

This commit is contained in:
Steffo 2024-04-16 03:02:19 +02:00
parent a3d98df9ff
commit 10f17c1e9e
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
5 changed files with 97 additions and 40 deletions

View file

@ -1,19 +1,20 @@
@icon("res://behaviours/spawner.svg")
extends Node2D extends Node2D
class_name Spawner class_name Spawner
signal spawned(entity: Node2D) signal spawned(entity: Node2D)
@export var scene: PackedScene @export var scene: PackedScene
@export var parent: Node2D @export var default_target: Node2D
func spawn():
func spawn(target: Node2D = null):
if not target:
target = default_target
if not target:
target = MainGame.get_ancestor(self).default_spawn_parent
var entity = scene.instantiate() var entity = scene.instantiate()
entity.global_scale = global_scale entity.global_scale = global_scale
entity.global_position = global_position entity.global_position = global_position
entity.global_rotation = global_rotation entity.global_rotation = global_rotation
parent.add_child.call_deferred(entity) # Not sure why this is needed. target.add_child.call_deferred(entity) # Not sure why this is needed.
func _ready():
if parent == null:
parent = MainGame.get_ancestor(self).get_node("SpawnedEntities")

47
behaviours/spawner.svg Normal file
View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 640 640"
version="1.1"
id="svg1"
sodipodi:docname="spawner.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="26.34375"
inkscape:cx="13.001186"
inkscape:cy="9.9264532"
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 504,376 v -64 h -64 c -13.3,0 -24,-10.7 -24,-24 0,-13.3 10.7,-24 24,-24 h 64 v -64 c 0,-13.3 10.7,-24 24,-24 13.3,0 24,10.7 24,24 v 64 h 64 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -64 v 64 c 0,13.3 -10.7,24 -24,24 -13.3,0 -24,-10.7 -24,-24 z"
id="path3"
style="fill:#73f280;fill-opacity:1" />
<path
d="M 0,546.3 C 0,447.8 79.8,368 178.3,368 h 91.4 c 98.5,0 178.3,79.8 178.3,178.3 0,16.4 -13.3,29.7 -29.7,29.7 H 29.7 C 13.3,576 0,562.7 0,546.3 Z"
id="path2"
style="fill:#8da5f3" />
<path
d="m 96,192 a 128,128 0 1 1 256,0 128,128 0 1 1 -256,0 z"
id="path1"
style="fill:#8da5f3" />
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://2okawpk7lh5j"
path="res://.godot/imported/spawner.svg-02e649ce51fee431d04ebb532f1c81e8.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://behaviours/spawner.svg"
dest_files=["res://.godot/imported/spawner.svg-02e649ce51fee431d04ebb532f1c81e8.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

View file

@ -15,3 +15,4 @@ static func get_ancestor(start: Node) -> MainGame:
@onready var gold_counter: Counter = $"GoldCounter" @onready var gold_counter: Counter = $"GoldCounter"
@onready var camera: GameCamera = $"GameCamera" @onready var camera: GameCamera = $"GameCamera"
@onready var default_spawn_parent: Node2D = %"DefaultSpawnParent"

File diff suppressed because one or more lines are too long