Ejemplo n.º 1
0
        public void UnregisterDevCommand(IDevCommand devCmd)
        {
            var lowerCaseKey = devCmd.Name.ToLower( );

            if (!DevCommands.ContainsKey(lowerCaseKey))
            {
                throw new Exception("UnregisterDevCommand:  Dev command " + lowerCaseKey + " not registered");
            }

            DevCommands.Remove(lowerCaseKey);
        }
Ejemplo n.º 2
0
        public void RegisterDevCommand(IDevCommand devCmd)
        {
            if (!GenerateArgSpec(devCmd))
            {
                throw new Exception("Problem in dev command argument spec generation");
            }

            if (!ValidateArgumentSpec(devCmd))
            {
                throw new Exception("Problem in dev command argument spec validation");
            }

            var lowerCaseKey = devCmd.Name.ToLower( );

            if (DevCommands.ContainsKey(lowerCaseKey))
            {
                throw new Exception("RegisterDevCommand:  Dev command " + lowerCaseKey + " already registered");
            }

            DevCommands[lowerCaseKey] = devCmd;
        }
Ejemplo n.º 3
0
        private void RunDevCommand(string cmdLine)
        {
            History.Enqueue(cmdLine);
            while (History.Count > MaxHistoryItems)
            {
                History.Dequeue( );
            }

            // Strip comments and whitespace at either end; convert tabs to spaces
            var stripped = cmdLine;

            var commentCharIndex = cmdLine.IndexOf('#');

            if (commentCharIndex >= 0)
            {
                stripped = cmdLine.Remove(commentCharIndex);
            }

            stripped = stripped.Trim( );
            stripped = stripped.Replace("\t", " ");

            // Recognize the command
            var spaceCharIndex = stripped.IndexOf(' ');
            var command        = stripped;

            if (spaceCharIndex >= 0) // (No space char is fine because it might just be a command with no arguments or options)
            {
                command = stripped.Substring(0, spaceCharIndex);
            }
            command = command.ToLower( );

            if (command.Length == 0)
            {
                return; // For empty string, or all whitespace, with or without a comment, do nothing (and don't report as error)
            }
            if (!DevCommands.ContainsKey(command))
            {
                Debug.Log("Dev command not recognized: \"" + command + "\"\n");
                return;
            }

            // Strip the command away
            if (spaceCharIndex >= 0)
            {
                stripped = stripped.Substring(spaceCharIndex).Trim( );
            }
            else
            {
                stripped = string.Empty;
            }

            // Use the dev command's specification of arguments and options to fill in its interpreted data, AND error-check
            var successForArgs = ParseDevCommandArguments(DevCommands[command], stripped);

            if (!successForArgs)
            {
                return;
            }

            // Execute the dev command
            var success = DevCommands[command].Execute( );

            if (!success)
            {
                Debug.Log("Error executing dev command \"" + cmdLine + "\"\n");
            }
        }
 void Start()
 {
     ServerDropdown.value = ServerToDropdownNumber(StaticNetworkSettings.CurrentServer);
     devCommands          = GetComponent <DevCommands>();
 }