qmuntal / stateless

Go library for creating finite state machines
https://wikipedia.org/wiki/Finite-state_machine
BSD 2-Clause "Simplified" License
974 stars 53 forks source link

Structure transition labels #86

Open codesoap opened 3 months ago

codesoap commented 3 months ago

Inspired by the discussion at #80 I have come up with a new suggestion for visualizing the different types of "self transitions". I'm using Graphviz ability to process HTML-like labels: https://graphviz.org/doc/info/shapes.html#html

The different types of transitions are now grouped and presented with a heading, which describes their type.

Exmaple

var (
    triggerEncounterProblem = "EncounterProblem"
    triggerPunchDesk        = "PunchDesk"
    triggerCry              = "Cry"
    triggerResolveProblems  = "ResolveProblems"
    stateHappy              = "Happy"
    stateUnhappy            = "Unhappy"
)
mood := stateless.NewStateMachine(stateHappy)
mood.Configure(stateHappy).
    Permit(triggerEncounterProblem, stateUnhappy)
mood.Configure(stateUnhappy).
    Permit(triggerResolveProblems, stateHappy).
    PermitReentry(triggerEncounterProblem).
    Ignore(triggerPunchDesk).
    Ignore(triggerCry)

Is rendered this way: mood_demo