Basic level bus

This commit is contained in:
Rendo 2025-08-01 03:38:38 +05:00
commit e1931f27e1
7 changed files with 169 additions and 3 deletions

View file

@ -17,20 +17,27 @@ warnings/check_angle_interpolation_type_conflicting=false
config/name="Liberation of the Neighbourville"
config/version="0.3.0"
run/main_scene="uid://bfstrli64u23y"
config/features=PackedStringArray("4.4", "C#", "Forward Plus")
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.png"
config/windows_native_icon="res://icon.ico"
[autoload]
LevelEventBus="*res://scripts/level_event_bus.gd"
[display]
window/size/viewport_width=600
window/size/viewport_height=400
window/stretch/mode="canvas_items"
[dotnet]
project/assembly_name="Liberation of the Neighbourville"
[editor_plugins]
enabled=PackedStringArray("res://addons/floatmodifiers/plugin.cfg", "res://addons/pvzadventure/plugin.cfg")
enabled=PackedStringArray()
[filesystem]

View file

@ -0,0 +1,89 @@
extends Node
## Base class for all hp-based objects
class_name Entity
## Maximum health points of an entity. Any heal cannot exceed this value
@export var max_hp : float
## Current amount of health points of an entity. Cannot be below 0 or [code]max_hp[/code]
var hp : float = max_hp
signal damaged
## Emitted when damage is taken
signal damage_taken(context : DamageTakenContext)
## Emitted when entity is healed
signal healed(context : HealedContext)
## Emitted on every health points change
signal hp_changed(context : HPChangedContext)
## Emitted when kill is requested
signal killed(context : KilledContext)
## Properly deal damage to entity
func deal_damage(amount : float, source : Entity):
var context = DamageTakenContext.new()
context.source = source
context.target = self
context.amount = amount
damage_taken.emit(context)
var delta_context = HPChangedContext.new()
delta_context.source = source
delta_context.target = self
delta_context.delta = -amount
hp_changed.emit(delta_context)
hp -= amount
if hp <= 0:
hp = 0
kill(source)
## Properly heal entity
func heal(amount : float, source : Entity):
var context = HealedContext.new()
context.source = source
context.target = self
context.amount = amount
healed.emit(context)
var delta_context = HPChangedContext.new()
delta_context.source = source
delta_context.target = self
delta_context.delta = amount
hp_changed.emit(delta_context)
hp += amount
if hp > max_hp:
hp = max_hp
## Invoked when an entity is killed by damage.
func kill(source : Entity):
var context = KilledContext.new()
context.source = source
context.target = self
killed.emit(context)
deconstruct()
## Method used to properly deconstruct entity
func deconstruct():
queue_free()
class DamageTakenContext:
var target : Entity
var source : Entity
var amount : float
class HealedContext:
var target : Entity
var source : Entity
var amount : float
class KilledContext:
var target : Entity
var source : Entity
class HPChangedContext:
var target : Entity
var source : Entity
var delta : float

View file

@ -0,0 +1 @@
uid://bwdvaov8sse4k

View file

@ -0,0 +1,64 @@
extends Node
## Event bus for levels in Liberation Of Neighborville
class_name LevelSignals
#region Entity
## Called for every entity that enters game
signal entity_created(entity : Entity)
## Called for every entity that exits game
signal entity_killed(context : Entity.KilledContext)
## Called for every entity that gets damage
signal entity_hp_changed(context : Entity.HPChangedContext)
#endregion
#region Seedpacket manipulation
## Called when player selects EntityResource
signal packet_selected(packet : EntityResource)
## Called when player selects EntityResource during game phase
signal packet_selected_during_game(packet : EntityResource)
## Called when something requests EntityResource to be added to hotbar collection
signal requested_packet_add
## Called when something requests EntityResource to be deleted from hotbar collection
signal requested_packet_remove
## Called when selected packets are updated
signal hotbar_packets_update(selected : Array[EntityResource])
#endregion
#region Level Running
## Called when huge wave is incoming, yet has not come
signal huge_wave_coming
## Called when huge wave has come
signal huge_wave
## Called when final wave has come
signal final_wave
## Called when game is progressing through level stages
signal state_changed(state : LevelStates)
## Called when something requests state to advance
signal state_advance_requested
#endregion
## Possible states of level
enum LevelStates {
## The game is during plant pick stage
PlantPick,
## The game is not yet started
Pregame,
## Game started
Game,
## Game ended
Postgame
}

View file

@ -0,0 +1 @@
uid://dmc03tudqcqj0

View file

@ -0,0 +1,3 @@
extends Resource
class_name EntityResource

View file

@ -0,0 +1 @@
uid://dtjdfji87kybn