-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathExpressionTemplateEditorData.cs
90 lines (74 loc) · 2.98 KB
/
ExpressionTemplateEditorData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TextAdventures.Quest
{
internal class ExpressionTemplateEditorData : IEditorData
{
private IDictionary<string, string> m_parameters;
private string m_originalPattern;
private IEditorData m_parentData;
public event EventHandler Changed;
public ExpressionTemplateEditorData(string expression, EditorDefinition definition, IEditorData parentData)
{
// We get passed in an expression like "Got(myobject)"
// The definition has pattern like "Got(#object#)" (as a regex)
// We create the parameter dictionary in the same way as the command parser, so
// we end up with a dictionary like "object=myobject".
m_parameters = Utility.Populate(definition.Pattern, expression);
m_originalPattern = definition.OriginalPattern;
m_parentData = parentData;
}
public string SaveExpression(string changedAttribute, string changedValue)
{
// Take the original pattern (e.g. "Got(#myobject#)") and replace the parameter
// names with their values. If changedAttribute and changedValue are set, then
// we're in the middle of editing, so use the specified change in place of the
// currently saved values.
string result = m_originalPattern;
foreach (var parameter in m_parameters)
{
string value = parameter.Key == changedAttribute ? changedValue : parameter.Value;
result = result.Replace(string.Format("#{0}#", parameter.Key), value);
}
return result;
}
public string Name
{
get { throw new NotImplementedException(); }
}
public object GetAttribute(string attribute)
{
return m_parameters[attribute];
}
public ValidationResult SetAttribute(string attribute, object value)
{
m_parameters[attribute] = (string)value;
if (Changed != null) Changed(this, new EventArgs());
return new ValidationResult { Valid = true };
}
public IEnumerable<string> GetAffectedRelatedAttributes(string attribute)
{
throw new NotImplementedException();
}
public string GetSelectedFilter(string filterGroup)
{
throw new NotImplementedException();
}
public void SetSelectedFilter(string filterGroup, string filter)
{
throw new NotImplementedException();
}
public bool ReadOnly
{
get;
set;
}
public IEnumerable<string> GetVariablesInScope()
{
return m_parentData.GetVariablesInScope();
}
public bool IsDirectlySaveable { get { return false; } }
}
}