Fix flow
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
extends PanelContainer
|
||||
|
||||
@export var buff_data: GeneratorBuffData
|
||||
@export var game_state: LevelGameState
|
||||
|
||||
@onready var _game_state: LevelGameState = find_parent("LevelGameState")
|
||||
@onready var _label: Label = $HBoxContainer/Label
|
||||
@onready var _button: Button = $HBoxContainer/Button
|
||||
|
||||
@@ -20,10 +20,10 @@ func _ready() -> void:
|
||||
_button.disabled = true
|
||||
|
||||
_button.pressed.connect(_on_button_pressed)
|
||||
if game_state:
|
||||
game_state.buff_level_changed.connect(_on_buff_level_changed)
|
||||
game_state.buff_unlocked_changed.connect(_on_buff_unlocked_changed)
|
||||
game_state.currency_changed.connect(_on_currency_changed)
|
||||
if _game_state:
|
||||
_game_state.buff_level_changed.connect(_on_buff_level_changed)
|
||||
_game_state.buff_unlocked_changed.connect(_on_buff_unlocked_changed)
|
||||
_game_state.currency_changed.connect(_on_currency_changed)
|
||||
_update_ui()
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ func _on_button_pressed() -> void:
|
||||
return
|
||||
|
||||
var cost: BigNumber = buff_data.get_cost_for_level(_current_level)
|
||||
if game_state and game_state.spend_currency_by_id(cost_currency_id, cost):
|
||||
if _game_state and _game_state.spend_currency_by_id(cost_currency_id, cost):
|
||||
var next_level: int = _current_level + 1
|
||||
game_state.set_buff_level(buff_data.id, next_level)
|
||||
_game_state.set_buff_level(buff_data.id, next_level)
|
||||
_apply_buff_effect(buff_data, next_level)
|
||||
_current_level = next_level
|
||||
_update_ui()
|
||||
@@ -56,17 +56,17 @@ func _apply_buff_effect(buff: GeneratorBuffData, level: int) -> void:
|
||||
return
|
||||
|
||||
var purchased_amount: BigNumber = buff.get_resource_purchase_amount_for_level(level)
|
||||
if purchased_amount.mantissa > 0.0 and game_state:
|
||||
game_state.add_currency_by_id(target_currency_id, purchased_amount)
|
||||
if purchased_amount.mantissa > 0.0 and _game_state:
|
||||
_game_state.add_currency_by_id(target_currency_id, purchased_amount)
|
||||
|
||||
|
||||
func _resolve_buff_target_currency_id(buff: GeneratorBuffData) -> StringName:
|
||||
if buff.resource_target_currency == null:
|
||||
return &""
|
||||
|
||||
if game_state == null:
|
||||
if _game_state == null:
|
||||
return &""
|
||||
return game_state.get_currency_id(buff.resource_target_currency)
|
||||
return _game_state.get_currency_id(buff.resource_target_currency)
|
||||
|
||||
|
||||
func _on_buff_level_changed(buff_id: StringName, new_level: int) -> void:
|
||||
@@ -86,7 +86,7 @@ func _update_ui() -> void:
|
||||
if buff_data == null:
|
||||
return
|
||||
|
||||
if game_state and not game_state.is_buff_unlocked(buff_data.id):
|
||||
if _game_state and not _game_state.is_buff_unlocked(buff_data.id):
|
||||
_button.disabled = true
|
||||
_button.text = "Locked"
|
||||
return
|
||||
@@ -97,7 +97,7 @@ func _update_ui() -> void:
|
||||
var cost_currency_id: StringName = _resolve_buff_cost_currency_id(buff_data)
|
||||
if cost_currency_id != &"":
|
||||
var cost: BigNumber = buff_data.get_cost_for_level(_current_level)
|
||||
var current_amount: BigNumber = game_state.get_currency_amount_by_id(cost_currency_id) if game_state else BigNumber.from_float(0.0)
|
||||
var current_amount: BigNumber = _game_state.get_currency_amount_by_id(cost_currency_id) if _game_state else BigNumber.from_float(0.0)
|
||||
can_buy = can_buy and (current_amount.is_greater_than(cost) or current_amount.is_equal_to(cost))
|
||||
|
||||
_button.disabled = not can_buy
|
||||
@@ -113,6 +113,6 @@ func _resolve_buff_cost_currency_id(buff: GeneratorBuffData) -> StringName:
|
||||
if buff.cost_currency == null:
|
||||
return &""
|
||||
|
||||
if game_state == null:
|
||||
if _game_state == null:
|
||||
return &""
|
||||
return game_state.get_currency_id(buff.cost_currency)
|
||||
return _game_state.get_currency_id(buff.cost_currency)
|
||||
|
||||
Reference in New Issue
Block a user