public void ReadAnAdventurerLine_GetEntries_ReturnsAnAdventurerEntryWithPopulatedProperties()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                string expectedType        = "A";
                string expectedName        = "Anna";
                int    expectedWidth       = 4;
                int    expectedHeight      = 3;
                string expectedOrientation = "S";
                string expectedMovements   = "AGAADAA";
                AppendString(inputStream, $"{expectedType}-{expectedName}-{expectedWidth}-{expectedHeight}-{expectedOrientation}-{expectedMovements}");
                inputStream.Position = 0;

                MapFileReader reader           = new MapFileReader();
                var           result           = reader.GetEntries(inputStream);
                var           firstEntryResult = result.FirstOrDefault();

                Assert.That(firstEntryResult, Is.Not.Null);
                Assert.That(firstEntryResult, Is.TypeOf(typeof(MapAdventurerEntry)));
                Assert.That(((MapAdventurerEntry)firstEntryResult).Name, Is.EqualTo(expectedName));
                Assert.That(((MapAdventurerEntry)firstEntryResult).X, Is.EqualTo(expectedWidth));
                Assert.That(((MapAdventurerEntry)firstEntryResult).Y, Is.EqualTo(expectedHeight));
                Assert.That(((MapAdventurerEntry)firstEntryResult).Orientation, Is.EqualTo(expectedOrientation));
                Assert.That(((MapAdventurerEntry)firstEntryResult).Movements, Is.EqualTo(expectedMovements));
            }
        }
示例#2
0
        public void Setup()
        {
            fakemapFile = Substitute.For <MapFileReader>();
            var _path = fakemapFile.rawPath;

            _uut = new Goblin(_path);
        }
示例#3
0
    private IEnumerator LoadCoroutine()
    {
        yield return null;
        string mapName = SelectedMap.Instance().mapName;
        Debug.unityLogger.Log("EditorFile", "Loading " + mapName);
        MapFileReader reader = new MapFileReader(mapName);
        List<string> warnings;
        try
        {
            warnings = reader.Read(cameraPivot, voxelArray, true);
        }
        catch (MapReadException e)
        {
            var dialog = loadingGUI.gameObject.AddComponent<DialogGUI>();
            dialog.message = e.Message;
            dialog.yesButtonText = "Close";
            dialog.yesButtonHandler = () =>
            {
                voxelArray.unsavedChanges = false;
                Close();
            };
            // fix issue where message dialog doesn't use correct skin:
            dialog.guiSkin = loadingGUI.guiSkin;
            Destroy(loadingGUI);
            Debug.Log(e.InnerException);
            yield break;
        }
        // reading the file creates new voxels which sets the unsavedChanges flag
        // and clears existing voxels which sets the selectionChanged flag
        voxelArray.unsavedChanges = false;
        voxelArray.selectionChanged = false;

        Destroy(loadingGUI);
        foreach (MonoBehaviour b in enableOnLoad)
            b.enabled = true;
        if (warnings.Count > 0)
        {
            string message = "There were some issues with reading the world:\n\n  •  " +
                string.Join("\n  •  ", warnings.ToArray());
            LargeMessageGUI.ShowLargeMessageDialog(loadingGUI.gameObject, message);
        }

        if (!PlayerPrefs.HasKey("last_editScene_version"))
        {
            var dialog = loadingGUI.gameObject.AddComponent<DialogGUI>();
            dialog.message = "This is your first time using the app. Would you like a tutorial?";
            dialog.yesButtonText = "Yes";
            dialog.noButtonText = "No";
            dialog.yesButtonHandler = () =>
            {
                TutorialGUI.StartTutorial(Tutorials.INTRO_TUTORIAL, dialog.gameObject, voxelArray, touchListener);
            };
        }
        PlayerPrefs.SetString("last_editScene_version", Application.version);
    }
        public void ReadACommentLine_GetEntries_ReturnsAnEmptyCollection()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                AppendString(inputStream, "# Super comment !");
                inputStream.Position = 0;

                MapFileReader reader = new MapFileReader();
                var           result = reader.GetEntries(inputStream);

                Assert.That(result, Is.Not.Null);
                Assert.That(result.Count, Is.EqualTo(0));
            }
        }
        public void ReadABadFormattedMapLine_GetEntries_ThrowsInvalidArgument()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                string expectedType   = "C";
                int    expectedWidth  = 4;
                int    expectedHeight = 3;
                AppendString(inputStream, $"{expectedType}-{expectedWidth}-{expectedHeight}-xx");
                inputStream.Position = 0;

                MapFileReader reader = new MapFileReader();

                Assert.That(() => reader.GetEntries(inputStream).ToList(), Throws.Exception.TypeOf <ArgumentException>());
            }
        }
