diff --git a/doc/source/netscript/basicfunctions/alert.rst b/doc/source/netscript/basicfunctions/alert.rst new file mode 100644 index 000000000..28d0cf1bc --- /dev/null +++ b/doc/source/netscript/basicfunctions/alert.rst @@ -0,0 +1,15 @@ +alert() Netscript Function +============================ + +.. js:function:: alert(message) + + :RAM cost: 0 GB + :param string message: message to display + + Spawns an alert box. + + Example: + + .. code-block:: javascript + + alert("Reached $1b"); diff --git a/doc/source/netscript/basicfunctions/toast.rst b/doc/source/netscript/basicfunctions/toast.rst new file mode 100644 index 000000000..16a9443af --- /dev/null +++ b/doc/source/netscript/basicfunctions/toast.rst @@ -0,0 +1,17 @@ +toast() Netscript Function +============================ + +.. js:function:: toast(message[, variant]) + + :RAM cost: 0 GB + :param string message: message to display + :param success|info|warning|error variant: color of the toast + + Spawns a toast (those bottom left notifications). + + Example: + + .. code-block:: javascript + + toast("Reached $1b"); + toast("Failed to hack home", "error"); diff --git a/src/Message/MessageHelpers.ts b/src/Message/MessageHelpers.ts index a5e080702..90dd104d1 100644 --- a/src/Message/MessageHelpers.ts +++ b/src/Message/MessageHelpers.ts @@ -13,12 +13,14 @@ import { Reviver } from "../utils/JSONReviver"; function sendMessage(msg: Message, forced = false): void { msg.recvd = true; if (forced || !Settings.SuppressMessages) { - showMessage(msg); + showMessage(msg.filename); } addMessageToServer(msg, "home"); } -function showMessage(msg: Message): void { +function showMessage(name: string): void { + const msg = Messages[name]; + if (!msg) throw new Error("trying to display unexistent message"); const txt = "Message received from unknown sender:

" + "" + @@ -39,12 +41,11 @@ function addMessageToServer(msg: Message, serverHostname: string): void { } for (let i = 0; i < server.messages.length; ++i) { const other = server.messages[i]; - if (typeof other === "string") continue; - if (msg.filename === other.filename) { + if (msg.filename === other) { return; //Already exists } } - server.messages.push(msg); + server.messages.push(msg.filename); } //Checks if any of the 'timed' messages should be sent diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index cc0192905..d748a8b77 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1336,7 +1336,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS { if (scriptname.endsWith(".lit")) { let found = false; for (let i = 0; i < currServ.messages.length; ++i) { - if (!(currServ.messages[i] instanceof Message) && currServ.messages[i] == scriptname) { + if (currServ.messages[i] == scriptname) { found = true; break; } @@ -1462,20 +1462,11 @@ function NetscriptFunctions(workerScript: WorkerScript): NS { for (let i = 0; i < server.messages.length; i++) { if (filter) { const msg = server.messages[i]; - if (msg instanceof Message) { - if (msg.filename.includes(filter)) { - allFiles.push(msg.filename); - } - } else if (msg.includes(filter)) { + if (msg.includes(filter)) { allFiles.push(msg); } } else { - const msg = server.messages[i]; - if (msg instanceof Message) { - allFiles.push(msg.filename); - } else { - allFiles.push(msg); - } + allFiles.push(server.messages[i]); } } @@ -1770,7 +1761,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS { } } for (let i = 0; i < server.messages.length; ++i) { - if (!(server.messages[i] instanceof Message) && filename.toLowerCase() === server.messages[i]) { + if (filename.toLowerCase() === server.messages[i]) { return true; } } diff --git a/src/SaveObject.tsx b/src/SaveObject.tsx index fb03e56fa..ddbbb382a 100755 --- a/src/SaveObject.tsx +++ b/src/SaveObject.tsx @@ -164,6 +164,13 @@ function evaluateVersionCompatibility(ver: string): void { if (anyPlayer.corporation === 0) { anyPlayer.corporation = null; } + // convert all Messages to just filename to save space. + const home = anyPlayer.getHomeComputer(); + for (let i = 0; i < home.messages.length; i++) { + if (home.messages[i].filename) { + home.messages[i] = home.messages[i].filename; + } + } } } diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index d1f06f372..a69478c95 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -61,7 +61,7 @@ export class BaseServer { // For Literature files, this array contains only the filename (string) // For Messages, it contains the actual Message object // TODO Separate literature files into its own property - messages: (Message | string)[] = []; + messages: string[] = []; // Name of company/faction/etc. that this server belongs to. // Optional, not applicable to all Servers diff --git a/src/Terminal/commands/cat.ts b/src/Terminal/commands/cat.ts index d3b433c6f..196843e96 100644 --- a/src/Terminal/commands/cat.ts +++ b/src/Terminal/commands/cat.ts @@ -3,7 +3,6 @@ import { IRouter } from "../../ui/Router"; import { IPlayer } from "../../PersonObjects/IPlayer"; import { BaseServer } from "../../Server/BaseServer"; import { showMessage } from "../../Message/MessageHelpers"; -import { Message } from "../../Message/Message"; import { showLiterature } from "../../Literature/LiteratureHelpers"; export function cat( @@ -29,12 +28,12 @@ export function cat( for (let i = 0; i < server.messages.length; ++i) { if (filename.endsWith(".lit") && server.messages[i] === filename) { const file = server.messages[i]; - if (file instanceof Message) throw new Error(".lit file should not be a .msg"); + if (file.endsWith(".msg")) throw new Error(".lit file should not be a .msg"); showLiterature(file); return; } else if (filename.endsWith(".msg")) { - const file = server.messages[i] as Message; - if (file.filename !== filename) continue; + const file = server.messages[i]; + if (file !== filename) continue; showMessage(file); return; } diff --git a/src/Terminal/commands/ls.tsx b/src/Terminal/commands/ls.tsx index 165df17d7..51956e8d8 100644 --- a/src/Terminal/commands/ls.tsx +++ b/src/Terminal/commands/ls.tsx @@ -2,7 +2,6 @@ import { ITerminal } from "../ITerminal"; import { IRouter } from "../../ui/Router"; import { IPlayer } from "../../PersonObjects/IPlayer"; import { BaseServer } from "../../Server/BaseServer"; -import { Message } from "../../Message/Message"; import { getFirstParentDirectory, isValidDirectoryPath, evaluateDirectoryPath } from "../../Terminal/DirectoryHelpers"; export function ls( @@ -103,8 +102,7 @@ export function ls( for (const script of s.scripts) handleFn(script.filename, allScripts); for (const txt of s.textFiles) handleFn(txt.fn, allTextFiles); for (const contract of s.contracts) handleFn(contract.fn, allContracts); - for (const msgOrLit of s.messages) - msgOrLit instanceof Message ? handleFn(msgOrLit.filename, allMessages) : handleFn(msgOrLit, allMessages); + for (const msgOrLit of s.messages) handleFn(msgOrLit, allMessages); // Sort the files/folders alphabetically then print each allPrograms.sort(); diff --git a/src/Terminal/commands/scp.ts b/src/Terminal/commands/scp.ts index a675cc668..03b8b25ed 100644 --- a/src/Terminal/commands/scp.ts +++ b/src/Terminal/commands/scp.ts @@ -34,7 +34,7 @@ export function scp( if (scriptname.endsWith(".lit")) { let found = false; for (let i = 0; i < server.messages.length; ++i) { - if (!(server.messages[i] instanceof Message) && server.messages[i] == scriptname) { + if (server.messages[i] == scriptname) { found = true; break; } diff --git a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts index 184f07e40..d65c8834d 100644 --- a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts +++ b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts @@ -71,7 +71,7 @@ export function determineAllPossibilitiesForTabCompletion( function addAllLitFiles(): void { for (const file of currServ.messages) { - if (!(file instanceof Message)) { + if (!file.endsWith(".msg")) { allPos.push(file); } } @@ -79,8 +79,8 @@ export function determineAllPossibilitiesForTabCompletion( function addAllMessages(): void { for (const file of currServ.messages) { - if (file instanceof Message) { - allPos.push(file.filename); + if (file.endsWith(".msg")) { + allPos.push(file); } } } diff --git a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts index b75bdda21..832b3addc 100644 --- a/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts +++ b/test/Terminal/determineAllPossibilitiesForTabCompletion.test.ts @@ -95,7 +95,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); - Player.getHomeComputer().messages.push(new Message("asl.msg")); + Player.getHomeComputer().messages.push("asl.msg"); Player.getHomeComputer().messages.push("af.lit"); expect(determineAllPossibilitiesForTabCompletion(Player, "rm ", 0)).equal([ "/www/script.js", @@ -120,7 +120,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { it("completes the cat command", () => { Player.getHomeComputer().writeToTextFile("/www/note.txt", "oh hai mark"); - Player.getHomeComputer().messages.push(new Message("asl.msg")); + Player.getHomeComputer().messages.push("asl.msg"); Player.getHomeComputer().messages.push("af.lit"); expect(determineAllPossibilitiesForTabCompletion(Player, "cat ", 0)).equal([ "asl.msg",