From 9c83f810bb79dcfee5b065286bf5d87037f17f7d Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Fri, 21 Jun 2024 02:23:13 +0200 Subject: [PATCH] added events --- src/diagram.typ | 9 +++++++++ src/lib.typ | 2 +- src/renderer.typ | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/diagram.typ b/src/diagram.typ index 1078454..c2c2656 100644 --- a/src/diagram.typ +++ b/src/diagram.typ @@ -9,6 +9,15 @@ ),) } +#let _evt(participant, event) = { + return (( + type: "evt", + participant: participant, + event: event, + lifeline-style: auto + ),) +} + #let diagram(elements) = { if elements == none { return diff --git a/src/lib.typ b/src/lib.typ index eb85b65..8574fbd 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -1,4 +1,4 @@ -#import "diagram.typ": diagram, from-plantuml, _gap +#import "diagram.typ": diagram, from-plantuml, _gap, _evt #import "sequence.typ": _seq #import "group.typ": _grp diff --git a/src/renderer.typ b/src/renderer.typ index e3a3f78..b4d6605 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -49,6 +49,18 @@ p.max-lifelines = calc.max(p.max-lifelines, p.lifeline-lvl) 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 } else if elmt.type == "gap" { 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 } }