#lang racket/base

; Pages with minor generators, often written in javascript
(require
  "templates.rkt"
  "../generators/pictogrammic-adventurer.rkt"
  "../generators/pizzeria.rkt")

(provide
  pages:other-generators
  pages:color-scheme-generator
  pages:pictogrammic-adventurer
  pages:phonagen
  pages:gener-communes
  pages:pizzeria)

; About page on the other generators
(define pages:other-generators
  (pages:template
    #:title "Miscellaneous Generators"
    #:author "Feufochmar"
    #:date "2019-11-08"
    #:content
      '(article
        (p "One of the thing I like to code as a hobby are procedural generators. "
           "This section regroups little other generators I wrote, but that are not important enough to have their own section. "
           "Some where made during the " (a ((href "http://www.procjam.com/")) "PROCJAM") " sessions, a recurrent coding jam about procedural generation. "
           "So they may also be present on my " (a ((href "https://feufochmar.itch.io/")) " itch.io page") ". ")
        )))

; Color Scheme Generator
(define (color-scheme-block name type)
  `(div ((class "palette-block"))
    (p ((id ,(string-append "wheel." type)) (class "palette-wheel")) "")
    (p ((class "palette-name")) ,name)
    ,@(build-list 5
        (lambda (i)
          (let ((j (+ 1 i)))
            `(p ((id ,(string-append "color-" (number->string j) "-" type))
                 (class "palette-color"))
                ,(string-append "Color." (number->string j) "." name)))))))

(define pages:color-scheme-generator
  (pages:template
    #:title "Color Scheme Generator"
    #:author "Feufochmar"
    #:date "2019-11-08"
    #:stylesheets '("/css/palette-generator.css")
    #:scripts '("/scripts/palette-generator.js")
    #:on-load "generateScheme();"
    #:content
      `(article
        (section
          (p (button ((onclick "generateScheme();")) "New color scheme")))
        (section
          ,(color-scheme-block "HSL" "hsl")
          ,(color-scheme-block "HSV" "hsv")
          ,(color-scheme-block "LCHab" "lchab")
          ,(color-scheme-block "LCHuv" "lchuv") )
        (section
          (p (h3 "About this generator")
             "This generator creates a small color palette using a cylindrical representation. "
             "This representation is mapped to four different color spaces to generate four color schemes. " (br)
             "The color wheel displayed shows for each colorspace the colors with the hues from 0° to 360°, "
             "a lightness or value of 50%, and a saturation or chroma of 100%. " (br)
             "The colors are displayed with their RGB values. "
             ))
       )))

(define *adventurer-generator* (make-pictogrammic-adventurer-generator "./static/data/pictogrammic-adventurer.json"))
(define pages:pictogrammic-adventurer
  (pages:template
    #:title "Pictogrammic Adventurer Generator"
    #:author "feuforeve.fr"
    #:stylesheets '("/css/adventurer-generator.css")
    #:content
      (lambda (param)
        (let ((adv (pictogrammic-adventurer-generate *adventurer-generator*)))
          `(article
            (section
              (a ((href "/Generators/PictogrammicAdventurer")) "New adventurer")
              (h3 "Adventurer's statistics")
              (table
                ,@(map
                    (lambda (x)
                      `(tr (td (strong ,(car x)))
                           (td ((class "adventurer-stats")) ,((cdr x) adv))))
                    `(("Name" . ,adventurer-name)
                      ("Gender" . ,adventurer-gender)
                      ("Species" . ,adventurer-species)
                      ("Class" . ,adventurer-class)
                      ("Health" . ,adventurer-health)
                      ("Mana" . ,adventurer-mana)
                      ("Spells" . ,adventurer-spells)
                      ("Status" . ,adventurer-status)
                      ("Equiped" . ,adventurer-equipment)
                      ("Inventory" . ,adventurer-inventory)
                      ("Party" . ,adventurer-party)
                      ("Battle cry" . ,adventurer-battle-cry)
                      ("Astrological sign" . ,adventurer-astrological-sign)
                      ("Home" . ,adventurer-living-place)
                      ("Destiny cards" . ,adventurer-cards)))))
            (section
              (h3 "About this generator")
              (p "This generator makes adventurer characters whose statistics are represented by symbols and pictograms. " (br)
                 "The font " (a ((href "http://users.teilar.gr/~g1951d/")) "Symbola") " is used to display the pictograms. "))
            )))))

