Implement custom ruleset config.
This commit is contained in:
@@ -16,6 +16,9 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
PropertyMasterPanel m_genericConfigPanel;
|
PropertyMasterPanel m_genericConfigPanel;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
PropertyMasterPanel m_rulesetConfigPanel;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
InputConfigPanel m_inputConfigPanel;
|
InputConfigPanel m_inputConfigPanel;
|
||||||
|
|
||||||
@@ -57,6 +60,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
||||||
|
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
||||||
|
|
||||||
var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
|
var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
|
||||||
proxy.LoadFrom(_rscfg.inputs);
|
proxy.LoadFrom(_rscfg.inputs);
|
||||||
|
@@ -29,6 +29,8 @@ namespace Cryville.Crtr.Config {
|
|||||||
ScrollVelocity = 1;
|
ScrollVelocity = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public Dictionary<string, object> configs
|
||||||
|
= new Dictionary<string, object>();
|
||||||
public Dictionary<string, InputEntry> inputs
|
public Dictionary<string, InputEntry> inputs
|
||||||
= new Dictionary<string, InputEntry>();
|
= new Dictionary<string, InputEntry>();
|
||||||
public class InputEntry {
|
public class InputEntry {
|
||||||
|
103
Assets/Cryville/Crtr/Config/RulesetConfigPropertyAdapter.cs
Normal file
103
Assets/Cryville/Crtr/Config/RulesetConfigPropertyAdapter.cs
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
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(); }
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c8b12ed5f582bb24fbc508f74f8ef79e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -69,12 +69,14 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class ConfigDefinition {
|
public class ConfigDefinition {
|
||||||
|
public string category;
|
||||||
public ConfigType type;
|
public ConfigType type;
|
||||||
public PdtExpression @default;
|
public PdtExpression @default;
|
||||||
|
public PdtExpression range;
|
||||||
public PdtExpression value;
|
public PdtExpression value;
|
||||||
}
|
}
|
||||||
public enum ConfigType {
|
public enum ConfigType {
|
||||||
none, number,
|
unknown, number, number_stepped,
|
||||||
}
|
}
|
||||||
public class MotionDefinition {
|
public class MotionDefinition {
|
||||||
// TODO
|
// TODO
|
||||||
|
Reference in New Issue
Block a user