Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (43 sloc) 1.59 KB
using System;
using HexCardGame.SharedData;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace HexCardGame.Runtime.GameBoard
{
public class BoardController : MonoBehaviour
{
public BoardDataShape dataShape;
[SerializeField] Tilemap tileMap;
public IBoard Board { get; private set; }
public IBoardManipulation BoardManipulation { get; private set; }
public event Action<IBoard> OnCreateBoard = board => { };
void Start() => CreateBoard();
void CreateBoard()
{
//using the tile map orientation to pick the default value
if (tileMap.orientation == Tilemap.Orientation.XY)
CreateBoardPointy();
else
CreateBoardFlat();
BoardManipulation = new BoardManipulationOddR(dataShape);
}
public void SetBoarDataAndCreate(BoardDataShape boardDataShape)
{
dataShape = boardDataShape;
CreateBoard();
}
public void CreateBoardFlat()
{
tileMap.orientation = Tilemap.Orientation.YX;
tileMap.layoutGrid.cellSwizzle = GridLayout.CellSwizzle.YXZ;
Board = new Board(this, dataShape, Orientation.FlatTop);
}
public void CreateBoardPointy()
{
tileMap.orientation = Tilemap.Orientation.XY;
tileMap.layoutGrid.cellSwizzle = GridLayout.CellSwizzle.XYZ;
Board = new Board(this, dataShape, Orientation.PointyTop);
}
public void DispatchCreateBoard(IBoard board) => OnCreateBoard(board);
}
}
You can’t perform that action at this time.