Esempio n. 1
0
        private bool TryInitialize(ModuleEmissiveControllerBase controller)
        {
            if (isInitialized)
            {
                return(isValid);
            }
            if ((controller == null) || (controller.Emissives == null) || (controller.Emissives.Count == 0))
            {
                return(DoneInitializing(false));
            }
            int total = 0;

            for (int emissiveIndex = 0; emissiveIndex < controller.Emissives.Count; ++emissiveIndex)
            {
                int count = controller.Emissives[emissiveIndex].Count;
                if (count < 0)
                {
                    return(false);           // not yet initialized, we'll try again later
                }
                total += count;
            }
            if (total < 1)
            {
                return(DoneInitializing(false));
            }

            sources = ColorSources.FindWithIndex(controller, colorSourceID, total);
            return(DoneInitializing(true));
        }
Esempio n. 2
0
        /// <summary>
        /// Try to set the colors of the meshes on the specified controller.
        /// </summary>
        /// <param name="controller"></param>
        public void SetColors(ModuleEmissiveControllerBase controller)
        {
            if (!TryInitialize(controller))
            {
                return;
            }

            int sourceIndex = 0;

            for (int emissiveIndex = 0; emissiveIndex < controller.Emissives.Count; ++emissiveIndex)
            {
                ModuleControllableEmissive emissive = controller.Emissives[emissiveIndex];
                for (int meshIndex = 0; meshIndex < emissive.Count; ++meshIndex)
                {
                    if (sourceIndex >= sources.Length)
                    {
                        return;
                    }
                    IColorSource source = sources[sourceIndex++];
                    if (source.HasColor)
                    {
                        emissive.SetColorAt(source.OutputColor, meshIndex);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Get a descriptive string for a ModuleEmissiveControllerBase.
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        private string DescribeController(ModuleEmissiveControllerBase controller)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(controller.ClassName);
            ModuleEmissiveController simpleController = controller as ModuleEmissiveController;

            if ((simpleController != null) && !string.IsNullOrEmpty(simpleController.controllerName))
            {
                builder.AppendFormat(" \"{0}\"", simpleController.controllerName);
            }
            builder.Append(", ");
            if (string.IsNullOrEmpty(controller.emissiveName))
            {
                builder.Append("no emissive");
            }
            else
            {
                builder.AppendFormat("emissive \"{0}\"", controller.emissiveName);
            }
            string description = controller.DebugDescription;

            if (string.IsNullOrEmpty(description))
            {
                IToggle toggle = controller as IToggle;
                if (toggle != null)
                {
                    description = string.Format("status = {0}", toggle.ToggleStatus);
                }
            }
            if (!string.IsNullOrEmpty(description))
            {
                builder.AppendFormat(": {0}", description);
            }
            return(builder.ToString());
        }
Esempio n. 4
0
        private void ShowController(ModuleEmissiveControllerBase controller, string[] arguments)
        {
            string           description = DescribeController(controller);
            List <BaseField> idFields    = new List <BaseField>();

            for (int i = 0; i < controller.Fields.Count; ++i)
            {
                BaseField field = controller.Fields[i];
                if (ToggleIDField.Is(field) || ScalarIDField.Is(field) || ColorSourceIDField.Is(field))
                {
                    idFields.Add(field);
                }
            }
            StringBuilder builder = new StringBuilder()
                                    .AppendFormat("{0}'s {1}:", controller.part.GetTitle(), controller.ClassName);

            if (arguments.Length < 1)
            {
                // Just show the controller.
                if (idFields.Count > 0)
                {
                    builder.AppendFormat("\n{0} parseable ID fields:", idFields.Count);
                    for (int i = 0; i < idFields.Count; ++i)
                    {
                        builder.AppendFormat("\n{0}: {1}", idFields[i].name, idFields[i].GetValue <string>(controller));
                    }
                }
                builder.AppendFormat("\nTo temporarily override a field: /{0} {1}", DebugConsole.COMMAND, COMMAND);
                for (int i = 0; i < originalArguments.Length; ++i)
                {
                    builder.AppendFormat(" {0}", originalArguments[i]);
                }
                builder.AppendFormat(" {0} <name> <value>", SET);
            }
            else
            {
                // See if they're setting a field.
                if (arguments[0] != SET)
                {
                    throw GetException("/" + DebugConsole.COMMAND + " " + COMMAND + ": unknown qualifier '" + arguments[0] + "'");
                }
                if (arguments.Length < 3)
                {
                    throw GetException("/" + DebugConsole.COMMAND + " " + COMMAND + ": '" + SET + "' command requires field name and value");
                }
                string    fieldName = arguments[1];
                BaseField field     = null;
                for (int i = 0; i < idFields.Count; ++i)
                {
                    if (idFields[i].name == fieldName)
                    {
                        field = idFields[i];
                        break;
                    }
                }
                if (field == null)
                {
                    throw GetException("/" + DebugConsole.COMMAND + " " + COMMAND + ": Unknown field '" + fieldName + "'");
                }
                string fieldValue = arguments.SubArray(2).Join(" ");
                builder.AppendFormat(" Setting {0} to: {1}", fieldName, fieldValue);
                field.SetValue(fieldValue, controller);
                controller.ParseIDs();
            }
            Logging.Log(builder.ToString());
        }