// in an area.groovy file somewhere in my code
def bb = new BeanBuilder(parentContext)
bb.beans{
townCenter(Room){
name="Town Centre"
description = "You are standing somewhere in the town centre"
exits = [ centreNorth, centreSouth ]
}
centreNorth(Exit){
…
}
..etc..
}
Currently in groovymud (0.2) you need to use the attendant to load groovy objects.
Currenly you can do this:
"load" calls the GroovyScriptEngine to load the object, and configures the instance by using the "configure" method of the MudObjectAttendant. The "configure" method adds the dependencies and registers the bean with the mud registry (effectively registering all the different names of the object in a TreeMap). It also initialises the object for the first time by calling the initialise method.
I've just figured out how to put spring to further use loading single instance objects from groovy. It was my intention just to keep spring for loading objects that require a single instance but were not mud objects. However, the presence of Spring in the groovy layer means I now have the opportunity to do something like this (if we put the mudspace on the runtime classpath):
(in a spring definition xml file)
and then in the code…
Of course I'd have to make MudObjectAttendant more of a "Customizer" object now (which extends the spring groovy Customizer interface) which more tightly integrates the code with Spring.
The other issue I can forsee is that you will need an spring xml file for (at least) every domain there is, if not every package the mud has AND THAT I WOULD BE REQUIRED TO FORMALLY REGISTER EVERY OBJECT IN THE SPRING CONTEXT XML that required loading by the mud. (possible yuckyness)
The bonus is that we can also keep track of every object that requires loading by the mud in the xml files. We could also use more abstract classes (less actual class files) and define those in the spring xml as beans instead of formal objects (and customize them with other beans?) or in the initialiser of a room object. So (for example) we could have a generic human object and then use spring to define 15 slightly different human objects (old man, grandmother, woodsman etc) which can be loaded by the app context in whatever room we want. In effect I go from formally using objects to define every object in the mud to defining beans which determine every object in the mud. The same goes for rooms. I move from formal room class declaration to bean declaration with code in the "virtual area object" to handle the fact the room object is the same actual object as somewhere else the player moves to, just updating internal state instead.
My other worry is that the spring configuration becomes unwieldy and daunting to change, where as code is (reletively) easy. However I could circumvent this by designing a reasonable tool to provide an interface.
My other other worry is that I will have to change the name of the mud from groovymud to springmud… but thats another discussion!
What are your thoughts? What method would you prefer? Spring framework for Mud Objects or Mud Framework for Groovy objects?