Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom extracts fully implemented 😎 #54

Open
wants to merge 8 commits into
base: next
Choose a base branch
from

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.

@@ -139,6 +143,12 @@ class PathToTarkov implements IPreSptLoadMod, IPostSptLoadMod {

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

@@ -137,7 +137,28 @@ const ALL_DUMPED_EXFILS_FROM_SCRIPT = {
'Nakatani_stairs_free_exit',
],
};

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
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