mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-05 23:27:55 +02:00
Fixed numerous reported bugs. Refactored some of the directory-related code. Added documentation for MasonDs changes to hack/grow/weaken
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
/**
|
||||
* Helper functions that implement "directory" functionality in the Terminal.
|
||||
* These aren't real directories, they're more of a pseudo-directory implementation
|
||||
* These aren't "real" directories, it's more of a pseudo-directory implementation
|
||||
* that uses mainly string manipulation.
|
||||
*
|
||||
* This file contains functions that deal only with that string manipulation.
|
||||
* Functions that need to access/process Server-related things can be
|
||||
* found in ./DirectoryServerHelpers.ts
|
||||
*/
|
||||
import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||
import { Server } from "../Server/Server";
|
||||
|
||||
/**
|
||||
* Removes leading forward slash ("/") from a string.
|
||||
@@ -149,44 +152,6 @@ export function getAllParentDirectories(path: string): string {
|
||||
return t_path.slice(0, lastSlash + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a directory (by the full directory path) and a server, returns all
|
||||
* subdirectories of that directory. This is only for FIRST-LEVEl/immediate subdirectories
|
||||
*/
|
||||
export function getSubdirectories(serv: Server | HacknetServer, dir: string): string[] {
|
||||
const res: string[] = [];
|
||||
|
||||
if (!isValidDirectoryPath(dir)) { return res; }
|
||||
|
||||
let t_dir = dir;
|
||||
if (!t_dir.endsWith("/")) { t_dir += "/"; }
|
||||
|
||||
function processFile(fn: string) {
|
||||
if (t_dir === "/" && isInRootDirectory(fn)) {
|
||||
const subdir = getFirstParentDirectory(fn);
|
||||
if (subdir !== "/" && !res.includes(subdir)) {
|
||||
res.push(subdir);
|
||||
}
|
||||
} else if (fn.startsWith(t_dir)) {
|
||||
const remaining = fn.slice(t_dir.length);
|
||||
const subdir = getFirstParentDirectory(remaining);
|
||||
if (subdir !== "/" && !res.includes(subdir)) {
|
||||
res.push(subdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const script of serv.scripts) {
|
||||
processFile(script.filename);
|
||||
}
|
||||
|
||||
for (const txt of serv.textFiles) {
|
||||
processFile(txt.fn);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file path refers to a file in the root directory.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user