/* Console::execute * Attempts to execute the command line given *******************************************************************/ void Console::execute(string command) { ::logMessage(1, "> %s", CHR(command)); // Don't bother doing anything else with an empty command if (command.size() == 0) return; // Add the command to the log cmd_log.insert(cmd_log.begin(), command); // Tokenize the command string Tokenizer tz; tz.openString(command); // Get the command name string cmd_name = tz.getToken(); // Get all args string arg = tz.getToken(); vector<string> args; while (arg != "") { args.push_back(arg); arg = tz.getToken(); } // Check that it is a valid command //for (size_t a = 0; a < commands.size(); a++) for (Command& command : commands) { // Found it, execute and return if (command.getName() == cmd_name) { command.execute(args); return; } } // Check if it is a cvar CVar* cvar = get_cvar(cmd_name); if (cvar) { // Arg(s) given, set cvar value if (args.size() > 0) { if ((cvar->flags & CVAR_LOCKED) > 0) logMessage(S_FMT("CVar \"%s\" can not be modified via the console", CHR(cmd_name))); else if (cvar->type == CVAR_BOOLEAN) { if (args[0] == "0" || args[0] == "false") *((CBoolCVar*)cvar) = false; else *((CBoolCVar*)cvar) = true; } else if (cvar->type == CVAR_INTEGER) *((CIntCVar*)cvar) = atoi(CHR(args[0])); else if (cvar->type == CVAR_FLOAT) *((CFloatCVar*)cvar) = (float)atof(CHR(args[0])); else if (cvar->type == CVAR_STRING) *((CStringCVar*)cvar) = args[0]; } // Print cvar value string value = ""; if (cvar->type == CVAR_BOOLEAN) { if (cvar->GetValue().Bool) value = "true"; else value = "false"; } else if (cvar->type == CVAR_INTEGER) value = S_FMT("%d", cvar->GetValue().Int); else if (cvar->type == CVAR_FLOAT) value = S_FMT("%1.4f", cvar->GetValue().Float); else value = ((CStringCVar*)cvar)->value; logMessage(S_FMT("\"%s\" = \"%s\"", CHR(cmd_name), CHR(value))); if (cmd_name == "log_verbosity") Global::log_verbosity = cvar->GetValue().Int; return; } // Toggle global debug mode if (cmd_name == "debug") { Global::debug = !Global::debug; if (Global::debug) logMessage("Debugging stuff enabled"); else logMessage("Debugging stuff disabled"); return; } // Command not found logMessage(S_FMT("Unknown command: \"%s\"", CHR(cmd_name))); return; }
/* SAction::parse * Loads a parsed SAction definition *******************************************************************/ bool SAction::parse(ParseTreeNode* node) { string linked_cvar; int custom_wxid = -1; for (unsigned a = 0; a < node->nChildren(); a++) { auto prop = node->getChildPTN(a); string prop_name = prop->getName(); // Text if (S_CMPNOCASE(prop_name, "text")) text = prop->stringValue(); // Icon else if (S_CMPNOCASE(prop_name, "icon")) icon = prop->stringValue(); // Help Text else if (S_CMPNOCASE(prop_name, "help_text")) helptext = prop->stringValue(); // Shortcut else if (S_CMPNOCASE(prop_name, "shortcut")) shortcut = prop->stringValue(); // Keybind (shortcut) else if (S_CMPNOCASE(prop_name, "keybind")) shortcut = S_FMT("kb:%s", prop->stringValue()); // Type else if (S_CMPNOCASE(prop_name, "type")) { string lc_type = prop->stringValue().Lower(); if (lc_type == "check") type = Type::Check; else if (lc_type == "radio") type = Type::Radio; } // Linked CVar else if (S_CMPNOCASE(prop_name, "linked_cvar")) linked_cvar = prop->stringValue(); // Custom wx id else if (S_CMPNOCASE(prop_name, "custom_wx_id")) custom_wxid = prop->intValue(); // Reserve ids else if (S_CMPNOCASE(prop_name, "reserve_ids")) reserved_ids = prop->intValue(); } // Setup wxWidgets id stuff if (custom_wxid == -1) { wx_id = cur_id; cur_id += reserved_ids; } else wx_id = custom_wxid; // Setup linked cvar if (type == Type::Check && !linked_cvar.IsEmpty()) { auto cvar = get_cvar(linked_cvar); if (cvar && cvar->type == CVAR_BOOLEAN) { this->linked_cvar = (CBoolCVar*)cvar; checked = cvar->GetValue().Bool; } } return true; }