Exemplo n.º 1
0
 public Sprite(string imagePath, Int2 origin = new Int2(), string codeName = null)
 {
     CodeName = codeName ?? Path.GetFileNameWithoutExtension(imagePath);
     DebugEx.Assert(IsValidElmFunctionName(CodeName));
     Origin    = origin;
     ImagePath = imagePath;
 }
Exemplo n.º 2
0
 public TileType(string codeName, Int2 gridSize, string toolboxIconSprite, TileCategory category, ITileTypeData data)
 {
     DebugEx.Assert(Sprite.IsValidElmFunctionName(codeName));
     CodeName          = codeName;
     GridSize          = gridSize;
     ToolboxIconSprite = toolboxIconSprite;
     Category          = category;
     Data = data;
 }
Exemplo n.º 3
0
        public void AssertPath(ITileTypeData data)
        {
            var margin = 0.01;

            bool ValueClose(double value0, double value1) => Math.Abs(value0 - value1) < margin;

            bool OnTileEdge(Double2 point) =>
            (ValueClose(point.X, 0) || ValueClose(point.X, GridSize.X)) &&
            (ValueClose(point.Y, 0) || ValueClose(point.Y, GridSize.Y));

            bool OnGridEdge(Double2 point) =>
            (ValueClose(point.X % 1, 0) && ValueClose(point.Y % 1, 0.5)) ||
            (ValueClose(point.Y % 1, 0) && ValueClose(point.X % 1, 0.5));

            bool PathValid(Double2 start, Double2 end) => OnTileEdge(start) && OnGridEdge(start) && OnTileEdge(end) && OnGridEdge(end);

            switch (data)
            {
            case Rail rail:
                DebugEx.Assert(
                    PathValid(rail.Path.Func(0), rail.Path.Func(1)),
                    "Path must start and end on different grid edges that are also on the edge of the tile.");
                break;

            case RailFork rail:
                var pathOnStart  = rail.PathOn.Func(0);
                var pathOffStart = rail.PathOn.Func(0);
                DebugEx.Assert(
                    PathValid(pathOnStart, rail.PathOn.Func(1)),
                    "On path must start and end on different grid edges that are also on the edge of the tile.");
                DebugEx.Assert(
                    PathValid(pathOffStart, rail.PathOff.Func(1)),
                    "Off path must start and end on different grid edges that are also on the edge of the tile.");
                DebugEx.Assert(
                    !ValueClose(pathOnStart.X, pathOffStart.X) || !ValueClose(pathOnStart.Y, pathOffStart.Y),
                    "On and off path must start at the same place.");
                break;

            case Depot depot:
                var pathStart = depot.Path.Func(0);
                DebugEx.Assert(
                    OnGridEdge(pathStart) && OnTileEdge(pathStart) && !OnTileEdge(depot.Path.Func(1)),
                    "Path should start at the edge of the tile and end inside it");
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
 public static double Clamp(this double value, double min, double max)
 {
     DebugEx.Assert(min <= max);
     return(Math.Max(min, Math.Min(max, value)));
 }