DEV Community

Daniel Neveux
Daniel Neveux

Posted on

1 1

Wizar devlog 05 - Advancement on Ravioli

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
})

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay