Skip to content

custom extracts fully implemented 😎#54

Open
GrooveypenguinX wants to merge 8 commits intomasterfrom
custom-extracts
Open

custom extracts fully implemented 😎#54
GrooveypenguinX wants to merge 8 commits intomasterfrom
custom-extracts

Conversation

@GrooveypenguinX
Copy link
Collaborator

Server:

  • added InstanceManager.ts : an easy way to get an instance of any sort of SPT import needed (OPTIONAL: if you choose not to implement this, just change the new files I added to dependency injection in the constructor and move the router-hooks to register in the mod.ts)
  • added router-hooks.ts : sets custom routes for the client and server to communicate back and forth. Included is the new route for custom extracts, PathToTarkov/CustomExtracts
  • added custom-extracts.ts : runs all the server logic to get the custom extract .jsons, process their data, and send it to the server/client where it can be used
  • changed path-to-tarkov-controller.ts : simply merged the customextracts with the location.exits at the end of the updateLocationBaseExits method
  • changed mod.ts : registered the instanceManager in preSptLoad and postDbLoad

Client:

  • cleaned up the entire project, organized into Core, Patches, and Utils
  • added WebRequestUtils.cs : sets up communication between server and client via routes
  • added CustomExtractHandler.cs : handles all logic of getting the customextracts from the server and adding them to the available extracts for the client
  • changed InitAllExfiltrations patch : merges the pmcExfilList with our customextracts

@guillaumearm guillaumearm added feature New feature config When related to the PTT config labels Aug 23, 2024
Copy link
Owner

@guillaumearm guillaumearm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a first static review of the code, I don't have tested yet.

Tomorrow I'll test it on my current fika modpack.

Comment on lines 185 to +187
const exfils = ALL_EXFILS[mapName] ?? [];
const customExfils = NEW_CUSTOM_EXFILS[mapName] ?? [];
exfils.push(...customExfils);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const exfils = ALL_EXFILS[mapName] ?? [];
const customExfils = NEW_CUSTOM_EXFILS[mapName] ?? [];
exfils.push(...customExfils);
const vanillaExfils = ALL_EXFILS[mapName] ?? [];
const customExfils = NEW_CUSTOM_EXFILS[mapName] ?? [];
const exfils = {
...vanillaExfils,
...customExfils,
};

everytime isValidExfilForMap is called, this will mutate ALL_EXFILS and add several time the same custom exfils.

mutations is the devil.

Comment on lines 96 to 120
public getJsonFiles(directory: string): string[] {
try {
return fs.readdirSync(path.resolve(__dirname, directory))
.filter(file => file.endsWith(".json"));
} catch (err) {
console.error(`Error reading directory ${directory}:`, err);
return [];
}
}

public loadConfigs(files: string[], directory: string): CustomExitConfig[] {
const configs: CustomExitConfig[] = [];

for (const file of files) {
try {
const filePath = path.resolve(__dirname, directory, file);
const rawData = fs.readFileSync(filePath, "utf8");
configs.push(...JSON.parse(rawData));
} catch (err) {
console.error(`Error reading file ${file}:`, err);
}
}

return configs;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reading json files should be done only once outside of this class. (the readed custom extracts can be just passed into the CustomExtracts constructor)

Comment on lines +148 to +151
if (!this.config.enabled) {
return;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break the current uninstall procedure.

This check is already done few lines later.


public postSptLoad(container: DependencyContainer): void {
this.container = container;
this.instanceManager.postDBLoad(container);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line should be moved into a real postDBLoad ? because we are in the postSptLoad here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a new configs/ExampleCustomExtracts/Tooltips.json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a new configs/ExampleCustomExtracts/config.json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a new configs/ExampleCustomExtracts/customExtracts/exfilConfig.json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a new configs/ExampleCustomExtracts/player_spawnpoints.json

],
};

const ALL_NEW_CUSTOM_EXFILS = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can introduce a new config field enable_custom_exfils that will bypass the validation of the exfils name.

For a first iteration it seems enough.

@guillaumearm guillaumearm changed the base branch from master to next August 24, 2024 08:41
Base automatically changed from next to master January 13, 2025 17:15
@guillaumearm guillaumearm mentioned this pull request Jan 13, 2025
@guillaumearm
Copy link
Owner

Don't worry @GrooveypenguinX I won't forget this PR. Now I'm more comfortable with C# and client-side modding. I think I'll make a standalone mod based on your implementation. stay tuned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config When related to the PTT config feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants