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)
|
||||
|
||||
@@ -32,92 +32,92 @@ script = ExtResource("5_x77df")
|
||||
config = ExtResource("6_xnhlc")
|
||||
game_state = NodePath("..")
|
||||
|
||||
[node name="World" type="Node2D" parent="." unique_id=2118297724]
|
||||
[node name="World" type="Node2D" parent="LevelGameState" unique_id=2118297724]
|
||||
|
||||
[node name="ForestProps" type="Node2D" parent="World" unique_id=649424542]
|
||||
[node name="ForestProps" type="Node2D" parent="LevelGameState/World" unique_id=649424542]
|
||||
|
||||
[node name="Tree1" parent="World/ForestProps" unique_id=1917119095 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree1" parent="LevelGameState/World/ForestProps" unique_id=1917119095 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1486, 543)
|
||||
|
||||
[node name="Tree2" parent="World/ForestProps" unique_id=1429193881 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree2" parent="LevelGameState/World/ForestProps" unique_id=1429193881 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1510, 586)
|
||||
|
||||
[node name="Tree3" parent="World/ForestProps" unique_id=856028883 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree3" parent="LevelGameState/World/ForestProps" unique_id=856028883 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1600, 586)
|
||||
|
||||
[node name="Tree4" parent="World/ForestProps" unique_id=547138642 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree4" parent="LevelGameState/World/ForestProps" unique_id=547138642 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1482, 655)
|
||||
|
||||
[node name="Tree5" parent="World/ForestProps" unique_id=660535343 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree5" parent="LevelGameState/World/ForestProps" unique_id=660535343 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1568, 656)
|
||||
|
||||
[node name="Tree6" parent="World/ForestProps" unique_id=894701042 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree6" parent="LevelGameState/World/ForestProps" unique_id=894701042 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1665, 650)
|
||||
|
||||
[node name="Tree7" parent="World/ForestProps" unique_id=1661458508 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree7" parent="LevelGameState/World/ForestProps" unique_id=1661458508 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1362, 792)
|
||||
|
||||
[node name="Tree8" parent="World/ForestProps" unique_id=2029836975 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree8" parent="LevelGameState/World/ForestProps" unique_id=2029836975 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1452, 790)
|
||||
|
||||
[node name="Tree9" parent="World/ForestProps" unique_id=1580665442 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree9" parent="LevelGameState/World/ForestProps" unique_id=1580665442 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1557, 793)
|
||||
|
||||
[node name="Tree10" parent="World/ForestProps" unique_id=1295721315 instance=ExtResource("14_0cs5o")]
|
||||
[node name="Tree10" parent="LevelGameState/World/ForestProps" unique_id=1295721315 instance=ExtResource("14_0cs5o")]
|
||||
position = Vector2(1644, 822)
|
||||
|
||||
[node name="GoldMine" parent="World" unique_id=341660167 instance=ExtResource("2_2j2oc")]
|
||||
[node name="GoldMine" parent="LevelGameState/World" unique_id=341660167 instance=ExtResource("2_2j2oc")]
|
||||
position = Vector2(274, 429)
|
||||
|
||||
[node name="Castle" parent="World" unique_id=1966557957 instance=ExtResource("3_5ru58")]
|
||||
[node name="Castle" parent="LevelGameState/World" unique_id=1966557957 instance=ExtResource("3_5ru58")]
|
||||
position = Vector2(853, 357)
|
||||
|
||||
[node name="Farm" parent="World" unique_id=283335851 instance=ExtResource("10_1lv5i")]
|
||||
[node name="Farm" parent="LevelGameState/World" unique_id=283335851 instance=ExtResource("10_1lv5i")]
|
||||
position = Vector2(380, 684)
|
||||
|
||||
[node name="Forestry" parent="World" unique_id=726284577 instance=ExtResource("11_pyqyw")]
|
||||
[node name="Forestry" parent="LevelGameState/World" unique_id=726284577 instance=ExtResource("11_pyqyw")]
|
||||
position = Vector2(825, 915)
|
||||
|
||||
[node name="UI" type="Control" parent="." unique_id=1299828389]
|
||||
[node name="UI" type="Control" parent="LevelGameState" unique_id=1299828389]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="GoldCurrencyTile" parent="UI" unique_id=1440583137 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
[node name="GoldCurrencyTile" parent="LevelGameState/UI" unique_id=1440583137 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
layout_mode = 0
|
||||
offset_right = 160.0
|
||||
offset_bottom = 31.0
|
||||
currency = ExtResource("9_1363k")
|
||||
game_state = NodePath("../../LevelGameState")
|
||||
game_state = NodePath("../..")
|
||||
|
||||
[node name="WorkerCurrencyTile" parent="UI" unique_id=1164876942 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
[node name="WorkerCurrencyTile" parent="LevelGameState/UI" unique_id=1164876942 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
layout_mode = 0
|
||||
offset_top = 32.0
|
||||
offset_right = 160.0
|
||||
offset_bottom = 63.0
|
||||
currency = ExtResource("10_i1cck")
|
||||
game_state = NodePath("../../LevelGameState")
|
||||
game_state = NodePath("../..")
|
||||
|
||||
[node name="FoodCurrencyTile" parent="UI" unique_id=1814936562 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
[node name="FoodCurrencyTile" parent="LevelGameState/UI" unique_id=1814936562 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
layout_mode = 0
|
||||
offset_top = 63.0
|
||||
offset_right = 160.0
|
||||
offset_bottom = 94.0
|
||||
currency = ExtResource("11_hskcg")
|
||||
game_state = NodePath("../../LevelGameState")
|
||||
game_state = NodePath("../..")
|
||||
|
||||
[node name="WoodCurrencyTile" parent="UI" unique_id=338003163 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
[node name="WoodCurrencyTile" parent="LevelGameState/UI" unique_id=338003163 node_paths=PackedStringArray("game_state") instance=ExtResource("7_0cs5o")]
|
||||
layout_mode = 0
|
||||
offset_top = 94.0
|
||||
offset_right = 160.0
|
||||
offset_bottom = 125.0
|
||||
currency = ExtResource("12_l6a68")
|
||||
game_state = NodePath("../../LevelGameState")
|
||||
game_state = NodePath("../..")
|
||||
|
||||
[node name="GoalsDebugUI" parent="UI" unique_id=1494700185 instance=ExtResource("10_qifrv")]
|
||||
[node name="GoalsDebugUI" parent="LevelGameState/UI" unique_id=1494700185 instance=ExtResource("10_qifrv")]
|
||||
layout_mode = 1
|
||||
offset_left = 1253.0
|
||||
offset_left = 1067.0
|
||||
offset_top = 817.0
|
||||
offset_right = 1913.0
|
||||
offset_bottom = 1076.0
|
||||
|
||||
Reference in New Issue
Block a user