I've given a lot of thought on the dsl for the story rules, and if you've seen my ElmConf presentation you know it went through a number of iterations.
However, I'm thinking of changing it one more time!
Reasons:
- Get rid of infix notation
- Add flexibility
- Add clarity
- Follow standard patterns
I really like Luke Westby's forward apply approach, and think it would work well, though it does have some implications on the design.
This is what it would look like:
myStoryRules =
[ Story.rule
|> onInteractionWith (location Hallway)
|> when (inLocation Kitchen)
|> moveTo Hallway
|> narrate "You find a back door leading out..."
...
]
That would build up a record for a story rule of trigger
, condition
, commands
and narration
.
As nice as that is, it loses some constraints from how I have it currently:
- You can "chain" pieces together in any order, though that's really not a problem.
- You can omit pieces, which is fine too, it just means I need some reasonable defaults (no trigger matches every rule, no condition matches every rule, no changes does nothing, no narration gives default narration for the item interacted with.)
- You can duplicate pieces, which gets trickier. Multiple triggers would probably match if any of them matches, multiple conditions would probably match if all of them match, multiple changes would make all of those changes, and multiple narrations would be appended together (which is weird, but works).
Although these implications change some of the fundamental ways of thinking about story rules, I think they make sense and are even more expressive. One downside is losing the possibility to specify all
or any
when giving multiple when
s. I don't see a clean way to add that to the dsl.
Thoughts?
For what it is worth, here are some other alternative approaches that I have considered, but don't like as much:
howItIsNow =
[ interactingWith (location Hallway)
`when` (inLocation Kitchen)
`changesWorld` []
`narrates` afraidOfHallway
]
rawRecord =
[ { trigger = interactingWith (location Hallway)
, condition = (inLocation Kitchen)
, changes = []
, narration = afraidOfHallway
}
]
constrainedTuple =
[ ( interactingWith (location Hallway)
, when (inLocation Kitchen)
, changesWorld []
, narrates afraidOfHallway
)
]