/// <summary> /// Invoke this hook with a certain parameter registry if optional conditional criteria are satisfied. /// </summary> /// <param name="registry">The registry containing the required values for this hook's execution.</param> /// <param name="resolver">A helper resolver for complex registry entries (automatically cached).</param> public override void SubInvoke(IRegistry registry, IRegistryResolver resolver) { IValueModifier modifier = ParameterRegistry.Get <IValueModifier>("modifier"); string identifier = ParameterRegistry.Get <string>("parameter_identifier"); object parameter = resolver.ResolveGetSingle <object>(identifier); INumber asNumber = parameter as INumber; INDArray asArray = parameter as INDArray; if (asNumber != null) { parameter = modifier.Modify(identifier, asNumber, asNumber.AssociatedHandler); } else if (asArray != null) { parameter = modifier.Modify(identifier, asArray, asArray.AssociatedHandler); } else { throw new InvalidOperationException($"Cannot apply modifier {modifier} to parameter \"{identifier}\" with value {parameter}, " + $"parameter is neither {nameof(INumber)} nor {nameof(INDArray)}."); } resolver.ResolveSet(identifier, parameter); }
public ApplyModifierHook(string parameter, IValueModifier modifier, TimeStep timeStep) : base(timeStep, parameter) { if (modifier == null) { throw new ArgumentNullException(nameof(modifier)); } ParameterRegistry.Set("parameter_identifier", parameter, typeof(string)); ParameterRegistry.Set("modifier", modifier, typeof(string)); }
public TweenScaleStrategy(Transform target, ITweenSharedState sharedSharedState, IValueModifier <Vector2> modHandler, ITweenPlayStyleStrategy style) { _target = target; _mod = modHandler; _style = style; _sharedState = (TweenSharedState <Vector2>)sharedSharedState; _state = TweenComponentState.None; _remote = new TweenRemoteControl(); _style.InitializeState(); SubscribeToRemote(); }
public TweenAlphaStrategy(Graphic target, ITweenSharedState sharedState, IValueModifier <float> modHandler, ITweenPlayStyleStrategy style) { _target = target; _mod = modHandler; _style = style; _sharedState = (TweenSharedState <float>)sharedState; _state = TweenComponentState.None; _remote = new TweenRemoteControl(); _style.InitializeState(); SubscribeToRemote(); }
// scans the given string and replaces any existing variables with their value protected string parseString(Dictionary <string, string> variables, string input) { StringBuilder output = new StringBuilder(input); int offset = 0; Regex variablePattern = new Regex(@"\${([^:{}]+)(?::([^}\(]+))?(?:\(([^\)]+)\))?}"); MatchCollection matches = variablePattern.Matches(input); foreach (Match currMatch in matches) { string varName = ""; string modifier = string.Empty; string value = string.Empty; string options = string.Empty; // get rid of the escaped variable string output.Remove(currMatch.Index + offset, currMatch.Length); // grab details for this parse varName = currMatch.Groups[1].Value; variables.TryGetValue(varName, out value); if (currMatch.Groups.Count >= 3) { modifier = currMatch.Groups[2].Value.ToLower(); } if (currMatch.Groups.Count >= 4) { options = currMatch.Groups[3].Value; } // if there is no variable for what was passed in we are done if (value == string.Empty || value == null) { offset -= currMatch.Length; continue; } // handle any modifiers if (!modifier.IsNullOrWhiteSpace()) { IValueModifier handler = Load(modifier); if (handler != null) { value = handler.Parse(this.Context, value, options); } } output.Insert(currMatch.Index + offset, value); offset = offset - currMatch.Length + value.Length; } // if we did some replacements search again to check forembeded variables if (matches.Count > 0) { return(parseString(variables, output.ToString())); } else { return(output.ToString()); } }
/// <inheritdoc /> public void AddValueModifier(string identifier, IValueModifier modifier) { _valueModifiers.TryGetValue(identifier, () => new HashSet <IValueModifier>()).Add(modifier); }