feat(diagrams): add fletcher template

This commit is contained in:
Kristofers Solo 2025-01-01 04:15:12 +02:00
parent d04531d1c1
commit c68065abc7
3 changed files with 272 additions and 0 deletions

123
diagrams.typ Normal file
View File

@ -0,0 +1,123 @@
#import "@preview/fletcher:0.5.3" as fletcher: diagram, node, edge
#import fletcher.shapes: diamond
#let default-node-stroke = 1pt
#let default-edge-stroke = 1pt
// Common filled circle node (terminal node)
#let terminal-node(pos, extrude: none) = {
if extrude != none {
node(
pos,
[],
radius: 6pt,
fill: black,
stroke: default-node-stroke,
extrude: extrude,
)
} else {
node(
pos,
[],
radius: 6pt,
fill: black,
)
}
}
// Common rounded rectangle node
#let action-node(pos, text) = {
node(
pos,
text,
corner-radius: 4pt,
stroke: default-node-stroke,
)
}
// Common diamond node (decision node)
#let decision-node(pos, text) = {
node(
pos,
text,
shape: diamond,
stroke: default-node-stroke,
)
}
// Standard arrow edge
#let std-edge(..args) = {
edge(..args, "-|>", label-pos: 0.1, stroke: default-edge-stroke)
}
// Fork/parallel function
#let parallel-fork(
pos,
paths,
path_spacing: 1,
join_pos: none,
) = {
let elements = ()
// Calculate positions
let path_count = paths.len()
let total_width = (path_count + 1) * path_spacing
let (start_x, start_y) = pos
// Fork bar (horizontal line)
elements.push(
edge(
(start_x - total_width / 2, start_y),
(start_x + total_width / 2, start_y),
stroke: default-edge-stroke * 3,
),
)
// Create paths
for path in paths {
let first_obj_path = path.first().value.pos.raw
let x_offset = first_obj_path.first()
let path_start = (x_offset, start_y)
// Vertical connector from fork bar
elements.push(
std-edge(
path_start,
first_obj_path,
),
)
// Add the path elements
elements += path
}
// Join paths if specified
if join_pos != none {
let (join_x, join_y) = join_pos
// Join bar (horizontal line)
elements.push(
edge(
(join_x - total_width / 2, join_y),
(join_x + total_width / 2, join_y),
stroke: default-edge-stroke * 3,
),
)
// Connect each path to join bar
for path in paths {
let last_obj_path = path.last().value.pos.raw
let x_offset = last_obj_path.first()
let path_end = (x_offset, join_y)
elements.push(
std-edge(
last_obj_path,
path_end,
),
)
}
}
elements
}

View File

