GODOT ?= godot

.PHONY: editor run test test-s0 test-s1 test-s2 test-s3 test-s4 test-s5 test-s6 test-mvp test-acceptance test-ui test-perf test-perf-full check export-windows

editor:
	$(GODOT) --editor --path .

run:
	$(GODOT) --path .

test:
	$(MAKE) test-s0
	$(MAKE) test-s1
	$(MAKE) test-s2
	$(MAKE) test-s3
	$(MAKE) test-supply
	$(MAKE) test-business
	$(MAKE) test-s4
	$(MAKE) test-s5
	$(MAKE) test-s6
	$(MAKE) test-mvp
	$(MAKE) test-acceptance
	$(MAKE) test-ui
	$(MAKE) test-transport
	$(MAKE) test-perf

test-s0:
	$(GODOT) --headless --path . --script res://tests/run_tests.gd
	$(GODOT) --headless --path . --script res://tests/s0/test_definition_registry.gd
	$(GODOT) --headless --path . --script res://tests/s0/test_command_transaction.gd
	$(GODOT) --headless --path . --script res://tests/s0/test_determinism.gd
	$(GODOT) --headless --path . --script res://tests/s0/test_stable_id_generator.gd
	$(GODOT) --headless --path . --script res://tests/s0/test_domain_events.gd
	$(GODOT) --headless --path . --script res://tests/s0/test_runtime_integration.gd

test-s1:
	$(GODOT) --headless --path . --script res://tests/s1/test_world_service.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_path_service.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_path_congestion.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_construction_service.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_excavation_service.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_spatial_subslot_service.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_route_subslot_path_adapter.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_facility_infrastructure_projector.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_runtime_infrastructure_integration.gd
	$(GODOT) --headless --path . --script res://tests/s1/test_runtime_world_construction.gd

test-s2:
	$(GODOT) --headless --path . --script res://tests/s2/test_facility_service.gd
	$(GODOT) --headless --path . --script res://tests/s2/test_inventory_logistics.gd
	$(GODOT) --headless --path . --script res://tests/s2/test_economy_service.gd
	$(GODOT) --headless --path . --script res://tests/s2/test_ledger_backed_resources.gd
	$(GODOT) --headless --path . --script res://tests/s2/test_mana_network_service.gd
	$(GODOT) --headless --path . --script res://tests/s2/test_runtime_operations_cycle.gd

test-s3:
	$(GODOT) --headless --path . --script res://tests/s3/test_runtime_staff_assignment.gd
	$(GODOT) --headless --path . --script res://tests/s3/test_guest_service.gd
	$(GODOT) --headless --path . --script res://tests/s3/test_staff_service.gd
	$(GODOT) --headless --path . --script res://tests/s3/test_staff_payroll_operations.gd
	$(GODOT) --headless --path . --script res://tests/s3/test_runtime_actor_cycle.gd
	$(GODOT) --headless --path . --script res://tests/s3/test_runtime_actor_hardening.gd
	$(GODOT) --headless --path . --script res://tests/s3/test_runtime_path_traffic.gd

test-s4:
	$(GODOT) --headless --path . --script res://tests/s4/test_relationship_event_service.gd
	$(GODOT) --headless --path . --script res://tests/s4/test_placement_risk_preview_service.gd
	$(GODOT) --headless --path . --script res://tests/s4/test_runtime_relationship_events.gd

test-s5:
	$(GODOT) --headless --path . --script res://tests/s5/test_authority_service.gd
	$(GODOT) --headless --path . --script res://tests/s5/test_defense_service.gd
	$(GODOT) --headless --path . --script res://tests/s5/test_runtime_authority_cycle.gd
	$(GODOT) --headless --path . --script res://tests/s5/test_runtime_defense_cycle.gd

test-s6:
	$(GODOT) --headless --path . --script res://tests/s6/test_save_operations.gd
	$(GODOT) --headless --path . --script res://tests/s6/test_performance_budget.gd
	$(GODOT) --headless --path . --script res://tests/s6/test_runtime_save_lifecycle.gd

test-mvp:
	$(GODOT) --headless --path . --script res://tests/mvp/test_operations_coordinator.gd
	$(GODOT) --headless --path . --script res://tests/mvp/test_mvp_content_catalog.gd
	$(GODOT) --headless --path . --script res://tests/mvp/test_progression_service.gd
	$(GODOT) --headless --path . --script res://tests/mvp/test_runtime_content_progression.gd
	$(GODOT) --headless --path . --script res://tests/mvp/test_runtime_operations_integration.gd

test-acceptance:
	$(GODOT) --headless --path . --script res://tests/mvp/test_runtime_operations_acceptance.gd

