ts convertion

This commit is contained in:
Olivier Gagnon 2021-09-24 16:02:38 -04:00
parent b8faa9dc0b
commit 47f54a11c3
8 changed files with 44 additions and 31 deletions

@ -10,7 +10,7 @@ import { Money } from "../ui/React/Money";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
interface IConstructorParams {
export interface IConstructorParams {
info: string | JSX.Element;
stats?: JSX.Element;
isSpecial?: boolean;

@ -1,3 +0,0 @@
export declare function isRepeatableAug(aug: Augmentation): boolean;
export declare function installAugmentations(): void;
export declare function applyAugmentation(aug: Augmentation, reapply?: boolean): void;

@ -1,6 +1,6 @@
import { Augmentation } from "./Augmentation";
import { Augmentation, IConstructorParams } from "./Augmentation";
import { Augmentations } from "./Augmentations";
import { PlayerOwnedAugmentation } from "./PlayerOwnedAugmentation";
import { PlayerOwnedAugmentation, IPlayerOwnedAugmentation } from "./PlayerOwnedAugmentation";
import { AugmentationNames } from "./data/AugmentationNames";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
@ -18,13 +18,13 @@ import { WHRNG } from "../Casino/RNG";
import React from "react";
function AddToAugmentations(aug) {
var name = aug.name;
function AddToAugmentations(aug: Augmentation): void {
const name = aug.name;
Augmentations[name] = aug;
}
function getRandomBonus() {
var bonuses = [
function getRandomBonus(): any {
const bonuses = [
{
bonuses: {
hacking_chance_mult: 1.25,
@ -124,7 +124,7 @@ function initAugmentations() {
//Time-Based Augment Test
const randomBonuses = getRandomBonus();
const UnstableCircadianModulatorParams = {
const UnstableCircadianModulatorParams: IConstructorParams = {
name: AugmentationNames.UnstableCircadianModulator,
moneyCost: 5e9,
repCost: 3.625e5,
@ -133,7 +133,7 @@ function initAugmentations() {
"unpredictable results based on your circadian rhythm.",
};
Object.keys(randomBonuses.bonuses).forEach(
(key) => (UnstableCircadianModulatorParams[key] = randomBonuses.bonuses[key]),
(key) => ((UnstableCircadianModulatorParams as any)[key] = randomBonuses.bonuses[key]),
);
const UnstableCircadianModulator = new Augmentation(UnstableCircadianModulatorParams);
@ -2359,7 +2359,7 @@ function initAugmentations() {
}
//Resets an Augmentation during (re-initizliation)
function resetAugmentation(newAugObject) {
function resetAugmentation(newAugObject: Augmentation): void {
if (!(newAugObject instanceof Augmentation)) {
throw new Error("Invalid argument 'newAugObject' passed into resetAugmentation");
}
@ -2370,18 +2370,16 @@ function resetAugmentation(newAugObject) {
AddToAugmentations(newAugObject);
}
function applyAugmentation(aug, reapply = false) {
function applyAugmentation(aug: IPlayerOwnedAugmentation, reapply = false): void {
Augmentations[aug.name].owned = true;
const augObj = Augmentations[aug.name];
// Apply multipliers
for (const mult in augObj.mults) {
if (Player[mult] == null) {
console.warn(`Augmentation has unrecognized multiplier property: ${mult}`);
} else {
Player[mult] *= augObj.mults[mult];
}
const v = Player.getMult(mult) * augObj.mults[mult];
Player.setMult(mult, v);
console.log(`${mult} ${v}`);
}
// Special logic for NeuroFlux Governor
@ -2445,11 +2443,11 @@ function installAugmentations() {
prestigeAugmentation();
}
function augmentationExists(name) {
function augmentationExists(name: string) {
return Augmentations.hasOwnProperty(name);
}
export function isRepeatableAug(aug) {
export function isRepeatableAug(aug: Augmentation): boolean {
const augName = aug instanceof Augmentation ? aug.name : aug;
if (augName === AugmentationNames.NeuroFluxGovernor) {

@ -1 +0,0 @@
export declare function showMessage(msg: Message): void;

@ -11,7 +11,7 @@ import { dialogBoxCreate } from "../../utils/DialogBox";
import { Reviver } from "../../utils/JSONReviver";
//Sends message to player, including a pop up
function sendMessage(msg, forced = false) {
function sendMessage(msg: Message, forced = false): void {
msg.recvd = true;
if (forced || !Settings.SuppressMessages) {
showMessage(msg);
@ -19,7 +19,7 @@ function sendMessage(msg, forced = false) {
addMessageToServer(msg, "home");
}
function showMessage(msg) {
function showMessage(msg: Message): void {
var txt =
"Message received from unknown sender: <br><br>" +
"<i>" +
@ -32,14 +32,16 @@ function showMessage(msg) {
}
//Adds a message to a server
function addMessageToServer(msg, serverHostname) {
function addMessageToServer(msg: Message, serverHostname: string): void {
var server = GetServerByHostname(serverHostname);
if (server == null) {
console.warn(`Could not find server ${serverHostname}`);
return;
}
for (var i = 0; i < server.messages.length; ++i) {
if (server.messages[i].filename === msg.filename) {
const msg = server.messages[i];
if (typeof msg === "string") continue;
if (msg.filename === msg.filename) {
return; //Already exists
}
}
@ -95,13 +97,13 @@ function checkForMessagesToSend() {
}
}
function AddToAllMessages(msg) {
function AddToAllMessages(msg: Message): void {
Messages[msg.filename] = msg;
}
let Messages = {};
let Messages: { [key: string]: Message | undefined } = {};
function loadMessages(saveString) {
function loadMessages(saveString: string): void {
Messages = JSON.parse(saveString, Reviver);
}

@ -201,7 +201,7 @@ export interface IPlayer {
inGang(): boolean;
isQualified(company: Company, position: CompanyPosition): boolean;
loseMoney(money: number): void;
reapplyAllAugmentations(resetMultipliers: boolean): void;
reapplyAllAugmentations(resetMultipliers?: boolean): void;
reapplyAllSourceFiles(): void;
regenerateHp(amt: number): void;
recordMoneySource(amt: number, source: string): void;
@ -272,4 +272,6 @@ export interface IPlayer {
commitCrime(numCycles: number): boolean;
checkForFactionInvitations(): void;
setBitNodeNumber(n: number): void;
getMult(name: string): number;
setMult(name: string, mult: number): void;
}

@ -208,7 +208,7 @@ export class PlayerObject implements IPlayer {
inGang: () => boolean;
isQualified: (company: Company, position: CompanyPosition) => boolean;
loseMoney: (money: number) => void;
reapplyAllAugmentations: (resetMultipliers: boolean) => void;
reapplyAllAugmentations: (resetMultipliers?: boolean) => void;
reapplyAllSourceFiles: () => void;
regenerateHp: (amt: number) => void;
recordMoneySource: (amt: number, source: string) => void;
@ -279,6 +279,8 @@ export class PlayerObject implements IPlayer {
commitCrime: (numCycles: number) => boolean;
checkForFactionInvitations: () => void;
setBitNodeNumber: (n: number) => void;
getMult: (name: string) => number;
setMult: (name: string, mult: number) => void;
constructor() {
//Skills and stats
@ -570,6 +572,9 @@ export class PlayerObject implements IPlayer {
this.factionWorkType = "";
this.committingCrimeThruSingFn = false;
this.singFnCrimeWorkerScript = null;
this.getMult = generalMethods.getMult;
this.setMult = generalMethods.setMult;
}
/**

@ -2625,3 +2625,13 @@ export function getIntelligenceBonus(this: IPlayer, weight: number) {
export function getCasinoWinnings(this: IPlayer) {
return this.moneySourceA.casino;
}
export function getMult(this: IPlayer, name: string): number {
if (!this.hasOwnProperty(name)) return 1;
return (this as any)[name];
}
export function setMult(this: IPlayer, name: string, mult: number): void {
if (!this.hasOwnProperty(name)) return;
(this as any)[name] = mult;
}