private void ParseSet(string input, ActuatorType type)
 {
     foreach (string actuatorConfig in input.Split(new [] { '|' }, StringSplitOptions.RemoveEmptyEntries))
     {
         actuators.Add(new Actuator(actuatorConfig.Trim(), type, part));
     }
 }
Esempio n. 2
0
        public IMessageService GetMessageService(ActuatorType type)
        {
            var service = _services.FirstOrDefault(i => i.MessageType.Equals(type));

            if (service == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            return(service);
        }
Esempio n. 3
0
    private GameObject[] TrackedObjectsByType(ActuatorType filterActuatorType)
    {
        List <GameObject> filteredObjects = new List <GameObject>();

        foreach (KeyValuePair <GameObject, ActuatorType[]> entry in trackedObjects)
        {
            foreach (ActuatorType actuatorType in entry.Value)
            {
                if (actuatorType == filterActuatorType)
                {
                    filteredObjects.Add(entry.Key);
                    break;
                }
            }
        }

        return(filteredObjects.ToArray());
    }
 private void ParseSet(string input, ActuatorType type)
 {
     foreach (string actuatorConfig in input.Split(new [] {'|'},StringSplitOptions.RemoveEmptyEntries)) {
         actuators.Add (new Actuator (actuatorConfig.Trim (), type, part));
     }
 }
Esempio n. 5
0
 public ActuatorBase(string name, ActuatorType type)
     : base(name, actuatorType[(int)type])
 {
     this.ThisIotType = IotType.Actuator;
 }
Esempio n. 6
0
        public Actuator(string configData, ActuatorType creatingType, Part thatPart)
        {
            savedNodePosition = faraway;

            type = creatingType;
            string remainder;

            if (configData.StartsWith("!", StringComparison.Ordinal))
            {
                inverted  = true;
                remainder = configData.Substring(1).Trim();
            }
            else
            {
                inverted  = false;
                remainder = configData;
            }

            string[] tokens = remainder.Split(',');
            switch (type)
            {
            case ActuatorType.PartComponent:
                moduleID = remainder;
                JUtil.LogMessage(this, "Controlling PartComponent with moduleID {0}, {1}", moduleID, inverted ? "inverted" : "regular");
                break;

            case ActuatorType.PartComponentGroup:
                moduleID = remainder;
                JUtil.LogMessage(this, "Controlling PartComponentGroup with groupID {0}, {1}", moduleID, inverted ? "inverted" : "regular");
                break;

            case ActuatorType.PartModule:
                int moduleIndex  = int.Parse(remainder.Split(',') [1]);
                var thoseModules = new List <PartModule> ();
                foreach (PartModule thatModule in thatPart.Modules)
                {
                    if (thatModule.ClassName == tokens [0].Trim())
                    {
                        thoseModules.Add(thatModule);
                    }
                }
                if (moduleIndex < thoseModules.Count)
                {
                    controlledModule = thoseModules [moduleIndex];
                }
                else
                {
                    JUtil.LogErrorMessage(this, "Could not find PartModule named {2} number {0} in part {1}", moduleIndex, thatPart.name, tokens [0].Trim());
                }
                JUtil.LogMessage(this, "Controlling PartModule named {0}, {1}", controlledModule.ClassName, inverted ? "inverted" : "regular");
                break;

            case ActuatorType.TransformTexture:

                if (tokens.Length == 3 || tokens.Length == 4)
                {
                    targetTransform = thatPart.FindModelTransform(tokens [0].Trim());
                    if (targetTransform == null)
                    {
                        throw new ArgumentException("Could not find model transform.");
                    }
                    if (GameDatabase.Instance.ExistsTexture(tokens [1].Trim()) && GameDatabase.Instance.ExistsTexture(tokens [2].Trim()))
                    {
                        falseString = tokens [1].Trim();
                        trueString  = tokens [2].Trim();
                        JUtil.LogMessage(this, "Controlling texture on transform '{0}', {1}", tokens [0].Trim(), inverted ? "inverted" : "regular");
                    }
                    else
                    {
                        throw new ArgumentException("Textures not found.");
                    }
                    if (tokens.Length == 4)
                    {
                        textureLayer = tokens [3].Trim();
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.TransformShader:
                if (tokens.Length == 3)
                {
                    targetTransform = thatPart.FindModelTransform(tokens [0].Trim());
                    if (targetTransform == null)
                    {
                        throw new ArgumentException("Could not find model transform.");
                    }
                    if (Shader.Find(tokens [1].Trim()) && Shader.Find(tokens [2].Trim()))
                    {
                        falseString = tokens [1].Trim();
                        trueString  = tokens [2].Trim();
                        JUtil.LogMessage(this, "Controlling shader on transform '{0}', {1}", tokens [0].Trim(), inverted ? "inverted" : "regular");
                    }
                    else
                    {
                        throw new ArgumentException("Shaders not found.");
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.StraightParameter:
                if (tokens.Length == 2)
                {
                    if (float.TryParse(tokens [1], out addToParameterWhenEnabled))
                    {
                        if (Array.IndexOf(knownStraightParameters, tokens [0].Trim()) >= 0)
                        {
                            nameOfParameter        = tokens [0].Trim();
                            originalParameterValue = GetParameter(nameOfParameter, thatPart);
                            JUtil.LogMessage(this, "Controlling parameter '{0}' on part {1}, {2}", nameOfParameter, thatPart.partName, inverted ? "inverted" : "regular");
                        }
                        else
                        {
                            throw new ArgumentException("Bad arguments, unknown straight parameter " + tokens [0]);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Bad argument, maxTemp must be a float.");
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.Resource:
                if (tokens.Length == 2)
                {
                    if (float.TryParse(tokens [1], out maxAmount))
                    {
                        bool found = false;
                        resourceName = tokens [0].Trim();
                        foreach (PartResourceDefinition thatResource in PartResourceLibrary.Instance.resourceDefinitions)
                        {
                            found |= thatResource.name == resourceName;
                        }
                        if (!found)
                        {
                            throw new ArgumentException("Bad resource name.");
                        }
                        JUtil.LogMessage(this, "Controlling resource tank for resource {0} in part {1}, {2}", resourceName, thatPart.partName, inverted ? "inverted" : "regular");
                    }
                    else
                    {
                        throw new ArgumentException("Bad resource amount.");
                    }
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.CrewCapacity:
                if (tokens.Length == 1)
                {
                    switch (tokens [0].ToLowerInvariant())
                    {
                    case "regular":
                        inverted = false;
                        break;

                    case "inverted":
                        inverted = true;
                        break;

                    default:
                        throw new ArgumentException("I need a 'regular' or 'inverted' here.");
                    }
                    JUtil.LogMessage(this, "Controlling crew capacity in part {0}, {1}", thatPart.partName, inverted ? "inverted" : "regular");
                }
                else
                {
                    throw new ArgumentException("Bad arguments.");
                }
                break;

            case ActuatorType.AttachmentNode:
                if (tokens.Length == 1)
                {
                    nodeName = tokens [0].Trim();
                    var foundNode = thatPart.findAttachNode(nodeName);
                    if (foundNode == null)
                    {
                        throw new ArgumentException("Node not found.");
                    }
                    savedNodePosition = foundNode.position;
                    JUtil.LogMessage(this, "Managing attach node in part {0}, node name {1}, {2}", thatPart.partName, nodeName, inverted ? "inverted" : "regular");
                }
                else
                {
                    throw new ArgumentException("Node name missing.");
                }
                break;
            }
        }
Esempio n. 7
0
        public Actuator(string configData, ActuatorType creatingType, Part thatPart)
        {
            savedNodePosition = faraway;

            type = creatingType;
            string remainder;
            if (configData.StartsWith ("!", StringComparison.Ordinal)) {
                inverted = true;
                remainder = configData.Substring (1).Trim ();
            } else {
                inverted = false;
                remainder = configData;
            }

            string[] tokens = remainder.Split (',');
            switch (type) {
            case ActuatorType.PartComponent:
                moduleID = remainder;
                JUtil.LogMessage (this, "Controlling PartComponent with moduleID {0}, {1}", moduleID, inverted ? "inverted" : "regular");
                break;
            case ActuatorType.PartComponentGroup:
                moduleID = remainder;
                JUtil.LogMessage (this, "Controlling PartComponentGroup with groupID {0}, {1}", moduleID, inverted ? "inverted" : "regular");
                break;
            case ActuatorType.PartModule:
                int moduleIndex = int.Parse (remainder.Split (',') [1]);
                var thoseModules = new List<PartModule> ();
                foreach (PartModule thatModule in thatPart.Modules) {
                    if (thatModule.ClassName == tokens [0].Trim ()) {
                        thoseModules.Add (thatModule);
                    }
                }
                if (moduleIndex < thoseModules.Count) {
                    controlledModule = thoseModules [moduleIndex];
                } else {
                    JUtil.LogErrorMessage (this, "Could not find PartModule named {2} number {0} in part {1}", moduleIndex, thatPart.name, tokens [0].Trim ());
                }
                JUtil.LogMessage (this, "Controlling PartModule named {0}, {1}", controlledModule.ClassName, inverted ? "inverted" : "regular");
                break;
            case ActuatorType.TransformTexture:

                if (tokens.Length == 3 || tokens.Length == 4) {
                    targetTransform = thatPart.FindModelTransform (tokens [0].Trim ());
                    if (targetTransform == null) {
                        throw new ArgumentException ("Could not find model transform.");
                    }
                    if (GameDatabase.Instance.ExistsTexture (tokens [1].Trim ()) && GameDatabase.Instance.ExistsTexture (tokens [2].Trim ())) {
                        falseString = tokens [1].Trim ();
                        trueString = tokens [2].Trim ();
                        JUtil.LogMessage (this, "Controlling texture on transform '{0}', {1}", tokens [0].Trim (), inverted ? "inverted" : "regular");
                    } else {
                        throw new ArgumentException ("Textures not found.");
                    }
                    if (tokens.Length == 4) {
                        textureLayer = tokens [3].Trim ();
                    }
                } else {
                    throw new ArgumentException ("Bad arguments.");
                }
                break;
            case ActuatorType.TransformShader:
                if (tokens.Length == 3) {
                    targetTransform = thatPart.FindModelTransform (tokens [0].Trim ());
                    if (targetTransform == null) {
                        throw new ArgumentException ("Could not find model transform.");
                    }
                    if (Shader.Find (tokens [1].Trim ()) && Shader.Find (tokens [2].Trim ())) {
                        falseString = tokens [1].Trim ();
                        trueString = tokens [2].Trim ();
                        JUtil.LogMessage (this, "Controlling shader on transform '{0}', {1}", tokens [0].Trim (), inverted ? "inverted" : "regular");
                    } else {
                        throw new ArgumentException ("Shaders not found.");
                    }
                } else {
                    throw new ArgumentException ("Bad arguments.");
                }
                break;
            case ActuatorType.StraightParameter:
                if (tokens.Length == 2) {
                    if (float.TryParse (tokens [1], out addToParameterWhenEnabled)) {
                        if (Array.IndexOf (knownStraightParameters, tokens [0].Trim ()) >= 0) {
                            nameOfParameter = tokens [0].Trim ();
                            originalParameterValue = GetParameter (nameOfParameter, thatPart);
                            JUtil.LogMessage (this, "Controlling parameter '{0}' on part {1}, {2}", nameOfParameter, thatPart.partName, inverted ? "inverted" : "regular");
                        } else {
                            throw new ArgumentException ("Bad arguments, unknown straight parameter " + tokens [0]);
                        }
                    } else {
                        throw new ArgumentException ("Bad argument, maxTemp must be a float.");
                    }
                } else {
                    throw new ArgumentException ("Bad arguments.");
                }
                break;
            case ActuatorType.Resource:
                if (tokens.Length == 2) {
                    if (float.TryParse (tokens [1], out maxAmount)) {
                        bool found = false;
                        resourceName = tokens [0].Trim ();
                        foreach (PartResourceDefinition thatResource in PartResourceLibrary.Instance.resourceDefinitions) {
                            found |= thatResource.name == resourceName;
                        }
                        if (!found)
                            throw new ArgumentException ("Bad resource name.");
                        JUtil.LogMessage (this, "Controlling resource tank for resource {0} in part {1}, {2}", resourceName, thatPart.partName, inverted ? "inverted" : "regular");
                    } else {
                        throw new ArgumentException ("Bad resource amount.");
                    }
                } else {
                    throw new ArgumentException ("Bad arguments.");
                }
                break;
            case ActuatorType.CrewCapacity:
                if (tokens.Length == 1) {
                    switch (tokens [0].ToLowerInvariant ()) {
                    case "regular":
                        inverted = false;
                        break;
                    case "inverted":
                        inverted = true;
                        break;
                    default:
                        throw new ArgumentException ("I need a 'regular' or 'inverted' here.");
                    }
                    JUtil.LogMessage (this, "Controlling crew capacity in part {0}, {1}", thatPart.partName, inverted ? "inverted" : "regular");
                } else {
                    throw new ArgumentException ("Bad arguments.");
                }
                break;
            case ActuatorType.AttachmentNode:
                if (tokens.Length == 1) {
                    nodeName = tokens [0].Trim ();
                    var foundNode = thatPart.FindAttachNode (nodeName);
                    if (foundNode == null) {
                        throw new ArgumentException ("Node not found.");
                    }
                    savedNodePosition = foundNode.position;
                    JUtil.LogMessage (this, "Managing attach node in part {0}, node name {1}, {2}", thatPart.partName, nodeName, inverted ? "inverted" : "regular");
                } else {
                    throw new ArgumentException ("Node name missing.");
                }
                break;
            }
        }