test-ui:
	$(MAKE) test-pixel-ui
	$(GODOT) --headless --path . --script res://tests/ui/test_main_dashboard.gd
	$(GODOT) --headless --path . --script res://tests/ui/test_staff_management.gd
	$(GODOT) --headless --path . --script res://tests/ui/test_supply_management.gd
	$(GODOT) --headless --path . --script res://tests/ui/test_business_management.gd
	$(GODOT) --headless --path . --script res://tests/ui/test_elevator_management.gd
	$(MAKE) test-opening

test-perf:
	$(GODOT) --headless --path . --script res://tests/performance/test_digest_performance.gd
	$(GODOT) --headless --path . --script res://tests/performance/test_perf_mvp_001.gd

test-perf-full:
	PERF_MVP_FULL=1 $(GODOT) --headless --path . --script res://tests/performance/test_perf_mvp_001.gd

check:
	$(GODOT) --headless --editor --path . --quit
	$(GODOT) --headless --path . --quit-after 2

export-windows:
	mkdir -p build/windows
	$(GODOT) --headless --path . --export-release "Windows Desktop"

# Pixel cutaway: interactive disposable inn, capture and input regression.
.PHONY: preview-pixel capture-pixel test-pixel-ui
preview-pixel:
	THE_TREE_PIXEL_PLAY=1 $(GODOT) --path . --script res://tests/ui/capture_pixel_tower.gd

capture-pixel:
	$(GODOT) --path . --script res://tests/ui/capture_pixel_tower.gd

test-pixel-ui:
	$(GODOT) --headless --path . --script res://tests/ui/test_pixel_tower.gd

.PHONY: test-opening capture-opening
test-opening:
	$(GODOT) --headless --path . --script res://tests/ui/test_first_operating_day.gd

capture-opening:
	THE_TREE_OPENING_CAPTURE=1 $(GODOT) --path . --script res://tests/ui/test_first_operating_day.gd

# Paid purchases, kitchen batches, and porter deliveries; isolated test saves.
.PHONY: test-supply capture-supply preview-supply
test-supply:
	$(GODOT) --headless --path . --script res://tests/s2/test_kitchen_production.gd
	$(GODOT) --headless --path . --script res://tests/supply/test_supply_save_migration.gd
	$(GODOT) --headless --path . --script res://tests/supply/test_supply_logistics_bridge.gd
	$(GODOT) --headless --path . --script res://tests/supply/test_supply_management_service.gd
	$(GODOT) --headless --path . --script res://tests/supply/test_normal_supply_chain.gd

capture-supply:
	THE_TREE_SUPPLY_CAPTURE=1 THE_TREE_SUPPLY_CAPTURE_ONLY=1 $(GODOT) --path . --script res://tests/supply/test_normal_supply_chain.gd

preview-supply:
	THE_TREE_SUPPLY_PREVIEW=1 $(GODOT) --path . --script res://tests/supply/test_normal_supply_chain.gd

.PHONY: test-business
test-business:
	$(GODOT) --headless --path . --script res://tests/s2/test_facility_pricing.gd
	$(GODOT) --headless --path . --script res://tests/business/test_business_operations.gd
	$(GODOT) --headless --path . --script res://tests/business/test_business_closure.gd

.PHONY: preview-business capture-business
preview-business:
	THE_TREE_BUSINESS_PREVIEW=1 THE_TREE_SUPPLY_PREVIEW=1 $(GODOT) --path . --script res://tests/supply/test_normal_supply_chain.gd

capture-business:
	THE_TREE_BUSINESS_UI_CAPTURE=1 $(GODOT) --path . --script res://tests/ui/test_business_management.gd

.PHONY: test-transport capture-transport preview-transport
test-transport:
	$(GODOT) --headless --path . --script res://tests/world/test_elevator_topology.gd
	$(GODOT) --headless --path . --script res://tests/transport/test_elevator_service.gd
	$(GODOT) --headless --path . --script res://tests/staff/test_staff_commute.gd
	$(GODOT) --headless --path . --script res://tests/transport/test_transport_save.gd
	$(GODOT) --headless --path . --script res://tests/transport/test_transport_boundaries.gd
	$(GODOT) --headless --path . --script res://tests/transport/test_runtime_transport.gd

capture-transport:
	THE_TREE_TRANSPORT_CAPTURE=1 $(GODOT) --path . --script res://tests/transport/test_runtime_transport.gd

preview-transport:
	THE_TREE_TRANSPORT_PREVIEW=1 $(GODOT) --path . --script res://tests/transport/test_runtime_transport.gd
