-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathEditorField.cs
More file actions
104 lines (87 loc) · 2.6 KB
/
Copy pathEditorField.cs
File metadata and controls
104 lines (87 loc) · 2.6 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using RPGCore.DataEditor.Manifest;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
namespace RPGCore.DataEditor;
/// <summary>
/// An editable hard-typed container for a value.
/// </summary>
public class EditorField : IEditorToken
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly List<string> comments;
/// <inheritdoc/>
public IList<string> Comments => comments;
/// <inheritdoc/>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public EditorSession Session => Parent.Session;
/// <summary>
/// The <see cref="EditorObject"/> that this <see cref="EditorField"/> belongs to.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public EditorObject Parent { get; }
/// <summary>
/// The name of this field.
/// </summary>
public string Name { get; } = string.Empty;
/// <summary>
/// The value contained within this <see cref="EditorField"/>.
/// </summary>
public EditorReplaceable Value { get; }
/// <summary>
/// A collection of <see cref="IEditorFeature"/>s associated with this <see cref="EditorField"/>.
/// </summary>
public FeatureCollection<EditorField> Features { get; }
/// <summary>
/// A <see cref="SchemaField"/> used to drive the behaviour of this <see cref="EditorField"/>.
/// </summary>
public SchemaField? Schema
{
get
{
var parentType = Session.ResolveType(Parent.Type);
if (parentType?.Fields == null)
{
return null;
}
foreach (var field in parentType.Fields)
{
if (field.Name == Name)
{
return field;
}
}
return null;
}
}
/// <inheritdoc/>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
FeatureCollection IEditorToken.Features => Features;
/// <inheritdoc/>
public event PropertyChangedEventHandler PropertyChanged;
internal EditorField(EditorObject parent, string name)
{
Parent = parent;
Name = name;
Value = new EditorReplaceable(parent.Session, Schema.Type, parent.Session.CreateDefaultValue(Schema.Type));
Features = new FeatureCollection<EditorField>(this);
comments = new List<string>();
PropertyChanged = delegate { };
}
/// <inheritdoc/>
public override string ToString()
{
if (Schema == null)
{
return $"unknown {Name}";
}
return Value.Value switch
{
EditorNull => $"{Schema.Type} {Schema.Name} = null",
EditorScalarValue editorScalarValue => $"{Schema.Type} {Schema.Name} = {editorScalarValue.Value}",
EditorDictionary => $"{Schema.Type} {Schema.Name} = {{ ... }}",
EditorList editorList => $"{Schema.Type} {Schema.Name} = [{editorList.Elements.Count}]",
_ => $"{Schema.Type} {Schema.Name}",
};
}
}