Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions STROOP.Variables/VariablePanel/VariableCellFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public static (string name, IVariable var) ParseXml(XElement element, VariableSp
var specialType = element.Attribute(XName.Get("specialType"))?.Value;
return (element.Value,
specialType != null
? sepcialVariables.TryGetValue(specialType, out var special)
? special
? sepcialVariables.TryGetValue(specialType, out var specialFactory)
? specialFactory(element.Attribute(XName.Get("groupList"))?.Value ?? "Special")
: null
: FromXml(element).view);
}
Expand Down
27 changes: 13 additions & 14 deletions STROOP.Variables/VariableSpecialDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ public class VariableSpecialDictionary
{
public static VariableSpecialDictionary Instance = new();

private readonly Dictionary<string, IVariable> _dictionary;
private readonly Dictionary<string, Func<string, IVariable>> _dictionary;

public VariableSpecialDictionary() => _dictionary = new Dictionary<string, IVariable>();
public VariableSpecialDictionary() => _dictionary = new Dictionary<string, Func<string, IVariable>>();

public bool TryGetValue(string key, out IVariable getterSetter)
=> _dictionary.TryGetValue(key, out getterSetter);
public bool TryGetValue(string key, out Func<string, IVariable> variableFactory)
=> _dictionary.TryGetValue(key, out variableFactory);

public void Add<T>(string key, IVariable<T>.ValueGetter getter, IVariable<T>.ValueSetter setter, string? subclass = null)
{
_dictionary[key] = new CustomVariable<T>(subclass.DefaultIfNull<T>())
_dictionary[key] = groupList =>
{
getter = getter,
setter = setter,
var result = new CustomVariable<T>(subclass.DefaultIfNull<T>())
{
getter = getter,
setter = setter,
};
result.SetValueByKey("groupList", groupList);
return result;
};
}

Expand All @@ -34,11 +39,5 @@ public void Add<T>(string key, string baseAddressType, Func<uint, T> getter, Fun
);

public void Add<T>(string key, Func<T> getter, IVariable<T>.ValueSetter setter, string? subclass = null)
{
_dictionary[key] = new CustomVariable<T>(subclass.DefaultIfNull<T>())
{
getter = () => getter().Yield(),
setter = setter,
};
}
=> Add(key, () => getter().Yield(), setter, subclass);
}
Loading