Amending NetscriptDefinitions

This commit is contained in:
Phil 2022-01-31 18:15:13 +00:00
parent af43e63415
commit 378f67097c
2 changed files with 15 additions and 12 deletions

@ -5878,19 +5878,22 @@ export interface NS extends Singularity {
tFormat(milliseconds: number, milliPrecision?: boolean): string; tFormat(milliseconds: number, milliPrecision?: boolean): string;
/** /**
* Prompt the player with a Yes/No modal. * Prompt the player with an input modal.
* @remarks * @remarks
* RAM cost: 0 GB * RAM cost: 0 GB
* *
* Prompts the player with a dialog box with two options: Yes and No. * Prompts the player with a dialog box. If `options.type` is undefined or "boolean",
* This function will return true if the player click Yes and false if * the player is shown "Yes" and "No" prompts, which return true and false respectively.
* the player clicks No. The scripts execution is halted until the player * Passing a type of "text" will give the player a text field and a value of "select"
* selects one of the options. * will show a drop-down field. Choosing type "select" will require an array or object
* to be passed via the `options.choices` property.
* The scripts execution is halted until the player selects one of the options.
* *
* @param txt - Text to appear in the prompt dialog box. * @param txt - Text to appear in the prompt dialog box.
* @returns True if the player click Yes and false if the player clicks No. * @param options - Options to modify the prompt the player is shown.
* @returns True if the player click Yes; false if the player clicks No; or the value entered by the player.
*/ */
prompt(txt: string): Promise<boolean>; prompt(txt: string, options?: { type?: "boolean"|"text"|"select"|undefined; choices?: string[] | { [key: string]: string | number } }): Promise<boolean | string>;
/** /**
* Open up a message box. * Open up a message box.

@ -12,7 +12,7 @@ export const PromptEvent = new EventEmitter<[Prompt]>();
interface Prompt { interface Prompt {
txt: string; txt: string;
options?: { type?: string; options?: string[] }; options?: { type?: string; choices?: string[] | { [key: string]: string | number } };
resolve: (result: boolean | string) => void; resolve: (result: boolean | string) => void;
} }
@ -153,11 +153,11 @@ function promptMenuSelect(prompt: Prompt | null, setPrompt: Dispatch<SetStateAct
setValue(event.target.value); setValue(event.target.value);
} }
const getItems = (options: string[] | { [key: string]: string }) : React.ReactElement[] => { const getItems = (choices: string[] | { [key: string]: string | number }) : React.ReactElement[] => {
const content = []; const content = [];
for (const i in options) { for (const i in choices) {
// @ts-ignore // @ts-ignore
content.push(<MenuItem value={i}>{options[i]}</MenuItem>); content.push(<MenuItem value={i}>{choices[i]}</MenuItem>);
} }
return content; return content;
} }
@ -166,7 +166,7 @@ function promptMenuSelect(prompt: Prompt | null, setPrompt: Dispatch<SetStateAct
<> <>
<div style={{ display: 'flex', alignItems: 'center', paddingTop: '10px' }}> <div style={{ display: 'flex', alignItems: 'center', paddingTop: '10px' }}>
<Select onChange={onChange} value={value} style={{ flex: '1 0 auto' }}> <Select onChange={onChange} value={value} style={{ flex: '1 0 auto' }}>
{getItems(prompt?.options?.options || [])} {getItems(prompt?.options?.choices || [])}
</Select> </Select>
<Button onClick={submit}>Confirm</Button> <Button onClick={submit}>Confirm</Button>
</div> </div>