/// <summary> /// Sets the value for this command on the target object. /// </summary> /// <param name="target"></param> /// <param name="val"></param> public void Set(object target, string val) { var element = target as TextArea; if (element != null) { element.TextAlign = (HorizontalAlignment)ScriptEnumAttribute.Lookup(val, typeof(HorizontalAlignment)); } }
/// <summary> /// /// </summary> /// <param name="vendorString"></param> /// <returns></returns> internal static GPUVendor VendorFromString(string vendorString) { var ret = GPUVendor.Unknown; var lookUpResult = ScriptEnumAttribute.Lookup(vendorString, typeof(GPUVendor)); if (lookUpResult != null) { ret = (GPUVendor)lookUpResult; } return(ret); }
/// <summary> /// Gets the value for this command from the target object. /// </summary> /// <param name="target"></param> /// <returns></returns> public string Get(object target) { var element = target as TextArea; if (element != null) { return(ScriptEnumAttribute.GetScriptAttribute((int)element.TextAlign, typeof(HorizontalAlignment))); } else { return(String.Empty); } }
public void Set(object target, string val) { LinearForceAffector affector = target as LinearForceAffector; // lookup the real enum equivalent to the script value object enumVal = ScriptEnumAttribute.Lookup(val, typeof(ForceApplication)); // if a value was found, assign it if (enumVal != null) { affector.ForceApplication = ((ForceApplication)enumVal); } else { ParseHelper.LogParserError(val, affector.Type, "Invalid enum value");; } }
/// <summary> /// Converts the node to an enum of type T and returns true if successful /// </summary> /// <typeparam name="T"></typeparam> /// <param name="node"></param> /// <param name="compiler"></param> /// <param name="property"></param> /// <returns>true if successful</returns> protected bool getEnumeration <T>(AbstractNode node, ScriptCompiler compiler, out T property) { // Set default property = default(T); if (node == null) { return(false); } // Verify Parameters if (!(node is AtomAbstractNode)) { return(false); } var atom = (AtomAbstractNode)node; if (compiler.KeywordMap.ContainsValue(atom.Id)) { var keyText = string.Empty; // For this ID, find the script Token foreach (var item in compiler.KeywordMap) { if (item.Value == atom.Id) { keyText = item.Key; } } // Now reflect over the enumeration to find the Token value var val = ScriptEnumAttribute.Lookup(keyText, typeof(T)); if (val != null) { property = (T)val; return(true); } } return(false); }
public static void ParseBillboardOrigin(string[] values, ParticleSystemRenderer _renderer) { if (values.Length != 1) { ParseHelper.LogParserError("billboard_origin", _renderer.Type, "Wrong number of parameters."); return; } // lookup the real enum equivalent to the script value object val = ScriptEnumAttribute.Lookup(values[0], typeof(BillboardOrigin)); BillboardParticleRenderer renderer = (BillboardParticleRenderer)_renderer; // if a value was found, assign it if (val != null) { renderer.BillboardOrigin = (BillboardOrigin)val; } else { ParseHelper.LogParserError("billboard_origin", _renderer.Type, "Invalid enum value"); } }
/// <see cref="Translator.Translate"/> public override void Translate(ScriptCompiler compiler, AbstractNode node) { var obj = (ObjectAbstractNode)node; var target = (CompositionTargetPass)obj.Parent.Context; this._Pass = target.CreatePass(); obj.Context = this._Pass; // The name is the type of the pass if (obj.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, obj.File, obj.Line); return; } var type = string.Empty; if (!getString(obj.Values[0], out type)) { compiler.AddError(CompileErrorCode.InvalidParameters, obj.File, obj.Line); return; } this._Pass.Type = (CompositorPassType)ScriptEnumAttribute.Lookup(type, typeof(CompositorPassType)); if (this._Pass.Type == CompositorPassType.RenderCustom) { var customType = string.Empty; //This is the ugly one liner for safe access to the second parameter. if (obj.Values.Count < 2 || !getString(obj.Values[1], out customType)) { compiler.AddError(CompileErrorCode.StringExpected, obj.File, obj.Line); return; } this._Pass.CustomType = customType; } else { compiler.AddError(CompileErrorCode.InvalidParameters, obj.File, obj.Line, "pass types must be \"clear\", \"stencil\", \"render_quad\", \"render_scene\" or \"render_custom\"."); return; } foreach (var i in obj.Children) { if (i is ObjectAbstractNode) { processNode(compiler, i); } else if (i is PropertyAbstractNode) { var prop = (PropertyAbstractNode)i; switch ((Keywords)prop.Id) { #region ID_MATERIAL case Keywords.ID_MATERIAL: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { var val = string.Empty; if (getString(prop.Values[0], out val)) { ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(ProcessResourceNameScriptCompilerEvent.ResourceType.Material, val); compiler._fireEvent(ref evt); this._Pass.MaterialName = ((ProcessResourceNameScriptCompilerEvent)evt).Name; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_MATERIAL #region ID_INPUT case Keywords.ID_INPUT: if (prop.Values.Count < 2) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 3) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { AbstractNode i0 = getNodeAt(prop.Values, 0), i1 = getNodeAt(prop.Values, 1), i2 = getNodeAt(prop.Values, 2); var id = 0; var name = string.Empty; if (getInt(i0, out id) && getString(i1, out name)) { var index = 0; if (!getInt(i2, out index)) { compiler.AddError(CompileErrorCode.NumberExpected, prop.File, prop.Line); return; } this._Pass.SetInput(id, name, index); } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_INPUT #region ID_IDENTIFIER case Keywords.ID_IDENTIFIER: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { uint val; if (getUInt(prop.Values[0], out val)) { this._Pass.Identifier = val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_IDENTIFIER #region ID_FIRST_RENDER_QUEUE case Keywords.ID_FIRST_RENDER_QUEUE: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { uint val; if (getUInt(prop.Values[0], out val)) { this._Pass.FirstRenderQueue = (RenderQueueGroupID)val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_FIRST_RENDER_QUEUE #region ID_LAST_RENDER_QUEUE case Keywords.ID_LAST_RENDER_QUEUE: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { uint val; if (getUInt(prop.Values[0], out val)) { this._Pass.LastRenderQueue = (RenderQueueGroupID)val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_LAST_RENDER_QUEUE #region ID_MATERIAL_SCHEME case Keywords.ID_MATERIAL_SCHEME: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { string val; if (getString(prop.Values[0], out val)) { this._Pass.MaterialScheme = val; } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_MATERIAL_SCHEME #region ID_QUAD_NORMALS case Keywords.ID_QUAD_NORMALS: if (prop.Values.Count == 0) { compiler.AddError(CompileErrorCode.StringExpected, prop.File, prop.Line); return; } else if (prop.Values.Count > 1) { compiler.AddError(CompileErrorCode.FewerParametersExpected, prop.File, prop.Line); return; } else { if (prop.Values[0] is AtomAbstractNode) { var atom = (AtomAbstractNode)prop.Values[0]; if (atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_VIEW_SPACE) { this._Pass.SetQuadFarCorners(true, true); } else if (atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_WORLD_SPACE) { this._Pass.SetQuadFarCorners(true, false); } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } else { compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line); } } break; #endregion ID_QUAD_NORMALS default: compiler.AddError(CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized"); break; } } } }
public static void ParseVertAlign(string[] parms, params object[] objects) { OverlayElement element = (OverlayElement)objects[0]; element.VerticalAlignment = (VerticalAlignment)ScriptEnumAttribute.Lookup(parms[0], typeof(VerticalAlignment)); }
public static void ParseMetricsMode(string[] parms, params object[] objects) { OverlayElement element = (OverlayElement)objects[0]; element.MetricsMode = (MetricsMode)ScriptEnumAttribute.Lookup(parms[0], typeof(MetricsMode)); }
/// <summary> /// /// </summary> /// <param name="v"></param> /// <returns></returns> internal static string VendorToString(GPUVendor v) { return(ScriptEnumAttribute.GetScriptAttribute((int)v, typeof(GPUVendor))); }
public void Set(object target, string val) { ((D3D9HLSLProgram)target).OptimizationLevel = (OptimizationLevel)ScriptEnumAttribute.Lookup(val, typeof(OptimizationLevel)); }
public string Get(object target) { OptimizationLevel level = ((D3D9HLSLProgram)target).OptimizationLevel; return(ScriptEnumAttribute.GetScriptAttribute((int)level, typeof(OptimizationLevel))); }
public void Set(object target, string val) { ((BillboardParticleRenderer)target).BillboardRotationType = (BillboardRotationType)ScriptEnumAttribute.Lookup(val, typeof(BillboardRotationType)); }
public string Get(object target) { BillboardRotationType r = ((BillboardParticleRenderer)target).BillboardRotationType; return(ScriptEnumAttribute.GetScriptAttribute((int)r, typeof(BillboardRotationType))); }
public string Get(object target) { BillboardOrigin o = ((BillboardParticleRenderer)target).BillboardOrigin; return(ScriptEnumAttribute.GetScriptAttribute((int)o, typeof(BillboardOrigin))); }