Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func _on_startup_new_game() -> void:
sync_dock_option(chosen_anchor)
save_settings()
# Backup current save before destructive reset (issue #178)
var _gs: GameState = GameState.new()
var _gs = GameState.new()
var _bk: String = _gs.backup_save()
if not _bk.is_empty():
push_event_safe("Backup saved before reset: %s" % _bk.get_file())
Expand Down
27 changes: 27 additions & 0 deletions scripts/worker_cap_logic.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Worker cap calculation logic — extracted from main.gd for testability.
## This module has no dependencies on GameState or scene nodes, making it
## suitable for headless unit testing.

const Constants := preload("res://scripts/constants.gd")


## Calculate the worker capacity based on builds and constants.
## - Base cap from Constants.BASE_WORKER_CAP
## - Hut bonus for each completed hut from Constants.WORKER_CAP_BONUSES
static func calculate_worker_cap(builds: Array) -> int:
var cap: int = Constants.BASE_WORKER_CAP
for build in builds:
if bool(build.get("complete", false)):
var kind: String = str(build.get("kind", ""))
cap += int(Constants.WORKER_CAP_BONUSES.get(kind, 0))
return cap


## Check if the colony can recruit another worker.
## - If no workers exist yet, always allow recruitment.
## - Otherwise, compare current count against calculated cap.
static func can_recruit(builds: Array, workers: Array) -> bool:
if workers.size() == 0:
return true
var cap: int = calculate_worker_cap(builds)
return workers.size() < cap
2 changes: 1 addition & 1 deletion tests/test_recruit_worker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func test_recruit_adds_worker_to_state(main: Control) -> void:
{"name": "Jun", "task": {"kind": "", "data": {}}},
])
_assert(main.can_recruit_worker(), "precondition: can recruit")
var initial_count := main.state.workers.size()
var initial_count: int = main.state.workers.size()
main.recruit_worker()
_assert_eq(main.state.workers.size(), initial_count + 1, "recruit: state workers count increases by 1")

Expand Down