@ -1,5 +1,6 @@
#import "@preview/i-figured:0.2.4"
#import "@preview/tablex:0.0.9": tablex
#import "@preview/pintorita:0.1.3"
#let indent = 1cm
@ -18,6 +19,7 @@
date: "",
body,
) = {
set document(author: authors)
set page(
@ -39,6 +41,8 @@
)
show raw: set text(font: "JetBrainsMono NF")
show raw.where(lang: "pintora"): it => pintorita.render(it.text)
show math.equation: set text(weight: 400)
// Formatting for regular text
@ -49,6 +53,7 @@
spacing: 1.5em,
)
show heading: set block(spacing: 1.5em)
set terms(separator: [ -- ])
// Headings
@ -168,6 +173,8 @@
show figure.where(kind: "i-figured-table"): set figure.caption(position: top)
show figure: set par(justify: false) // disable justify for figures (tables)
show figure.where(kind: table): set par(leading: 1em)
show figure.where(kind: image): set par(leading: 0.75em)
show figure.caption: set text(size: 11pt)
show figure.caption: it => {

142
main.typ
View File

@ -3,7 +3,10 @@
#import "@preview/tablex:0.0.9": tablex, rowspanx, colspanx, cellx
#import "@preview/wordometer:0.1.3": word-count, total-words
#import "layout.typ": project, indent-par
#import "@preview/fletcher:0.5.3" as fletcher: diagram, node, edge
#import fletcher.shapes: diamond
#import "utils.typ": *
#import "diagrams.typ": *
#show: word-count
#show: project.with(
@ -830,6 +833,145 @@ Spēle izmanto vairākus resursus globālās konfigurācijas un stāvokļa pārv
#todo("pievienot funkciju projektējumu +diagrammas")
#figure(
caption: "Stāva pārejas diagramma",
kind: image,
diagram(
terminal-node((0, 0)),
std-edge(),
action-node((0, 1), [Pārbaudīt stāva\ pārejas notikumu]),
std-edge(),
decision-node((0, 2), [Vai stāvi\ kustās?]),
std-edge("l,d", [jā]),
std-edge("r,d", [nē]),
terminal-node((-1, 3), extrude: (0, 3)),
action-node((1, 3), [Iegūt pašreizējo\ stāvu]),
std-edge(),
decision-node((1, 4), [Stāva\ notikuma\ tips?]),
std-edge("d", [Pacelties]),
std-edge("r,d,d", [Nolaisties]),
decision-node((1, 5), [Vai nākamais\ stāvs eksistē?]),
std-edge("d", [jā]),
std-edge("l,d", [nē]),
action-node((0, 6), [Izsaukt jauna stāva\ izveides notikumu]),
std-edge("d,d,r"),
action-node((1, 6), [Aprēķināt katra stāva\ jaunās $Y$ koordinātas]),
std-edge("d"),
action-node((1, 7), [Pārvieto visus stāvus\ uz jaunajām $Y$ koordinātām]),
std-edge("d"),
decision-node((2, 6), [Pašreizējais\ stāvs $== 1$?]),
std-edge("d,d,l", [jā]),
std-edge("l", [nē]),
terminal-node((1, 8), extrude: (0, 3)),
),
) <floor-transition-diagram>
#figure(
caption: "Spēlētaja pārejas diagramma",
kind: image,
diagram(
terminal-node((0, 0)),
std-edge(),
action-node((0, 1), [Pārbaudīt stāva\ pārejas notikumu]),
std-edge(),
decision-node((0, 2), [Vai stāvi\ kustās?]),
std-edge("l,d", [jā]),
std-edge("r,d", [nē]),
terminal-node((-1, 3), extrude: (0, 3)),
action-node((1, 3), [Iegūt pašreizējo\ stāvu]),
std-edge(),
decision-node((1, 4), [Stāva\ notikuma\ tips?]),
std-edge("d", [Pacelties]),
std-edge("r,d,d", [Nolaisties]),
decision-node((1, 5), [Vai nākamais\ stāvs eksistē?]),
std-edge("d", [jā]),
std-edge("l,d", [nē]),
action-node((0, 6), [Izsaukt jauna stāva\ izveides notikumu]),
std-edge("d,d,r"),
action-node((1, 6), [Aprēķināt katra stāva\ jaunās $Y$ koordinātas]),
std-edge("d"),
action-node((1, 7), [Pārvieto visus stāvus\ uz jaunajām $Y$ koordinātām]),
std-edge("d"),
decision-node((2, 6), [Pašreizējais\ stāvs $== 1$?]),
std-edge("d,d,l", [jā]),
std-edge("l", [nē]),
terminal-node((1, 8), extrude: (0, 3)),
),
) <player-activity-diagram>
// ```pintora
// activityDiagram
// start
// partition "Ievades apstrāde" {
// :Pārbaudīt spēlētāja ievadi;
// if (Vai ir mērķpozīcija?) then (jā)
// :Skip Movement;
// else (nē)
// :Saņemt virzienu no ievades;
// if (Vai ir pareizs virziens?) then (jā)
// if (Vai ir siena virzienā?) then (jā)
// :Skip Movement;
// else (nē)
// :Iestata mērķpozīciju;
// endif
// else (nē)
// :Skip Movement;
// endif
// endif
// }
//
// partition "Movement Processing" {
// :Calculate Movement Speed;
// if (Has Target?) then (yes)
// :Calculate Target Position;
// if (Reached Target?) then (yes)
// :Update Current Position;
// :Clear Target;
// else (no)
// :Update Position;
// endif
// endif
// }
// partition "Floor Transition" {
// :Check Player Position;
// if (At End Position?) then (yes)
// :Send Ascend Event;
// else (no)
// if (At Start Position?) then (yes)
// if (Floor > 1?) then (yes)
// :Send Descend Event;
// endif
// endif
// endif
// }
// stop
// ```
=== Plākšņu pārvaldas sistēma
Projekta sākotnējā plānošanas posmā tika apsvēra iespēja labirinta elementu