예제 #1
0
            /// <summary>
            /// Try to get an "if" color source from a ParsedParameters. The expected format is:
            ///
            /// if(toggle, onSource)
            /// if(toggle, onSource, offSource)
            /// </summary>
            public static IColorSource TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                if (!TYPE_NAME.Equals(parsedParams.Identifier))
                {
                    return(null);
                }
                parsedParams.RequireCount(module, 2, 3);
                IToggle toggle = null;

                try
                {
                    toggle = Toggles.Require(module, parsedParams[0]);
                }
                catch (ArgumentException e)
                {
                    throw new ColorSourceException(module, "Invalid toggle specified for " + TYPE_NAME + "(): " + e.Message);
                }
                IColorSource onSource  = Find(module, parsedParams[1]);
                IColorSource offSource = (parsedParams.Count > 2) ? Find(module, parsedParams[2]) : BLACK;

                return(new IfColorSource(toggle, parsedParams[0], onSource, offSource));
            }
예제 #2
0
 public static IScalar TryParse(PartModule module, ParsedParameters parsedParams)
 {
     if (parsedParams == null)
     {
         return(null);
     }
     if (parsedParams.Identifier != TYPE_NAME)
     {
         return(null);
     }
     parsedParams.RequireCount(module, 1);
     return(Of(Toggles.Require(module, parsedParams[0]), 1, 0));
 }
 /// <summary>
 /// Find the specified toggle. Throws ArgumentException if there's a problem.
 /// </summary>
 /// <param name="toggleID"></param>
 /// <returns></returns>
 protected IToggle RequireToggle(string toggleID)
 {
     return(Toggles.Require(this, toggleID));
 }
 /// <summary>
 /// Try to find the specified toggle. Returns null if not found or there's a problem.
 /// </summary>
 /// <param name="toggleID"></param>
 /// <returns></returns>
 protected IToggle TryFindToggle(string toggleID)
 {
     return(Toggles.TryParse(this, toggleID));
 }