seedpacket base
This commit is contained in:
parent
e1931f27e1
commit
2a7c402cd0
16 changed files with 345 additions and 24 deletions
61
scripts/gui/seedpacket/seedpacket.gd
Normal file
61
scripts/gui/seedpacket/seedpacket.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
extends AspectRatioContainer
|
||||
|
||||
@onready var button := $TextureButton
|
||||
@onready var preview :=$TextureButton/PreviewContainer/Preview
|
||||
@onready var cost := $TextureButton/Cost
|
||||
@onready var avaibility := $TextureButton/AvaiabilityRect
|
||||
@onready var recharge_timer := $RechargeTimer
|
||||
@onready var forbidden_rect := $TextureButton/Forbidden
|
||||
@onready var locked_rect := $TextureButton/Locked
|
||||
|
||||
var held_resource : SeedpacketResource
|
||||
var forbidden : bool = false
|
||||
var locked : bool = false
|
||||
var hotbar : bool = false
|
||||
var disabled : bool = false
|
||||
|
||||
#region Godot methods
|
||||
func _ready() -> void:
|
||||
LevelEventBus.entity_placed.connect(on_entity_placed)
|
||||
LevelEventBus.sun_count_updated.connect(on_sun_count_updated)
|
||||
LevelEventBus.state_changed.connect(on_level_state_changed)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
button.disabled = recharge_timer.time_left > 0 or forbidden or locked or disabled
|
||||
update_contents()
|
||||
#endregion
|
||||
|
||||
#region Signal methods
|
||||
func on_pressed():
|
||||
LevelEventBus.packet_selected.emit(held_resource)
|
||||
if LevelData.state == LevelData.LevelStates.Game:
|
||||
LevelEventBus.packet_selected_during_game.emit(held_resource)
|
||||
|
||||
func on_entity_placed(entity : SeedpacketResource):
|
||||
if entity == held_resource:
|
||||
recharge_timer.start()
|
||||
#endregion
|
||||
|
||||
func set_resource(to : SeedpacketResource):
|
||||
held_resource = to
|
||||
update_contents()
|
||||
|
||||
func update_contents():
|
||||
cost.text = str(held_resource.cost)
|
||||
preview.texture = held_resource.preview
|
||||
avaibility.visible = forbidden or locked or disabled
|
||||
locked_rect.visible = locked
|
||||
forbidden_rect.visible = forbidden
|
||||
|
||||
func on_sun_count_updated(to : float):
|
||||
if hotbar:
|
||||
disabled = held_resource.cost < to
|
||||
|
||||
func on_level_state_changed(state : LevelData.LevelStates):
|
||||
match state:
|
||||
LevelData.LevelStates.Game:
|
||||
disabled = held_resource.cost < LevelData.sun_count
|
||||
LevelData.LevelStates.PlantPick:
|
||||
disabled = false
|
||||
_:
|
||||
disabled = true
|
||||
1
scripts/gui/seedpacket/seedpacket.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cepaa3acqx70d
|
||||
8
scripts/gui/seedpacket/seedpacket_cost_label.gd
Normal file
8
scripts/gui/seedpacket/seedpacket_cost_label.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
@tool
|
||||
extends Label
|
||||
|
||||
const BASE_FONT_SIZE := 10
|
||||
const BASE_HEIGHT := 11
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
label_settings.font_size = int(BASE_FONT_SIZE * (size.y/BASE_HEIGHT))
|
||||
1
scripts/gui/seedpacket/seedpacket_cost_label.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket_cost_label.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bppehhpn0u7ep
|
||||
6
scripts/gui/seedpacket/seedpacket_progressbar.gd
Normal file
6
scripts/gui/seedpacket/seedpacket_progressbar.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends ProgressBar
|
||||
|
||||
@onready var timer := $"../../RechargeTimer"
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
value = timer.time_left/timer.wait_time
|
||||
1
scripts/gui/seedpacket/seedpacket_progressbar.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket_progressbar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bx7k7g0ebkwef
|
||||
20
scripts/level/level_data.gd
Normal file
20
scripts/level/level_data.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
extends Node
|
||||
|
||||
class_name LevelData
|
||||
|
||||
static var state : LevelStates = LevelStates.NotInGame
|
||||
static var sun_count : float
|
||||
|
||||
## 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,
|
||||
## Not in a level,
|
||||
NotInGame
|
||||
}
|
||||
1
scripts/level/level_data.gd.uid
Normal file
1
scripts/level/level_data.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://co3yto3q7mnm7
|
||||
|
|
@ -4,6 +4,13 @@ extends Node
|
|||
|
||||
class_name LevelSignals
|
||||
|
||||
#region Field
|
||||
|
||||
## Emitted when entity is placed by player via seedpacket
|
||||
signal entity_placed(entity : SeedpacketResource)
|
||||
|
||||
#endregion
|
||||
|
||||
#region Entity
|
||||
|
||||
## Called for every entity that enters game
|
||||
|
|
@ -17,20 +24,20 @@ signal entity_hp_changed(context : Entity.HPChangedContext)
|
|||
|
||||
#region Seedpacket manipulation
|
||||
|
||||
## Called when player selects EntityResource
|
||||
signal packet_selected(packet : EntityResource)
|
||||
## Called when player selects SeedpacketResource
|
||||
signal packet_selected(packet : SeedpacketResource)
|
||||
|
||||
## Called when player selects EntityResource during game phase
|
||||
signal packet_selected_during_game(packet : EntityResource)
|
||||
## Called when player selects SeedpacketResource during game phase
|
||||
signal packet_selected_during_game(packet : SeedpacketResource)
|
||||
|
||||
## Called when something requests EntityResource to be added to hotbar collection
|
||||
signal requested_packet_add
|
||||
## Called when something requests SeedpacketResource to be added to hotbar collection
|
||||
signal requested_packet_add(packet : SeedpacketResource)
|
||||
|
||||
## Called when something requests EntityResource to be deleted from hotbar collection
|
||||
signal requested_packet_remove
|
||||
## Called when something requests SeedpacketResourcesource to be deleted from hotbar collection
|
||||
signal requested_packet_remove(packet : SeedpacketResource)
|
||||
|
||||
## Called when selected packets are updated
|
||||
signal hotbar_packets_update(selected : Array[EntityResource])
|
||||
signal hotbar_packets_update(selected : Array[SeedpacketResource])
|
||||
#endregion
|
||||
|
||||
#region Level Running
|
||||
|
|
@ -44,21 +51,10 @@ signal huge_wave
|
|||
signal final_wave
|
||||
|
||||
## Called when game is progressing through level stages
|
||||
signal state_changed(state : LevelStates)
|
||||
signal state_changed(state : LevelData.LevelStates)
|
||||
|
||||
## Called when something requests state to advance
|
||||
signal state_advance_requested
|
||||
## Called when sun counter updates to value [code]to[/code]
|
||||
signal sun_count_updated(to : float)
|
||||
#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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,30 @@
|
|||
extends Resource
|
||||
|
||||
class_name EntityResource
|
||||
## Base class for every possible entity in game. Makes possible for entities to be spawned using seedpackets
|
||||
class_name SeedpacketResource
|
||||
|
||||
## Thumbnail of an entity
|
||||
@export var preview : Texture2D
|
||||
|
||||
## Cost of entity in local units
|
||||
@export var cost : float
|
||||
|
||||
## Recharge time for seedpacket in seconds
|
||||
@export_range(0.05,60,0.01,"or_greater","suffix:seconds") var recharge_time : float = 3
|
||||
|
||||
## Initial recharge fraction. Zero equals that seedpacket recharges instantly, one equals that packet starts uncharged
|
||||
@export_range(0,1,0.01) var initial_recharge_percent : float = 1
|
||||
|
||||
## Scene that can be spawned
|
||||
@export var scene : PackedScene
|
||||
|
||||
## Order to sort in almanach
|
||||
@export_range(0,4056,1,"or_greater","hide_slider") var order : int
|
||||
|
||||
var gid : StringName = ""
|
||||
|
||||
func get_gid() -> StringName:
|
||||
if gid == "":
|
||||
var split_path = resource_path.split("/")
|
||||
gid = split_path[split_path.size()].trim_suffix(".tres").to_lower()
|
||||
return gid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue