コード例 #1
0
ファイル: NarrativeGenerator.cs プロジェクト: Yann4/Thesis
 public NarrativeGenerator(TextAsset nodeGraph, TextAsset ruleSet, BeatTemplates templates, WorldStateManager worldState)
 {
     _nodeGraph     = nodeGraph;
     _nodeGraphPath = AssetDatabase.GetAssetPath(_nodeGraph);
     _worldState    = worldState;
     _templates     = templates;
     _ruleManager   = new RuleManager(ruleSet, _templates);
 }
コード例 #2
0
ファイル: Rule.cs プロジェクト: Yann4/Thesis
        public Rule(string ruleToParse, BeatTemplates templates)
        {
            Right = new List <Token>();
            Left  = new Token();
            string[] ruleSides = ruleToParse.Split('>');

            Match            lhsMatch   = m_RuleRegex.Match(ruleSides[0]);
            List <Parameter> parameters = new List <Parameter>();

            for (int groupIdx = 2; groupIdx < lhsMatch.Groups.Count;)             //Start at 2 because 0 is the complete match & 1 is the name
            {
                string tag   = lhsMatch.Groups[groupIdx++].Value;
                string value = lhsMatch.Groups[groupIdx++].Value;

                if (!string.IsNullOrEmpty(tag) && !string.IsNullOrEmpty(value))
                {
                    parameters.Add(new Parameter(tag, value));
                }
            }

            string    ruleName = lhsMatch.Groups[1].Value;
            TextAsset graph    = templates.GetTemplate(ruleName);

            Left = graph == null ? new Token(ruleName, parameters.ToArray())
                                : new Token(ruleName, graph, parameters.ToArray());

            foreach (Match match in m_RuleRegex.Matches(ruleSides[1]))
            {
                parameters.Clear();

                for (int groupIdx = 2; groupIdx < match.Groups.Count;)                 //Start at 2 because 0 is the complete match & 1 is the name
                {
                    string tag   = match.Groups[groupIdx++].Value;
                    string value = match.Groups[groupIdx++].Value;

                    if (!string.IsNullOrEmpty(tag) && !string.IsNullOrEmpty(value))
                    {
                        parameters.Add(new Parameter(tag, value));
                    }
                }

                ruleName = match.Groups[1].Value;
                graph    = templates.GetTemplate(ruleName);
                Right.Add(graph == null ? new Token(ruleName, parameters.ToArray())
                                : new Token(ruleName, graph, parameters.ToArray()));
            }

            Debug.Assert(Right.Count >= 1, "Must have values on the right hand side of the rule");
        }
コード例 #3
0
ファイル: RuleManager.cs プロジェクト: Yann4/Thesis
        public RuleManager(TextAsset ruleSet, BeatTemplates templates)
        {
            _Templates = templates;

            if (ruleSet == null)
            {
                Debug.LogWarning("Ruleset asset null, no narrative generation can occur");
            }
            else
            {
                foreach (string line in ruleSet.text.Split('\n'))
                {
                    _Rules.Add(new Rule(line, templates));
                }
            }
        }