qmuntal / stateless

Go library for creating finite state machines
BSD 2-Clause "Simplified" License
942 stars 49 forks source link

Structure transition labels #86

Open codesoap opened 1 month ago

codesoap commented 1 month 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