2022-12-02 21:09:40 +01:00
|
|
|
using Godot;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
public class StreamContainer : Spatial
|
|
|
|
{
|
|
|
|
// scene nodes
|
|
|
|
private MeshInstance _bounds;
|
|
|
|
private Spatial _activeTiles;
|
|
|
|
|
|
|
|
// resources
|
|
|
|
private PackedScene _hexTileScene = GD.Load<PackedScene>("res://scenes/HexTile3D.tscn");
|
|
|
|
|
2022-12-03 00:43:19 +01:00
|
|
|
// exports
|
2022-12-02 21:09:40 +01:00
|
|
|
[Export] public Vector2 _dimensions = new Vector2(8, 4);
|
|
|
|
|
2022-12-03 00:43:19 +01:00
|
|
|
// other members
|
|
|
|
private Rect2 _worldRect;
|
|
|
|
private Rect2 _offsetCoordRect;
|
|
|
|
private HexGrid _hexGrid;
|
|
|
|
|
|
|
|
public Rect2 OffsetCoordRect
|
|
|
|
{
|
|
|
|
get { return _offsetCoordRect; }
|
|
|
|
}
|
2022-12-02 21:09:40 +01:00
|
|
|
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
_bounds = GetNode<MeshInstance>("Bounds");
|
|
|
|
_activeTiles = GetNode<Spatial>("ActiveTiles");
|
2022-12-03 00:43:19 +01:00
|
|
|
|
|
|
|
_hexGrid = new HexGrid();
|
2022-12-02 21:09:40 +01:00
|
|
|
|
|
|
|
Transform boundsTransform = Transform.Identity;
|
2022-12-03 00:43:19 +01:00
|
|
|
boundsTransform = boundsTransform.Scaled(new Vector3(_dimensions.x, 1, _dimensions.y));
|
|
|
|
_bounds.Transform = boundsTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateRects(Vector2 centerPlane)
|
|
|
|
{
|
|
|
|
Vector2 bottomLeftCoord = centerPlane - new Vector2(_dimensions.x / 2, _dimensions.y / 2);
|
|
|
|
Vector2 topRightCoord = centerPlane + new Vector2(_dimensions.x / 2, _dimensions.y / 2);
|
|
|
|
|
|
|
|
_worldRect = new Rect2(bottomLeftCoord, _dimensions);
|
|
|
|
GD.Print("World rect now: " + _worldRect.ToString() + " center: " + _worldRect.GetCenter());
|
|
|
|
|
|
|
|
// y axis needs to be inverted as HexGrid's offset coordinates use the opposite axis direction
|
|
|
|
HexCell bottomLeftCell = _hexGrid.GetHexAt(new Vector2(bottomLeftCoord.x, topRightCoord.y));
|
|
|
|
HexCell topRightCell = _hexGrid.GetHexAt(new Vector2(topRightCoord.x, bottomLeftCoord.y));
|
|
|
|
_offsetCoordRect = new Rect2(bottomLeftCell.OffsetCoords,
|
|
|
|
topRightCell.OffsetCoords - bottomLeftCell.OffsetCoords + Vector2.One);
|
|
|
|
GD.Print("Offset rect now: " + _offsetCoordRect.ToString() + " center: " + _offsetCoordRect.GetCenter());
|
|
|
|
|
|
|
|
Transform boundsTransform = _bounds.Transform;
|
|
|
|
boundsTransform.origin.x = centerPlane.x;
|
|
|
|
boundsTransform.origin.z = centerPlane.y;
|
2022-12-02 21:09:40 +01:00
|
|
|
_bounds.Transform = boundsTransform;
|
|
|
|
|
2022-12-03 00:43:19 +01:00
|
|
|
GD.Print("Bounds Transform: " + boundsTransform.ToString());
|
|
|
|
GD.Print("Bounds Global : " + _bounds.GlobalTransform.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetCenterTile(HexCell cell)
|
|
|
|
{
|
|
|
|
UpdateRects(_hexGrid.GetHexCenter(cell));
|
2022-12-02 21:09:40 +01:00
|
|
|
}
|
|
|
|
}
|