home Components

ComponentGuidelines

A Component is a PUB object that has some specific behaviour or is simply a small part of an object. Let me explain:

Think of a Desk.
~ How can a desk look in code?
~ In PUB a desk is a container of sorts.
~ It can probably contain things ON it and maybe even IN it(drawers).
~ This is where components come into play.

# The following is a bit wrong. The drawer in itself can be used as a component
# on the Desk. When looking for the right way to put stuff "in" the container
# invoke simply checks each component to see if it can be used in that way.
# (try: self.contain[key]?.append(cmd.dirobj)
# except KeyError?: return chain.next().bla(chain,cmd) ) or something the like.

drawer = pub.objs.Container(['Drawer']) desk = pub.objs.Container(['Desk']) desk.contain['on'] = desk.contents desk.contain['in'] = drawer.contents

~ The reason I don't supply drawer.contain is that it defaults to

self.contain['in'] = self.contents. 

So the above is a desk. You can put things on it or in it(in which case it will be put in the drawer.
Or you can put things directly in the drawer.

You could even skip initialisation of drawer and instead do:

desk.contain['in'] = pub.objs.Container(['Drawer']).contents

Umm ok so I didn't really touch on the component part yet.
That's because there hasn't been much added to the desk.

~ We want the drawer to be openable
~ We want it to be lockable
~ We want the desk to be pushable(it's standing on a trapdoor.)

drawer_open_close = pub.components.Openable()
drawer_lock_unlock = pub.components.Lockable()
desk_push = pub.components.Pushable()

~ First we should set things like the key for the drawer
~ We should also create a component that support IPushL? that tells the trapdoor it is revealed when a player pushes it.

drawer.addComponents([drawer_open_close, drawer_lock_unlock])
desk.addComponets([desk_push, desk_reveal_trapdoor])

So lets's see what happens.

You are in a small room there is a desk here.
> examine desk
It looks like an ordinary desk. There is a drawer in it.
>open drawer
The drawer is locked.
>unlock drawer with key
You unlock the drawer with the key.
>open drawer
The drawer is now open, there is a note in the drawer.
>read note
The note reads: Push the desk!
>push desk
You push the desk revealing a trapdoor.
...SNIP...

This is what components should eventually do at a basic level. On a more non-basic level it could be used to create multiple personalities, talking toilets, poisons like alchohol or arsenic. In other words I belive it can be very flexible. All it will need is a good interfaces for object creation(Not easy but it will happen)



subject:
(0 subscribers)