Esempio n. 1
0
 public ConstantColorSource(Color color)
 {
     this.color = color;
     this.id    = Colors.ToString(color);
 }
Esempio n. 2
0
 public ConstantColorSource(DefaultColor color)
 {
     this.color = color.Value();
     this.id    = Colors.ToString(color);
 }
Esempio n. 3
0
        /// <summary>
        /// Given a color source ID (which might be a literal color, the ID of a controller,
        /// or a parameterized source), try to find the appropriate source. If it can't
        /// be parsed or found, throws a ColorSourceException.
        private static IColorSource FindPrivate(PartModule module, string sourceID)
        {
            if (string.IsNullOrEmpty(sourceID))
            {
                throw new ColorSourceException(module, "Null or empty color source");
            }

            // Maybe it's a color string.
            if (Colors.IsColorString(sourceID))
            {
                return(Constant(Colors.Parse(sourceID, Color.black)));
            }

            // Is it a parameterized source?
            ParsedParameters parsedParams = ParsedParameters.TryParse(sourceID);

            if (parsedParams != null)
            {
                // It has the right syntax for a parameterizeed source. Do we recognize it?
                for (int i = 0; i < PARSEABLE_SOURCES.Length; ++i)
                {
                    IColorSource candidate = PARSEABLE_SOURCES[i](module, parsedParams);
                    if (candidate != null)
                    {
                        return(candidate);
                    }
                }
                throw new ColorSourceException(module, "Unknown function type '" + parsedParams.Identifier + "'");
            }

            // Maybe it's another field on the module?
            for (int i = 0; i < module.Fields.Count; ++i)
            {
                BaseField field = module.Fields[i];
                if (!sourceID.Equals(field.name))
                {
                    continue;
                }
                if (!ColorSourceIDField.Is(field))
                {
                    throw new ColorSourceException(
                              module, sourceID + " field on " + module.ClassName + " of "
                              + module.part.GetTitle() + " is not a color source ID field");
                }
                return(Find(module, field.GetValue <string>(module)));
            }

            // Maybe it's a module on the part?
            for (int i = 0; i < module.part.Modules.Count; ++i)
            {
                IColorSource candidate = module.part.Modules[i] as IColorSource;
                if (candidate == null)
                {
                    continue;
                }
                if (sourceID.Equals(candidate.ColorSourceID))
                {
                    return(candidate);
                }
            }

            // not found
            throw new ColorSourceException(module, "Can't find a color source named '" + sourceID + "'");
        }