mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 22:22:26 +01:00
Merge pull request #2665 from MartinFournier/feature/ns-ui-getgameinfo
Add ns.ui.getGameInfo() to retrieve game version
This commit is contained in:
commit
b5357ec04e
@ -368,6 +368,7 @@ export const RamCosts: IMap<any> = {
|
||||
getStyles: 0,
|
||||
setStyles: 0,
|
||||
resetStyles: 0,
|
||||
getGameInfo: 0,
|
||||
},
|
||||
|
||||
heart: {
|
||||
|
@ -2,11 +2,13 @@ import { INetscriptHelper } from "./INetscriptHelper";
|
||||
import { WorkerScript } from "../Netscript/WorkerScript";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { getRamCost } from "../Netscript/RamCostGenerator";
|
||||
import { IStyleSettings, UserInterface as IUserInterface, UserInterfaceTheme } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { GameInfo, IStyleSettings, UserInterface as IUserInterface, UserInterfaceTheme } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { Settings } from "../Settings/Settings";
|
||||
import { ThemeEvents } from "../ui/React/Theme";
|
||||
import { defaultTheme } from "../Settings/Themes";
|
||||
import { defaultStyles } from "../Settings/Styles";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { hash } from "../hash/hash";
|
||||
|
||||
export function NetscriptUserInterface(
|
||||
player: IPlayer,
|
||||
@ -84,6 +86,19 @@ export function NetscriptUserInterface(
|
||||
Settings.styles = { ...defaultStyles };
|
||||
ThemeEvents.emit();
|
||||
workerScript.log("ui.resetStyles", () => `Reinitialized styles to default`);
|
||||
},
|
||||
|
||||
getGameInfo: function (): GameInfo {
|
||||
helper.updateDynamicRam("getGameInfo", getRamCost(player, "ui", "getGameInfo"));
|
||||
const version = CONSTANTS.VersionString;
|
||||
const commit = hash();
|
||||
const platform = (navigator.userAgent.toLowerCase().indexOf(" electron/") > -1) ? 'Steam' : 'Browser';
|
||||
|
||||
const gameInfo = {
|
||||
version, commit, platform,
|
||||
}
|
||||
|
||||
return gameInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
17
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4065,6 +4065,13 @@ interface UserInterface {
|
||||
* RAM cost: 0 GB
|
||||
*/
|
||||
resetStyles(): void;
|
||||
|
||||
/**
|
||||
* Gets the current game information (version, commit, ...)
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*/
|
||||
getGameInfo(): GameInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6573,3 +6580,13 @@ interface IStyleSettings {
|
||||
fontFamily: string;
|
||||
lineHeight: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Game Information
|
||||
* @internal
|
||||
*/
|
||||
interface GameInfo {
|
||||
version: string;
|
||||
commit: string;
|
||||
platform: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user