mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
NETSCRIPT: Revert FormattedCode type (#500)
This commit is contained in:
parent
6e028a0744
commit
ad5a1c4bac
@ -6,13 +6,11 @@ import { roundToTwo } from "../utils/helpers/roundToTwo";
|
||||
import { RamCostConstants } from "../Netscript/RamCostGenerator";
|
||||
import { ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
import { ContentFile } from "../Paths/ContentFile";
|
||||
/** Type for ensuring script code is always trimmed */
|
||||
export type FormattedCode = string & { __type: "FormattedCode" };
|
||||
|
||||
/** A script file as a file on a server.
|
||||
* For the execution of a script, see RunningScript and WorkerScript */
|
||||
export class Script implements ContentFile {
|
||||
code: FormattedCode;
|
||||
code: string;
|
||||
filename: ScriptFilePath;
|
||||
server: string;
|
||||
|
||||
@ -34,8 +32,7 @@ export class Script implements ContentFile {
|
||||
get content() {
|
||||
return this.code;
|
||||
}
|
||||
set content(code: string) {
|
||||
const newCode = Script.formatCode(code);
|
||||
set content(newCode: string) {
|
||||
if (this.code === newCode) return;
|
||||
this.code = newCode;
|
||||
this.invalidateModule();
|
||||
@ -43,7 +40,7 @@ export class Script implements ContentFile {
|
||||
|
||||
constructor(fn = "default.js" as ScriptFilePath, code = "", server = "") {
|
||||
this.filename = fn;
|
||||
this.code = Script.formatCode(code);
|
||||
this.code = code;
|
||||
this.server = server; // hostname of server this script is on
|
||||
}
|
||||
|
||||
@ -138,8 +135,8 @@ export class Script implements ContentFile {
|
||||
* @param {string} code - The code to format
|
||||
* @returns The formatted code
|
||||
*/
|
||||
static formatCode(code: string): FormattedCode {
|
||||
return code.replace(/^\s+|\s+$/g, "") as FormattedCode;
|
||||
static formatCode(code: string): string {
|
||||
return code.replace(/^\s+|\s+$/g, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ export abstract class BaseServer implements IServer {
|
||||
// Check if the script already exists, and overwrite it if it does
|
||||
const script = this.scripts.get(filename);
|
||||
if (script) {
|
||||
// content setter handles module invalidation and code formatting
|
||||
// content setter handles module invalidation
|
||||
script.content = code;
|
||||
return { overwritten: true };
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
||||
import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
|
||||
import { Player } from "@player";
|
||||
import { FormattedCode, Script } from "../Script/Script";
|
||||
import { Script } from "../Script/Script";
|
||||
import { GetAllServers } from "../Server/AllServers";
|
||||
import { resolveTextFilePath } from "../Paths/TextFilePath";
|
||||
import { resolveScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
@ -54,7 +54,7 @@ function hasChanges(code: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function convert(code: string): FormattedCode {
|
||||
function convert(code: string): string {
|
||||
const lines = code.split("\n");
|
||||
const out: string[] = [];
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user