✨ ARCANUM RUNE DIFFICULTY: Apprentice Behavioral

The State Machine of Spellcasting

Allow an object to alter its behavior when its internal state changes in Move.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Flow
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module arcane::state {
    struct Context has store {
        state_id: u8,
    }

    public fun new(): Context {
        Context { state_id: 0 } // 0: Idle
    }

    public fun trigger_action(ctx: &mut Context) {
        if (ctx.state_id == 0) {
            // Idle to Casting
            ctx.state_id = 1;
        } else if (ctx.state_id == 1) {
            // Casting to Cooldown
            ctx.state_id = 2;
        } else if (ctx.state_id == 2) {
            // Cooldown to Idle
            ctx.state_id = 0;
        }
    }
}
Runic Tags: #behavioral #state #move #state-machine