mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
API: Updating typing for ns.singularity.getCurrentWork() (#989)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Singularity as ISingularity } from "@nsdefs";
|
||||
import type { Singularity as ISingularity, Task as ITask } from "@nsdefs";
|
||||
|
||||
import { Player } from "@player";
|
||||
import {
|
||||
@@ -1137,7 +1137,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
getCurrentWork: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
if (!Player.currentWork) return null;
|
||||
return Player.currentWork.APICopy();
|
||||
return Player.currentWork.APICopy() as ITask;
|
||||
},
|
||||
exportGame: (ctx) => () => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
@@ -81,7 +81,7 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
||||
|
||||
APICopy(sleeve: Sleeve) {
|
||||
return {
|
||||
type: SleeveWorkType.BLADEBURNER as "BLADEBURNER",
|
||||
type: SleeveWorkType.BLADEBURNER as const,
|
||||
actionType: this.actionType,
|
||||
actionName: this.actionName,
|
||||
tasksCompleted: this.tasksCompleted,
|
||||
|
||||
@@ -42,7 +42,7 @@ export class SleeveClassWork extends SleeveWorkClass {
|
||||
|
||||
APICopy() {
|
||||
return {
|
||||
type: SleeveWorkType.CLASS as "CLASS",
|
||||
type: SleeveWorkType.CLASS as const,
|
||||
classType: this.classType,
|
||||
location: this.location,
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ export class SleeveCompanyWork extends SleeveWorkClass {
|
||||
|
||||
APICopy() {
|
||||
return {
|
||||
type: SleeveWorkType.COMPANY as "COMPANY",
|
||||
type: SleeveWorkType.COMPANY as const,
|
||||
companyName: this.companyName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export class SleeveCrimeWork extends SleeveWorkClass {
|
||||
|
||||
APICopy() {
|
||||
return {
|
||||
type: SleeveWorkType.CRIME as "CRIME",
|
||||
type: SleeveWorkType.CRIME as const,
|
||||
crimeType: this.crimeType,
|
||||
tasksCompleted: this.tasksCompleted,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
|
||||
@@ -53,7 +53,7 @@ export class SleeveFactionWork extends SleeveWorkClass {
|
||||
|
||||
APICopy() {
|
||||
return {
|
||||
type: SleeveWorkType.FACTION as "FACTION",
|
||||
type: SleeveWorkType.FACTION as const,
|
||||
factionWorkType: this.factionWorkType,
|
||||
factionName: this.factionName,
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ export class SleeveInfiltrateWork extends SleeveWorkClass {
|
||||
|
||||
APICopy() {
|
||||
return {
|
||||
type: SleeveWorkType.INFILTRATE as "INFILTRATE",
|
||||
type: SleeveWorkType.INFILTRATE as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
cyclesNeeded: this.cyclesNeeded(),
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ export class SleeveRecoveryWork extends SleeveWorkClass {
|
||||
}
|
||||
|
||||
APICopy() {
|
||||
return { type: SleeveWorkType.RECOVERY as "RECOVERY" };
|
||||
return { type: SleeveWorkType.RECOVERY as const };
|
||||
}
|
||||
|
||||
/** Serialize the current object to a JSON save state. */
|
||||
|
||||
@@ -21,7 +21,7 @@ export class SleeveSupportWork extends SleeveWorkClass {
|
||||
}
|
||||
|
||||
APICopy() {
|
||||
return { type: SleeveWorkType.SUPPORT as "SUPPORT" };
|
||||
return { type: SleeveWorkType.SUPPORT as const };
|
||||
}
|
||||
|
||||
/** Serialize the current object to a JSON save state. */
|
||||
|
||||
@@ -19,7 +19,7 @@ export class SleeveSynchroWork extends SleeveWorkClass {
|
||||
}
|
||||
|
||||
APICopy() {
|
||||
return { type: SleeveWorkType.SYNCHRO as "SYNCHRO" };
|
||||
return { type: SleeveWorkType.SYNCHRO as const };
|
||||
}
|
||||
|
||||
/** Serialize the current object to a JSON save state. */
|
||||
|
||||
+82
-1
@@ -1579,6 +1579,87 @@ export interface TIX {
|
||||
nextUpdate(): Promise<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Study
|
||||
* @remarks
|
||||
* An object representing the current study task
|
||||
* @public
|
||||
*/
|
||||
export interface StudyTask {
|
||||
type: "CLASS";
|
||||
cyclesWorked: number;
|
||||
classType: string;
|
||||
location: string;
|
||||
}
|
||||
/**
|
||||
* Company Work
|
||||
* @remarks
|
||||
* An object representing the current work for a company
|
||||
* @public
|
||||
*/
|
||||
export interface CompanyWorkTask {
|
||||
type: "COMPANY";
|
||||
cyclesWorked: number;
|
||||
companyName: CompanyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Program
|
||||
* @remarks
|
||||
* An object representing the status of the program being created
|
||||
* @public
|
||||
*/
|
||||
export interface CreateProgramWorkTask {
|
||||
type: "CREATE_PROGRAM";
|
||||
cyclesWorked: number;
|
||||
programName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crime
|
||||
* @remarks
|
||||
* An object representing the crime being commited
|
||||
* @public
|
||||
*/
|
||||
export interface CrimeTask {
|
||||
type: "CRIME";
|
||||
cyclesWorked: number;
|
||||
crimeType: CrimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Faction Work
|
||||
* @remarks
|
||||
* An object representing the current work for a faction
|
||||
* @public
|
||||
*/
|
||||
export interface FactionWorkTask {
|
||||
type: "FACTION";
|
||||
cyclesWorked: number;
|
||||
factionWorkType: FactionWorkType;
|
||||
factionName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Faction Work
|
||||
* @remarks
|
||||
* An object representing the current grafting status
|
||||
* @public
|
||||
*/
|
||||
export interface GraftingTask {
|
||||
type: "GRAFTING";
|
||||
cyclesWorked: number;
|
||||
augmentation: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task
|
||||
* @remarks
|
||||
* Represents any task, such as studying, working for a faction etc.
|
||||
* @public
|
||||
*/
|
||||
export type Task = StudyTask | CompanyWorkTask | CreateProgramWorkTask | CrimeTask | FactionWorkTask | GraftingTask;
|
||||
|
||||
/**
|
||||
* Singularity API
|
||||
* @remarks
|
||||
@@ -2487,7 +2568,7 @@ export interface Singularity {
|
||||
*
|
||||
* @returns - An object representing the current work. Fields depend on the kind of work.
|
||||
*/
|
||||
getCurrentWork(): any | null;
|
||||
getCurrentWork(): Task | null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,7 +79,6 @@ interface ClassWorkParams {
|
||||
}
|
||||
|
||||
export const isClassWork = (w: Work | null): w is ClassWork => w !== null && w.type === WorkType.CLASS;
|
||||
|
||||
export class ClassWork extends Work {
|
||||
classType: ClassType;
|
||||
location: LocationName;
|
||||
@@ -132,9 +131,9 @@ export class ClassWork extends Work {
|
||||
}
|
||||
}
|
||||
|
||||
APICopy(): Record<string, unknown> {
|
||||
APICopy() {
|
||||
return {
|
||||
type: this.type,
|
||||
type: WorkType.CLASS as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
classType: this.classType,
|
||||
location: this.location,
|
||||
|
||||
@@ -61,9 +61,9 @@ export class CompanyWork extends Work {
|
||||
}
|
||||
}
|
||||
|
||||
APICopy(): Record<string, unknown> {
|
||||
APICopy() {
|
||||
return {
|
||||
type: this.type,
|
||||
type: WorkType.COMPANY as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
companyName: this.companyName,
|
||||
};
|
||||
|
||||
@@ -96,9 +96,9 @@ export class CreateProgramWork extends Work {
|
||||
}
|
||||
}
|
||||
|
||||
APICopy(): Record<string, unknown> {
|
||||
APICopy() {
|
||||
return {
|
||||
type: this.type,
|
||||
type: WorkType.CREATE_PROGRAM as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
programName: this.programName,
|
||||
};
|
||||
|
||||
@@ -82,9 +82,9 @@ export class CrimeWork extends Work {
|
||||
/** nothing to do */
|
||||
}
|
||||
|
||||
APICopy(): Record<string, unknown> {
|
||||
APICopy() {
|
||||
return {
|
||||
type: this.type,
|
||||
type: WorkType.CRIME as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
crimeType: this.crimeType,
|
||||
};
|
||||
|
||||
@@ -67,9 +67,9 @@ export class FactionWork extends Work {
|
||||
}
|
||||
}
|
||||
|
||||
APICopy(): Record<string, unknown> {
|
||||
APICopy() {
|
||||
return {
|
||||
type: this.type,
|
||||
type: WorkType.FACTION as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
factionWorkType: this.factionWorkType,
|
||||
factionName: this.factionName,
|
||||
|
||||
@@ -79,9 +79,9 @@ export class GraftingWork extends Work {
|
||||
}
|
||||
}
|
||||
|
||||
APICopy(): Record<string, unknown> {
|
||||
APICopy() {
|
||||
return {
|
||||
type: this.type,
|
||||
type: WorkType.GRAFTING as const,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
augmentation: this.augmentation,
|
||||
};
|
||||
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
import { IReviverValue } from "../utils/JSONReviver";
|
||||
import type { IReviverValue } from "../utils/JSONReviver";
|
||||
import type { Task } from "@nsdefs";
|
||||
|
||||
export abstract class Work {
|
||||
type: WorkType;
|
||||
@@ -13,7 +14,7 @@ export abstract class Work {
|
||||
|
||||
abstract process(cycles: number): boolean;
|
||||
abstract finish(cancelled: boolean, suppressDialog?: boolean): void;
|
||||
abstract APICopy(): Record<string, unknown>;
|
||||
abstract APICopy(): Task;
|
||||
abstract toJSON(): IReviverValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user