From 5dc9ac040aeb410ef97294f1d545137ff98cd5bf Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Mon, 20 Dec 2021 13:29:04 -0500 Subject: [PATCH] toast time config --- src/Locations/ui/SpecialLocation.tsx | 2 +- src/NetscriptFunctions.ts | 4 ++-- .../Player/PlayerObjectGeneralMethods.tsx | 10 +++++++--- src/SaveObject.tsx | 2 +- src/ScriptEditor/NetscriptDefinitions.d.ts | 3 ++- src/ui/React/Snackbar.tsx | 5 +++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Locations/ui/SpecialLocation.tsx b/src/Locations/ui/SpecialLocation.tsx index d158b22cf..0d2b1cd83 100644 --- a/src/Locations/ui/SpecialLocation.tsx +++ b/src/Locations/ui/SpecialLocation.tsx @@ -86,7 +86,7 @@ export function SpecialLocation(props: IProps): React.ReactElement { function renderNoodleBar(): React.ReactElement { function EatNoodles(): void { - SnackbarEvents.emit("You ate some delicious noodles and feel refreshed", "success"); + SnackbarEvents.emit("You ate some delicious noodles and feel refreshed", "success", 2000); N00dles(); // This is the true power of the noodles. if (player.sourceFiles.length > 0) player.giveExploit(Exploit.N00dles); if (player.sourceFileLvl(5) > 0 || player.bitNodeN === 5) { diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index ab0344c2e..89aef6a1a 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -2134,12 +2134,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { message = argsToString([message]); dialogBoxCreate(message); }, - toast: function (message: any, variant: any = "success"): void { + toast: function (message: any, variant: any = "success", duration: any = 2000): void { if (!["success", "info", "warning", "error"].includes(variant)) throw new Error(`variant must be one of "success", "info", "warning", or "error"`); message = argsToString([message]); - SnackbarEvents.emit(message, variant); + SnackbarEvents.emit(message, variant, duration); }, prompt: function (txt: any): any { if (!isString(txt)) { diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index 604fe7a16..b85dee8e7 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -26,7 +26,11 @@ import { Locations } from "../../Locations/Locations"; import { CityName } from "../../Locations/data/CityNames"; import { LocationName } from "../../Locations/data/LocationNames"; import { Sleeve } from "../../PersonObjects/Sleeve/Sleeve"; -import { calculateSkill as calculateSkillF, calculateSkillProgress as calculateSkillProgressF, ISkillProgress } from "../formulas/skill"; +import { + calculateSkill as calculateSkillF, + calculateSkillProgress as calculateSkillProgressF, + ISkillProgress, +} from "../formulas/skill"; import { calculateIntelligenceBonus } from "../formulas/intelligence"; import { getHackingWorkRepGain, @@ -1648,7 +1652,7 @@ export function regenerateHp(this: IPlayer, amt: number): void { export function hospitalize(this: IPlayer): number { const cost = getHospitalizationCost(this); - SnackbarEvents.emit(`You've been Hospitalized for ${numeralWrapper.formatMoney(cost)}`, "warning"); + SnackbarEvents.emit(`You've been Hospitalized for ${numeralWrapper.formatMoney(cost)}`, "warning", 2000); this.loseMoney(cost, "hospitalization"); this.hp = this.max_hp; @@ -2591,7 +2595,7 @@ export function canAccessResleeving(this: IPlayer): boolean { export function giveExploit(this: IPlayer, exploit: Exploit): void { if (!this.exploits.includes(exploit)) { this.exploits.push(exploit); - SnackbarEvents.emit("SF -1 acquired!", "success"); + SnackbarEvents.emit("SF -1 acquired!", "success", 2000); } } diff --git a/src/SaveObject.tsx b/src/SaveObject.tsx index 8e9cd4737..1e0457a72 100755 --- a/src/SaveObject.tsx +++ b/src/SaveObject.tsx @@ -69,7 +69,7 @@ class BitburnerSaveObject { save(saveString) .then(() => { if (!Settings.SuppressSavedGameToast) { - SnackbarEvents.emit("Game Saved!", "info") + SnackbarEvents.emit("Game Saved!", "info", 2000); } }) .catch((err) => console.error(err)); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index f1602a461..e825e73cf 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5296,8 +5296,9 @@ export interface NS extends Singularity { * Queue a toast (bottom-right notification). * @param msg - Message in the toast. * @param variant - Type of toast, must be one of success, info, warning, error. Defaults to success. + * @param duration - Duration of toast in ms, defaults to 2000 */ - toast(msg: any, variant?: string): void; + toast(msg: any, variant?: string, duration?: number): void; /** * Download a file from the internet. diff --git a/src/ui/React/Snackbar.tsx b/src/ui/React/Snackbar.tsx index d70e28af9..30f59b2bd 100644 --- a/src/ui/React/Snackbar.tsx +++ b/src/ui/React/Snackbar.tsx @@ -16,16 +16,17 @@ export function SnackbarProvider(props: IProps): React.ReactElement { ); } -export const SnackbarEvents = new EventEmitter<[string, "success" | "warning" | "error" | "info"]>(); +export const SnackbarEvents = new EventEmitter<[string, "success" | "warning" | "error" | "info", number]>(); export function Snackbar(): React.ReactElement { const { enqueueSnackbar } = useSnackbar(); useEffect(() => - SnackbarEvents.subscribe((s, variant) => + SnackbarEvents.subscribe((s, variant, duration) => enqueueSnackbar({s}, { content: (k, m) => {m}, variant: variant, + autoHideDuration: duration, }), ), );