private void DrawWatchedStores() { var name = string.Empty; IVariableStore add = null; VariableStoreControl remove = null; foreach (var watched in _watchedStores) { watched.Draw(); if (watched.Selected != null) { name = watched.SelectedName; add = watched.Selected; } if (watched.ShouldClose) { remove = watched; } } if (add != null) { AddWatch(name, add); } if (remove != null) { RemoveWatch(remove); } }
public void Setup(VariableSchema schema, IVariableStore owner) { _schema = schema; _owner = owner; Update(); }
public override VariableValue Evaluate(IVariableStore variables) { var left = Left.Evaluate(variables); var right = Right.Evaluate(variables); return(VariableValue.Create(left >= right)); }
public override VariableValue Evaluate(IVariableStore variables) { var left = Left.Evaluate(variables); var right = Right.Evaluate(variables); return(And(this, ref left, ref right)); }
public VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count >= 2) { var biggestValue = VariableValue.Empty; var biggestNumber = float.MinValue; for (var i = 0; i < parameters.Count; i++) { var p = parameters[i].Evaluate(variables); if (!p.HasNumber) { throw CommandEvaluationException.WrongParameterType(name, i, p.Type, VariableType.Int, VariableType.Float); } if (p.Number > biggestNumber) { biggestNumber = p.Number; biggestValue = p; } } return(biggestValue); } else { throw CommandEvaluationException.TooFewParameters(name, parameters.Count, 2); } }
private void CreateItems(IVariableStore variables, IEnumerable <MenuItemTemplate> items) { var index = 0; foreach (var item in items) { if (item.Variables.IsAssigned) { var value = item.Variables.GetValue(variables); if (value.HasList) { CreateListItem(item, value, ref index); } else if (value.HasStore) { CreateStoreItem(item, value, ref index); } else if (value.IsEmpty) { Debug.LogErrorFormat(this, _missingItemError, item.Id, name, item.Variables); } else { Debug.LogErrorFormat(this, _invalidItemError, item.Id, name, item.Variables); } } else { CreateStoreItem(item, VariableValue.Empty, ref index); } } OnCreate(); }
public override VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count < 2) { throw new CommandEvaluationException(name, TooFewParametersException, parameters.Count, parameters.Count == 1 ? "" : "s", 2); } var smallest = VariableValue.Create(int.MaxValue); for (var i = 0; i < parameters.Count; i++) { var p = parameters[i].Evaluate(variables); if (p.Type != VariableType.Integer && p.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType2Exception, p.Type, i, VariableType.Integer, VariableType.Number); } if (p < smallest) { smallest = p; } } return(smallest); }
public string ToString(IVariableStore store) { if (Variables.Count == 0) { return(Coefficient.ToString()); } StringBuilder sb = new StringBuilder(); if (Coefficient != 1) { if (Coefficient == -1) { sb.Append('-'); } else { sb.Append(Coefficient); } } foreach (var variable in Variables) { sb.Append(variable.ToString(store)); } return(sb.ToString()); }
public VariableByIdDataLoader( IVariableStore variableStore, IBatchScheduler batchScheduler) : base(batchScheduler) { _variableStore = variableStore; }
public void Play(BattleAnimationClip animation, IVariableStore variables) { switch (animation.AnimationTarget) { case CreatureDisplayTarget.Battler: { var clip = GetAnimation(animation, variables); if (clip) { BattlerPlayer.PlayAnimation(clip); } else { Debug.LogWarningFormat(this, _missingAnimationWarning, animation.Animation, animation.AnimationSource); } break; } case CreatureDisplayTarget.Creature: { CreatureAnimator.SetTrigger(animation.Parameter); break; } } }
public override VariableValue Evaluate(IVariableStore variables) { var left = Left.Evaluate(variables); var value = VariableHandler.Cast(left, _rightIdentifier.Name); if (value.IsEmpty) { throw new ExpressionEvaluationException(_invalidCastException, left, _rightIdentifier.Name); } if (!value.IsEmpty && !left.HasReference) { if (Left is IAssignableOperation assignable) { var result = assignable.SetValue(variables, value); if (result == SetVariableResult.Success) { return(value); } } throw new ExpressionEvaluationException(_invalidAssignException, value, left, Left); } return(value); }
public VariableStoreControl Setup(string name, IVariableStore store, bool isStatic, bool isClosable) { Store = store; Selected = null; SelectedName = string.Empty; _label = new GUIContent(name); _proxy = isStatic ? (ValuesProxy) new StaticValuesProxy { Names = store.GetVariableNames() } : new DynamicValuesProxy { Store = store }; Setup(_proxy) .MakeEmptyLabel(new GUIContent("The store is empty")) .MakeCollapsable(true) .MakeCustomHeight(GetHeight); if (store is Object obj) { MakeHeaderButton(EditButton, rect => Selection.activeObject = obj, Color.white); } if (isClosable) { MakeHeaderButton(CloseButton, rect => ShouldClose = true, Color.white); } return(this); }
public override VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count == 3) { var value = parameters[0].Evaluate(variables); var min = parameters[1].Evaluate(variables); var max = parameters[2].Evaluate(variables); if (value.Type != VariableType.Integer && value.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType2Exception, value.Type, 0, VariableType.Integer, VariableType.Number); } if (min.Type != VariableType.Integer && min.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType2Exception, min.Type, 1, VariableType.Integer, VariableType.Number); } if (max.Type != VariableType.Integer && max.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType2Exception, max.Type, 2, VariableType.Integer, VariableType.Number); } if (min.Number > max.Number) { throw new CommandEvaluationException(name, InvalidRangeException, min.Number, max.Number); } return(VariableValue.Create(Mathf.Clamp(value.Number, min.Number, max.Number))); } else { throw new CommandEvaluationException(name, WrongParameterCountException, parameters.Count, parameters.Count == 1 ? "" : "s", 3); } }
public VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { var store = ReserveStore(); if (Parameters.Count != parameters.Count) { throw CommandEvaluationException.WrongParameterCount(name, parameters.Count, Parameters.Count); } for (var i = 0; i < parameters.Count; i++) { var parameter = Parameters[i]; var value = parameters[i].Evaluate(variables); if (parameter.Type != VariableType.Empty && parameter.Type != value.Type) { throw CommandEvaluationException.WrongParameterType(name, i, value.Type, parameter.Type); } store.AddVariable(Parameters[i].Name, value); } store.AddVariable(CompositionManager.GlobalStoreName, VariableValue.Create(CompositionManager.Instance.GlobalStore)); store.AddVariable(CompositionManager.SceneStoreName, VariableValue.Create(CompositionManager.Instance.SceneStore)); var result = Expression.Evaluate(store); ReleaseStore(store); return(result); }
public override VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count == 1) { var value = parameters[0].Evaluate(variables); if (value.Type != VariableType.Integer && value.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType1Exception, value.Type, 0, VariableType.Number); } return(VariableValue.Create(Mathf.Atan(value.Number))); } else if (parameters.Count == 2) { var y = parameters[0].Evaluate(variables); var x = parameters[1].Evaluate(variables); if (y.Type != VariableType.Integer && y.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType1Exception, y.Type, 0, VariableType.Number); } if (x.Type != VariableType.Integer && x.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType1Exception, x.Type, 1, VariableType.Number); } return(VariableValue.Create(Mathf.Atan2(y.Number, x.Number))); } else { throw new CommandEvaluationException(name, WrongParameterRangeException, parameters.Count, "s", 1, 2); } }
private void Append(IVariableStore variables, string input, StringBuilder output) { var start = 0; while (start < input.Length) { var open = input.IndexOf('{', start); var close = input.IndexOf('}', open + 1); if (open > start && input[open - 1] == '\\') { output.Append(input, start, open - start - 1); output.Append('{'); start = open + 1; } else if (open < 0 || close < 0) { output.Append(input, start, input.Length - start); break; } else { output.Append(input, start, open - start); var variable = input.Substring(open + 1, close - open - 1); _temporaryReference.Update(variable); var value = _temporaryReference.GetValue(variables); Append(variables, value.ToString(), output); start = close + 1; } } }
public void UpdateBinding(IVariableStore store, string group, BindingAnimationStatus status) { if (string.IsNullOrEmpty(group) || BindingGroup == group) { UpdateBinding(store, status); } }
private void Trigger(IVariableStore variables, Animator animator) { if (Parameter.TryGetValue(variables, this, out var parameter)) { switch (Type) { case AnimatorControllerParameterType.Bool: { if (BoolValue.TryGetValue(variables, this, out var value)) { animator.SetBool(parameter, value); } else { Debug.LogWarningFormat(this, _valueNotFoundWarning, Name); } break; } case AnimatorControllerParameterType.Int: { if (IntValue.TryGetValue(variables, this, out var value)) { animator.SetInteger(parameter, value); } else { Debug.LogWarningFormat(this, _valueNotFoundWarning, Name); } break; } case AnimatorControllerParameterType.Float: { if (FloatValue.TryGetValue(variables, this, out var value)) { animator.SetFloat(parameter, value); } else { Debug.LogWarningFormat(this, _valueNotFoundWarning, Name); } break; } case AnimatorControllerParameterType.Trigger: { animator.SetTrigger(parameter); break; } } } else { Debug.LogWarningFormat(this, _parameterNotFoundWarning, Name); } }
public SetVariableResult SetValue(IVariableStore variables, VariableValue value) { var left = Left.Evaluate(variables); var right = Right.Evaluate(variables); var result = VariableHandler.Apply(ref left, right, value); if (result == SetVariableResult.Success && !left.HasReference) { if (Left is IAssignableOperation assignable) { return(assignable.SetValue(variables, value)); } else { throw new ExpressionEvaluationException(_invalidAssignException, value, right, Left); } } switch (result) { case SetVariableResult.NotFound: throw new ExpressionEvaluationException(_missingAssignmentException, value, right, left); case SetVariableResult.ReadOnly: throw new ExpressionEvaluationException(_readOnlyAssignmentException, value, right, left); case SetVariableResult.TypeMismatch: throw new ExpressionEvaluationException(_mismatchedAssignmentException, value, value.Type, right, left); } return(result); }
public override VariableValue Evaluate(IVariableStore variables) { var left = Left.Evaluate(variables); var right = Right.Evaluate(variables); if (left.HasList) { var result = left.List.AddVariable(right); if (result != SetVariableResult.Success) { switch (result) { case SetVariableResult.NotFound: throw new ExpressionEvaluationException(_missingAddException, Left); case SetVariableResult.ReadOnly: throw new ExpressionEvaluationException(_readOnlyAddException, Left); case SetVariableResult.TypeMismatch: throw new ExpressionEvaluationException(_mismatchedAddException, Left, right.Type); } } return(right); } else { var value = VariableHandler.Add(left, right); if (value.IsEmpty) { throw TypeMismatch(left.Type, right.Type); } return(Assign(variables, value)); } }
public override VariableValue Evaluate(IVariableStore variables) { var left = Left.Evaluate(variables); if (left.HasList) { var result = left.List.Count > 0 ? left.List.RemoveVariable(left.List.Count - 1) : SetVariableResult.NotFound; if (result != SetVariableResult.Success) { switch (result) { case SetVariableResult.NotFound: throw new ExpressionEvaluationException(_missingRemoveException, Left); case SetVariableResult.ReadOnly: throw new ExpressionEvaluationException(_readOnlyRemoveException, Left); case SetVariableResult.TypeMismatch: throw new ExpressionEvaluationException(_mismatchedRemoveException, Left); } } return(left); } else { var value = VariableHandler.Add(left, VariableValue.Create(-1)); if (value.IsEmpty) { throw TypeMismatch(left.Type, VariableType.Int); } Assign(variables, value); return(left); } }
private float GetFill(IVariableStore variables) { var amountValue = AmountVariable.GetValue(variables); var totalValue = TotalVariable.GetValue(variables); float amount, total; switch (amountValue.Type) { case VariableType.Empty: Debug.LogErrorFormat(this, _missingAmountError, AmountVariable); amount = 0.0f; break; case VariableType.Integer: amount = amountValue.Integer; break; case VariableType.Number: amount = amountValue.Number; break; default: Debug.LogErrorFormat(this, _invalidAmountError, AmountVariable); amount = 0.0f; break; } switch (totalValue.Type) { case VariableType.Empty: Debug.LogErrorFormat(this, _missingTotalError, TotalVariable); total = 1.0f; break; case VariableType.Integer: total = totalValue.Integer; break; case VariableType.Number: total = totalValue.Number; break; default: Debug.LogErrorFormat(this, _invalidTotalError, TotalVariable); total = 1.0f; break; } return(amount / total); }
private void ValidateStore(IVariableStore store, Dictionary <Variable, Expr> expected) { Assert.AreEqual(expected.Count, store.Count); int keysCount = 0; foreach (var v in store.Keys) { ++keysCount; Assert.IsTrue(expected.ContainsKey(v)); Assert.IsTrue(store.ContainsKey(v)); } Assert.AreEqual(expected.Count, keysCount); // Dummy var var dummyVar = MkSimpleVar("dummy", BPLType.Bool); Assert.IsFalse(store.ContainsKey(dummyVar)); int pairsCount = 0; foreach (var pair in store) { ++pairsCount; Assert.IsTrue(expected.ContainsKey(pair.Key)); Assert.AreSame(expected[pair.Key], pair.Value); } Assert.AreEqual(expected.Count, pairsCount); }
public VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count == 3) { var xValue = parameters[0].Evaluate(variables); var yValue = parameters[1].Evaluate(variables); var zValue = parameters[2].Evaluate(variables); if (!xValue.HasNumber) { throw CommandEvaluationException.WrongParameterType(name, 0, xValue.Type, VariableType.Float); } if (!yValue.HasNumber) { throw CommandEvaluationException.WrongParameterType(name, 1, yValue.Type, VariableType.Float); } if (!zValue.HasNumber) { throw CommandEvaluationException.WrongParameterType(name, 2, zValue.Type, VariableType.Float); } return(VariableValue.Create(new Vector3(xValue.Number, yValue.Number, zValue.Number))); } throw CommandEvaluationException.WrongParameterCount(name, parameters.Count, 3); }
public void Clear() { _variables.Clear(); _version = 0; _schema = null; _owner = null; }
private IVariableStore GetStore(IVariableStore variables, SelectionItem item) { if (!item.Variables.IsAssigned) { return(variables); } else { var value = item.Variables.GetValue(variables); if (value.Type == VariableType.Empty) { Debug.LogErrorFormat(this, _missingItemError, item.Id, item.Variables); return(null); } else if (!value.TryGetStore(out var store)) { Debug.LogErrorFormat(this, _invalidItemError, item.Id, item.Variables); return(null); } else { return(store); } } }
public ConfiguratorViewModel(IApplicationLogger logger, IEventAggregator events, IApplicationCommands commands, ITemplateManager templateManager, IDriveDetector driveDetector, IMessageDisplayService messageService, ElementViewModelFactory elementFactory, IConfiguratorService configurator, IVariableStore variables) { _logger = logger; _templateManager = templateManager; _driveDetector = driveDetector; _messageService = messageService; _elementFactory = elementFactory; _configurator = configurator; _variables = variables; Title = "Configurator"; events.GetEvent <TemplateSelectedEvent>().Subscribe(OnTemplateSelected); events.GetEvent <ScanDrivesCompletedEvent>().Subscribe(OnScanDrivesCompleted); ImportCommand = new DelegateCommand(OnImport, () => true); commands.ImportCommand.RegisterCommand(ImportCommand); PrevPageCommand = new DelegateCommand <PageViewModel>(OnPrevPage, CanPrevPage); NextPageCommand = new DelegateCommand <PageViewModel>(OnNextPage, page => true); RescanCommand = new DelegateCommand(OnScanDrives, () => !IsScanning); RescanCommand.Execute(); }
public VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count == 0) { return(VariableValue.Create(new VariableStore())); } else if (parameters.Count == 1) { var schemaName = parameters[0].Evaluate(variables); if (!schemaName.HasString) { throw CommandEvaluationException.WrongParameterType(name, 0, schemaName.Type, VariableType.String); } var schema = Resources.Load <VariableSchema>(schemaName.String); if (!schema) { Debug.LogWarningFormat(_invalidSchemaWarning, schemaName.String); } return(VariableValue.Create(schema ? new ConstrainedStore(schema) : new VariableStore())); } throw CommandEvaluationException.WrongParameterCount(name, parameters.Count, 0, 1); }
public override VariableValue Evaluate(IVariableStore variables, string name, List <Operation> parameters) { if (parameters.Count == 3) { var a = parameters[0].Evaluate(variables); var b = parameters[1].Evaluate(variables); var t = parameters[2].Evaluate(variables); if (a.Type != VariableType.Integer && a.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType1Exception, a.Type, 0, VariableType.Number); } if (b.Type != VariableType.Integer && b.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType1Exception, b.Type, 1, VariableType.Number); } if (t.Type != VariableType.Integer && t.Type != VariableType.Number) { throw new CommandEvaluationException(name, WrongParameterType1Exception, t.Type, 2, VariableType.Number); } return(VariableValue.Create(Mathf.Lerp(a.Number, b.Number, t.Number))); } else { throw new CommandEvaluationException(name, WrongParameterCountException, parameters.Count, parameters.Count == 1 ? "" : "s", 3); } }
private void AddWatch(string name, IVariableStore store) { var control = new VariableStoreControl(); control.Setup(name, store, false, true); _watchedStores.Add(control); }