mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 04:35:46 +01:00
DOCUMENTATION: Add link to NS API documentation (#1460)
This commit is contained in:
parent
8ade4801a9
commit
f18d28fc6e
@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
|
- [NS API documentation](https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.ns.md)
|
||||||
- [Learn to program](programming/learn.md)
|
- [Learn to program](programming/learn.md)
|
||||||
- [Remote API](programming/remote_api.md)
|
- [Remote API](programming/remote_api.md)
|
||||||
- [Game Frozen or Stuck?](programming/game_frozen.md)
|
- [Game Frozen or Stuck?](programming/game_frozen.md)
|
||||||
|
@ -15,7 +15,6 @@ import SettingsIcon from "@mui/icons-material/Settings";
|
|||||||
|
|
||||||
import { makeTheme, sanitizeTheme } from "./themes";
|
import { makeTheme, sanitizeTheme } from "./themes";
|
||||||
|
|
||||||
import { CONSTANTS } from "../../Constants";
|
|
||||||
import { Modal } from "../../ui/React/Modal";
|
import { Modal } from "../../ui/React/Modal";
|
||||||
import { Page } from "../../ui/Router";
|
import { Page } from "../../ui/Router";
|
||||||
import { Router } from "../../ui/GameRoot";
|
import { Router } from "../../ui/GameRoot";
|
||||||
@ -23,11 +22,8 @@ import { useBoolean } from "../../ui/React/hooks";
|
|||||||
import { Settings } from "../../Settings/Settings";
|
import { Settings } from "../../Settings/Settings";
|
||||||
import { OptionsModal, OptionsModalProps } from "./OptionsModal";
|
import { OptionsModal, OptionsModalProps } from "./OptionsModal";
|
||||||
import { useScriptEditorContext } from "./ScriptEditorContext";
|
import { useScriptEditorContext } from "./ScriptEditorContext";
|
||||||
|
import { getNsApiDocumentationUrl } from "../../utils/StringHelperFunctions";
|
||||||
|
|
||||||
const docUrl =
|
|
||||||
"https://github.com/bitburner-official/bitburner-src/blob/" +
|
|
||||||
(CONSTANTS.isDevBranch ? "dev" : "stable") +
|
|
||||||
"/markdown/bitburner.ns.md";
|
|
||||||
type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;
|
type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
@ -75,7 +71,7 @@ export function Toolbar({ editor, onSave }: IProps) {
|
|||||||
Terminal (Ctrl/Cmd + b)
|
Terminal (Ctrl/Cmd + b)
|
||||||
</Button>
|
</Button>
|
||||||
<Typography>
|
<Typography>
|
||||||
<Link target="_blank" href={docUrl}>
|
<Link target="_blank" href={getNsApiDocumentationUrl()}>
|
||||||
Documentation
|
Documentation
|
||||||
</Link>
|
</Link>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
@ -3,6 +3,7 @@ import { Link } from "@mui/material";
|
|||||||
import { useNavigator } from "../React/Documentation";
|
import { useNavigator } from "../React/Documentation";
|
||||||
import { CorruptableText } from "../React/CorruptableText";
|
import { CorruptableText } from "../React/CorruptableText";
|
||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
|
import { getNsApiDocumentationUrl } from "../../utils/StringHelperFunctions";
|
||||||
|
|
||||||
export const isSpoiler = (title: string): boolean => title.includes("advanced/") && Player.sourceFileLvl(1) === 0;
|
export const isSpoiler = (title: string): boolean => title.includes("advanced/") && Player.sourceFileLvl(1) === 0;
|
||||||
|
|
||||||
@ -13,12 +14,19 @@ export const A = (props: React.PropsWithChildren<{ href?: string }>): React.Reac
|
|||||||
const onClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
const onClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||||
navigator.navigate(ref, event.ctrlKey);
|
navigator.navigate(ref, event.ctrlKey);
|
||||||
};
|
};
|
||||||
if (ref.startsWith("http"))
|
if (ref.startsWith("http")) {
|
||||||
|
let href = ref;
|
||||||
|
// The URL of NS API documentation in index.md always points to the stable branch, so we need to intercept it here
|
||||||
|
// and change it if necessary.
|
||||||
|
if (href === getNsApiDocumentationUrl(false)) {
|
||||||
|
href = getNsApiDocumentationUrl();
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Link rel="noopener noreferrer" href={props.href} target="_blank">
|
<Link rel="noopener noreferrer" href={href} target="_blank">
|
||||||
{props.children}
|
{props.children}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (isSpoiler(ref))
|
if (isSpoiler(ref))
|
||||||
return (
|
return (
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { Settings } from "../Settings/Settings";
|
import { Settings } from "../Settings/Settings";
|
||||||
|
import { CONSTANTS } from "../Constants";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Converts a date representing time in milliseconds to a string with the format H hours M minutes and S seconds
|
Converts a date representing time in milliseconds to a string with the format H hours M minutes and S seconds
|
||||||
e.g. 10000 -> "10 seconds"
|
e.g. 10000 -> "10 seconds"
|
||||||
120000 -> "2 minutes and 0 seconds"
|
120000 -> "2 minutes and 0 seconds"
|
||||||
*/
|
*/
|
||||||
function convertTimeMsToTimeElapsedString(time: number, showMilli = false): string {
|
export function convertTimeMsToTimeElapsedString(time: number, showMilli = false): string {
|
||||||
const negFlag = time < 0;
|
const negFlag = time < 0;
|
||||||
time = Math.abs(Math.floor(time));
|
time = Math.abs(Math.floor(time));
|
||||||
const millisecondsPerSecond = 1000;
|
const millisecondsPerSecond = 1000;
|
||||||
@ -51,7 +52,7 @@ function convertTimeMsToTimeElapsedString(time: number, showMilli = false): stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finds the longest common starting substring in a set of strings
|
// Finds the longest common starting substring in a set of strings
|
||||||
function longestCommonStart(strings: string[]): string {
|
export function longestCommonStart(strings: string[]): string {
|
||||||
if (!containsAllStrings(strings)) {
|
if (!containsAllStrings(strings)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -72,12 +73,12 @@ function longestCommonStart(strings: string[]): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether an array contains entirely of string objects
|
// Returns whether an array contains entirely of string objects
|
||||||
function containsAllStrings(arr: string[]): boolean {
|
export function containsAllStrings(arr: string[]): boolean {
|
||||||
return arr.every((value) => typeof value === "string");
|
return arr.every((value) => typeof value === "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates a random alphanumeric string with N characters
|
// Generates a random alphanumeric string with N characters
|
||||||
function generateRandomString(n: number): string {
|
export function generateRandomString(n: number): string {
|
||||||
let str = "";
|
let str = "";
|
||||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ function generateRandomString(n: number): string {
|
|||||||
* @param seed A seed to randomize the result
|
* @param seed A seed to randomize the result
|
||||||
* @returns An hexadecimal string representation of the hashed input
|
* @returns An hexadecimal string representation of the hashed input
|
||||||
*/
|
*/
|
||||||
function cyrb53(str: string, seed = 0): string {
|
export function cyrb53(str: string, seed = 0): string {
|
||||||
let h1 = 0xdeadbeef ^ seed;
|
let h1 = 0xdeadbeef ^ seed;
|
||||||
let h2 = 0x41c6ce57 ^ seed;
|
let h2 = 0x41c6ce57 ^ seed;
|
||||||
for (let i = 0, ch; i < str.length; i++) {
|
for (let i = 0, ch; i < str.length; i++) {
|
||||||
@ -108,23 +109,19 @@ function cyrb53(str: string, seed = 0): string {
|
|||||||
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16);
|
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalizeFirstLetter(s: string): string {
|
export function capitalizeFirstLetter(s: string): string {
|
||||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalizeEachWord(s: string): string {
|
export function capitalizeEachWord(s: string): string {
|
||||||
return s
|
return s
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.map((word) => capitalizeFirstLetter(word))
|
.map((word) => capitalizeFirstLetter(word))
|
||||||
.join(" ");
|
.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export function getNsApiDocumentationUrl(isDevBranch = CONSTANTS.isDevBranch): string {
|
||||||
convertTimeMsToTimeElapsedString,
|
return `https://github.com/bitburner-official/bitburner-src/blob/${
|
||||||
longestCommonStart,
|
isDevBranch ? "dev" : "stable"
|
||||||
containsAllStrings,
|
}/markdown/bitburner.ns.md`;
|
||||||
generateRandomString,
|
}
|
||||||
cyrb53,
|
|
||||||
capitalizeFirstLetter,
|
|
||||||
capitalizeEachWord,
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user