mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 01:03:01 +02:00
REFACTORING: ScriptEditor (#560)
This commit is contained in:
committed by
GitHub
parent
886f402a43
commit
99954ebd1e
@@ -0,0 +1,25 @@
|
||||
import { GetServer } from "../../Server/AllServers";
|
||||
|
||||
import { OpenScript } from "./OpenScript";
|
||||
|
||||
function getServerCode(scripts: OpenScript[], index: number): string | null {
|
||||
const openScript = scripts[index];
|
||||
const server = GetServer(openScript.hostname);
|
||||
if (server === null) throw new Error(`Server '${openScript.hostname}' should not be null, but it is.`);
|
||||
const data = server.getContentFile(openScript.path)?.content ?? null;
|
||||
return data;
|
||||
}
|
||||
|
||||
function dirty(scripts: OpenScript[], index: number): string {
|
||||
const openScript = scripts[index];
|
||||
const serverData = getServerCode(scripts, index);
|
||||
if (serverData === null) return " *";
|
||||
return serverData !== openScript.code ? " *" : "";
|
||||
}
|
||||
|
||||
function reorder(list: unknown[], startIndex: number, endIndex: number): void {
|
||||
const [removed] = list.splice(startIndex, 1);
|
||||
list.splice(endIndex, 0, removed);
|
||||
}
|
||||
|
||||
export { getServerCode, dirty, reorder };
|
||||
Reference in New Issue
Block a user