Streamlining

As I transition from engine construction to content creation, I’m finding it a bit cumbersome. Take for example the frequent task of adding small, inconsequential items and scenery, where I just need a name, some accepted identifiers, and a block of descriptive text. Here’s what that process looks like now:

1
2
3
4
5
6
7
8
ecs.e('shiny-trinket', ['thing'], {
'name':'shiny trinket',
'nouns':['trinket','shiny trinket'],
'spawn':'dim-clearing',
'descriptions':{
'default':"A shiny locket, someone's discarded knick-knack. It's empty."
}
});

I think I can do better with some helper functions/macros. When approaching problems like this, I like to work in reverse: writing the code I want to work, then writing the necessary functions and support structures to make it actually run. The target code I want is something like this:

1
item('shiny trinket', "A shiny locket, someone's discarded knick-knack. It's empty.")

This is mostly suitable for barebones items and scenery, where the player doesn’t interact with the entity beyond looking at it and possibly picking it up. Note that the location of the object isn’t specified; the intention is that it’s inferred from context (a bit of a dangerous game, but an idea I’m exploring). The function would work like so:

1
2
3
4
5
6
7
8
9
10
11
12
function item(name, description) {
var item_key = getKeyFromName(name);
var parent = getParentFromContext();
ecs.e(item_key, {
'name':name,
'nouns':[name],
'spawn':parent,
'descriptions':{
'default':description
}
});
}

This got me thinking, though. For the Rulebook system, I built an ORM-style “query builder” of sorts, which uses method chaining to allow expressive creation of rules. Something similar could work for item creation, and support the above trinket example with added flexibility. See:

1
2
3
4
item('shiny trinket', "A shiny locket, someone's discarded knick-knack. It's empty.")
.alias('trinket')
.at('dim-clearing')
.done()

Again, this is mainly intended for simple items. For more complex items and scenery, the current style would be preferred.