static VGPChoice GetChoiceNode(string line, VGPBlock parent, ref TextManager tm) { var m = choice_re.Match(line); if (!m.Success) { throw new Exception("Invalid Choice!"); } var tag = m.Groups[1].Value; var text = UnescapeTextString(m.Groups[2].Value); var condition = m.Groups[3].Value; var to_interpolate = IsToInterpolate(text, line, ref tm); var hash = tm.AddText(parent.Label, text); if (string.IsNullOrEmpty(m.Groups[1].Value)) { return(new VGPChoice.VGPAnonymousChoice(hash, parent, to_interpolate, condition)); } else { return(new VGPChoice.VGPNamedChoice(tag, hash, parent, to_interpolate, condition)); } }
public VGPChoice(string hash, VGPBlock parent, bool to_interpolate, string condition_label = null) : this() { TextHash = hash; Tag = condition_label; Parent = parent; ToInterpolate = to_interpolate; }
static Line tokens2Line(ParserRule[] rules, string[] tokens, VGPBlock parent = null, Func <string[], Line> fallback = null) { var first_token = tokens[0]; foreach (var rule in rules) { if ((rule.Keyword == first_token || string.IsNullOrEmpty(rule.Keyword)) && (!rule.Count.HasValue || tokens.Length == rule.Count.Value) && (rule.Validator == null || rule.Validator(tokens))) { return(rule.Constructor(tokens, parent)); } } var line = fallback?.Invoke(tokens); return(line); // if (line != null) return line; // Utils.LogArray("Invalid line", tokens, Logger); // throw new Exception(string.Format("Invalid line with tokens: {0}!", string.Join(", ", tokens))); }
public VGPIfElse(Conditional first_condition, VGPBlock parent) : this(parent) { Contents.Add(first_condition); }
public VGPMenu(List <VGPChoice> choices, VGPBlock parent, int?duration = null) : this(parent, duration) { Contents = choices ?? new List <VGPChoice>(); }
public VGPMenu(VGPBlock parent, int?duration = null) { Parent = parent; Duration = duration; InitializeContainer(); }
public void SetTarget(Script script) { Target = script.Blocks[_target]; }
static Line tokens2Node(string[] tokens, VGPBlock parent) { return(tokens2Line(NodeRules, tokens, parent)); }
public VGPAnonymousChoice(string hash, VGPBlock parent, bool to_interpolate, string condition_label = null) : base(hash, parent, to_interpolate, condition_label) { }
static Line node2ILine(Node node, Type parent_type, VGPBlock block, ref TextManager tm, bool ignore_unsupported_renpy = false) { Line iline = null; var line = node.Label; var n = line.Length; string[] tokens; VGPBlock current_block = block; if (node.IsEmpty) { // Leaf /*if (line.Contains(QUOTE)) { * * iline = GetLineLeaf(line, current_block.Label, ref tm); * * } else { * * tokens = line.Split(WHITESPACE); * * //Console.WriteLine(string.Format(">>> {0}", string.Join(", ", tokens))); * * //if (!tokens.All(y => y.All(x => char.IsLetterOrDigit(x) || x == UNDERSCORE || x == '(' || x == ')' || x == ','))) * //throw new Exception(string.Format("Invalid characters for a functional line in {0}!", node.Line.ExceptionString)); * * iline = tokens2Leaf(tokens); * }*/ tokens = line.Split(WHITESPACE); iline = tokens2Leaf(tokens); if (iline == null) { iline = GetLineLeaf(line, current_block.Label, ref tm); } if (iline == null) { throw new Exception(string.Format("Null leaf from line '{0}'", node.Line.ExceptionString)); } /*var definition = iline as VGPDefine; * if (definition != null) { * current_block.Variables.Add(definition.Key, definition.Value); * }*/ } else { // Node if (ignore_unsupported_renpy && unsupported_renpy_block_re.IsMatch(line)) { Logger.Log(string.Format("Ignoring Ren'Py block '{0}'", line)); return(new VGPPass()); } var contents = new List <Line>(); var ifelse = new VGPIfElse(current_block); if (line[n - 1] != COLON) { throw new Exception(string.Format("Expected ending colon in {0}!", node.Line.ExceptionString)); } var trimmed_line = line.Substring(0, n - 1); if (parent_type == null) { // Block tokens = line.Substring(0, n - 1).Split(WHITESPACE); iline = new VGPBlock(tokens[1]); current_block = iline as VGPBlock; } else if (parent_type == typeof(VGPMenu)) { iline = GetChoiceNode(trimmed_line, current_block, ref tm); } else { iline = tokens2Node(trimmed_line.Split(WHITESPACE), current_block); } if (iline == null) { throw new Exception(string.Format("Null node from {0}!", node.Line.ExceptionString)); } if (iline is VGPChoice && parent_type != typeof(VGPMenu)) { throw new Exception(string.Format("Choice out of menu in {0}!", node.Line.ExceptionString)); } foreach (var child in node.Children) { var tmp = node2ILine(child, iline.GetType(), current_block, ref tm, ignore_unsupported_renpy); if (tmp == null) { throw new Exception(string.Format("Null child ILine in {0}!", node.Line.ExceptionString)); } if (tmp is Conditional) { ifelse.AddCondition(tmp as Conditional); } else { // Add previous IfElse block if (!ifelse.IsEmpty) { AddIfElse(ref ifelse, ref contents); } // Skip VGPDefine objects //if (!(tmp is VGPDefine)) { contents.Add(tmp); //} } } if (!ifelse.IsEmpty) { AddIfElse(ref ifelse, ref contents); } if (iline is VGPMenu) { (iline as VGPMenu).Contents = contents.Select(x => x as VGPChoice).ToList(); } else if (iline is VGPIfElse) { (iline as VGPIfElse).Contents = contents.Select(x => x as Conditional).ToList(); } else if (iline is IterableContainer) { (iline as IterableContainer).Contents = contents; } else { throw new Exception(string.Format("Unexpected ILine container in {0}!", node.Line.ExceptionString)); } } return(iline); }
public VGPWhile(string label, VGPBlock parent) : this() { Tag = label; Parent = parent; }
Conditional(string label, VGPBlock parent = null) : this() { Tag = label; Parent = parent; }
public Else(VGPBlock parent = null) : base(TRUE, parent) { }
public ElseIf(string label, VGPBlock parent = null) : base(label, parent) { }
public VGPIfElse(List <Conditional> conditions, VGPBlock parent) : this(parent) { Contents = conditions; }
public VGPIfElse(VGPBlock parent) { Parent = parent; Contents = new List <Conditional>(); }
public VGPNamedChoice(string label, string text, VGPBlock parent, bool to_interpolate, string condition_label = null) : base(text, parent, to_interpolate, condition_label) { Label = label; }