MISC: Add file metadata (timestamps) (#2199)

This commit is contained in:
catloversg
2025-06-17 06:34:06 +07:00
committed by GitHub
parent e5bfa641e1
commit a794fddaf7
19 changed files with 297 additions and 30 deletions
+11 -8
View File
@@ -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 {