Move ExhaustableArray
into its own file + make it implement interface
This commit is contained in:
parent
946dc52f1a
commit
1dda9efbd7
@ -1,6 +1,6 @@
|
||||
import { inject, injectable } from "tsyringe";
|
||||
|
||||
import { BotGeneratorHelper, ExhaustableArray } from "@spt-aki/helpers/BotGeneratorHelper";
|
||||
import { BotGeneratorHelper } from "@spt-aki/helpers/BotGeneratorHelper";
|
||||
import { BotHelper } from "@spt-aki/helpers/BotHelper";
|
||||
import { BotWeaponGeneratorHelper } from "@spt-aki/helpers/BotWeaponGeneratorHelper";
|
||||
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||
@ -17,6 +17,7 @@ import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
||||
import { ModSpawn } from "@spt-aki/models/enums/ModSpawn";
|
||||
import { IChooseRandomCompatibleModResult } from "@spt-aki/models/spt/bots/IChooseRandomCompatibleModResult";
|
||||
import { EquipmentFilterDetails, EquipmentFilters, IBotConfig } from "@spt-aki/models/spt/config/IBotConfig";
|
||||
import { ExhaustableArray } from "@spt-aki/models/spt/server/ExhaustableArray";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { inject, injectable } from "tsyringe";
|
||||
|
||||
import { ExhaustableArray } from "@spt-aki/helpers/BotGeneratorHelper";
|
||||
import { HandbookHelper } from "@spt-aki/helpers/HandbookHelper";
|
||||
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
||||
@ -32,6 +31,7 @@ import {
|
||||
IRepeatableQuestConfig,
|
||||
} from "@spt-aki/models/spt/config/IQuestConfig";
|
||||
import { IQuestTypePool } from "@spt-aki/models/spt/repeatable/IQuestTypePool";
|
||||
import { ExhaustableArray } from "@spt-aki/models/spt/server/ExhaustableArray";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { EventOutputHolder } from "@spt-aki/routers/EventOutputHolder";
|
||||
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
||||
|
@ -16,7 +16,6 @@ import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
||||
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
||||
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
||||
|
||||
@injectable()
|
||||
@ -512,49 +511,3 @@ export class BotGeneratorHelper
|
||||
: botRole;
|
||||
}
|
||||
}
|
||||
|
||||
/** TODO - move into own class */
|
||||
export class ExhaustableArray<T>
|
||||
{
|
||||
private pool: T[];
|
||||
|
||||
constructor(private itemPool: T[], private randomUtil: RandomUtil, private jsonUtil: JsonUtil)
|
||||
{
|
||||
this.pool = this.jsonUtil.clone(itemPool);
|
||||
}
|
||||
|
||||
public getRandomValue(): T
|
||||
{
|
||||
if (!this.pool?.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = this.randomUtil.getInt(0, this.pool.length - 1);
|
||||
const toReturn = this.jsonUtil.clone(this.pool[index]);
|
||||
this.pool.splice(index, 1);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public getFirstValue(): T
|
||||
{
|
||||
if (!this.pool?.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
const toReturn = this.jsonUtil.clone(this.pool[0]);
|
||||
this.pool.splice(0, 1);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public hasValues(): boolean
|
||||
{
|
||||
if (this.pool?.length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,3 @@ export interface IBotGenerator
|
||||
isPmc: boolean,
|
||||
): PmcInventory;
|
||||
}
|
||||
|
||||
export interface IExhaustableArray<T>
|
||||
{
|
||||
getRandomValue(): T;
|
||||
getFirstValue(): T;
|
||||
hasValues(): boolean;
|
||||
}
|
||||
|
54
project/src/models/spt/server/ExhaustableArray.ts
Normal file
54
project/src/models/spt/server/ExhaustableArray.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
||||
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
||||
|
||||
export class ExhaustableArray<T> implements IExhaustableArray<T>
|
||||
{
|
||||
private pool: T[];
|
||||
|
||||
constructor(private itemPool: T[], private randomUtil: RandomUtil, private jsonUtil: JsonUtil)
|
||||
{
|
||||
this.pool = this.jsonUtil.clone(itemPool);
|
||||
}
|
||||
|
||||
public getRandomValue(): T
|
||||
{
|
||||
if (!this.pool?.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = this.randomUtil.getInt(0, this.pool.length - 1);
|
||||
const toReturn = this.jsonUtil.clone(this.pool[index]);
|
||||
this.pool.splice(index, 1);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public getFirstValue(): T
|
||||
{
|
||||
if (!this.pool?.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
const toReturn = this.jsonUtil.clone(this.pool[0]);
|
||||
this.pool.splice(0, 1);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public hasValues(): boolean
|
||||
{
|
||||
if (this.pool?.length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IExhaustableArray<T>
|
||||
{
|
||||
getRandomValue(): T;
|
||||
getFirstValue(): T;
|
||||
hasValues(): boolean;
|
||||
}
|
Loading…
Reference in New Issue
Block a user