mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 04:35:46 +01:00
Added aliases
This commit is contained in:
parent
a6e1fb6cfb
commit
a3c104ca4e
44
src/Alias.js
Normal file
44
src/Alias.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* Alias.js */
|
||||||
|
Aliases = {};
|
||||||
|
|
||||||
|
//Print all aliases to terminal
|
||||||
|
function printAliases() {
|
||||||
|
for (var name in Aliases) {
|
||||||
|
if (Aliases.hasOwnProperty(name)) {
|
||||||
|
post("alias " + name + "=" + Aliases[name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//True if successful, false otherwise
|
||||||
|
function parseAliasDeclaration(dec) {
|
||||||
|
var re = /([^=]+)="(.+)"/;
|
||||||
|
var matches = dec.match(re);
|
||||||
|
if (matches == null || matches.length != 3) {return false;}
|
||||||
|
addAlias(matches[1], matches[2]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAlias(name, value) {
|
||||||
|
Aliases[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAlias(name) {
|
||||||
|
if (Aliases.hasOwnProperty(name)) {
|
||||||
|
return Aliases[name];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns the original string with any aliases substituted in
|
||||||
|
//Aliases only applied to "whole words", one level deep
|
||||||
|
function substituteAliases(origCommand) {
|
||||||
|
var commandArray = origCommand.split(" ");
|
||||||
|
for (var i = 0; i < commandArray.length; ++i) {
|
||||||
|
var alias = getAlias(commandArray[i]);
|
||||||
|
if (alias != null) {
|
||||||
|
commandArray[i] = alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandArray.join(" ");
|
||||||
|
}
|
@ -128,7 +128,8 @@ CONSTANTS = {
|
|||||||
CrimeHeist: "pull off the ultimate heist",
|
CrimeHeist: "pull off the ultimate heist",
|
||||||
|
|
||||||
//Text that is displayed when the 'help' command is ran in Terminal
|
//Text that is displayed when the 'help' command is ran in Terminal
|
||||||
HelpText: "analyze Get statistics and information about current machine <br>" +
|
HelpText: 'alias [name="value"] Create aliases for Terminal commands, or list existing aliases<br>' +
|
||||||
|
"analyze Get statistics and information about current machine <br>" +
|
||||||
"clear Clear all text on the terminal <br>" +
|
"clear Clear all text on the terminal <br>" +
|
||||||
"cls See 'clear' command <br>" +
|
"cls See 'clear' command <br>" +
|
||||||
"connect [ip/hostname] Connects to the machine given by its IP or hostname <br>" +
|
"connect [ip/hostname] Connects to the machine given by its IP or hostname <br>" +
|
||||||
|
@ -10,6 +10,7 @@ function BitburnerSaveObject() {
|
|||||||
this.FactionsSave = "";
|
this.FactionsSave = "";
|
||||||
this.SpecialServerIpsSave = "";
|
this.SpecialServerIpsSave = "";
|
||||||
this.AugmentationsSave = "";
|
this.AugmentationsSave = "";
|
||||||
|
this.AliasesSave = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
BitburnerSaveObject.prototype.saveGame = function() {
|
BitburnerSaveObject.prototype.saveGame = function() {
|
||||||
@ -19,6 +20,7 @@ BitburnerSaveObject.prototype.saveGame = function() {
|
|||||||
this.FactionsSave = JSON.stringify(Factions);
|
this.FactionsSave = JSON.stringify(Factions);
|
||||||
this.SpecialServerIpsSave = JSON.stringify(SpecialServerIps);
|
this.SpecialServerIpsSave = JSON.stringify(SpecialServerIps);
|
||||||
this.AugmentationsSave = JSON.stringify(Augmentations);
|
this.AugmentationsSave = JSON.stringify(Augmentations);
|
||||||
|
this.AliasesSave = JSON.stringify(Aliases);
|
||||||
|
|
||||||
var saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
var saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
||||||
window.localStorage.setItem("bitburnerSave", saveString);
|
window.localStorage.setItem("bitburnerSave", saveString);
|
||||||
@ -41,6 +43,7 @@ loadGame = function(saveObj) {
|
|||||||
Factions = JSON.parse(saveObj.FactionsSave, Reviver);
|
Factions = JSON.parse(saveObj.FactionsSave, Reviver);
|
||||||
SpecialServerIps = JSON.parse(saveObj.SpecialServerIpsSave, Reviver);
|
SpecialServerIps = JSON.parse(saveObj.SpecialServerIpsSave, Reviver);
|
||||||
Augmentations = JSON.parse(saveObj.AugmentationsSave, Reviver);
|
Augmentations = JSON.parse(saveObj.AugmentationsSave, Reviver);
|
||||||
|
Aliases = JSON.parse(saveObj.AliasesSave, Reviver);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,6 +360,10 @@ var Terminal = {
|
|||||||
}
|
}
|
||||||
Terminal.commandHistoryIndex = Terminal.commandHistory.length;
|
Terminal.commandHistoryIndex = Terminal.commandHistory.length;
|
||||||
|
|
||||||
|
//Process any aliases
|
||||||
|
command = substituteAliases(command);
|
||||||
|
console.log("command after alises: " + command);
|
||||||
|
|
||||||
//Only split the first space
|
//Only split the first space
|
||||||
var commandArray = command.split(" ");
|
var commandArray = command.split(" ");
|
||||||
if (commandArray.length > 1) {
|
if (commandArray.length > 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user