fix(ui): Report the proper tonnage of commodities sold when departing
Bug fix
This PR addresses the bug described in issue #2172. Closes #2172.
Acknowledgement
- [x] I acknowledge that I have read and understand the Contributing article.
Summary
The trading panel currently increments a "tonsSold" variable any time you sell a commodity. This is then displayed in the "You sold X tons of cargo for Y credits" message when you depart. The problem is that this is incremented for ANY commodity you sell, meaning you could rapidly buy and sell the same commodity over and over again, and as long as you legitimately sold at least one ton of something that you'd brought to the planet (which causes a profit variable to become non-zero and display the message), then the displayed number of tons of cargo sold will have no relation to the profit/loss that is displayed.
This PR changes it so that instead of keeping track of every ton of commodity that you sell, it instead keeps track of which commodities you have on you when you land and compares that to which commodities you have as you're departing. If any particular type of commodity that you depart with is less than it was when you landed, then that is what gets used for the displayed tonnage sold.
Testing Done
Yes.
Could this be added to the existing "basis" tracking infrastructure? When commodities are bought or sold, the cost basis is updated. Could those methods also maintain a second collection of the number of units of each commodity that have been bought or sold, and clear that list when taking off or landing?
Perhaps.
Given that there are other issues with the trading panel's message (see the inaccurate profit count of the issue I linked a few days ago), I'm closing this PR and I'll come back later with a refactor of the cost basis system that addresses both linked issues.