Exemplo n.º 1
0
        public IEnumerable <PgnGame> Find(FindOptions options)
        {
            var results = new List <PgnGame>();

            foreach (var fileSource in options.FileSources)
            {
                var games = PgnGame.ReadAllGamesFromFile(fileSource).ToList();
                OnFileRead?.Invoke(this, fileSource, games);

                var matchedGames = games.AsEnumerable().FindGames(options).ToList();
                OnMatchesFound?.Invoke(this, matchedGames);

                results.AddRange(matchedGames);
            }

            return(results);
        }
Exemplo n.º 2
0
        private void LoadLevel(Action onFinish)
        {
            var url = Persistence.selectedLevelPath;

            if (Application.isEditor && debugLevelIndex >= 0)
            {
                Persistence.RefreshLevels();
                url = Persistence.levelPaths[debugLevelIndex];
            }

            Debug.Assert(url != null);

            currentMap = new MapData();

            if (!File.Exists(url))
            {
                Debug.Log("File doesn't exist boss: " + url);
                return;
            }

            try
            {
                // read through the file until the last line, looking for keys (see notes in MapData)
                using (StreamReader reader = File.OpenText(url))
                {
                    Debug.Log("opened StreamReader successfully for: " + url + ", beginning read...");

                    MapParserState currentDataType   = MapParserState.None;
                    int            lineIndexFromType = 0;
                    int            mapHeight         = 0;

                    string line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = reader.ReadLine()) != null)
                    {
                        //Debug.Log( line );

                        // before anything else parse out which kind of text we should be expecting
                        if (line[0] == '/')
                        {
                            switch (line[1])
                            {
                            case 'd':
                                currentDataType = MapParserState.Data;
                                break;

                            case 'm':
                                currentDataType = MapParserState.MapLayout;
                                break;

                            case 'x':
                                currentDataType = MapParserState.TrapDescriptors;
                                break;

                            case 't':
                                currentDataType = MapParserState.TrapTriggerDescriptors;
                                break;

                            case 'b':
                                currentDataType = MapParserState.BestPlayer;
                                break;
                            }

                            lineIndexFromType = 0; // reset index to 0

                            // and skip the rest of the reader code
                            continue;
                        }

                        // now act based on current data type and line index
                        switch (currentDataType)
                        {
                        case MapParserState.None:
                            // do nothing
                            break;

                        case MapParserState.Data:
                            if (lineIndexFromType != 0
                                ) // on the first read, just do all the needed lines, and skip onwards
                            {
                                continue;
                            }
                            currentMap.name        = line;
                            currentMap.creator     = reader.ReadLine();
                            currentMap.description = reader.ReadLine();
                            currentMap.date        = reader.ReadLine();
                            break;

                        case MapParserState.MapLayout:
                            // for the map, just keep reading across parsing lines until we hit the next boundary
                            // where we read from the top-left, across to the bottom right of the whole map
                            int x = 0;
                            foreach (char c in line)
                            {
                                currentMap.tiles.Add(new TileData(c, x, lineIndexFromType));
                                x++;
                            }

                            mapHeight = lineIndexFromType;
                            break;

                        case MapParserState.TrapDescriptors:
                            // todo: read through, convert numbers to index counts, then setup trap links
                            break;

                        case MapParserState.TrapTriggerDescriptors:
                            // todo: read through, find all trap numbers for a type, and setup
                            break;

                        case MapParserState.BestPlayer:
                            if (lineIndexFromType != 0
                                ) // on the first read, just do all the needed lines, and skip onwards
                            {
                                continue;
                            }
                            currentMap.bestPlayerName       = line;
                            currentMap.bestPlayerTurnsTaken = Int32.Parse(reader.ReadLine());
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        lineIndexFromType++;
                    }

                    Debug.Log("read map successfully!");

                    currentMap.DoPostImport(mapHeight);

                    Debug.Log("did post import, calling read event");
                    OnFileRead?.Invoke();
                    onFinish?.Invoke();
                }
            }
            catch (Exception e)
            {
                Debug.Log("The file could not be read:");
                Debug.LogException(e);
            }
        }