diff --git a/scenes/tests/NavigationTests.cs b/scenes/tests/NavigationTests.cs index a4a0ab5..966dbfa 100644 --- a/scenes/tests/NavigationTests.cs +++ b/scenes/tests/NavigationTests.cs @@ -27,18 +27,16 @@ public class NavigationTests : Spatial { _editorUi = GetNode("EditorUI"); _world = GetNode("World"); - _world.Connect("WorldGenerated", this, nameof(OnWorldGenerated)); - _streamContainer = GetNode("StreamContainer"); - - _streamContainer.SetCenterTile(_currentTile); _player = GetNode("Player"); _playerNavigationComponent = _player.GetNode("Navigation"); - - // input handling - // _groundLayer.Connect("input_event", this, nameof(OnGroundLayerInputEvent)); + + // connect signals _world.Connect("TileClicked", this, nameof(OnTileClicked)); _world.Connect("TileHovered", this, nameof(OnTileHovered)); + _world.Connect("OnWorldViewTileTypeImageChanged", this, nameof(OnWorldViewTileTypeImageChanged)); + _world.Connect("OnHeightmapImageChanged", this, nameof(OnHeightmapImageChanged)); + CorrectEntityGridPositions(); } @@ -61,27 +59,24 @@ public class NavigationTests : Spatial { entity.GlobalTranslation = entityGlobalTranslation; } } - - public void OnWorldGenerated() { - _streamContainer.OnWorldGenerated(); - - // Properly place the Player - Vector2 centerTileCoord = (Vector2.One * _world.Size / 2).Round(); - Vector3 worldCenterTileCoords = _world.GetTileWorldCenterFromOffset(centerTileCoord); - worldCenterTileCoords.y = _world.GetHeightAtOffset(centerTileCoord); - Transform playerTransform = Transform.Identity; - playerTransform.origin = worldCenterTileCoords; - _player.Transform = playerTransform; - - ImageTexture newWorldTexture = new(); - newWorldTexture.CreateFromImage(_world.ColormapImage, + + private void OnHeightmapImageChanged(Image heightmapImage) { + ImageTexture newHeightmapTexture = new(); + newHeightmapTexture.CreateFromImage(heightmapImage, (uint)(Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat)); - _tileMaterial.SetShaderParam("MapAlbedoTexture", newWorldTexture); - _tileMaterial.SetShaderParam("TextureSize", (int)_world.ColormapImage.GetSize().x); - - CorrectEntityGridPositions(); } + private void OnWorldViewTileTypeImageChanged(Image viewTileTypeImage) { + ImageTexture newWorldTexture = new(); + newWorldTexture.CreateFromImage(viewTileTypeImage, + (uint)(Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat)); + + _tileMaterial.SetShaderParam("MapAlbedoTexture", newWorldTexture); + _tileMaterial.SetShaderParam("TextureSize", (int)newWorldTexture.GetSize().x); + _tileMaterial.SetShaderParam("CoordinateOffsetU", (int)_world.WorldTextureCoordinateOffset.x); + _tileMaterial.SetShaderParam("CoordinateOffsetV", (int)_world.WorldTextureCoordinateOffset.y); + } + public void UpdateCurrentTile(HexCell tile) { if (_currentTile.AxialCoords == tile.AxialCoords) { @@ -98,12 +93,6 @@ public class NavigationTests : Spatial { } Vector2 planeCoords = _hexGrid.GetHexCenterFromOffset(_currentTile.OffsetCoords); - Transform tileTransform = Transform.Identity; - tileTransform.origin.x = planeCoords.x; - tileTransform.origin.y = _world.GetHeightAtOffset(_currentTile.OffsetCoords) + 0.1f; - tileTransform.origin.z = planeCoords.y; - - _mouseHighlight.Transform = tileTransform; } public void OnGroundLayerInputEvent(Node camera, InputEvent inputEvent, Vector3 position, Vector3 normal,