Esempio n. 1
0
 public void Clear()
 {
     cmd                   = null;
     currentParam          = 0;
     InvalidCommandMessage = string.Empty;
     obj                   = null;
     behavior              = null;
     method                = null;
 }
Esempio n. 2
0
        internal object DeserializeMethodItem(string value, RCDItem item)
        {
            if (item == null)
            {
                return(null);
            }

            if (item.components.ContainsKey(value))
            {
                return((object)item.components[value]);
            }
            return(null);
        }
Esempio n. 3
0
        ///------------Methods Part-------------///

        ///<summary> Initialize the list of items </summary>
        internal void InitializeItems()
        {
            if (Initialized)
            {
                ClearItems();
            }

            GameObject[] pAllObjects = (GameObject [])Object.FindObjectsOfType(typeof(GameObject));

            foreach (GameObject pObject in pAllObjects)
            {
                if (pObject.hideFlags == HideFlags.NotEditable || pObject.hideFlags == HideFlags.HideAndDontSave ||
                    pObject.hideFlags == HideFlags.HideInHierarchy || pObject.hideFlags == HideFlags.HideInInspector || pObject.hideFlags == HideFlags.DontSave)
                {
                    continue;
                }

                RCDItem item = new RCDItem(pObject);
                CacheItems.Add(item);
            }

            Initialized = true;
        }
Esempio n. 4
0
        /// <summary> command parser method </summary>
        internal void ParseCommand(string cmd)
        {
            string [] parsedCmd = cmd.Split(' ');
            int       i;

            string cmdName = parsedCmd[0];

            string parameters = "";

            for (i = 1; i < parsedCmd.Length; i++)
            {
                parameters += parsedCmd[i] + " ";
            }

            if (!CacheMethods.ContainsKey(cmdName))
            {
                Manager.RegisterCommand(cmdName, parameters, "Unknown command");
                return;
            }

            Command command = CacheMethods[cmdName];

            if (command.ParamCount != parsedCmd.Length - 1)
            {
                Manager.RegisterCommand(cmdName, parameters, "Wrong params count");
                return;
            }

            int count = command.ParamCount;

            if (command.HaveLogParam)
            {
                count++;
            }

            object []      paramsobj = new object[count];
            RCDItem        item      = null;
            RCDMethodsItem behavior  = null;

            for (i = 0; i < command.ParamCount; i++)
            {
                System.Type type = command.GetParamType(i);

                if (type == typeof(RCDMethodsItem))
                {
                    paramsobj[i] = Manager.Serializer.DeserializeMethodItem(parsedCmd[i + i], item);
                    behavior     = (RCDMethodsItem)paramsobj[i];
                }

                else if (type == typeof(MethodInfo))
                {
                    paramsobj[i] = Manager.Serializer.DeserializeMethod(parsedCmd[i + 1], behavior);
                }

                else
                {
                    paramsobj[i] = Manager.Serializer.Deserialize(command.GetParamType(i), parsedCmd[i + 1]);
                    if (type == typeof(RCDItem))
                    {
                        item = (RCDItem)paramsobj[i];
                    }
                }

                if (paramsobj[i] == null)
                {
                    Manager.RegisterCommand(cmdName, parameters, "Wrong params");
                    return;
                }
            }

            LogMessage log = Manager.RegisterCommand(cmdName, parameters, command.HaveLogParam ? "Waiting" : "Succesfull");

            if (command.HaveLogParam)
            {
                paramsobj[paramsobj.Length - 1] = log;
            }

            Launch(cmdName, paramsobj);
            Manager.CommandLaunched(log);
        }
