-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathFeatureCollection.cs
More file actions
53 lines (45 loc) · 1012 Bytes
/
Copy pathFeatureCollection.cs
File metadata and controls
53 lines (45 loc) · 1012 Bytes
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
using System.Collections.Generic;
namespace RPGCore.DataEditor;
public abstract class FeatureCollection
{
internal readonly List<IEditorFeature> features;
private readonly IEditorToken token;
internal FeatureCollection(IEditorToken token)
{
this.token = token;
features = new List<IEditorFeature>();
}
public T? GetFeature<T>()
where T : class, IEditorFeature
{
var getFeatureType = typeof(T);
foreach (var feature in features)
{
var featureType = feature.GetType();
if (getFeatureType.IsAssignableFrom(featureType))
{
return (T)feature;
}
}
return null;
}
public T GetOrCreateFeature<T>()
where T : class, IEditorFeature, new()
{
var feature = GetFeature<T>();
if (feature == null)
{
feature = new T();
feature.AttachToToken(token);
features.Add(feature);
}
return feature;
}
}
public class FeatureCollection<TToken> : FeatureCollection
where TToken : IEditorToken
{
public FeatureCollection(IEditorToken token) : base(token)
{
}
}