Skip to content

Commit

Permalink
CODEBASE: Move Availability and Attempt to a more generic place
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg committed Nov 3, 2024
1 parent a12c48e commit 5719fa1
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/Bladeburner/Actions/Action.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/Bladeburner/Actions/BlackOperation.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/Bladeburner/Actions/LevelableAction.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/Bladeburner/Actions/Operation.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/Bladeburner/Bladeburner.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/Bladeburner/Skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
8 changes: 0 additions & 8 deletions src/Bladeburner/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ export interface SuccessChanceParams {
est: boolean;
}

type AvailabilitySuccess<T extends object> = { available: true } & T;
type AvailabilityFailure = { available?: undefined; error: string };
export type Availability<T extends object = object> = AvailabilitySuccess<T> | AvailabilityFailure;

type AttemptSuccess<T extends object> = { success: true; message?: string } & T;
type AttemptFailure = { success?: undefined; message: string };
export type Attempt<T extends object = object> = AttemptSuccess<T> | AttemptFailure;

export type Action = Contract | Operation | BlackOperation | GeneralAction;
export type ActionIdFor<ActionType extends Action> = Pick<ActionType, "type" | "name">;

Expand Down
14 changes: 12 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ export type Member<T> = T extends (infer arrayMember)[] ? arrayMember : T[keyof
//** Get the keys of an object where the values match a given type */
export type TypedKeys<Obj, T> = { [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<T extends object> = { available: true } & T;
type AvailabilityFailure = { available?: undefined; error: string };
export type Availability<T extends object = object> = AvailabilitySuccess<T> | AvailabilityFailure;

type AttemptSuccess<T extends object> = { success: true; message?: string } & T;
type AttemptFailure = { success?: undefined; message: string };
export type Attempt<T extends object = object> = AttemptSuccess<T> | 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. */
Expand Down

0 comments on commit 5719fa1

Please sign in to comment.