rlazarus / MUSS

Multi-User Shared Setting, a modern-day reimplementation of the multiuser text game.
8 stars 1 forks source link

Move equipment commands to muss.equipment. #90

Open relsqui opened 11 years ago

relsqui commented 11 years ago

If that doesn't work, make it work. That's what modules are FOR.

relsqui commented 11 years ago

So it doesn't, because all_commands looks in muss.commands and nowhere else. Should it look in the whole module, is there a better way to do it, or should I not be trying to do this at all?

rlazarus commented 11 years ago

Having all_commands look only in muss.commands was a first iteration, not a permanent solution. In general we'll want to be able to pull in global commands from outside of that module.

Searching all of muss.* would be one way, but is pretty kludgey. Some sort of registration might be the better way to go -- each module registers its commands once at import time, and they're stored centrally in a data structure that can be quickly searched at parse time.

This is still only for globals -- local commands will be a different animal. We can flesh this out some more either here or in IRC, or you can take it away and prototype if you'd rather. (Or I can add it to my pile if you're not into it.)

relsqui commented 11 years ago

Hmm-- by registering commands, do you mean something like this, in my module?

from muss import parser

def Foo(parser.Command):
    pass

parser.command_registry[__loader__] = [Foo]

That rather than command-name-based dictionary keys because command names are complicated--although if we specifically wanted to optimize for that, it wouldn't be hard to do. Grouping them by module seems like a good idea anyway, for when we want to unload or reload a module.

Off the top of my head, I figure local commands will use normal parser tricks to locate objects in scope (NearbyObject seems sensible) and then just look for commands (subclasses of Command?) on 'em.

I could take this one on, or let you if you want to work on it. I don't feel strongly about it.