fix: better currency state management
This commit is contained in:
parent
59625e704f
commit
54ab071bf6
@ -118,6 +118,8 @@ func set_wallet(value) -> void:
|
||||
gsr.wallet = value
|
||||
SaveManager.save_default()
|
||||
|
||||
func get_wallet() -> int:
|
||||
return gsr.wallet
|
||||
|
||||
func reinstate() -> void:
|
||||
if gsr.input_map.size() <= 1:
|
||||
|
||||
@ -140,8 +140,8 @@ texture = ExtResource( 317 )
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 316 )
|
||||
volume_db = -10.0
|
||||
pitch_scale = 1.1
|
||||
volume_db = -15.0
|
||||
pitch_scale = 1.09
|
||||
bus = "Effects"
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
||||
@ -28,6 +28,7 @@ func selfActivate():
|
||||
|
||||
func _on_ActivatorArea_area_entered(area:Area2D) -> void:
|
||||
$Label.visible = true
|
||||
$Label.text = "Orbs in Wallet: " + str(level_state.check_balance())
|
||||
$Highlight.visible = true
|
||||
activatable = true
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ z_index = -1
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Highlight" type="TextureRect" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
@ -37,13 +38,14 @@ margin_bottom = 34.0
|
||||
texture = SubResource( 22 )
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
margin_left = -18.0
|
||||
visible = false
|
||||
margin_left = -32.0
|
||||
margin_top = -30.0
|
||||
margin_right = 48.0
|
||||
margin_right = 78.0
|
||||
margin_bottom = -16.0
|
||||
rect_scale = Vector2( 0.590909, 0.627907 )
|
||||
custom_fonts/font = ExtResource( 3 )
|
||||
text = "[purchase]"
|
||||
text = "Orbs in wallet: 999"
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
position = Vector2( 0, -4 )
|
||||
|
||||
@ -15,8 +15,6 @@ var level_time := 0.0
|
||||
func _ready() -> void:
|
||||
GlobalState.gsr.last_played_level = levelName
|
||||
SaveManager.save_default()
|
||||
if GlobalState.get_level_completed(levelName):
|
||||
GlobalState.set_level_completed(levelName, false)
|
||||
signal_manager.connect("level_completed", self, "_on_level_completed")
|
||||
signal_manager.connect("player_died", self, "player_dying")
|
||||
|
||||
@ -39,12 +37,11 @@ func set_currency(value: int) -> void:
|
||||
signal_manager.emit_signal("currency_updated")
|
||||
|
||||
func get_currency() -> int:
|
||||
return GlobalState.gsr.wallet + currency
|
||||
return currency
|
||||
|
||||
func set_deaths(value: int) -> void:
|
||||
deaths = value
|
||||
|
||||
|
||||
func set_dead(value: bool) -> void:
|
||||
is_dead = value
|
||||
|
||||
@ -96,7 +93,7 @@ func spend_currency(cost: int) -> bool:
|
||||
# TODO member that
|
||||
if OS.is_debug_build():
|
||||
return true
|
||||
if get_currency() < cost:
|
||||
if check_balance() < cost:
|
||||
return false
|
||||
var remainder = currency - cost
|
||||
if remainder >= 0:
|
||||
@ -107,6 +104,9 @@ func spend_currency(cost: int) -> bool:
|
||||
GlobalState.set_wallet(GlobalState.gsr.wallet + remainder)
|
||||
return true
|
||||
|
||||
func check_balance() -> int:
|
||||
var balance = currency + GlobalState.get_wallet()
|
||||
return balance
|
||||
|
||||
func _on_level_completed():
|
||||
#if(OS.is_debug_build()):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user