EDITOR: Reorganization and minor efficiency improvements (#886)

This commit is contained in:
Snarling
2023-10-23 07:02:33 -04:00
committed by GitHub
parent e339b5dc5f
commit 87925f1900
8 changed files with 300 additions and 323 deletions
+1 -22
View File
@@ -1,4 +1,3 @@
import { dialogBoxCreate } from "./ui/React/DialogBox";
import { BaseServer } from "./Server/BaseServer";
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "./utils/JSONReviver";
import { TextFilePath } from "./Paths/TextFilePath";
@@ -25,11 +24,6 @@ export class TextFile implements ContentFile {
this.text = txt;
}
/** Concatenates the raw values to the end of current content. */
append(txt: string): void {
this.text += txt;
}
/** Serves the file to the user as a downloadable resource through the browser. */
download(): void {
const file: Blob = new Blob([this.text], { type: "text/plain" });
@@ -41,30 +35,15 @@ export class TextFile implements ContentFile {
a.click();
setTimeout(() => {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
URL.revokeObjectURL(url);
}, 0);
}
/** Retrieve the content of the file. */
read(): string {
return this.text;
}
/** Shows the content to the user via the game's dialog box. */
show(): void {
dialogBoxCreate(`${this.filename}\n\n${this.text}`);
}
/** Serialize the current file to a JSON save state. */
toJSON(): IReviverValue {
return Generic_toJSON("TextFile", this);
}
/** Replaces the current content with the text provided. */
write(txt: string): void {
this.text = txt;
}
deleteFromServer(server: BaseServer): boolean {
if (!server.textFiles.has(this.filename)) return false;
server.textFiles.delete(this.filename);