103 lines
3.1 KiB
C#
103 lines
3.1 KiB
C#
using Cryville.Common;
|
|
using Cryville.Common.Pdt;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Cryville.Crtr.Config {
|
|
internal class RulesetConfigPropertyMasterAdapter : IPropertyMasterAdapter {
|
|
readonly List<IPropertyAdapter> _props;
|
|
readonly Dictionary<string, object> _values;
|
|
|
|
public RulesetConfigPropertyMasterAdapter(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
|
|
_values = values;
|
|
_props = new List<IPropertyAdapter>();
|
|
PdtEvaluator.Instance.ContextCascadeInsert();
|
|
if (defs == null) return;
|
|
foreach (var def in defs) {
|
|
var name = (string)def.Key.Name;
|
|
if (!_values.ContainsKey(name)) {
|
|
float value = 0;
|
|
PdtEvaluator.Instance.Evaluate(new PropOp.Float(v => value = v), def.Value.@default);
|
|
_values.Add(name, value);
|
|
}
|
|
_props.Add(new RulesetConfigPropertyAdapter(def.Key, def.Value, this));
|
|
}
|
|
}
|
|
|
|
public string DefaultCategory { get { return "miscellaneous"; } }
|
|
|
|
public IEnumerable<IPropertyAdapter> GetProperties() { return _props; }
|
|
|
|
public object GetValue(string key) {
|
|
return _values[key];
|
|
}
|
|
|
|
public void SetValue(string key, object value) {
|
|
_values[key] = value;
|
|
}
|
|
}
|
|
|
|
internal class RulesetConfigPropertyAdapter : IPropertyAdapter {
|
|
readonly RulesetConfigPropertyMasterAdapter _master;
|
|
readonly ConfigDefinition _def;
|
|
|
|
public RulesetConfigPropertyAdapter(Identifier key, ConfigDefinition def, RulesetConfigPropertyMasterAdapter master) {
|
|
_master = master;
|
|
_def = def;
|
|
Name = (string)key.Name;
|
|
switch (_def.type) {
|
|
case ConfigType.number: Type = PropertyType.Number; break;
|
|
case ConfigType.number_stepped: Type = PropertyType.NumberStepped; break;
|
|
default: Type = PropertyType.Unknown; break;
|
|
}
|
|
_rangeOp = new PropOp.Clip(v => {
|
|
m_range[0] = (double)v.Behind;
|
|
m_range[1] = (double)v.Ahead;
|
|
});
|
|
_numsrc = new PropSrc.Float(() => _buf);
|
|
_numop = new PropOp.Float(v => _buf = v);
|
|
PdtEvaluator.Instance.ContextCascadeUpdate(key.Key, _numsrc);
|
|
}
|
|
|
|
public string Category { get { return _def.category; } }
|
|
|
|
public string Name { get; private set; }
|
|
|
|
public PropertyType Type { get; private set; }
|
|
|
|
readonly PdtOperator _rangeOp;
|
|
readonly object[] m_range = new object[] { double.NegativeInfinity, double.PositiveInfinity };
|
|
public object[] Range {
|
|
get {
|
|
if (_def.range != null)
|
|
PdtEvaluator.Instance.Evaluate(_rangeOp, _def.range);
|
|
return m_range;
|
|
}
|
|
}
|
|
|
|
public object GetValue() {
|
|
return _master.GetValue(Name);
|
|
}
|
|
|
|
public void SetValue(object value) {
|
|
_master.SetValue(Name, value);
|
|
}
|
|
|
|
public bool SetMapped { get { return false; } }
|
|
|
|
float _buf;
|
|
readonly PropSrc _numsrc;
|
|
readonly PropOp _numop;
|
|
public object MapValue(object value) {
|
|
_buf = (float)(double)value;
|
|
if (_def.value == null) return _buf;
|
|
_numsrc.Invalidate();
|
|
PdtEvaluator.Instance.ContextSelfValue = _numsrc;
|
|
PdtEvaluator.Instance.Evaluate(_numop, _def.value);
|
|
PdtEvaluator.Instance.ContextSelfValue = null;
|
|
return _buf;
|
|
}
|
|
|
|
public object MapValueInverse(object value) { throw new NotSupportedException(); }
|
|
}
|
|
} |