// ----- Project theme ----- #import "variables.typ": theme, theme-var #import "spacers.typ" as spacers #import "set_tables.typ" as st #import "macros.typ" as macros // ============================================================================= // ----- Technique TSV importer ----- // // Imports technique data from a TSV file and renders it as tiered tables. // // Usage: // #techniques("techniques.tsv") // // Expected structure: // // Tier 1 // Technique Niv Type Coût [jauge] Effet ... // ... // // Tier 2 // Technique Niv Type Coût [jauge] Effet ... // ... // ============================================================================= // ----- Define the TSV column mapping ----- // The TSV keeps blood / jauge / other costs separate. // They are merged into a single displayed "Coût" cell. #let technique-columns = ( technique: 0, level: 1, type: 2, blood: 3, jauge: 4, other: 5, effect: 6, ) // ============================================================================= // ----- TSV parsing helpers ----- // ============================================================================= // ----- Safely retrieve a cell with a fallback value ----- #let cell(row, index, default: "") = { if index < row.len() { row.at(index) } else { default } } // ----- Check whether a row contains no data ----- #let is-empty-row(row) = { row.all(value => value.trim() == "") } // ----- Check whether a row is a repeated TSV header ----- #let is-header-row(row) = { row.len() > 0 and cell(row, 0).trim() == "Technique" } // ----- Extract the tier number from a tier marker row ----- #let tier-name(row) = { if row.len() == 0 { none } else { let value = cell(row, 0).trim() if value.starts-with("Tier ") { value.slice(5).trim() } else { none } } } // ============================================================================= // ----- Technique cost formatting ----- // ============================================================================= // ----- Merge blood, jauge and other costs into one displayed cell ----- #let format-cost(blood, jauge, other) = { let parts = () if blood != "" { parts.push(blood + "@blood:short") } if jauge != "" { parts.push(jauge + "@jauge:short") } if other != "" { parts.push(other) } if parts.len() == 0 { "" } else { parts.join(" ") } } // ----- Convert a TSV row into the table's five displayed cells ----- #let technique-row(row) = { let c = technique-columns ( cell(row, c.technique), cell(row, c.level), cell(row, c.type), eval( format-cost( cell(row, c.blood), cell(row, c.jauge), cell(row, c.other), ), mode: "markup", ), eval(cell(row, c.effect), mode: "markup", scope: macros.bigscope), ) } // ============================================================================= // ----- Render a single technique tier ----- // ============================================================================= #let technique-tier-table(tier, rows) = { st.set-table-style( table-headers: (1,), text-size: 8pt, table( columns: ( 3.1cm, 0.48cm, 2.15cm, 0.72cm, 1fr, ), // ----- Use continuous backgrounds without column gutters ----- column-gutter: 0pt, row-gutter: 0pt, stroke: none, align: ( left, center, left, center, left, ), // ------------------------------------------------------------------------- // Tier title // ------------------------------------------------------------------------- ..( table.cell( [ #grid( columns: (auto, 1fr), column-gutter: 0.45em, align: horizon, )[ #text( size: 7.5pt, weight: "bold", fill: theme.gold, )[ #theme-var("section-symbol") ] ][ #text( size: 8.5pt, weight: "bold", fill: theme.dark-gold, tracking: 0.08em, )[ TIER #tier ] ] ], colspan: 5, fill: none, stroke: (top: 0pt, bottom: 0.6pt + theme.border), inset: ( x: 5pt, y: 2.5pt, ), ), // ------------------------------------------------------------------------- // Table header // ------------------------------------------------------------------------- table.header( [Technique], [Niv], [Type], [Coût], [Effet], ), // ------------------------------------------------------------------------- // Technique rows // ------------------------------------------------------------------------- ..rows .enumerate() .map(((index, row)) => { technique-row(row) }) .flatten(), ), ), ) } // ============================================================================= // ----- Parse all technique tiers ----- // ============================================================================= // ----- Group TSV rows by their tier markers ----- #let parse-techniques(data) = { let tiers = () let current-tier = none let current-rows = () for row in data { // ----- Ignore empty separator rows ----- if is-empty-row(row) { continue } // ----- Start a new tier when a tier marker is found ----- let tier = tier-name(row) if tier != none { // Save the previous tier. if current-tier != none { tiers.push(( current-tier, current-rows, )) } current-tier = tier current-rows = () continue } // ----- Ignore repeated TSV headers ----- if is-header-row(row) { continue } // ----- Add technique rows to the current tier ----- // Rows before the first tier are ignored. if current-tier != none { current-rows.push(row) } } // ----- Save the final tier ----- if current-tier != none { tiers.push(( current-tier, current-rows, )) } tiers } // ============================================================================= // ----- Public technique importer ----- // ============================================================================= // ----- Import a TSV file and render its technique tiers ----- #let techniques(path) = { let data = csv( path, delimiter: "\t", ) let tiers = parse-techniques(data) for (index, tier) in tiers.enumerate() { // ----- Limit the number of rendered tiers ----- // TODO: Remove this magic value if (index >= 4) { break } let name = tier.at(0) let rows = tier.at(1) technique-tier-table( name, rows, ) // ----- Add spacing between tiers, but not after the last ----- if index < tiers.len() - 1 { v(0.7em) } } } // ============================================================================= // ----- Class presentation template ----- // ============================================================================= // ----- Render the complete presentation for a class ----- #let school_presentation(class_info) = { set text( font: theme-var("font"), fill: theme.ink, ) // --------------------------------------------------------------------------- // ----- Header ----- // --------------------------------------------------------------------------- align(center)[ #text( size: 20pt, weight: "bold", fill: theme.ink, )[ == #class_info.title ] #v(0.35em) // ----- Ornamental divider ----- #grid( columns: (1fr, auto, 1fr), column-gutter: 0.55em, align: horizon, )[ #line( length: 100%, stroke: 0.7pt + theme.border, ) ][ #text( size: 10pt, fill: theme.gold, )[#theme-var("section-symbol")] ][ #line( length: 100%, stroke: 0.7pt + theme.border, ) ] ] v(1em) // --------------------------------------------------------------------------- // ----- Illustration and introduction ----- // --------------------------------------------------------------------------- grid( columns: (1.05fr, 1.7fr), column-gutter: 1.3em, align: top, // ----- Class illustration ----- [ #block( fill: theme.parchment-dark, stroke: 0.8pt + theme.border, inset: 0.3em, )[ #block( clip: true, stroke: 0.5pt + theme.border, )[ #image( class_info.illustration, width: 100%, ) ] ] ], // ----- Class introduction ----- [ #spacers.fantasy-section("PRÉSENTATION", theme-name: "warm")[ #text( size: 10.2pt, )[ #class_info.description ] ] ], ) v(1em) // --------------------------------------------------------------------------- // ----- Class profile and mechanics ----- // --------------------------------------------------------------------------- spacers.fantasy-rule(theme-name: "warm") v(0.7em) grid( columns: (1fr, 1.35fr), column-gutter: 1.2em, align: top, // ----- Class profile / radar ----- [ #block( fill: theme.parchment, stroke: 0.7pt + theme.border, inset: 0.65em, )[ #align(center)[ #spacers.fantasy-section("PROFIL", theme-name: "warm")[ #image( class_info.radar, width: 82%, ) ] ] ] ], // ----- Class mechanics ----- [ // ----- Exclusive mechanic ----- #block( fill: theme.parchment-dark, stroke: 0.8pt + theme.gold, inset: (x: 0.8em, y: 0.65em), )[ #grid( columns: (auto, 1fr), column-gutter: 0.5em, align: horizon, )[ #text( size: 10pt, fill: theme.gold, )[#theme-var("section-symbol")] ][ #spacers.fantasy-label("MÉCANIQUE EXCLUSIVE", theme-name: "warm") ] #v(0.4em) #text( size: 13pt, weight: "bold", fill: theme.ink, )[ #class_info.mechanic ] #text( size: 10pt, // fill: theme.ink, )[ #class_info.mechanic_description ] ] #v(0.7em) // ----- Display the class difficulty rating ----- #grid( columns: (1fr, auto), align: horizon, )[ #spacers.fantasy-label("DIFFICULTÉ", theme-name: "warm") ][ #grid( // columns: repeat(5, 0.7em), column-gutter: 0.25em, )[ #macros.difficulty-stars(class_info.difficulty) ] ] ], ) v(1em) pagebreak() if ( "introduction" in class_info and class_info.introduction != none ) { class_info.introduction pagebreak() } // ----- Techniques section ----- heading("Techniques", level: 3, numbering: none, outlined: false) techniques(class_info.techniques) }