Indeed! I pulled a few below (too many?) from my current project, Dino, which is
on github if you want to dig into more.
Some of these make use of custom autoloads, but should still show the
idea. Note the use of bind in places as well, which is making use of the same func/callable improvements.
Inlining a setup_fn to be called on the player after they're respawned:
Creating a bunch of actions that use predicates heavily:
I have a general actions system, so it's nice to be able to
implement small functions to describe some behavior rather than create a fully named function for every piece of logic.
var actions = [
Action.mk({label="Open", fn=open_door,
source_can_execute=func(): return state == door_state.CLOSED}),
Action.mk({label="Close", fn=close_door,
source_can_execute=func(): return state == door_state.OPEN}),
Action.mk({label="Unlock", fn=unlock_door,
source_can_execute=func(): return state == door_state.LOCKED,
actor_can_execute=func(actor):
if actor.has_method("can_unlock_door"):
return actor.can_unlock_door()
}),
Action.mk({label="Jostle", fn=jostle_door,
source_can_execute=func(): return state == door_state.LOCKED,
actor_can_execute=func(actor):
if actor.has_method("can_unlock_door"):
return not actor.can_unlock_door()
return true
})
]