// Should only input SimulationProperties as a parameter public void Add(Amplitude.StaticString name, float value) { SingleSimulationModifierDescriptor modif = new SingleSimulationModifierDescriptor(name, SimulationModifierDescriptor.ModifierOperation.Addition, value); Properties.Add(new SimulationPropertyDescriptor(name)); Modifiers.Add(modif); }
private void DisplayModifier(float indent, SimulationModifierProvider provider, SimulationObject context) { string text = string.Empty; if (provider.ModifierDescriptor is SingleSimulationModifierDescriptor) { SingleSimulationModifierDescriptor singleSimulationModifierDescriptor = provider.ModifierDescriptor as SingleSimulationModifierDescriptor; text = text + provider.ModifierDescriptor.Operation.ToString() + " "; text += singleSimulationModifierDescriptor.Value; } else if (provider.ModifierDescriptor is BinarySimulationModifierDescriptor) { BinarySimulationModifierDescriptor binarySimulationModifierDescriptor = provider.ModifierDescriptor as BinarySimulationModifierDescriptor; text += string.Format("{0} ({1} {2} {3})", new object[] { provider.ModifierDescriptor.Operation.ToString(), binarySimulationModifierDescriptor.Left, binarySimulationModifierDescriptor.BinaryOperation.ToString(), binarySimulationModifierDescriptor.Right }); } else if (provider.ModifierDescriptor is CountSimulationModifierDescriptor) { CountSimulationModifierDescriptor countSimulationModifierDescriptor = provider.ModifierDescriptor as CountSimulationModifierDescriptor; text += string.Format("{0} ({1} {2})", provider.ModifierDescriptor.Operation.ToString(), countSimulationModifierDescriptor.Value, countSimulationModifierDescriptor.XmlSerializableCountPath); } provider.DisplayContent = this.IndentedToggle(indent, provider.DisplayContent, text, new object[0]); if (provider.DisplayContent) { indent += 20f; this.IndentedLabel(indent, "Target:", " <b>{0}</b>", new object[] { provider.ModifierDescriptor.TargetPropertyName }); this.IndentedLabel(indent, "Operation:", " <b>{0}</b>", new object[] { provider.ModifierDescriptor.Operation.ToString() }); this.IndentedLabel(indent, "Value:", " <b>{0}</b>", new object[] { provider.ModifierDescriptor.ComputeValue(context, provider.DescriptorHolder.Context, SimulationPropertyRefreshContext.GetContext(-1)).ToString() }); this.IndentedLabel(indent, "Path:", " <b>{0}</b>", new object[] { provider.ModifierDescriptor.Path.ToString() }); this.IndentedLabel(indent, "Source:", " <b>{0} ({1})</b>", new object[] { provider.DescriptorHolder.Context.Name, provider.DescriptorHolder.Descriptor.Name }); indent -= 20f; } }
protected EffectDescription ParseSingleModifier(SimulationDescriptor simulationDescriptor, SingleSimulationModifierDescriptor modifierDescriptor, SimulationObject context = null, bool forcePercent = false) { EffectDescription effectDescription = new EffectDescription(); bool round = false; string valueFormat = string.Empty; string empty = string.Empty; float neutralValue = this.ComputeOperationTypeToken(modifierDescriptor.Operation, ref empty, ref valueFormat, ref round); effectDescription.Operator = empty; object obj = modifierDescriptor.PrecomputedValue; if (forcePercent) { valueFormat = "#####0%"; } if (obj is float) { effectDescription.ValueFloat = (float)obj; effectDescription.ValueFormat = valueFormat; effectDescription.Value = this.ComputeReadableFloat((float)obj, round, valueFormat, neutralValue); if (string.IsNullOrEmpty(effectDescription.Value)) { return(null); } if ((float)obj < 0f && (modifierDescriptor.Operation == SimulationModifierDescriptor.ModifierOperation.Addition || modifierDescriptor.Operation == SimulationModifierDescriptor.ModifierOperation.Percent)) { effectDescription.Operator = string.Empty; } } else if (obj is StaticString) { if (context != null) { obj = context.GetPropertyValue(obj as StaticString); } else if (simulationDescriptor.SimulationPropertyDescriptors != null) { StaticString staticString = obj as StaticString; for (int i = 0; i < simulationDescriptor.SimulationPropertyDescriptors.Length; i++) { if (staticString != null && simulationDescriptor.SimulationPropertyDescriptors[i].Name == staticString) { obj = simulationDescriptor.SimulationPropertyDescriptors[i].BaseValue; break; } } } if (obj is StaticString) { effectDescription.Value = this.ComputePropertySymbol(obj.ToString()); } else { effectDescription.ValueFloat = (float)obj; effectDescription.ValueFormat = valueFormat; effectDescription.Value = this.ComputeReadableFloat((float)obj, round, valueFormat, neutralValue); if (string.IsNullOrEmpty(effectDescription.Value)) { return(null); } } } return(effectDescription); }