// Update is called once per frame void Update() { for (int i = 0; i < macroListing.macros.Count; i++) { if (macroListing.macros[i].keyName == null || macroListing.macros[i].keyName.Length == 0) { continue; } if (Input.GetKeyDown(macroListing.macros[i].keyName)) { //Build replacement tuples Dictionary <string, string> replacementTuples = new Dictionary <string, string>(); for (int argIndex = 0; argIndex < macroListing.macros[i].args.Count; argIndex++) { MacroArg arg = macroListing.macros[i].args[argIndex]; replacementTuples.Add(MACRO_ARG_PREFIX + arg.id, arg.defaultValue); } //Submit commands foreach (string macroCommand in macroListing.macros[i].commands) { string finalCommand = macroCommand; //Do string replacement for arguments foreach (string key in replacementTuples.Keys) { finalCommand = finalCommand.Replace(key, replacementTuples[key]); } Console.Post(finalCommand); } break; } } }
public void HandleCommand(Command command) { //Check for the macro prefix if (!command.msg.StartsWith(MACRO_PREFIX)) { //If it isn't there, lets bail because we don't want to check every macro :| return; } //Get the part of the message that is relevant for matching string msg = command.msg.Substring(MACRO_PREFIX.Length); for (int i = 0; i < macroListing.macros.Count; i++) { if (msg.Equals(macroListing.macros[i].commandName)) { //Build replacement tuples Dictionary <string, string> replacementTuples = new Dictionary <string, string>(); for (int argIndex = 0; argIndex < macroListing.macros[i].args.Count; argIndex++) { MacroArg arg = macroListing.macros[i].args[argIndex]; string argVal; if (command.args.Length > argIndex) { argVal = command.args[argIndex]; } else if (arg.defaultValue != null && arg.defaultValue.Length > 0) { argVal = arg.defaultValue; } else { Console.Error("<b>Macro Error:</b>\nArgument " + argIndex + " is required."); return; } replacementTuples.Add(MACRO_ARG_PREFIX + arg.id, argVal); } //Submit commands foreach (string macroCommand in macroListing.macros[i].commands) { string finalCommand = macroCommand; //Do string replacement for arguments foreach (string key in replacementTuples.Keys) { finalCommand = finalCommand.Replace(key, replacementTuples[key]); } Console.Post(finalCommand); } break; } } }