//----------------------------------------------------------------------------------------------- void DeveloperConsole::ExecuteConsoleCommand( const std::string& consoleCommandName, const std::string& argsString ) { std::map<std::string, CommandFuncPtr>::iterator mapIter; mapIter = m_commandFunctionPtrs.find( GetLowercaseString( consoleCommandName ) ); if( mapIter == m_commandFunctionPtrs.end() ) { ConsoleLogLine funcNotFoundLine( "Could not find function: " + consoleCommandName, FUNCTION_NOT_FOUND_LINE_COLOR ); m_consoleLogLines.push_back( funcNotFoundLine ); return; } ConsoleCommandArgs commandArgs( argsString ); bool commandSuccess = mapIter->second( commandArgs ); if( commandSuccess ) { if( consoleCommandName == "clear" ) return; ConsoleLogLine funcSuccessLine( consoleCommandName + " " + argsString, FUNCTION_SUCCESS_LINE_COLOR ); m_consoleLogLines.push_back( funcSuccessLine ); } else { ConsoleLogLine funcUnsuccessfulLine( "Function \"" + consoleCommandName + "\" failed" , FUNCTION_UNSUCCESSFUL_LINE_COLOR ); m_consoleLogLines.push_back( funcUnsuccessfulLine ); } }
void setValue( const PropertyAccessor & pa, const Variant & data ) { Key key; if (!createKey( pa, key )) { pa.setValue( data ); return; } std::unique_ptr< ReflectedPropertyCommandArgument > args( new ReflectedPropertyCommandArgument ); args->setContextId( key.first ); args->setPath( key.second.c_str() ); args->setValue( data ); // Access is only on the main thread assert( std::this_thread::get_id() == commandManager_.ownerThreadId() ); const auto commandId = getClassIdentifier< SetReflectedPropertyCommand >(); const auto pArgsDefinition = pa.getDefinitionManager()->getDefinition< ReflectedPropertyCommandArgument >(); ObjectHandle commandArgs( std::move( args ), pArgsDefinition ); auto command = commandManager_.queueCommand( commandId, commandArgs ); // Queuing may cause it to execute straight away // Based on the thread affinity of SetReflectedPropertyCommand if (!command->isComplete()) { commands_.emplace( std::pair< Key, CommandInstancePtr >( key, command ) ); } }
void ConsoleSession::onCommand(const std::vector<std::string>& args) { if(args.empty()) { printPrompt(); return; } const std::string& commandName = args[0]; std::vector<std::string> commandArgs(args.begin() + 1, args.end()); const ConsoleCommands::Command* command = consoleCommands->getCommand(commandName); if(!command) { writef("Unknown command : %s\r\n", commandName.c_str()); } else { ConsoleCommands::Command::CallStatus status = command->call(this, commandArgs); switch(status) { case ConsoleCommands::Command::CS_Success: break; case ConsoleCommands::Command::CS_NotEnoughArgs: write("Not enough arguments\r\n"); break; case ConsoleCommands::Command::CS_TooMuchArgs: write("Too many arguments\r\n"); break; }; if(status != ConsoleCommands::Command::CS_Success) { writef("Usage:\r\n%s\r\n", command->usageExample.c_str()); } } printPrompt(); }
// Command 17: call external command void RivenSimpleCommand::runExternalCommand(uint16 op, const ArgumentArray &args) { uint16 commandNameid = args[0]; uint16 argumentCount = args[1]; Common::Array<uint16> commandArgs(argumentCount ? &args[2] : nullptr, argumentCount); _vm->getStack()->runCommand(commandNameid, commandArgs); }