From 5719fa1f7321d4e4f2b5bdba981cdaf92f23a406 Mon Sep 17 00:00:00 2001 From: CatLover <152669316+catloversg@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:11:26 +0700 Subject: [PATCH] CODEBASE: Move Availability and Attempt to a more generic place --- src/Bladeburner/Actions/Action.ts | 3 ++- src/Bladeburner/Actions/BlackOperation.ts | 3 ++- src/Bladeburner/Actions/LevelableAction.ts | 2 +- src/Bladeburner/Actions/Operation.ts | 3 ++- src/Bladeburner/Bladeburner.ts | 3 ++- src/Bladeburner/Skill.ts | 2 +- src/Bladeburner/Types.ts | 8 -------- src/types.ts | 14 ++++++++++++-- 8 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Bladeburner/Actions/Action.ts b/src/Bladeburner/Actions/Action.ts index 71163d810e..0c7699cced 100644 --- a/src/Bladeburner/Actions/Action.ts +++ b/src/Bladeburner/Actions/Action.ts @@ -1,6 +1,7 @@ import type { Bladeburner } from "../Bladeburner"; import type { Person } from "../../PersonObjects/Person"; -import type { Availability, SuccessChanceParams } from "../Types"; +import type { SuccessChanceParams } from "../Types"; +import type { Availability } from "../../types"; import type { Skills as PersonSkills } from "../../PersonObjects/Skills"; import { addOffset } from "../../utils/helpers/addOffset"; diff --git a/src/Bladeburner/Actions/BlackOperation.ts b/src/Bladeburner/Actions/BlackOperation.ts index fd75cd4698..0ae2f35669 100644 --- a/src/Bladeburner/Actions/BlackOperation.ts +++ b/src/Bladeburner/Actions/BlackOperation.ts @@ -1,5 +1,6 @@ import type { Bladeburner } from "../Bladeburner"; -import type { ActionIdFor, Availability } from "../Types"; +import type { ActionIdFor } from "../Types"; +import type { Availability } from "../../types"; import { BladeburnerActionType, BladeburnerBlackOpName } from "@enums"; import { ActionClass, ActionParams } from "./Action"; diff --git a/src/Bladeburner/Actions/LevelableAction.ts b/src/Bladeburner/Actions/LevelableAction.ts index 8b52151220..421218c05f 100644 --- a/src/Bladeburner/Actions/LevelableAction.ts +++ b/src/Bladeburner/Actions/LevelableAction.ts @@ -1,6 +1,6 @@ import type { Bladeburner } from "../Bladeburner"; import type { IReviverValue } from "../../utils/JSONReviver"; -import type { Availability } from "../Types"; +import type { Availability } from "../../types"; import { ActionClass, ActionParams } from "./Action"; import { getRandomIntInclusive } from "../../utils/helpers/getRandomIntInclusive"; diff --git a/src/Bladeburner/Actions/Operation.ts b/src/Bladeburner/Actions/Operation.ts index 614839d099..e4d810efca 100644 --- a/src/Bladeburner/Actions/Operation.ts +++ b/src/Bladeburner/Actions/Operation.ts @@ -1,7 +1,8 @@ import type { Person } from "../../PersonObjects/Person"; import type { BlackOperation } from "./BlackOperation"; import type { Bladeburner } from "../Bladeburner"; -import type { ActionIdFor, Availability, SuccessChanceParams } from "../Types"; +import type { ActionIdFor, SuccessChanceParams } from "../Types"; +import type { Availability } from "../../types"; import { BladeburnerActionType, BladeburnerMultName, BladeburnerOperationName } from "@enums"; import { BladeburnerConstants } from "../data/Constants"; diff --git a/src/Bladeburner/Bladeburner.ts b/src/Bladeburner/Bladeburner.ts index b55b833f18..b6fc6a0e29 100644 --- a/src/Bladeburner/Bladeburner.ts +++ b/src/Bladeburner/Bladeburner.ts @@ -1,6 +1,7 @@ import type { PromisePair } from "../Types/Promises"; import type { BlackOperation, Contract, GeneralAction, Operation } from "./Actions"; -import type { Action, ActionIdFor, ActionIdentifier, Attempt } from "./Types"; +import type { Action, ActionIdFor, ActionIdentifier } from "./Types"; +import type { Attempt } from "../types"; import type { Person } from "../PersonObjects/Person"; import type { Skills as PersonSkills } from "../PersonObjects/Skills"; diff --git a/src/Bladeburner/Skill.ts b/src/Bladeburner/Skill.ts index c14c0724af..86246261d9 100644 --- a/src/Bladeburner/Skill.ts +++ b/src/Bladeburner/Skill.ts @@ -2,7 +2,7 @@ import type { BladeburnerMultName, BladeburnerSkillName } from "@enums"; import { currentNodeMults } from "../BitNode/BitNodeMultipliers"; import { Bladeburner } from "./Bladeburner"; -import { Availability } from "./Types"; +import type { Availability } from "../types"; import { PositiveInteger, PositiveNumber, isPositiveInteger } from "../types"; import { PartialRecord, getRecordEntries } from "../Types/Record"; diff --git a/src/Bladeburner/Types.ts b/src/Bladeburner/Types.ts index 00517f0d28..aea1432b3f 100644 --- a/src/Bladeburner/Types.ts +++ b/src/Bladeburner/Types.ts @@ -5,14 +5,6 @@ export interface SuccessChanceParams { est: boolean; } -type AvailabilitySuccess = { available: true } & T; -type AvailabilityFailure = { available?: undefined; error: string }; -export type Availability = AvailabilitySuccess | AvailabilityFailure; - -type AttemptSuccess = { success: true; message?: string } & T; -type AttemptFailure = { success?: undefined; message: string }; -export type Attempt = AttemptSuccess | AttemptFailure; - export type Action = Contract | Operation | BlackOperation | GeneralAction; export type ActionIdFor = Pick; diff --git a/src/types.ts b/src/types.ts index 384bbdd8d9..293e268643 100644 --- a/src/types.ts +++ b/src/types.ts @@ -24,13 +24,23 @@ export type Member = T extends (infer arrayMember)[] ? arrayMember : T[keyof //** Get the keys of an object where the values match a given type */ export type TypedKeys = { [K in keyof Obj]-?: Obj[K] extends T ? K : never }[keyof Obj]; -/** Status object for functions that return a boolean indicating success/failure - * and an optional message */ +/** + * Status object for functions that return a boolean indicating success/failure + * and an optional message + */ export interface IReturnStatus { res: boolean; msg?: string; } +type AvailabilitySuccess = { available: true } & T; +type AvailabilityFailure = { available?: undefined; error: string }; +export type Availability = AvailabilitySuccess | AvailabilityFailure; + +type AttemptSuccess = { success: true; message?: string } & T; +type AttemptFailure = { success?: undefined; message: string }; +export type Attempt = AttemptSuccess | AttemptFailure; + /** Defines the minimum and maximum values for a range. * It is up to the consumer if these values are inclusive or exclusive. * It is up to the implementor to ensure max > min. */