added events

This commit is contained in:
Louis Heredero 2024-06-21 02:23:13 +02:00
parent fd5b147e86
commit 9c83f810bb
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
3 changed files with 45 additions and 1 deletions

View File

@ -9,6 +9,15 @@
),) ),)
} }
#let _evt(participant, event) = {
return ((
type: "evt",
participant: participant,
event: event,
lifeline-style: auto
),)
}
#let diagram(elements) = { #let diagram(elements) = {
if elements == none { if elements == none {
return return

View File

@ -1,4 +1,4 @@
#import "diagram.typ": diagram, from-plantuml, _gap #import "diagram.typ": diagram, from-plantuml, _gap, _evt
#import "sequence.typ": _seq #import "sequence.typ": _seq
#import "group.typ": _grp #import "group.typ": _grp

View File

@ -49,6 +49,18 @@
p.max-lifelines = calc.max(p.max-lifelines, p.lifeline-lvl) p.max-lifelines = calc.max(p.max-lifelines, p.lifeline-lvl)
participants.at(i2) = p participants.at(i2) = p
} }
} else if elmt.type == "evt" {
let par-name = elmt.participant
let i = pars-i.at(par-name)
let par = participants.at(i)
if elmt.event == "disable" or elmt.event == "destroy" {
par.lifeline-lvl -= 1
} else if elmt.event == "enable" {
par.lifeline-lvl += 1
par.max-lifelines = calc.max(par.max-lifelines, par.lifeline-lvl)
}
participants.at(i) = par
} }
} }
@ -173,6 +185,29 @@
// Gap // Gap
} else if elmt.type == "gap" { } else if elmt.type == "gap" {
y -= elmt.size y -= elmt.size
// Event
} else if elmt.type == "evt" {
let par-name = elmt.participant
let i = pars-i.at(par-name)
let par = participants.at(i)
let line = lifelines.at(i)
if elmt.event == "disable" {
line.level -= 1
line.lines.push(("disable", y))
} else if elmt.event == "destroy" {
line.lines.push(("destroy", y))
} else if elmt.event == "enable" {
line.level += 1
line.lines.push(("enable", y, elmt.lifeline-style))
} else if elmt.event == "create" {
shapes += participant.render(x-pos, par, y: y)
line.lines.push(("create", y))
}
lifelines.at(i) = line
} }
} }