Replace CurrencyType with Currency resource
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
extends HBoxContainer
|
||||
|
||||
@export var currency: GameState.CurrencyType
|
||||
@export var currency: Resource = GameState.GOLD_CURRENCY
|
||||
|
||||
@onready var _label_start = $LabelStart
|
||||
@onready var _label_end = $LabelEnd
|
||||
@@ -9,6 +9,7 @@ extends HBoxContainer
|
||||
var _start: BigNumber
|
||||
var _end: BigNumber
|
||||
var _current: BigNumber
|
||||
var _currency_id: StringName = &""
|
||||
|
||||
func set_limits(start: BigNumber, end: BigNumber) -> void:
|
||||
_start = start
|
||||
@@ -21,17 +22,17 @@ func set_limits(start: BigNumber, end: BigNumber) -> void:
|
||||
_progress_bar.max_value = _end.get_ratio(_start)
|
||||
|
||||
func _ready() -> void:
|
||||
if currency == null:
|
||||
currency = GameState.GOLD_CURRENCY
|
||||
_currency_id = GameState.get_currency_id(currency)
|
||||
|
||||
GameState.currency_changed.connect(_on_currency_changed)
|
||||
match currency:
|
||||
GameState.CurrencyType.gold:
|
||||
_current = GameState.gold
|
||||
GameState.CurrencyType.gems:
|
||||
_current = GameState.gems
|
||||
_current = GameState.get_currency_amount_by_id(_currency_id)
|
||||
|
||||
set_limits(_current, _current.add(BigNumber.new(1, 1)))
|
||||
|
||||
func _on_currency_changed(changed_currency: GameState.CurrencyType, amount: BigNumber) -> void:
|
||||
if changed_currency != currency:
|
||||
func _on_currency_changed(changed_currency_id: StringName, amount: BigNumber) -> void:
|
||||
if changed_currency_id != _currency_id:
|
||||
return
|
||||
_current = amount
|
||||
_progress_bar.value = amount.get_ratio(_end)
|
||||
|
||||
Reference in New Issue
Block a user