Allow customizing the first line of the report #60
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.
Use case
We had this great idea to customize the lang files to replace the "Cause of death:" on the first line of the report with "Skill issue:". However, as not all deaths are necessarily skill issues (although some of them surely are), we found the thought of randomly picking either of those very amusing. Making one of the options a rare/easter-egg kind of thing would be next level, but let's not get ahead of ourselves. Just being able to randomize the first line of the report would be great!
The issue
To our great disappointment, it turns out, the report only ever uses the first
UINotesorUICauseOfDeathdefined in the language XML. A somewhat of a major setback, as this prevents any chance of randomizing the darn thing.The solution
Being a persistent bunch of idiots, we didn't let this stop us! When there's a will there's a way!
Rundown of the changes in this PR:
StringifyCauseOfDeath/SelectCauseOfDeathand called it a day, but that would have been a bit messy.LanguageHandler.GetRandomValueByTag(similar toLanguageHandler.GetFirstValueByTag)SelectCauseOfDeathhappened to get the full list of translation values, which was somewhat incompatible with the idea of generalizing the logic. I needed to tweak this to work only with the language tags instead of getting the full list of values.StringifyCauseOfDeathcan simply call eitherGetRandomValueByTagorGetFirstValueByTag, depending on the value ofshouldRandomize. Theresult.Length > 1check is now an implementation detail ofGetRandomValueByTag, so it could be removed from here.HUDManagerPatch.csare very simple: Instead of always callingGetFirstValueByTagwith theTAG_UI_DEATHandTAG_UI_NOTES, use the newGetRandomValueByTag.I tested the changes by adding a bunch of translation variations for
TAG_UI_DEATHandTAG_UI_NOTES, and then proceeding to die in various ways. Seemed to work like a charm, the reports were properly randomized, the first line included.