19 {
21 {
22 return value(dm, line);
23 }
24 return false;
25 }
26
28 {
30 Debug.Log(
"#drama added new action parser '" + action +
"' from '" + parser.Method.TryToString() +
"'");
31 bool SafeInvoke(
DramaManager dm, Dictionary<string, string> line)
32 {
33 try
34 {
35 return parser(dm, line);
36 }
37 catch (Exception ex)
38 {
39 ModUtil.LogModError("exception while parsing drama action '" + action + "'\n" + ex.Message, parser.Method.DeclaringType);
40 Debug.LogException(ex);
41 }
42 return false;
43 }
44 }
45
46 public static void AddDramaInvokeMethod(string name, MethodInfo method, string contract = null)
47 {
49 }
50
51 public static void AddDramaInvokeMethod(
string name,
DramaInvokeFunc func,
string contract =
null)
52 {
53 AddDramaInvokeMethod(name, func.Method, contract);
54 }
55
56 internal static (
DramaInvokeDetail invoke,
string[] parameters) BuildInvokeExpression(
string expression)
57 {
58 (string, string[]) tuple = ParseInvokeExpression(expression);
59 if (!tuple.Item1.IsEmpty() &&
_invokes.TryGetValue(tuple.Item1, out var value))
60 {
61 return (invoke: value, parameters: tuple.Item2);
62 }
63 if (expression.Length <= 1)
64 {
66 }
67 return expression[0] switch
68 {
69 '!' => BuildInvokeExpression("not(" + expression[1..] + ")"),
70 '&' => BuildInvokeExpression("and(" + expression[1..] + ")"),
71 '?' => BuildInvokeExpression("or(" + expression[1..] + ")"),
delegate bool DramaActionParser(DramaManager dm, Dictionary< string, string > line)
delegate bool DramaInvokeFunc(DramaManager dm, Dictionary< string, string > line, params string[] parameters)
static readonly Dictionary< string, DramaInvokeDetail > _invokes
static readonly Dictionary< string, DramaActionParser > _actionParsers