mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 16:22:56 +02:00
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder. * TypeSafety and other helper functions related to these types * Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands * Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way * Server.textFiles is now a map * TextFile no longer uses a fn property, now it is filename * Added a shared ContentFile interface for shared functionality between TextFile and Script. * related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa. * File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root. * Singularized the MessageFilename and LiteratureName enums * Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath). * Fix several issues with tab completion, which included pretty much a complete rewrite * Changed the autocomplete display options so there's less chance it clips outside the display area. * Turned CompletedProgramName into an enum. * Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine. * For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
This commit is contained in:
@@ -11,7 +11,7 @@ import { CompanyPositions } from "../../Company/CompanyPositions";
|
||||
import { CompanyPosition } from "../../Company/CompanyPosition";
|
||||
import * as posNames from "../../Company/data/JobTracks";
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
import { Programs } from "../../Programs/Programs";
|
||||
import { CompletedProgramName } from "../../Programs/Programs";
|
||||
import { Exploit } from "../../Exploits/Exploit";
|
||||
import { Faction } from "../../Faction/Faction";
|
||||
import { Factions } from "../../Faction/Factions";
|
||||
@@ -45,6 +45,7 @@ import { isCompanyWork } from "../../Work/CompanyWork";
|
||||
import { serverMetadata } from "../../Server/data/servers";
|
||||
|
||||
import type { PlayerObject } from "./PlayerObject";
|
||||
import { ProgramFilePath } from "src/Paths/ProgramFilePath";
|
||||
|
||||
export function init(this: PlayerObject): void {
|
||||
/* Initialize Player's home computer */
|
||||
@@ -60,7 +61,7 @@ export function init(this: PlayerObject): void {
|
||||
this.currentServer = SpecialServers.Home;
|
||||
AddToAllServers(t_homeComp);
|
||||
|
||||
this.getHomeComputer().programs.push(Programs.NukeProgram.name);
|
||||
this.getHomeComputer().programs.push(CompletedProgramName.nuke);
|
||||
}
|
||||
|
||||
export function prestigeAugmentation(this: PlayerObject): void {
|
||||
@@ -171,18 +172,9 @@ export function calculateSkillProgress(this: PlayerObject, exp: number, mult = 1
|
||||
return calculateSkillProgressF(exp, mult);
|
||||
}
|
||||
|
||||
export function hasProgram(this: PlayerObject, programName: string): boolean {
|
||||
export function hasProgram(this: PlayerObject, programName: CompletedProgramName | ProgramFilePath): boolean {
|
||||
const home = this.getHomeComputer();
|
||||
if (home == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < home.programs.length; ++i) {
|
||||
if (programName.toLowerCase() == home.programs[i].toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return home.programs.includes(programName);
|
||||
}
|
||||
|
||||
export function setMoney(this: PlayerObject, money: number): void {
|
||||
|
||||
Reference in New Issue
Block a user