Merge pull request #2665 from MartinFournier/feature/ns-ui-getgameinfo

Add ns.ui.getGameInfo() to retrieve game version
This commit is contained in:
hydroflame 2022-01-17 15:53:43 -05:00 committed by GitHub
commit b5357ec04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

@ -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;
}
}
}

@ -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;
}