mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 19:37:07 +02:00
MISC: Add file metadata (timestamps) (#2199)
This commit is contained in:
+11
-8
@@ -1,15 +1,15 @@
|
||||
import type { BaseServer } from "../Server/BaseServer";
|
||||
import { calculateRamUsage, RamUsageEntry } from "./RamCalculations";
|
||||
import { LoadedModule, ScriptURL } from "./LoadedModule";
|
||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../utils/JSONReviver";
|
||||
import { calculateRamUsage, type RamUsageEntry } from "./RamCalculations";
|
||||
import type { LoadedModule, ScriptURL } from "./LoadedModule";
|
||||
import { Generic_fromJSON, Generic_toJSON, type IReviverValue, constructorsForReviver } from "../utils/JSONReviver";
|
||||
import { roundToTwo } from "../utils/helpers/roundToTwo";
|
||||
import { RamCostConstants } from "../Netscript/RamCostGenerator";
|
||||
import { ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
import type { ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
import { ContentFile } from "../Paths/ContentFile";
|
||||
|
||||
/** A script file as a file on a server.
|
||||
* For the execution of a script, see RunningScript and WorkerScript */
|
||||
export class Script implements ContentFile {
|
||||
export class Script extends ContentFile {
|
||||
code: string;
|
||||
filename: ScriptFilePath;
|
||||
server: string;
|
||||
@@ -31,16 +31,19 @@ export class Script implements ContentFile {
|
||||
dependencies = new Map<ScriptURL, Script>();
|
||||
|
||||
get content() {
|
||||
this.metadata.read();
|
||||
return this.code;
|
||||
}
|
||||
set content(newCode: string) {
|
||||
this.metadata.edit();
|
||||
if (this.code === newCode) return;
|
||||
this.code = newCode;
|
||||
this.invalidateModule();
|
||||
}
|
||||
|
||||
constructor(fn = "default.js" as ScriptFilePath, code = "", server = "") {
|
||||
this.filename = fn;
|
||||
constructor(filename = "default.js" as ScriptFilePath, code = "", server = "") {
|
||||
super();
|
||||
this.filename = filename;
|
||||
this.code = code;
|
||||
this.server = server; // hostname of server this script is on
|
||||
}
|
||||
@@ -94,7 +97,7 @@ export class Script implements ContentFile {
|
||||
}
|
||||
|
||||
/** The keys that are relevant in a save file */
|
||||
static savedKeys = ["code", "filename", "server"] as const;
|
||||
static savedKeys = ["code", "filename", "server", "metadata"] as const;
|
||||
|
||||
// Serialize the current object to a JSON save state
|
||||
toJSON(): IReviverValue {
|
||||
|
||||
Reference in New Issue
Block a user