I did an event flag system this morning. No gif because it's an event flag system: just take my word for it, if you open the chest in the starting room and reload the scene it stays open. Excitement!
Anyway, I had one of those moments while I was doing it: I was lamenting
how I couldn't very easily fit all my event flags into one enum, and I
was thinking of a way to handle that! I had halfway designed this completely ludicrous
solution which would require a custom inspector, and included both an
int to cast to the necessary enum and a separate index value that we'd
use to look up the enum type to cast to and the parameter in
GameStateManager we needed to compare that to.
Basically, it would've been a giant clusterfuck that'd break horribly if you looked at it wrong.
But then I realized that, no, wait, why was I trying to do this?
So I just defined a generic FlagManager type and decided that things
would take a reference to that, and I could then extend FlagManager to
implement the abstract methods that'd actually do the heavy lifting. You
don't need to do some overcomplicated quasi-dynamic type system to
figure out which enum this flag should be cast to and what to compare it
to - just stick the appropriate FlagManager on the thing, pick the flag
from the dropdown, point the thing that needs to look at the flag to
I spent more time designing and scrapping the ludicrously
overcomplicated, look-how-clever-I-am solution to the problem of "event
flags" than I did actually implementing the thing that's in place and
works. And it's not even ugly or anything? There's a little bit of code
repetition that's completely fucking worth it because it lets me
Just Say No to dynamic typing, but it's eminently readable in the way
that the "smarter" solution I came up with in the first place definitely
would not have been.
I do hope the compiler basically inlines the FlagManager object out of
existence, though, lol. Since an enum isn't a "real" type - it's just a
friendly face for the integral type behind it - it'd be really
embarrassing if the result of this design was that I wound up repeating
the same tiny section of machine code 20 times and having
different things using different repetitions of that code to do their
checks for no apparent reason.
Event flags being a thing means keys can be a thing, so keys are now a thing.
Also: man, I really need to build a fight that's not complete shit
sometime soon. Well past the point where that room with the ghosts is