Skip to content

Commit 780ceee

Browse files
committed
Less Static
1 parent e11586f commit 780ceee

File tree

2 files changed

+59
-60
lines changed

2 files changed

+59
-60
lines changed

src/OpenExtracts.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,51 @@ import { Configuration } from "./types";
99
/**
1010
* The main class of the OpenExtracts mod.
1111
*/
12-
export class OpenExtracts implements IPostDBLoadMod, IPreSptLoadMod {
13-
public static container: DependencyContainer;
14-
public static logger: ILogger;
15-
public static config: Configuration | null = null;
12+
class OpenExtracts implements IPostDBLoadMod, IPreSptLoadMod {
13+
public logger: ILogger;
14+
public config: Configuration | null = null;
1615

1716
/**
1817
* Handle loading the configuration file and registering our custom MatchCallbacks class.
1918
* Runs before the database is loaded.
2019
*/
2120
public preSptLoad(container: DependencyContainer): void {
22-
OpenExtracts.container = container;
21+
this.logger = container.resolve<ILogger>("WinstonLogger");
2322

24-
// Resolve the logger and save it to the static logger property for simple access.
25-
OpenExtracts.logger = container.resolve<ILogger>("WinstonLogger");
26-
27-
// Load and validate the configuration file, saving it to the static config property for simple access.
23+
// Load and validate the configuration file.
2824
try {
29-
OpenExtracts.config = new ConfigServer().loadConfig().validateConfig().getConfig();
25+
this.config = new ConfigServer().loadConfig().validateConfig().getConfig();
3026
} catch (error: any) {
31-
OpenExtracts.config = null; // Set the config to null so we know it's failed to load or validate.
32-
OpenExtracts.logger.log(`OpenExtracts: ${error.message}`, "red");
27+
this.config = null; // Set the config to null so we know it's failed to load or validate.
28+
this.logger.log(`OpenExtracts: ${error.message}`, "red");
3329
}
3430

3531
// Set a flag so we know that we shouldn't continue when the postDBLoad method fires... just setting the config
3632
// back to null should do the trick. Use optional chaining because we have not yet checked if the config is
3733
// loaded and valid yet.
38-
if (OpenExtracts.config?.general?.enabled === false) {
39-
OpenExtracts.config = null;
40-
OpenExtracts.logger.log("OpenExtracts is disabled in the config file.", "red");
34+
if (this.config?.general?.enabled === false) {
35+
this.config = null;
36+
this.logger.log("OpenExtracts is disabled in the config file.", "red");
4137
}
4238

4339
// If the configuration is null at this point we can stop here.
44-
if (OpenExtracts.config === null) {
40+
if (this.config === null) {
4541
return;
4642
}
4743
}
4844

4945
/**
5046
* Trigger the changes to extracts once the database has loaded.
5147
*/
52-
public postDBLoad(): void {
48+
public postDBLoad(container: DependencyContainer): void {
5349
// If the configuration is null at this point we can stop here. This will happen if the configuration file
5450
// failed to load, failed to validate, or if the mod is disabled in the configuration file.
55-
if (OpenExtracts.config === null) {
51+
if (this.config === null) {
5652
return;
5753
}
5854

5955
// Modify the extracts based on the configuration.
60-
new ExtractAdjuster();
56+
new ExtractAdjuster(container, this.config).makeAdjustments();
6157
}
6258
}
6359

src/adjusters/ExtractAdjuster.ts

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { Exit, ILocationBase } from "@spt/models/eft/common/ILocationBase";
22
import { ILocations } from "@spt/models/spt/server/ILocations";
33
import { DatabaseServer } from "@spt/servers/DatabaseServer";
4-
import { OpenExtracts } from "../OpenExtracts";
4+
import { DependencyContainer } from "tsyringe";
5+
import { ILogger } from "@spt/models/spt/utils/ILogger";
6+
import { Configuration } from "../types";
57

68
/**
79
* The `ExtractAdjuster` class is responsible for orchestrating adjustments to game extracts according to a predefined
810
* configuration. It contains methods to adjust individual and global extract properties based on the current
911
* configuration settings.
1012
*/
1113
export class ExtractAdjuster {
14+
private container: DependencyContainer;
15+
private logger: ILogger;
16+
private config: Configuration;
17+
1218
// This is a mapping of location names as they are represented in the game to their configuration and human-readable
1319
// counterparts. This is used to convert the location name from the game to the name used in the configuration file.
1420
/* eslint-disable @typescript-eslint/naming-convention */
@@ -29,20 +35,20 @@ export class ExtractAdjuster {
2935
/* eslint-enable @typescript-eslint/naming-convention */
3036

3137
/**
32-
* Make the adjustments to the extracts once the class is instantiated.
38+
* Constructs a new instance of the `ExtractAdjuster` class.
3339
*/
34-
constructor() {
35-
this.makeAdjustments();
40+
constructor(container: DependencyContainer, config: Configuration) {
41+
this.container = container;
42+
this.logger = this.container.resolve<ILogger>("WinstonLogger");
43+
this.config = config;
3644
}
3745

3846
/**
3947
* Orchestrates the adjustment of extracts according to the configuration. It iterates over enabled locations and
4048
* performs various adjustments on the extracts based on the rules defined in the configuration.
4149
*/
42-
private makeAdjustments(): void {
43-
const locations: ILocations = OpenExtracts.container
44-
.resolve<DatabaseServer>("DatabaseServer")
45-
.getTables().locations;
50+
public makeAdjustments(): void {
51+
const locations: ILocations = this.container.resolve<DatabaseServer>("DatabaseServer").getTables().locations;
4652
const enabledLocations = ExtractAdjuster.getEnabledLocations();
4753

4854
// Iterate over all of the enabled location's exits.
@@ -66,10 +72,7 @@ export class ExtractAdjuster {
6672
}
6773
}
6874

69-
OpenExtracts.logger.log(
70-
"OpenExtracts: Extracts have successfully adjusted according to the configuration.",
71-
"cyan"
72-
);
75+
this.logger.log("OpenExtracts: Extracts have successfully adjusted according to the configuration.", "cyan");
7376
}
7477

7578
/**
@@ -95,7 +98,7 @@ export class ExtractAdjuster {
9598
* Enables all entry points for a specified extract, making it usable regardless of the player's spawn location.
9699
*/
97100
private enableAllEntryPoints(extract: Exit, location: ILocationBase): void {
98-
if (!OpenExtracts.config.extracts.ignoreEntryPoint) {
101+
if (!this.config.extracts.ignoreEntryPoint) {
99102
// Option has been disabled in the configuration file.
100103
return;
101104
}
@@ -107,8 +110,8 @@ export class ExtractAdjuster {
107110
if (extract.EntryPoints !== allEntryPoints) {
108111
extract.EntryPoints = allEntryPoints;
109112

110-
if (OpenExtracts.config.general.debug) {
111-
OpenExtracts.logger.log(
113+
if (this.config.general.debug) {
114+
this.logger.log(
112115
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
113116
location.Id,
114117
"human"
@@ -123,12 +126,12 @@ export class ExtractAdjuster {
123126
* Adjusts the probability of the extract being enabled based on the configuration settings.
124127
*/
125128
private adjustChanceEnabled(extract: Exit, location: ILocationBase): void {
126-
if (!OpenExtracts.config.extracts.random.enabled) {
129+
if (!this.config.extracts.random.enabled) {
127130
// Option has been disabled in the configuration file.
128131
return;
129132
}
130133

131-
const locationConfig = OpenExtracts.config.extracts.random.chances[this.getLocationName(location.Id, "config")];
134+
const locationConfig = this.config.extracts.random.chances[this.getLocationName(location.Id, "config")];
132135

133136
// Return early if we can't find the configuration information for this extract.
134137
if (locationConfig === undefined || locationConfig[extract.Name.trim()] === undefined) {
@@ -140,8 +143,8 @@ export class ExtractAdjuster {
140143
const originalChance = extract.Chance;
141144
extract.Chance = configChance;
142145

143-
if (OpenExtracts.config.general.debug) {
144-
OpenExtracts.logger.log(
146+
if (this.config.general.debug) {
147+
this.logger.log(
145148
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
146149
location.Id,
147150
"human"
@@ -157,7 +160,7 @@ export class ExtractAdjuster {
157160
*/
158161
private adjustMaximumExtractTime(extract: Exit, location: ILocationBase): void {
159162
const originalExtractTime = extract.ExfiltrationTime;
160-
const maxTime = OpenExtracts.config.extracts.maxExtractionTime;
163+
const maxTime = this.config.extracts.maxExtractionTime;
161164

162165
if (originalExtractTime <= maxTime) {
163166
// The original extraction time is already less than or equal to the maximum extraction time.
@@ -166,8 +169,8 @@ export class ExtractAdjuster {
166169

167170
extract.ExfiltrationTime = maxTime;
168171

169-
if (OpenExtracts.config.general.debug) {
170-
OpenExtracts.logger.log(
172+
if (this.config.general.debug) {
173+
this.logger.log(
171174
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
172175
location.Id,
173176
"human"
@@ -181,7 +184,7 @@ export class ExtractAdjuster {
181184
* Converts a cooperation extract to a payment extract according to the configuration settings.
182185
*/
183186
private convertCooperationToPayment(extract: Exit, location: ILocationBase): void {
184-
if (!OpenExtracts.config.extracts.cooperation.convertToPayment) {
187+
if (!this.config.extracts.cooperation.convertToPayment) {
185188
// Option has been disabled in the configuration file.
186189
return;
187190
}
@@ -193,11 +196,11 @@ export class ExtractAdjuster {
193196

194197
extract.PassageRequirement = "TransferItem";
195198
extract.RequirementTip = "EXFIL_Item";
196-
extract.Id = OpenExtracts.config.extracts.cooperation.item;
197-
extract.Count = OpenExtracts.config.extracts.cooperation.number;
199+
extract.Id = this.config.extracts.cooperation.item;
200+
extract.Count = this.config.extracts.cooperation.number;
198201

199-
if (OpenExtracts.config.general.debug) {
200-
OpenExtracts.logger.log(
202+
if (this.config.general.debug) {
203+
this.logger.log(
201204
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
202205
location.Id,
203206
"human"
@@ -218,7 +221,7 @@ export class ExtractAdjuster {
218221
* Removes the backpack requirement from an extract based on the configuration settings.
219222
*/
220223
private removeBackpackRequirement(extract: Exit, location: ILocationBase): void {
221-
if (!OpenExtracts.config.extracts.ignoreBackpackRequirements) {
224+
if (!this.config.extracts.ignoreBackpackRequirements) {
222225
// Option has been disabled in the configuration file.
223226
return;
224227
}
@@ -232,8 +235,8 @@ export class ExtractAdjuster {
232235
extract.RequiredSlot = "FirstPrimaryWeapon";
233236
extract.RequirementTip = "";
234237

235-
if (OpenExtracts.config.general.debug) {
236-
OpenExtracts.logger.log(
238+
if (this.config.general.debug) {
239+
this.logger.log(
237240
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
238241
location.Id,
239242
"human"
@@ -264,7 +267,7 @@ export class ExtractAdjuster {
264267
* Removes the cliff requirement from an extract based on the configuration settings.
265268
*/
266269
private removeCliffRequirements(extract: Exit, location: ILocationBase): void {
267-
if (!OpenExtracts.config.extracts.ignoreCliffRequirements) {
270+
if (!this.config.extracts.ignoreCliffRequirements) {
268271
// Option has been disabled in the configuration file.
269272
return;
270273
}
@@ -277,8 +280,8 @@ export class ExtractAdjuster {
277280
extract.Id = "";
278281
extract.PassageRequirement = "None";
279282

280-
if (OpenExtracts.config.general.debug) {
281-
OpenExtracts.logger.log(
283+
if (this.config.general.debug) {
284+
this.logger.log(
282285
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
283286
location.Id,
284287
"human"
@@ -322,7 +325,7 @@ export class ExtractAdjuster {
322325
* Adjusts the vehicle payment item information.
323326
*/
324327
private adjustVehiclePayment(extract: Exit, location: ILocationBase): void {
325-
if (!OpenExtracts.config.extracts.vehicle.adjustPayment) {
328+
if (!this.config.extracts.vehicle.adjustPayment) {
326329
// Option has been disabled in the configuration file.
327330
return;
328331
}
@@ -332,11 +335,11 @@ export class ExtractAdjuster {
332335
return;
333336
}
334337

335-
extract.Id = OpenExtracts.config.extracts.vehicle.item;
336-
extract.Count = OpenExtracts.config.extracts.vehicle.number;
338+
extract.Id = this.config.extracts.vehicle.item;
339+
extract.Count = this.config.extracts.vehicle.number;
337340

338-
if (OpenExtracts.config.general.debug) {
339-
OpenExtracts.logger.log(
341+
if (this.config.general.debug) {
342+
this.logger.log(
340343
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
341344
location.Id,
342345
"human"
@@ -369,7 +372,7 @@ export class ExtractAdjuster {
369372
* This will cause the timer for an extract to reset when a player leaves the extract zone.
370373
*/
371374
private resetTimerOnLeave(extract: Exit, location: ILocationBase): void {
372-
if (!OpenExtracts.config.extracts.resetTimerOnLeave) {
375+
if (!this.config.extracts.resetTimerOnLeave) {
373376
// Option has been disabled in the configuration file.
374377
return;
375378
}
@@ -382,8 +385,8 @@ export class ExtractAdjuster {
382385
extract.ExfiltrationType = "Individual";
383386
extract.PlayersCount = 0;
384387

385-
if (OpenExtracts.config.general.debug) {
386-
OpenExtracts.logger.log(
388+
if (this.config.general.debug) {
389+
this.logger.log(
387390
`OpenExtracts: ${extract.Name.trim()} on ${this.getLocationName(
388391
location.Id,
389392
"human"

0 commit comments

Comments
 (0)