示例#1
0
        private bool LoadFile(string fileName)
        {
            Debug.Log("Loading " + fileName);

            try
            {
                var lexer  = new PGNLexer(new AntlrInputStream(new StreamReader(fileName)));
                var stream = new CommonTokenStream(lexer);
                var parser = new PGNParser(stream);
                parser.ErrorHandler = new BailErrorStrategy();

                var context = parser.parse();

                Debug.Log("Count games in PGN file: " + context.pgn_database().pgn_game().Length);

                var walker = ParseTreeWalker.Default;

                // listen stream and build game data
                var listener = new PGNListener();
                walker.Walk(listener, context);

                // Copy moves from Listener to Game Manager
                //GameManager.Instance.GameData.Moves = new Dictionary<int, List<string>>(listener.Moves);
                GameManager.Instance.GameData.SetTags(listener.Tags);
            }
            catch (Exception e)
            {
                errorDialog.GetComponentInChildren <TextMeshProUGUI>().text = "File cannot be read. " + e.Message;
                errorDialog.gameObject.SetActive(true);
                return(false);
            }

            return(true);
        }