#lang racket/base

; Yggdrasil pages

(require
  "templates.rkt"
  "../webcontainer/weblets.rkt"
  "../generators/yggdrasil.rkt"
  "../generators/yggdrasil/tile-renderer.rkt"
  "../graphics/color.rkt")

(provide
  pages:yggdrasil
  pages:yggdrasil-raw-image
  pages:yggdrasil-about)

; Default renderer
(define yggdrasil-default (make-tile-renderer "static/images/yggdrasil-default.png" 15 (named-color "black")))

; Raw page
(define pages:yggdrasil-raw-image
  (raw-data-weblet
    #:content-type #"image/png"
    #:body
      (lambda (param)
        (define output-port (open-output-bytes))
        (yggdrasil-default
          (yggdrasil-generate)
          output-port)
        (get-output-bytes output-port))))

; Yggdrasil page
(define pages:yggdrasil
  (pages:template
    #:title "Yggdrasil Generator"
    #:author "feuforeve.fr"
    #:stylesheets '("/css/yggdrasil.css")
    #:content
      '(article
        (a ((href "/Yggdrasil")) "New level")
        (p
          (section ((style "display: inline-block;"))
            (img ((alt "Generated Maze") (src "/Yggdrasil/Raw"))))
          (section ((class "keys"))
            (h4 "Keys")
            (span ((class "yggdrasil-default")(id "wall"))) " Wall" (br)
            (span ((class "yggdrasil-default")(id "path"))) " Path" (br)
            (span ((class "yggdrasil-default")(id "staircase-down"))) " Staircase – Start point (go to previous level)" (br)
            (span ((class "yggdrasil-default")(id "staircase-up"))) " Staircase – End point (go to next level)" (br)
            (span ((class "yggdrasil-default")(id "door"))) " Door" (br)
            (span ((class "yggdrasil-default")(id "chest"))) " Chest" (br)
            (span ((class "yggdrasil-default")(id "event"))) " Event (immediate)" (br)
            (span ((class "yggdrasil-default")(id "check"))) " Event (must check)" (br)
            (span ((class "yggdrasil-default")(id "resource-chop"))) " Collect spot (Chop)" (br)
            (span ((class "yggdrasil-default")(id "resource-mine"))) " Collect spot (Mine)" (br)
            (span ((class "yggdrasil-default")(id "resource-take"))) " Collect spot (Take)" (br)
            (span ((class "yggdrasil-default")(id "resource-harvest"))) " Collect spot (Harvest)" (br)
            (span ((class "yggdrasil-default")(id "shortcut-EW"))) " Shortcut (east-west, unlocked from east)" (br)
            (span ((class "yggdrasil-default")(id "shortcut-WE"))) " Shortcut (east-west, unlocked from west)" (br)
            (span ((class "yggdrasil-default")(id "shortcut-NS"))) " Shortcut (north-south, unlocked from north)" (br)
            (span ((class "yggdrasil-default")(id "shortcut-SN"))) " Shortcut (north-south, unlocked from south)" (br)
            )))
      ))

; Yggdrasil about page
(define pages:yggdrasil-about
  (pages:template
    #:title "About the Yggdrasil generator"
    #:author "Feufochmar"
    #:date "2020-04-12"
    #:content
      '(article
        (p "This generator makes dungeons maps. "
           "By default, it displays them in the style of the game series " (a ((href "https://en.wikipedia.org/wiki/Etrian_Odyssey")) "Etrian Odyssey") ". " (br)
           "This generator is named after the giant tree Yggdrasil hosting the labyrinth in those games. " (br)
           "This generator was initially made for the " (a ((href "https://itch.io/jam/procjam2017/rate/193843")) "ProcJam 2017") ". " (br)
           ))
      ))
