mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-10-23 10:13:13 +02:00
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
|
import { ITerminal } from "../ITerminal";
|
||
|
import { IEngine } from "../../IEngine";
|
||
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||
|
import { BaseServer } from "../../Server/BaseServer";
|
||
|
import { Programs } from "../../Programs/Programs";
|
||
|
|
||
|
export function runProgram(
|
||
|
terminal: ITerminal,
|
||
|
engine: IEngine,
|
||
|
player: IPlayer,
|
||
|
server: BaseServer,
|
||
|
args: (string | number)[],
|
||
|
): void {
|
||
|
if (args.length < 1) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Check if you have the program on your computer. If you do, execute it, otherwise
|
||
|
// display an error message
|
||
|
const programName = args[0] + "";
|
||
|
|
||
|
if (!player.hasProgram(programName)) {
|
||
|
terminal.error("No such executable on home computer (Only programs that exist on your home computer can be run)");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (args.length < 1) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for (const program of Object.values(Programs)) {
|
||
|
if (program.name === programName) {
|
||
|
program.run(
|
||
|
terminal,
|
||
|
player,
|
||
|
server,
|
||
|
args.slice(1).map((arg) => arg + ""),
|
||
|
);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
terminal.print("Invalid executable. Cannot be run");
|
||
|
}
|