示例#6
0
    private IEnumerator LoadCoroutine()
    {
        yield return(null);

        MapFileReader reader = new MapFileReader(SelectedMap.Instance().mapName);

        try
        {
            reader.Read(null, GetComponent <VoxelArray>(), false);
        }
        catch (MapReadException)
        {
            SceneManager.LoadScene("editScene"); // TODO: this is a very bad solution
        }
        loadingText.enabled = false;
    }
        public void ReadAWellFormattedLine_GetEntries_ReturnsOneMapEntryWithRightType()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                string expectedType = "C";
                AppendString(inputStream, $"{expectedType}-2-3");
                inputStream.Position = 0;

                MapFileReader          fileReader = new MapFileReader();
                IEnumerable <MapEntry> result     = fileReader.GetEntries(inputStream).ToList();

                Assert.That(result, Is.Not.Null);
                Assert.That(result.Count(), Is.EqualTo(1));
                Assert.That(result.First().Type, Is.EqualTo(expectedType));
            }
        }
        public void Read3WellFormattedLine_GetEntries_Returns3MapEntry()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                int expectedEntriesCount = 3;
                AppendString(inputStream, "C-3-3");
                AppendString(inputStream, "M-1-1");
                AppendString(inputStream, "T-2-2-2");
                inputStream.Position = 0;

                MapFileReader reader = new MapFileReader();
                var           result = reader.GetEntries(inputStream);

                Assert.That(result, Is.Not.Null);
                Assert.That(result.Count(), Is.EqualTo(expectedEntriesCount));
            }
        }
        public void ReadABadFormattedAdventurerLine_GetEntries_ThrowsInvalidArgument()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                string expectedType        = "A";
                string expectedName        = "Anna";
                int    expectedWidth       = 4;
                int    expectedHeight      = 3;
                string expectedOrientation = "S";
                string expectedMovements   = "AGAADAA";
                AppendString(inputStream, $"{expectedType}-{expectedName}-{expectedWidth}-{expectedHeight}-{expectedOrientation}-{expectedMovements}-xx");
                inputStream.Position = 0;

                MapFileReader reader = new MapFileReader();

                Assert.That(() => reader.GetEntries(inputStream).ToList(), Throws.Exception.TypeOf <ArgumentException>());
            }
        }
示例#10
0
        public MimGLTextureReader(MimFileReader mim, MapFileReader map, bool accessorsOwner)
        {
            try
            {
                _mim            = Exceptions.CheckArgumentNull(mim, "mim");
                _map            = Exceptions.CheckArgumentNull(map, "map");
                _accessorsOwner = accessorsOwner;

                if (_map.LayersCount != 1)
                {
                    throw new ArgumentException("map");
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
示例#11
0
        public bool GetBackgroundReader(Location location)
        {
            ArchiveFileEntry mapEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".map");
            ArchiveFileEntry mimEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".mim");

            if (mapEntry == null || mimEntry == null)
            {
                return(true);
            }

            MimFileReader mimReader = new MimFileReader(mimEntry.OpenReadableContentStream());
            MapFileReader mapReader = new MapFileReader(mapEntry.OpenReadableContentStream());

            location.BackgroundReader = new MimGLTextureReader(mimReader, mapReader, true);

            location.SaveRequest &= ~LocationProperty.Background;
            location.Importable  &= ~LocationProperty.Background;
            return(true);
        }
示例#12
0
        public Maps(string mapName) //constructor
        {
            //var mapToLoad = "_mapName";
            //LoadMap(mapToLoad);

            var mapfile = new MapFileReader(/*mapName*/);

            mapfile.ReadMapFile(mapName);
            mapName          = mapfile.mapName;
            mapImageFilePath = mapfile.mapImageFilepath;

            initialPlayerBank = mapfile.initialPlayerBank;

            numberOfWaves          = mapfile.numberOfWaves;
            numberOfOffensiveUnits = mapfile.numberOfOffensiveUnits;
            offensiveUnitType      = mapfile.offensiveUnitType;
            timeDelaybetweenSpawns = mapfile.timeDelaybetweenSpawns;

            rawPath = mapfile.rawPath;
        }
        public void ReadAMapLine_GetEntries_ReturnsAMapEntryWithPopulatedProperties()
        {
            using (MemoryStream inputStream = new MemoryStream())
            {
                string expectedType   = "C";
                int    expectedWidth  = 4;
                int    expectedHeight = 3;
                AppendString(inputStream, $"{expectedType}-{expectedWidth}-{expectedHeight}");
                inputStream.Position = 0;

                MapFileReader reader           = new MapFileReader();
                var           result           = reader.GetEntries(inputStream);
                var           firstEntryResult = result.FirstOrDefault();

                Assert.That(firstEntryResult, Is.Not.Null);
                Assert.That(firstEntryResult, Is.TypeOf(typeof(MapSizeEntry)));
                Assert.That(((MapSizeEntry)firstEntryResult).Width, Is.EqualTo(expectedWidth));
                Assert.That(((MapSizeEntry)firstEntryResult).Height, Is.EqualTo(expectedHeight));
            }
        }
示例#14
0
        static void Main(string[] args)
        {
            var mapReader = new MapFileReader(args[0]);

            Maze maze = mapReader.Read();

            var pathFinder = new PathFinder(new MapConverter());
            IEnumerable <DataEdge> path = pathFinder.Find(maze);

            var pathHandler = new PathHandler();

            string commands  = pathHandler.Run(new DataCommandFormater(), path);
            string edgeOrder = pathHandler.Run(new EdgeInfoFormater <DataEdge>(), path);

            var reportBuilder = new ConsoleReportBuilder();

            reportBuilder.AppendMessage("The commands", commands);
            reportBuilder.AppendMessage(nameof(edgeOrder), edgeOrder);

            reportBuilder.AppendSeparator();

            Console.WriteLine(reportBuilder.Build());
        }
示例#15
0
 public void Setup()
 {
     string _mapName = "";
     _uut = new MapFileReader();
 }
示例#16
0
 public void Setup()
 {
     _uut        = new Maps("Map01");
     fakeMapFile = Substitute.For <MapFileReader>();
 }