Пример #1
0
        public void ShouldCountEnums()
        {
            // Act
            var count = EnumHelper.Count <Weekday>();

            // Assert
            count.Should().Be(7);
        }
Пример #2
0
        public void ShouldGetDescriptions()
        {
            // Act
            var weekdayDescriptions = EnumHelper.GetDescriptions <Weekday>();

            // Assert
            weekdayDescriptions.Should().HaveCount(EnumHelper.Count <Weekday>());
        }
Пример #3
0
        public void Count_Default_ReturnsNumberOfEnumMember()
        {
            // act
            var result = EnumHelper <TestEnum> .Count();

            // assert
            result.Should().Be(3);
        }
Пример #4
0
        public void ConvertToListItems_Test()
        {
            var data = new EnumHelper().ConvertToListItems(typeof(Colors));

            Assert.Equal(2, data.Count());
            Assert.Equal("Green", data.First().Text);
            Assert.Equal("Cyan", data.Last().Text);
        }
Пример #5
0
    private void Awake()
    {
        // Init Actions Dictionary
        events = new Dictionary <PlayerActions, List <PlayerActionEvent> >();

        // Init Keys
        for (int i = 0; i < EnumHelper.Count <PlayerActions>(); i++)
        {
            events.Add((PlayerActions)i, new List <PlayerActionEvent>());
        }
    }
Пример #6
0
        public void LoadFrom(string path)
        {
            // Get Raw Data
            string rawData = File.ReadAllText(path, Encoding.UTF8);

            rawData.Trim();

            // Get Info
            string info = rawData.Substring(rawData.IndexOf("[Info]") + "[Info]".Length);

            info = info.Substring(0, info.IndexOf('[')).Trim();

            var sizeX = info.Substring(info.IndexOf("Size X : ") + "Size X : ".Length);

            sizeX = sizeX.Substring(0, sizeX.IndexOf(';')).Trim();

            var sizeY = info.Substring(info.IndexOf("Size Y : ") + "Size Y : ".Length);

            sizeY = sizeY.Substring(0, sizeY.IndexOf(';')).Trim();

            mapData.SetSize(int.Parse(sizeX), int.Parse(sizeY));
            ResetGrid();

            string data = rawData.Replace("[Info]", "").Replace(info, "");

            for (int layer = 0; layer < EnumHelper.Count <MapLayer>(); layer++)
            {
                var curLayer = (MapLayer)layer;

                string thisLayer = data.Substring(data.IndexOf($"[{curLayer.ToString()}]") + $"[{curLayer.ToString()}]".Length);
                thisLayer = thisLayer.Substring(0, thisLayer.IndexOf(';'));

                string[] rows = thisLayer.Split(new string[] { "^" }, StringSplitOptions.None);
                for (int y = 0; y < rows.Length; y++)
                {
                    rows[y] = rows[y].Trim();
                    var tiles = rows[y].Split(new string[] { "||" }, StringSplitOptions.None);
                    for (int x = 0; x < tiles.Length; x++)
                    {
                        var prefab = GetTilePrefab(tiles[x].Trim());

                        if (prefab == null || tiles[x] == "null")
                        {
                            continue;
                        }

                        var tile = Instantiate(prefab.gameObject, layerParents[curLayer]).GetComponent <Tile>();
                        tile.gameObject.name    = prefab.gameObject.name;
                        tile.transform.position = GridDisplay.Inst.GridToWorld(new Vector2Int(x, y));
                        grids[curLayer][x, y]   = tile;
                    }
                }
            }
        }
Пример #7
0
        public void SaveTo(string path)
        {
            StringBuilder data = new StringBuilder();

            data.Append("[Info]\n");
            data.Append("Size X: ");
            data.Append(mapData.MaxSizeX);
            data.Append(";\nSize Y: ");
            data.Append(mapData.MaxSizeY);
            data.Append(";\n");

            for (int layer = 0; layer < EnumHelper.Count <MapLayer>(); layer++)
            {
                data.Append("[");
                data.Append(((MapLayer)layer).ToString());
                data.Append("]\n");

                for (int y = 0; y < mapData.MaxSizeY; y++)
                {
                    for (int x = 0; x < mapData.MaxSizeX; x++)
                    {
                        if (grids[(MapLayer)layer][x, y] == null)
                        {
                            data.Append("null");
                        }
                        else
                        {
                            data.Append(grids[(MapLayer)layer][x, y].gameObject.name);
                        }

                        if (x != mapData.MaxSizeX - 1)
                        {
                            data.Append(" || ");
                        }
                    }

                    if (y != mapData.MaxSizeY - 1)
                    {
                        data.Append(" ^\n");
                    }
                }
                data.Append(";\n");
            }

            File.WriteAllText(path, data.ToString(), Encoding.UTF8);
        }