(define pages:phonagen
  (pages:template
    #:title "Phonagen"
    #:author "Feufochmar"
    #:date "2019-11-10"
    #:stylesheets '("/css/phonagen.css")
    #:scripts '("/scripts/phonagen.js")
    #:on-load "phonagen.load('/data/phonagen.json');"
    #:content
      '(article
        (p "Select a word generator from the list and click generate.")
        (section ((id "phonagen")))
        (section
          (h3 "About this generator")
          (p
            "This generator creates words from a JSON representation of phonologies and word generators. "
            "This is an in-browser version of the generator used in the " (a ((href "/Floraverse/CharacterGenerator")) "Floraverse Character Generator") " for the character's name." (br)
            "It was made for the " (a ((href "https://itch.io/jam/procjam/rate/271994")) "ProcJam:Summer 2018") ". " (br)
            "The tools used to assemble the JSON representation and the source code of the in-browser generator is available through git: "
            (pre "git clone https://projects.feuforeve.fr/phonagen.git")))
      )))

(define pages:gener-communes
  (pages:template
    #:title "Un Village en France"
    #:author "Feufochmar"
    #:date "2019-11-10"
    #:stylesheets '("/css/gener-communes.css")
    #:scripts '("/scripts/gener-communes.js")
    #:on-load "genercommunes.load('/data/gener-communes.json')"
    #:content
      '(article
        (p "Select a departement from the list and click generate.")
        (section ((id "gener-communes")))
        (section
          (h3 "About this generator")
          (p
            "This generator was made for the " (a ((href "https://itch.io/jam/procjam/rate/511765")) "ProcJam 2019") ". " (br)
            "It creates municipality names from a JSON file that was generated after analysing the list of all french municipalities by departement. " (br)
            "The generator uses grammatical trees to represent the possible names, and fill them with either words taken from lists or generated using Markov chains. " (br)
            "The JSON file was generated by analysing the names to compute the possible trees and their probabilities, the distributions of words, and Markov chain generators. " (br)
            "For instance, a name like " (code "Saint-Pourçain-sur-Sioule") " was analysed as the tree " (code "(sur (Saint $MasculineName$) $RiverName$)") ", "
            "the word " (code "Pourçain") " as an element of the " (code "$MasculineName$") " word distribution, "
            "and the word " (code "Sioule") " as an input of the Markov chain generating river names. "
            ))
      )))

(define *pizzeria-generator* (make-pizzeria-generator "./static/data/pizza.json"))
(define pages:pizzeria
  (pages:template
    #:title "Pizzeria"
    #:author "feuforeve.fr"
    #:content
      (lambda (param)
        (define pizzeria (pizzeria-generate *pizzeria-generator*))
        `(article
           (a ((href "/Generators/Pizzeria")) "Nouveau menu")
           (h2 ,(pizzeria-name pizzeria))
           (section
             ,@(map
                 (lambda (pzz)
                   `(article
                       (strong ,(string-upcase (pizza-name pzz)))
                       " — "
                       ,(number->string (pizza-price pzz)) " €"
                       " — "
                       ,(pizza-ingredients-fr pzz)))
                 (pizzeria-menu pizzeria)))
           (section
             (p "Les prix sont toutes taxes comprises et service inclus. "))
           (section
             (h3 "À propos de ce générateur")
             (p "Ce générateur crée un menu de pizzeria à partir de divers ingrédients et de recettes types. " (br)
                "Entrée tardive pour le " (a ((href "https://itch.io/jam/procjam/rate/865690")) "ProcJam 2020") ".")))
        )))
