Wizar devlog 05 - Advancement on Ravioli
Daniel Neveux
Posted on February 21, 2020
Great advancements on Ravioli this week !
To make it short I am now able to create component instance and add them :
- acceptors
- action
- basic next action predicate
I have also implemented sync, async, cancelable async and composable action.
It remains to implements:
- control state
- more advanced next action predicate
- representation of the model
Here is an example with a mini scenario: A player hits a grunt which auto heals itself twice in reaction.
Next week I will put a live demo online on code sandbox.
test('A player hits a grunt which auto heal itself twice in reaction.',
function() {
const Grunt = component(
object({ hp: number() })
)
.addAcceptor('setHP', model => ({
mutator({ hp }: { hp: number }) {
model.hp = model.hp + hp / 2
},
}))
.addActions({
hit() {
return [
{
type: 'setHP',
payload: {
hp: -2,
},
},
]
},
heal() {
return [
{
type: 'setHP',
payload: {
hp: 6,
},
},
]
},
})
.addNAP("double damage", ({acceptedMutations}, {heal}) => {
const isHit = acceptedMutations.some(({type, payload}) => type === 'setHP' && payload.hp < 0)
const isHealed = acceptedMutations .some(({type, payload}) => type === 'setHP' && payload.hp > 0)
if(isHit) {
console.log("Thrall is hit: -3")
console.log("Buff double heal")
heal()
heal()
}
if (isHealed) {
console.log("Thrall is healed: +6")
}
})
const Thrall = Grunt.create({ hp: 10000 })
Thrall.actions.hit()
expect(getData(Thrall).hp).toBe(10003)
// Battle log:
// Thrall is hit: -3
// Buff double heal
// Thrall is healed: +6
})
💖 💪 🙅 🚩
Daniel Neveux
Posted on February 21, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.