public override void OnLoad(XDataHolder data) { base.OnLoad(data); Script.DeSerialize(data.Read("bmt-" + Script.Key)); CheckScript(Script.Value); var newPio = data.ReadAll().Where(x => x.Key.StartsWith("bmt-pio")).Select(x => { var key = new MExtKey(x.Key.Substring(4), x.Key.Substring(4), KeyCode.None, BlockBehaviour, true); key.DeSerialize(x); if (!long.TryParse(key.Key.Replace("pio", ""), out long id)) { return(null); } return(new KeyValuePair <long, MExtKey>?(new KeyValuePair <long, MExtKey>(id, key))); }).Where(x => x != null).ToDictionary(x => x.Value.Key, x => x.Value.Value); // merge into old pio because we don't want to replace MExtKey every time BlockBehaviour.KeyList.Clear(); foreach (var kp in newPio) { if (PIO.ContainsKey(kp.Key)) { PIO[kp.Key].CopyFrom(kp.Value); BlockBehaviour.KeyList.Add(PIO[kp.Key]); } else { PIO[kp.Key] = kp.Value; BlockBehaviour.KeyList.Add(kp.Value); } } }
private UIObject[] GetObjects( Plugin plugin, XDataHolder input, ValueInfo valueInfo ) { ///Create UI elements for each input var uiObjects = new List <UIObject>(); foreach (var data in input.ReadAll()) { switch (data.Type) { case "Single": uiObjects.Add(new UIObject(data.Key)); uiObjects.Add( new UIObject( data.RawValue, null, (single) => { input.Write(data.Key, (float)single); valueInfo.ValueChanged = true; }, true ) ); break; case "Integer": uiObjects.Add(new UIObject(data.Key)); uiObjects.Add( new UIObject( (float)(int)data.RawValue, null, (single) => { input.Write(data.Key, (int)(float)single); valueInfo.ValueChanged = true; }, true ) ); break; case "Vector3": void Put(object single, int i) { var v3 = input.ReadVector3(data.Key); v3[i] = (float)single; input.Write(data.Key, v3); valueInfo.ValueChanged = true; } uiObjects.Add(new UIObject(data.Key)); uiObjects.Add( new UIObject( ((Vector3)data.RawValue).x, null, f => Put(f, 0) ) ); uiObjects.Add( new UIObject( ((Vector3)data.RawValue).y, null, f => Put(f, 1) ) ); uiObjects.Add( new UIObject( ((Vector3)data.RawValue).z, null, f => Put(f, 2), true ) ); break; case "Boolean": uiObjects.Add(new UIObject(data.Key)); uiObjects.Add( new UIObject( data.RawValue, null, (boolean) => { input.Write(data.Key, (bool)boolean); valueInfo.ValueChanged = true; }, true ) ); break; } } if (uiObjects.Count > 0) { var lastObj = uiObjects[uiObjects.Count - 1]; lastObj.NewLine = true; uiObjects[uiObjects.Count - 1] = lastObj; } ///Create global UI elements ApplyRule applyRule = (ApplyRule)((int)plugin.ApplyRule % (int)ApplyRule.NoEnable); if (applyRule == ApplyRule.OnApply) { uiObjects.Add( new UIObject( null, "Apply", (b) => { valueInfo.WasApplied |= b is bool?(bool)b: false; } ) ); } if ((plugin.ApplyRule & ApplyRule.NoEnable) == ApplyRule.Disabled) { uiObjects.Add( new UIObject( "Enabled:" ) ); uiObjects.Add( new UIObject( plugin.Enabled, null, (b) => { plugin.Enabled = b is bool ?(bool)b : plugin.Enabled; valueInfo.ValueChanged = true; valueInfo.WasApplied = true; }, true ) ); } return(uiObjects.ToArray()); }
public IEnumerator GetEnumerator() { return(_xDataHolder.ReadAll().GetEnumerator()); }