Use worker for research
This commit is contained in:
@@ -19,6 +19,10 @@ extends Resource
|
||||
## Associated Buff (single buff per research track)
|
||||
@export var associated_buff_id: StringName = &""
|
||||
|
||||
## Worker Scaling Configuration
|
||||
@export var worker_scaling_factor: float = 0.01
|
||||
@export var min_workers_for_xp: int = 1
|
||||
|
||||
func get_xp_required_for_level(level: int) -> float:
|
||||
return base_xp_required * pow(xp_growth_multiplier, float(maxi(level - 1, 0)))
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ const RESEARCH_ROW_SCENE: PackedScene = preload("res://core/research/research_ro
|
||||
|
||||
@onready var _title_label: Label = $ScrollContainer/VBoxContainer/TitleLabel
|
||||
@onready var _research_rows_container: VBoxContainer = $ScrollContainer/VBoxContainer/ResearchRows
|
||||
@onready var _buy_worker_button: Button = $ScrollContainer/VBoxContainer/HBoxContainer/BuyWorkerButton
|
||||
|
||||
var _game_state: LevelGameState
|
||||
var _research_rows: Dictionary = {}
|
||||
@@ -18,9 +19,12 @@ func _ready() -> void:
|
||||
|
||||
_game_state.research_xp_changed.connect(_on_research_xp_changed)
|
||||
_game_state.research_level_up.connect(_on_research_level_up)
|
||||
_game_state.currency_changed.connect(_on_currency_changed)
|
||||
_game_state.research_workers_changed.connect(_on_research_workers_changed)
|
||||
|
||||
_build_research_rows()
|
||||
_refresh_all()
|
||||
_refresh_worker_button()
|
||||
|
||||
func _build_research_rows() -> void:
|
||||
for child in _research_rows_container.get_children():
|
||||
@@ -109,3 +113,43 @@ func activate_research(research_id: StringName) -> void:
|
||||
if _research_rows.has(research_id):
|
||||
var row: ResearchRow = _research_rows[research_id]
|
||||
row.set_active(true)
|
||||
|
||||
func _on_currency_changed(currency_id: StringName, _new_amount: BigNumber) -> void:
|
||||
if currency_id == &"worker":
|
||||
_refresh_worker_button()
|
||||
|
||||
func _on_research_workers_changed(_new_count: int) -> void:
|
||||
_refresh_worker_button()
|
||||
|
||||
func _can_buy_worker() -> bool:
|
||||
if _game_state == null:
|
||||
return false
|
||||
|
||||
var worker_currency: BigNumber = _game_state.get_currency_amount_by_id(&"worker")
|
||||
|
||||
return worker_currency.mantissa >= 1.0
|
||||
|
||||
func _buy_worker() -> void:
|
||||
if _game_state == null:
|
||||
return
|
||||
|
||||
_game_state.assign_worker_to_research()
|
||||
|
||||
func _on_buy_worker_pressed() -> void:
|
||||
_buy_worker()
|
||||
_refresh_worker_button()
|
||||
|
||||
func _refresh_worker_button() -> void:
|
||||
if _buy_worker_button == null:
|
||||
return
|
||||
|
||||
if _game_state == null:
|
||||
_buy_worker_button.disabled = true
|
||||
return
|
||||
|
||||
var can_buy: bool = _can_buy_worker()
|
||||
_buy_worker_button.disabled = not can_buy
|
||||
|
||||
var worker_currency: BigNumber = _game_state.get_currency_amount_by_id(&"worker")
|
||||
var research_workers: int = _game_state.get_research_workers()
|
||||
_buy_worker_button.text = "Assign Worker to Research (%d available, %d assigned)" % [int(worker_currency.mantissa), research_workers]
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
[gd_scene format=3 uid="uid://dd8roif0mqirl"]
|
||||
[gd_scene format=3 uid="uid://6d101h70mcx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://fdl7ftxw8w1e" path="res://core/research/research_panel.gd" id="1_script"]
|
||||
[ext_resource type="PackedScene" uid="uid://bpo8pl5tipav" path="res://core/research/research_row.tscn" id="2_3m5ee"]
|
||||
[ext_resource type="PackedScene" uid="uid://ckr805xqy6h4w" path="res://core/research/worker_summary_label.tscn" id="3_worker"]
|
||||
|
||||
[node name="ResearchPanel" type="PanelContainer" unique_id=1105274967]
|
||||
[node name="ResearchPanel" type="PanelContainer" unique_id=600021293]
|
||||
custom_minimum_size = Vector2(400, 100)
|
||||
offset_right = 400.0
|
||||
offset_bottom = 100.0
|
||||
script = ExtResource("1_script")
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="." unique_id=1099596602]
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="." unique_id=973132184]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer" unique_id=692886617]
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer" unique_id=1679714014]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="ScrollContainer/VBoxContainer" unique_id=1565843659]
|
||||
[node name="TitleLabel" type="Label" parent="ScrollContainer/VBoxContainer" unique_id=990297493]
|
||||
layout_mode = 2
|
||||
text = "Research"
|
||||
|
||||
[node name="ResearchRows" type="VBoxContainer" parent="ScrollContainer/VBoxContainer" unique_id=1200240263]
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="ScrollContainer/VBoxContainer" unique_id=1419318708]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ResearchRow" parent="ScrollContainer/VBoxContainer/ResearchRows" unique_id=245375198 instance=ExtResource("2_3m5ee")]
|
||||
[node name="WorkerSummaryLabel" parent="ScrollContainer/VBoxContainer/HBoxContainer" unique_id=13607753 instance=ExtResource("3_worker")]
|
||||
|
||||
[node name="BuyWorkerButton" type="Button" parent="ScrollContainer/VBoxContainer/HBoxContainer" unique_id=1083899286]
|
||||
layout_mode = 2
|
||||
text = "Invest Worker (0 available)"
|
||||
|
||||
[node name="ResearchRows" type="VBoxContainer" parent="ScrollContainer/VBoxContainer" unique_id=2066050169]
|
||||
layout_mode = 2
|
||||
|
||||
[connection signal="pressed" from="ScrollContainer/VBoxContainer/HBoxContainer/BuyWorkerButton" to="." method="_buy_worker"]
|
||||
|
||||
27
core/research/worker_summary_label.gd
Normal file
27
core/research/worker_summary_label.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
class_name WorkerSummaryLabel
|
||||
extends Label
|
||||
|
||||
@onready var _game_state: LevelGameState = find_parent("LevelGameState")
|
||||
|
||||
signal research_workers_changed(new_count: int)
|
||||
|
||||
func _ready() -> void:
|
||||
if _game_state == null:
|
||||
push_error("WorkerSummaryLabel: Could not find LevelGameState parent")
|
||||
return
|
||||
|
||||
_game_state.currency_changed.connect(_on_currency_changed)
|
||||
_game_state.research_workers_changed.connect(_on_research_workers_changed)
|
||||
_update_worker_display()
|
||||
|
||||
func _on_currency_changed(currency_id: StringName, _new_amount: BigNumber) -> void:
|
||||
if currency_id == "worker":
|
||||
_update_worker_display()
|
||||
|
||||
func _on_research_workers_changed(new_count: int) -> void:
|
||||
_update_worker_display()
|
||||
|
||||
func _update_worker_display() -> void:
|
||||
var worker_currency: int = int(_game_state.get_currency_amount_by_id("worker").mantissa)
|
||||
var research_workers: int = _game_state.get_research_workers()
|
||||
text = "Workers: %d available, %d assigned" % [worker_currency, research_workers]
|
||||
1
core/research/worker_summary_label.gd.uid
Normal file
1
core/research/worker_summary_label.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://brvoy607b3nft
|
||||
8
core/research/worker_summary_label.tscn
Normal file
8
core/research/worker_summary_label.tscn
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_scene format=3 uid="uid://ckr8z5xqy6h4w"]
|
||||
|
||||
[ext_resource type="Script" path="res://core/research/worker_summary_label.gd" id="1_script"]
|
||||
|
||||
[node name="WorkerSummaryLabel" type="Label"]
|
||||
layout_mode = 2
|
||||
script = ExtResource("1_script")
|
||||
text = "Workers: 0"
|
||||
Reference in New Issue
Block a user