From 36399bad338091cc5738764953c041a2997d7526 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Fri, 13 Dec 2024 12:41:48 -0700 Subject: [PATCH] Amount is an inherent property of all item pickups --- levels/debug_level/debug_level.tscn | 4 ++++ src/items/extra_ball/brick_item.tscn | 2 +- src/items/extra_ball/extra_ball.gd | 5 +---- src/items/item/item.gd | 4 ++++ src/items/item_spawner.gd | 4 ++++ src/player/world_player.gd | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/levels/debug_level/debug_level.tscn b/levels/debug_level/debug_level.tscn index 0cd39af..d4fadbf 100644 --- a/levels/debug_level/debug_level.tscn +++ b/levels/debug_level/debug_level.tscn @@ -383,6 +383,7 @@ spawn_turns = 2 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.54289, 1.1, 4.28708) script = ExtResource("8_5kaye") item = ExtResource("12_tj0lh") +amount = 5 spawn_on_ready = true spawn_turns = 1 @@ -390,6 +391,7 @@ spawn_turns = 1 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.02452, 1.1, 5.12384) script = ExtResource("8_5kaye") item = ExtResource("15_ir4ss") +amount = 5 spawn_on_ready = true spawn_turns = 1 @@ -425,6 +427,7 @@ transform = Transform3D(-0.734269, 0.305072, -0.606448, 0, 0.893336, 0.44939, 0. transform = Transform3D(0.909686, 0, 0.415297, 0, 1, 0, -0.415297, 0, 0.909686, 537.767, 5.1, 452.434) script = ExtResource("8_5kaye") item = ExtResource("12_tj0lh") +amount = -1 spawn_on_ready = true spawn_turns = 1 @@ -447,6 +450,7 @@ transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, -0. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 25.5, 0) script = ExtResource("8_5kaye") item = ExtResource("15_ir4ss") +amount = 3 spawn_on_ready = true spawn_turns = 2 diff --git a/src/items/extra_ball/brick_item.tscn b/src/items/extra_ball/brick_item.tscn index 22a4516..ad591fb 100644 --- a/src/items/extra_ball/brick_item.tscn +++ b/src/items/extra_ball/brick_item.tscn @@ -98,7 +98,7 @@ _data = { [node name="BrickItem" instance=ExtResource("1_gflnq")] script = ExtResource("2_vfkkm") ball_type = 3 -amount = -1 +amount = 0 [node name="Pivot" parent="Pivot/Octahedron/ItemMeshContainer" index="0"] transform = Transform3D(0.99863, 0.052336, 0, -0.052336, 0.99863, 0, 0, 0, 1, 0, 0, 0) diff --git a/src/items/extra_ball/extra_ball.gd b/src/items/extra_ball/extra_ball.gd index e8d5a19..7a74410 100644 --- a/src/items/extra_ball/extra_ball.gd +++ b/src/items/extra_ball/extra_ball.gd @@ -1,13 +1,10 @@ class_name ExtraBall extends Item ## Item which grants extra balls when picked up. +## Amount values < 0 will instead grant the player unlimited ammunition of this type. ## Type of ball which will be replenished. @export var ball_type: GameBall.Type -## Amount to grant. -## Values < 0 will instead grant the player unlimited ammunition of this type. -@export var amount: int = -1 - func _collect(player: WorldPlayer) -> void: if amount < 0: diff --git a/src/items/item/item.gd b/src/items/item/item.gd index 20d2db9..890f551 100644 --- a/src/items/item/item.gd +++ b/src/items/item/item.gd @@ -3,6 +3,10 @@ class_name Item extends Node3D signal on_collect(player: WorldPlayer) +## Quantity of the underlying item this pick-up will grant when collected. +## What this actually means is implementation-dependent. +@export var amount: int = 1 + @onready var explosion_player: AnimationPlayer = %ExplosionPlayer diff --git a/src/items/item_spawner.gd b/src/items/item_spawner.gd index 87ba40b..ee78b72 100644 --- a/src/items/item_spawner.gd +++ b/src/items/item_spawner.gd @@ -8,6 +8,9 @@ const POP_IN_TIME := 1.618 ## Item to be spawned @export var item: PackedScene +## Quantity of the given item to include in the spawned item pickup, where applicable. +@export var amount: int = 1 + @export_category("Spawn Conditions") ## Spawn an item when the tree is loaded. @export var spawn_on_ready: bool = false @@ -43,6 +46,7 @@ func _ready() -> void: ## This can be called manually if an item needs complex spawning logic. func spawn() -> void: var instance: Item = item.instantiate() + instance.amount = amount instance.on_collect.connect(_on_item_collected) add_child(instance) diff --git a/src/player/world_player.gd b/src/player/world_player.gd index 00d3300..463726a 100644 --- a/src/player/world_player.gd +++ b/src/player/world_player.gd @@ -70,7 +70,7 @@ func set_balls(type: GameBall.Type, value: int) -> void: ## Change the quantity of a ball type func mutate_balls(type: GameBall.Type, delta: int) -> void: - if _balls[type] >= 0: + if _balls.get(type, 0) >= 0: _balls[type] = _balls.get(type, 0) + delta on_balls_changed.emit(type, _balls[type])