Refactor of StationBankAccountComponent.Accounts #42212
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About the PR
I replaced the Accounts and RevenueDistribution fields of StationBankAccountComponent with a single field that uses a CargoAccountData record. I updated all uses of Accounts and RevenueDistribution to use the new field.
Why / Balance
The way it was handled made it really annoying to add new fields for cargo accounts. Each field had its own dictionary mapping accounts to a value. The keys in the dictionaries were all coupled and values were hardcoded into the component.
In the future, new fields can be created by adding a new datafield to CargoAccountData and adjusting the constructor.
Technical details
Replaced the Accounts and RevenueDistribution fields of StationBankAccountComponent with a single field that uses a CargoAccountData record.
Updated all uses of Accounts and RevenueDistribution to use the new field.
Created CargoAccountData record with Balance and RevenueDistribution fields.
Added TryGetAccountBalance. It does what TryGetAccount used to do, but is named better.
TryGetAccount now gets the CargoAccountData and not the balance.
Unhardcoded default balance and distribution values and moved them into base.yml.
Media
Requirements
Breaking changes
StationBankAccountComponent.Accounts is now a dictionary mapping accounts to CargoAccountData. The values that were previously held in StationBankAccountComponent.Accounts and StationBankAccountComponent.RevenueDistribution are now stored in the CargoAccountData in StationBankAccountComponent.Accounts.
TryGetAccount now gets the CargoAccountData and not the balance. Use TryGetAccountBalance to achieve the same effect as the old TryGetAccount.
Changelog
not player facing