Add currency database, cleanup legacy system

This commit is contained in:
2026-03-14 17:20:22 +01:00
parent 6da962a53d
commit 7b58c36414
20 changed files with 353 additions and 222 deletions

View File

@@ -1,5 +1,5 @@
class_name CurrencyGenerator
extends Node
extends Node2D
## Handles generator economy behavior:
## - automatic production cycles
@@ -18,7 +18,7 @@ signal production_tick(amount: BigNumber, cycle_count: int, total_owned: int)
const HUGE_COST_EXPONENT: int = 1000000
## Currency target updated by this generator.
@export var currency: Resource = GameState.GOLD_CURRENCY
@export var currency: Resource
## Data resource containing balancing values and defaults (required).
@export var data: CurrencyGeneratorData
## Enables per-cycle automatic production when true.
@@ -30,6 +30,8 @@ const HUGE_COST_EXPONENT: int = 1000000
## Extra multiplier applied to automatic production output.
@export var run_multiplier: float = 1.0
## True while the pointer is inside the generator Area2D.
var _mouse_entered: bool = false
## Time left until next click/hover grant is allowed.
@@ -82,14 +84,14 @@ var _is_registered: bool = false
## Resolves and registers this generator state before gameplay updates.
func _ready() -> void:
assert(currency != null, "Currency cannot be null")
assert(data != null, "Data cannot be null")
_generator_id = _resolve_generator_id()
_ensure_registered()
cycle_progress_seconds = 0.0
if currency == null:
push_warning("CurrencyGenerator '%s' has no currency set; defaulting to Gold." % String(name))
currency = GameState.GOLD_CURRENCY
if data == null:
push_error("CurrencyGenerator '%s' is missing CurrencyGeneratorData." % String(name))
GameState.generator_state_changed.connect(_on_generated_state_changed)
## Updates click cooldown/click grants and runs automatic production cycles.
func _process(delta: float) -> void:
@@ -342,3 +344,10 @@ func _on_area_2d_mouse_entered() -> void:
## Area2D callback: pointer exited generator interaction region.
func _on_area_2d_mouse_exited() -> void:
_mouse_entered = false
func _on_generated_state_changed(generator_id: StringName, state: Dictionary) -> void:
if generator_id == _generator_id:
print(_generator_id)
print(state)
visible = true

View File

@@ -0,0 +1,25 @@
[gd_scene format=3 uid="uid://jeoiinukrrsp"]
[ext_resource type="Script" uid="uid://dtbxopw6ulhl8" path="res://generator/currency_generator.gd" id="1_4n4ca"]
[ext_resource type="Resource" uid="uid://brqaojindcxa5" path="res://currency/magic.tres" id="2_5tmvy"]
[ext_resource type="Resource" uid="uid://co0mcc2kvcpo5" path="res://generator/primary_generator.tres" id="3_wx13b"]
[ext_resource type="Texture2D" uid="uid://bgtt3wu43tajh" path="res://icon.svg" id="4_ruf1h"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_y5m1q"]
size = Vector2(128, 128)
[node name="CurrencyGenerator" type="Node2D" unique_id=967969064]
script = ExtResource("1_4n4ca")
currency = ExtResource("2_5tmvy")
data = ExtResource("3_wx13b")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=807584513]
texture = ExtResource("4_ruf1h")
[node name="Area2D" type="Area2D" parent="." unique_id=707349247]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=1572620025]
shape = SubResource("RectangleShape2D_y5m1q")
[connection signal="mouse_entered" from="Area2D" to="." method="_on_area_2d_mouse_entered"]
[connection signal="mouse_exited" from="Area2D" to="." method="_on_area_2d_mouse_exited"]

View File

@@ -4,8 +4,8 @@
[resource]
script = ExtResource("1_c6y77")
id = &"Gold"
name = "Gold Mine"
id = &"Magic"
name = "Magic Orb"
initial_time = 0.6
initial_productivity = 1.67
metadata/_custom_type_script = "uid://b00tqsuhxdy0d"

View File

@@ -4,8 +4,8 @@
[resource]
script = ExtResource("1_s3g28")
id = &"Gems"
name = "Gems Mine"
id = &"Knowledge"
name = "Library"
starts_unlocked = false
starts_available = false
initial_cost = 60.0