Example #1
0
    private void LoadFile(string fileName)
    {
        try
        {
            var comment   = false;
            var lineArray = File.ReadAllLines(Application.streamingAssetsPath + "/" + fileName);

            foreach (var line in lineArray)
            {
                try
                {
                    var wordReader = new WordReader(line);
                    if (wordReader.IsEnd())
                    {
                        continue;
                    }

                    var word = wordReader.GetWord();

                    if (word == CommentEndKeyword && comment)
                    {
                        comment = false;
                    }
                    else if (comment)
                    {
                    }
                    else if (word == CommentStartKeyword)
                    {
                        comment = true;
                    }
                    else if (word == LineCommentKeyword)
                    {
                    }
                    else if (word == StateVarKeyword)
                    {
                        ParseStateVar(wordReader);
                    }
                    else if (word == PersKeyword)
                    {
                        ParsePers(wordReader);
                    }
                    else if (word == StateKeyword)
                    {
                        ParseState(wordReader);
                    }
                    else if (word == PropIntKeyword)
                    {
                        ParsePropIntVar(wordReader);
                    }
                    else if (word == PropBoolKeyword)
                    {
                        ParsePropBoolVar(wordReader);
                    }
                    else if (word == KnowledgeKeyword)
                    {
                        ParseKnowledgeVar(wordReader);
                    }
                    else if (word == DayKnowledgeKeyword)
                    {
                        ParseDayKnowledge(wordReader);
                    }
                    else if (word == InsightKeyword)
                    {
                        ParseInsight(wordReader);
                    }
                    else if (word == PrintPersInsightKeyword)
                    {
                        ParsePrintPersInsight(wordReader);
                    }
                    else if (word == PrintPropIntKeyword)
                    {
                        ParsePrintPropInt(wordReader);
                    }
                    else if (word == PrintPropBoolKeyword)
                    {
                        ParsePrintPropBool(wordReader, (b) => true);
                    }
                    else if (word == PrintPropBoolTrueKeyword)
                    {
                        ParsePrintPropBool(wordReader, (b) => b);
                    }
                    else if (word == PrintPropBoolFalseKeyword)
                    {
                        ParsePrintPropBool(wordReader, (b) => !b);
                    }
                    else if (word == PrintKnowledgeKeyword)
                    {
                        ParsePrintKnowledge(wordReader, (b) => true);
                    }
                    else if (word == PrintKnowledgeTrueKeyword)
                    {
                        ParsePrintKnowledge(wordReader, (b) => b);
                    }
                    else if (word == PrintKnowledgeFalseKeyword)
                    {
                        ParsePrintKnowledge(wordReader, (b) => !b);
                    }
                    else
                    {
                        Debug.LogError(line);
                    }
                }
                catch (Exception e)
                {
                    throw new ParseException(line, e);
                }
            }
        }
        catch (ParseException e)
        {
            Log("");
            Log("Error: " + e.Exception.Message);
            Log("");
            Log("Code line: " + e.Line);
            Debug.LogError(e.Exception);
        }
    }