Esempio n. 5
0
        private CommandHelperHierarchy CalculateCommandHelper(string input)
        {
            string [] ParsedCmd = input.Split(' ');

            CmdHelperStruct.Clear();

            if (ParsedCmd.Length == 1)
            {
                return(CommandHelperHierarchy.Commands);
            }
            //if there is more than one string in ParsedCmd, it means he's not anymore at the command selection, so we should check if his command is valid or not
            else if (ParsedCmd.Length > 1)
            {
                //invalid case
                if (!Manager.Commands.Exists(ParsedCmd[0]))
                {
                    CmdHelperStruct.InvalidCommandMessage = "Unknown command";
                    return(CommandHelperHierarchy.InvalidCommand);
                }

                Command cmd = Manager.Commands.Get(ParsedCmd[0]);
                CmdHelperStruct.cmd = cmd;

                //invalid case
                if (ParsedCmd.Length - 1 > cmd.ParamCount)
                {
                    CmdHelperStruct.InvalidCommandMessage = "Command doesnt accept more params";
                    return(CommandHelperHierarchy.NoMoreParams);
                }

                CmdHelperStruct.currentParam = ParsedCmd.Length - 2;

                for (int i = 1; i < ParsedCmd.Length; i++)
                {
                    System.Type paramType = cmd.GetParamType(i - 1);
                    if (paramType == typeof(RCDItem))
                    {
                        /// not last element, check if this element (which is done) is correct
                        if (i < ParsedCmd.Length - 1)
                        {
                            int obj = -1;
                            if (int.TryParse(ParsedCmd[i], out obj))
                            {
                                RCDItem item = Manager.InternalItems.Get(obj);
                                if (item != null)
                                {
                                    CmdHelperStruct.obj = item;
                                }
                                else
                                {
                                    CmdHelperStruct.InvalidCommandMessage = "Item ID not found";
                                    return(CommandHelperHierarchy.InvalidCommand);
                                }
                            }
                            else
                            {
                                CmdHelperStruct.InvalidCommandMessage = "Wrong parameters type, should be type of int";
                                return(CommandHelperHierarchy.InvalidCommand);
                            }
                        }
                        /// its the last element, give the user the choice
                        else
                        {
                            return(CommandHelperHierarchy.Items);
                        }
                    }
                    else if (paramType == typeof(RCDMethodsItem))
                    {
                        if (CmdHelperStruct.CanShowBehaviours())
                        {
                            if (i < ParsedCmd.Length - 1)
                            {
                                if (CmdHelperStruct.obj.components.ContainsKey(ParsedCmd[i]))
                                {
                                    CmdHelperStruct.behavior = CmdHelperStruct.obj.components[ParsedCmd[i]];
                                }
                                else
                                {
                                    CmdHelperStruct.InvalidCommandMessage = "No behaviour named " + ParsedCmd[i] + " found on " + CmdHelperStruct.obj.Obj.name;
                                    return(CommandHelperHierarchy.InvalidCommand);
                                }
                            }
                            else
                            {
                                return(CommandHelperHierarchy.Behaviours);
                            }
                        }
                        else
                        {
                            CmdHelperStruct.InvalidCommandMessage = "No object to search for behaviours passed in";
                            return(CommandHelperHierarchy.InvalidCommand);
                        }
                    }
                    else if (paramType == typeof(MethodInfo))
                    {
                        if (CmdHelperStruct.CanShowMethods())
                        {
                            if (i < ParsedCmd.Length - 1)
                            {
                                if (CmdHelperStruct.behavior.MethodLookup.ContainsKey(ParsedCmd[i]))
                                {
                                    CmdHelperStruct.method = CmdHelperStruct.behavior.MethodLookup[ParsedCmd[i]];
                                }
                                else
                                {
                                    CmdHelperStruct.InvalidCommandMessage = "No methods named " + ParsedCmd[i] + " found on " + CmdHelperStruct.behavior.nameBehaviour;
                                    return(CommandHelperHierarchy.InvalidCommand);
                                }
                            }
                            else
                            {
                                return(CommandHelperHierarchy.Methods);
                            }
                        }
                        else
                        {
                            CmdHelperStruct.InvalidCommandMessage = "No behaviour to search for methods passed in";
                            return(CommandHelperHierarchy.InvalidCommand);
                        }
                    }
                    else
                    {
                        return(CommandHelperHierarchy.Parameters);
                    }
                }
            }

            CmdHelperStruct.InvalidCommandMessage = "Unknown error for invalid command";
            return(CommandHelperHierarchy.InvalidCommand);
        }