apetavern / grubs

A worms-inspired artillery game for s&box with randomly generated levels.
MIT License
34 stars 7 forks source link

Player stats in Menu #318

Closed DrewBritt closed 1 year ago

DrewBritt commented 1 year ago

In the lobby menu, players now have their "games won" and "grubs killed" stats listed in addition to their playtime.

https://github.com/apetavern/sbox-grubs/assets/43252311/32fca608-1870-43b9-981f-6f3e618c3824

To accomplish this, I refactored PlayMenu's player entries into PlayerEntry.razor, which holds player data + cached stats (rather than fetching everytime we swap stats). Currently, the interval between stats swapping is 15 seconds (for sake of demonstration, the video has 5 second intervals).

DrewBritt commented 1 year ago

Refactored how stats are defined and stored in PlayerEntry, as well as the timer/stat rotation functionality.

I think my only gripe with this system now is that we rely on a static index (_statsIndex), which by itself I think is fine, however, this means that PlayerEntry.NextStat() needs to know the length of the (instanced) Stats container to wrap around to index 0. To circumvent this, I have a static int _statsLength that gets populated in OnAfterTreeRender(), but this feels gross to me. The reason the StatInfo container (_stats) is instanced instead of one static definition is that we have unique values per player entry, meaning with a static StatInfo container we'd need an extra container to hold each value + reaching all around to bring the two together.

Any ideas?