Cleanup
This commit is contained in:
66
generator_container.gd
Normal file
66
generator_container.gd
Normal file
@@ -0,0 +1,66 @@
|
||||
extends VBoxContainer
|
||||
|
||||
@export var _generator: CurrencyGenerator
|
||||
|
||||
@onready var _buy_button: Button = $HBoxContainerGenerators/BuyOneButton
|
||||
@onready var _buy_max_button: Button = $HBoxContainerGenerators/BuyMaxButton
|
||||
@onready var _name_label: Label = $Label
|
||||
@onready var _owned_value: Label = $GeneratorStatsGrid/OwnedValue
|
||||
@onready var _next_cost_value: Label = $GeneratorStatsGrid/NextCostValue
|
||||
@onready var _production_value: Label = $GeneratorStatsGrid/ProductionValue
|
||||
|
||||
func _ready() -> void:
|
||||
_generator.purchase_completed.connect(_on_generator_updated)
|
||||
_generator.production_tick.connect(_on_generator_updated)
|
||||
_generator.purchase_failed.connect(_on_generator_updated)
|
||||
|
||||
match _generator.currency:
|
||||
GameState.CurrencyType.gold:
|
||||
GameState.gold_changed.connect(_on_currency_changed)
|
||||
GameState.CurrencyType.gems:
|
||||
GameState.gems_changed.connect(_on_currency_changed)
|
||||
|
||||
GameState.generator_state_changed.connect(_on_generator_state_changed)
|
||||
|
||||
_name_label.text = _generator.data.name if _generator.data != null else "Generator"
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _on_buy_pressed() -> void:
|
||||
_generator.buy(1)
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _on_buy_max_pressed() -> void:
|
||||
_generator.buy_max()
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _on_debug_income_pressed() -> void:
|
||||
_generator.grant_currency(BigNumber.from_float(100.0))
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _on_currency_changed(_new_value: BigNumber) -> void:
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _on_generator_updated(_a = null, _b = null, _c = null, _d = null) -> void:
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _on_generator_state_changed(generator_id: StringName, _state: Dictionary) -> void:
|
||||
if generator_id == _generator.get_generator_id():
|
||||
_refresh_generator_ui()
|
||||
|
||||
func _refresh_generator_ui() -> void:
|
||||
var can_interact: bool = _generator.is_available_to_player()
|
||||
_buy_button.disabled = not can_interact
|
||||
_buy_max_button.disabled = not can_interact
|
||||
|
||||
_owned_value.text = str(_generator.owned)
|
||||
_next_cost_value.text = _generator.get_next_cost().to_string_suffix(2) if can_interact else "-"
|
||||
|
||||
var production_per_second: float = 0.0
|
||||
if _generator.data != null and can_interact:
|
||||
production_per_second = _generator.data.production_per_second(
|
||||
_generator.owned,
|
||||
_generator.run_multiplier,
|
||||
_generator.purchased_count
|
||||
)
|
||||
|
||||
_production_value.text = BigNumber.from_float(production_per_second).to_string_suffix(2)
|
||||
Reference in New Issue
Block a user