diff --git a/Makefile b/Makefile index eaec20fcf..f7a85f1d8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ GODOT := $(shell command -v godot4 2>/dev/null || command -v godot 2>/dev/null) -.PHONY: help setup build client server test lint ci ci-client ci-server clean \ +.PHONY: help setup build client server game stop test lint ci ci-client ci-server clean \ decisions-sync decisions-coverage decisions-active decisions-orphan \ db-backup db-install validate-content content-ron @@ -14,7 +14,9 @@ help: @echo "" @echo " make setup Install dev dependencies (Rust, Godot, tooling)" @echo " make build Build client and server" - @echo " make client Run the Godot client" + @echo " make game Build and run the full game (server + client)" + @echo " make stop Stop any running server instance" + @echo " make client Run the Godot client (test mode)" @echo " make server Run the Rust simulation server" @echo " make test Run all tests" @echo " make lint Run all linters" @@ -72,6 +74,19 @@ client: @test -n "$(GODOT)" || { echo "Godot not found. Run 'make setup' first."; exit 1; } $(GODOT) --path client +game: stop build-server + @test -n "$(GODOT)" || { echo "Godot not found. Run 'make setup' first."; exit 1; } + @echo "Starting server..." + @cd server && cargo run & + @sleep 2 + @echo "Starting client..." + @SR_LIVE=1 $(GODOT) --path client + @$(MAKE) stop + +stop: + @lsof -ti :9876 | xargs -r kill 2>/dev/null || true + @echo "Stopped any running server on port 9876" + # --- Test --- test: test-server test-client diff --git a/client/scripts/autoloads/game_state.gd b/client/scripts/autoloads/game_state.gd index 1ab7a0dd7..5a04eea3f 100644 --- a/client/scripts/autoloads/game_state.gd +++ b/client/scripts/autoloads/game_state.gd @@ -30,16 +30,18 @@ func apply_snapshot(snapshot: Dictionary) -> void: if snapshot.has("entities"): visible_entities = snapshot.entities - # Derive player position from the player entity + # Derive player position from the entity with kind.variant == "Player" var found_player := false for entity in visible_entities: - if entity.has("entity_id") and entity.entity_id == player_entity_id: + if entity.has("kind") and entity.kind is Dictionary and entity.kind.get("variant") == "Player": player_position = Vector2(entity.x, entity.y) + if entity.has("entity_id"): + player_entity_id = entity.entity_id found_player = true break if not found_player and visible_entities.size() > 0: - push_warning("GameState: player entity_id %d not found in %d entities" % [ - player_entity_id, visible_entities.size()]) + push_warning("GameState: no Player entity found in %d entities" % [ + visible_entities.size()]) if snapshot.has("tiles"): visible_tiles = snapshot.tiles diff --git a/client/scripts/autoloads/sim_bridge.gd b/client/scripts/autoloads/sim_bridge.gd index 72538f0e6..53551a2bb 100644 --- a/client/scripts/autoloads/sim_bridge.gd +++ b/client/scripts/autoloads/sim_bridge.gd @@ -4,7 +4,7 @@ extends Node enum ConnectionState { DISCONNECTED, CONNECTING, CONNECTED, ERROR } var state: ConnectionState = ConnectionState.DISCONNECTED -var test_mode: bool = true # Enable test mode for development without Rust server +var test_mode: bool = OS.get_environment("SR_LIVE") != "1" # SR_LIVE=1 connects to real server var _test_tick: int = 0 var _test_player_pos: Vector2i = Vector2i(10, 10) var _test_facing: String = "North"