Decouple everything from globals

This commit is contained in:
2026-04-10 01:09:57 +02:00
parent b758803afe
commit f671ab3419
56 changed files with 993 additions and 1291 deletions

View File

@@ -4,7 +4,7 @@
[ext_resource type="Texture2D" uid="uid://cry4arn00kgrt" path="res://docs/gyms/tiny_sword/buildings/castle/Castle.png" id="1_tgvch"]
[ext_resource type="PackedScene" uid="uid://dlidx2x0otpjg" path="res://core/prestige/prestige_panel.tscn" id="3_l7gct"]
[ext_resource type="Script" uid="uid://cpfmctd4xsfho" path="res://docs/gyms/tiny_sword/buildings/castle/test_buff.gd" id="4_l7gct"]
[ext_resource type="Resource" uid="uid://bjc6qmvr7pe12" path="res://docs/gyms/buffs/spawn_worker.tres" id="5_s3a5k"]
[ext_resource type="Resource" uid="uid://bjc6qmvr7pe12" path="res://docs/gyms/tiny_sword/buffs/spawn_worker_buff.tres" id="5_s3a5k"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_tgvch"]
size = Vector2(312, 198)

View File

@@ -1,6 +1,7 @@
extends PanelContainer
@export var buff_data: GeneratorBuffData
@export var game_state: LevelGameState
@onready var _label: Label = $HBoxContainer/Label
@onready var _button: Button = $HBoxContainer/Button
@@ -19,9 +20,10 @@ func _ready() -> void:
_button.disabled = true
_button.pressed.connect(_on_button_pressed)
GameState.buff_level_changed.connect(_on_buff_level_changed)
GameState.buff_unlocked_changed.connect(_on_buff_unlocked_changed)
GameState.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()
@@ -35,9 +37,9 @@ func _on_button_pressed() -> void:
return
var cost: BigNumber = buff_data.get_cost_for_level(_current_level)
if GameState.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
GameState.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()
@@ -54,15 +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:
GameState.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 &""
return CurrencyDatabase.get_currency_id(buff.resource_target_currency)
if game_state == null:
return &""
return game_state.get_currency_id(buff.resource_target_currency)
func _on_buff_level_changed(buff_id: StringName, new_level: int) -> void:
@@ -82,7 +86,7 @@ func _update_ui() -> void:
if buff_data == null:
return
if not GameState.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
@@ -93,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 = GameState.get_currency_amount_by_id(cost_currency_id)
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
@@ -109,4 +113,6 @@ func _resolve_buff_cost_currency_id(buff: GeneratorBuffData) -> StringName:
if buff.cost_currency == null:
return &""
return CurrencyDatabase.get_currency_id(buff.cost_currency)
if game_state == null:
return &""
return game_state.get_currency_id(buff.cost_currency)

View File

@@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://djedqovgngrx5"]
[ext_resource type="PackedScene" uid="uid://jeoiinukrrsp" path="res://core/generator/currency_generator.tscn" id="1_rvsna"]
[ext_resource type="Resource" uid="uid://bxg2au0ijp242" path="res://docs/gyms/currencies/food.tres" id="2_djlc5"]
[ext_resource type="Resource" uid="uid://d08h51y0pnsnf" path="res://docs/gyms/generators/farm.tres" id="3_82rmq"]
[ext_resource type="Resource" uid="uid://bxg2au0ijp242" path="res://docs/gyms/tiny_sword/currencies/food.tres" id="2_djlc5"]
[ext_resource type="Resource" uid="uid://d08h51y0pnsnf" path="res://docs/gyms/tiny_sword/buildings/farm/farm_generator.tres" id="3_82rmq"]
[ext_resource type="Texture2D" uid="uid://dfdh8r03sj7qv" path="res://docs/gyms/tiny_sword/buildings/farm/House1.png" id="4_djlc5"]
[ext_resource type="PackedScene" uid="uid://ckos7f22pnmyh" path="res://core/generator/generator_container.tscn" id="5_82rmq"]

View File

@@ -0,0 +1,25 @@
[gd_resource type="Resource" script_class="CurrencyGeneratorData" format=3 uid="uid://d08h51y0pnsnf"]
[ext_resource type="Script" uid="uid://dnhocfsuvmeyb" path="res://core/generator/generator_buff_data.gd" id="1_cl7uf"]
[ext_resource type="Resource" uid="uid://cg7os1rfknw05" path="res://docs/gyms/tiny_sword/buffs/farm_auto_flux_buff.tres" id="2_bbypn"]
[ext_resource type="Resource" uid="uid://dfxk30o34qe2s" path="res://docs/gyms/tiny_sword/currencies/worker.tres" id="3_bbypn"]
[ext_resource type="Script" uid="uid://b00tqsuhxdy0d" path="res://core/generator/currency_generator_data.gd" id="4_0kvfm"]
[ext_resource type="Resource" uid="uid://cts0407h130d6" path="res://docs/gyms/tiny_sword/goals/gold_total_1300_goal.tres" id="5_qiy1b"]
[resource]
script = ExtResource("4_0kvfm")
id = &"farm"
name = "Farm"
starts_unlocked = false
starts_available = false
initial_owned = 1
purchase_currency = ExtResource("3_bbypn")
unlock_goal = ExtResource("5_qiy1b")
unlock_goal_behavior = 1
initial_cost = 1.0
coefficient = 1.0
initial_time = 3.0
initial_revenue = 60.0
initial_productivity = 20.0
buffs = Array[ExtResource("1_cl7uf")]([ExtResource("2_bbypn")])
metadata/_custom_type_script = "uid://b00tqsuhxdy0d"

View File

@@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://cf01wvy3f17i"]
[ext_resource type="PackedScene" uid="uid://jeoiinukrrsp" path="res://core/generator/currency_generator.tscn" id="1_7j1xc"]
[ext_resource type="Resource" uid="uid://bgsk8h4w80h45" path="res://docs/gyms/currencies/wood.tres" id="2_23x2t"]
[ext_resource type="Resource" uid="uid://v6hjoa2vky5k" path="res://docs/gyms/generators/forestry.tres" id="3_pby1g"]
[ext_resource type="Resource" uid="uid://bgsk8h4w80h45" path="res://docs/gyms/tiny_sword/currencies/wood.tres" id="2_23x2t"]
[ext_resource type="Resource" uid="uid://v6hjoa2vky5k" path="res://docs/gyms/tiny_sword/buildings/forestry/forestry_generator.tres" id="3_pby1g"]
[ext_resource type="Texture2D" uid="uid://doxauaa3vn3lm" path="res://docs/gyms/tiny_sword/buildings/forestry/House3.png" id="4_5yp33"]
[ext_resource type="PackedScene" uid="uid://ckos7f22pnmyh" path="res://core/generator/generator_container.tscn" id="5_rh3m6"]

View File

@@ -0,0 +1,23 @@
[gd_resource type="Resource" script_class="CurrencyGeneratorData" format=3 uid="uid://v6hjoa2vky5k"]
[ext_resource type="Script" uid="uid://dnhocfsuvmeyb" path="res://core/generator/generator_buff_data.gd" id="1_mgk3v"]
[ext_resource type="Resource" uid="uid://dfxk30o34qe2s" path="res://docs/gyms/tiny_sword/currencies/worker.tres" id="2_fs80u"]
[ext_resource type="Resource" uid="uid://kamgujbqqhg3" path="res://docs/gyms/tiny_sword/buffs/forestry_auto_flux_buff.tres" id="2_mgk3v"]
[ext_resource type="Resource" uid="uid://bo463s6jt0ep7" path="res://docs/gyms/tiny_sword/goals/gold_total_13k_goal.tres" id="4_mgk3v"]
[ext_resource type="Script" uid="uid://b00tqsuhxdy0d" path="res://core/generator/currency_generator_data.gd" id="4_rij12"]
[resource]
script = ExtResource("4_rij12")
id = &"forestry"
name = "Forestry"
starts_unlocked = false
starts_available = false
initial_owned = 1
purchase_currency = ExtResource("2_fs80u")
unlock_goal = ExtResource("4_mgk3v")
unlock_goal_behavior = 1
initial_cost = 1.0
coefficient = 1.0
initial_productivity = 20.0
buffs = Array[ExtResource("1_mgk3v")]([ExtResource("2_mgk3v")])
metadata/_custom_type_script = "uid://b00tqsuhxdy0d"

View File

@@ -1,10 +1,10 @@
[gd_scene format=3 uid="uid://brgkkw2n3o1ox"]
[ext_resource type="PackedScene" uid="uid://jeoiinukrrsp" path="res://core/generator/currency_generator.tscn" id="1_dgq4l"]
[ext_resource type="Resource" uid="uid://w4u1hddplb4e" path="res://docs/gyms/currencies/gold.tres" id="2_d2x03"]
[ext_resource type="Resource" uid="uid://w4u1hddplb4e" path="res://docs/gyms/tiny_sword/currencies/gold.tres" id="2_d2x03"]
[ext_resource type="PackedScene" uid="uid://ckos7f22pnmyh" path="res://core/generator/generator_container.tscn" id="2_lnbxc"]
[ext_resource type="Texture2D" uid="uid://bqf6yhtsnmjad" path="res://docs/gyms/tiny_sword/buildings/gold_mine/Gold Stone 6.png" id="2_n0fgx"]
[ext_resource type="Resource" uid="uid://dliilvvjvksk1" path="res://docs/gyms/generators/gold_mine.tres" id="2_sbi6i"]
[ext_resource type="Resource" uid="uid://dliilvvjvksk1" path="res://docs/gyms/tiny_sword/buildings/gold_mine/gold_mine_generator.tres" id="2_sbi6i"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sbi6i"]
size = Vector2(82, 84)

View File

@@ -0,0 +1,18 @@
[gd_resource type="Resource" script_class="CurrencyGeneratorData" format=3 uid="uid://dliilvvjvksk1"]
[ext_resource type="Script" uid="uid://dnhocfsuvmeyb" path="res://core/generator/generator_buff_data.gd" id="1_1ni3y"]
[ext_resource type="Resource" uid="uid://dlq2ke6i2pfob" path="res://docs/gyms/tiny_sword/buffs/gold_click_buff.tres" id="2_cnabh"]
[ext_resource type="Resource" uid="uid://dfxk30o34qe2s" path="res://docs/gyms/tiny_sword/currencies/worker.tres" id="2_j1lw5"]
[ext_resource type="Resource" uid="uid://c3op2mqy02sow" path="res://docs/gyms/tiny_sword/buffs/gold_auto_flux_buff.tres" id="3_baaj7"]
[ext_resource type="Script" uid="uid://b00tqsuhxdy0d" path="res://core/generator/currency_generator_data.gd" id="3_cnabh"]
[resource]
script = ExtResource("3_cnabh")
id = &"goldmine"
name = "Gold Mine"
purchase_currency = ExtResource("2_j1lw5")
initial_cost = 1.0
coefficient = 1.0
initial_productivity = 20.0
buffs = Array[ExtResource("1_1ni3y")]([ExtResource("2_cnabh"), ExtResource("3_baaj7")])
metadata/_custom_type_script = "uid://b00tqsuhxdy0d"