Proposal: Using Enums for command switches#399
Proposal: Using Enums for command switches#399LeBulldoge wants to merge 2 commits intoArx-Game:stable_orphanfrom LeBulldoge:alternative_switch
Conversation
|
This doesn't appear to be working: I've never been very fond of Enums. They always seem to result in errors much like the above when you intuitively try to use the thing itself rather than specifying the name or value property. I agree that switches should be more formalized, and Enums do make sense for that, but in this case it looks like you might need to add an |
|
Oh, this PR is more of an example of a way we could possibly use them. It wouldn't work as is, because as I mentioned:
Thinking back, I guess I should've put this in as an issue instead. |
|
Looks like we could just use the |
|
Or, the |
|
Yeah, long term what I'd really want is something equivalent to a DRF viewset where the syntax and helpfile would be built from the different methods you provide, sorta like using the |
Brief overview of PR changes/additions
An example of an alternative for how Arx handles command switches.
Motivation for adding to Arx
After spending some time exploring the code for various commands, it seems to me that the current way Evennia handles command switches tends to completely and utterly destroy code consistency and readability. Jumping into code for a command you've yet to see, is like diving into a minefield. Standardizing the way we handle switches should drastically improve that and Enums seem like the perfect candidate for the job, especially whenever we decide to move to Python 3.10, which adds
matchstatements, making handling this implementation even more of a breeze.As enums require a default value, that means that we could enforce providing documentation for every switch:
This would make helpfiles much more consistent for both the player and the developer.
I provided an example of that in the PR as well.
Thankfully, Evennia already provides us with
switch_optionsinMuxCommand, however, that field expects a list of strings, but changing that is extremely easy, especially since we use a fork of Evennia anyway.As it stands, this implementation wouldn't break any commands that don't utilize
self.switch_optionsalready, letting us port them over at our own pace. In the future,self.switchescould also be changed to provide us with a list of switches already casted to the Enum provided inself.switch_options.