Initialize the floraverse character generator with birthday generation. Implement a calendar conversion to get Floraverse dates.

This commit is contained in:
Feufochmar 2020-02-08 20:24:17 +01:00
parent 6d3276822c
commit ced2dbd15c
3 changed files with 232 additions and 1 deletions

View File

@ -12,20 +12,37 @@
"src/pages/sitemap.rkt"
"src/pages/home.rkt"
"src/pages/other-generators.rkt"
"src/pages/arnytron.rkt")
"src/pages/arnytron.rkt"
"src/pages/floraverse.rkt")
; Website
(define *website*
(website
"" weblet pages:home
("AboutMe" weblet pages:about-me)
("Fonts" weblet pages:fonts)
; ToyCatCreator used to be hosted here before moving on its own page
("ToyCatCreator" redirection "http://beleth.pink")
; Symlinks to the character generator
("generator-v1" symlink "/Floraverse/CharacterGenerator")
("generator-v2" symlink "/Floraverse/CharacterGenerator")
("generator" symlink "/Floraverse/CharacterGenerator")
("generator2" symlink "/Floraverse/CharacterGenerator")
("FloraCharacterGenerator" symlink "/Floraverse/CharacterGenerator")
; Floraverse section
("Floraverse" weblet pages:floraverse
("CharacterGenerator" weblet pages:floraverse-character-generator)
("AboutCharacterGenerator" weblet pages:floraverse-character-generator-about)
("Calendar" weblet pages:floraverse-calendar)
("Calendar/{month}/{day}" matching-weblet pages:floraverse-calendar)
)
; Other generators
("Generators" weblet pages:other-generators
("ColorScheme" weblet pages:color-scheme-generator)
("PictogrammicAdventurer" weblet pages:pictogrammic-adventurer)
("Phonagen" weblet pages:phonagen)
("GenerCommunes" weblet pages:gener-communes)
)
; ArnYtron3000
("ArnYtron3000" weblet pages:arnytron
("brut" weblet pages:arnytron-raw)
("json" weblet pages:arnytron-json)
@ -39,6 +56,11 @@
("Home" "/" #f
("About Me" "/AboutMe" #f)
("Fonts I made" "/Fonts" #f))
("Floraverse" "/Floraverse" #f
("Character Generator" "/Floraverse/CharacterGenerator" #t)
("Calendar" "/Floraverse/Calendar" #f)
("About the character generator" "/Floraverse/AboutCharacterGenerator" #f)
)
("Miscellaneous Generators" "/Generators" #f
("Color Scheme" "/Generators/ColorScheme" #f)
("Pictogrammic Adventurer" "/Generators/PictogrammicAdventurer" #t)

View File

@ -0,0 +1,42 @@
#lang racket/base
; Floraverse character generator
; Generates a character and transform it into various formats
(require
json
"flora/calendar.rkt"
)
(provide
; Build generator from a path containing the different json files
make-flora-generator
; Accessors to various parts of the generator
flora-generator-calendar
; Generation of a character
flora-generator-character-generate
; Character accessors
character-birthday)
; Flora generator structure
(struct flora-generator
(calendar ; calendar informations, to generate dates
))
; Build flora generator from json files
(define (make-flora-generator data-dir phonagen-file)
(flora-generator
(jsexpr->calendar (read-json (open-input-file (string-append data-dir "/calendar.json"))))
))
; Character structure
(struct character
(birthday ; Date of birth, as a date+sign
))
; Generator
; Generate a character from a hash of constraints
(define (flora-generator-character-generate floragen (constraints (make-hash)))
(character
(calendar-generate-date (flora-generator-calendar floragen))
))

167
src/pages/floraverse.rkt Normal file
View File

@ -0,0 +1,167 @@
#lang racket/base
; Floraverse-related pages
; Includes the floraverse character generator
(require
racket/string
racket/date
"templates.rkt"
"../generators/flora-character.rkt"
"../generators/flora/calendar.rkt"
"../webcontainer/weblet-parameter.rkt")
(provide
pages:floraverse
pages:floraverse-character-generator-about
pages:floraverse-character-generator
pages:floraverse-calendar)
; The generator
(define *FloraGen* (make-flora-generator "./static/data/flora-generator-data" "./static/data/phonagen.json"))
; Floraverse welcome page
(define pages:floraverse
(pages:template
#:title "Floraverse"
#:author "Feufochmar"
#:date "2020-02-02"
#:content
'(article
(p "As I'm a fan of the " (a ((href "http://floraverse.com")) "Floraverse comic") ", I wrote a generator making characters living in the world of the comic. "
"In fact, I originally made this website to host the generator. "
"This section regroups the character generator and other tools related to the Floraverse universe. ")
)))
; About the generator
(define pages:floraverse-character-generator-about
(pages:template
#:title "About the Floraverse Character Generator"
#:author "Feufochmar"
#:date "2020-02-02"
#:content
'(article
(section
(h3 "Origin")
(p "The character generator is inspired by " (a ((href "http://fav.me/d7569je")) "this journal post on deviantArt") ", "
"which used the " (a ((href "http://marnok.com/content/_adventure/101npcs.php")) "Marnok's NPC generator") " to generate personality traits. "))
(section
(h3 "History")
(p "The current generator is the fifth iteration of the generator. " (br)
"The first version was a written in Java and started as a desktop application, before I added features to run it as a webservice. " (br)
"The second version was written in Guile Scheme and ran only as a webservice. " (br)
"The third version was based on the previous version and was the result of the merger "
"of several generators I wrote and hosted on this website into a single project. " (br)
"The fourth version was caused by a rewrite of this website's backend in Racket. " (br)
"The fifth and current version is an iteration of the previous to separate the data used by the generators from the code. "))
(section
(h3 "Data")
(p "The data used by the generator is available in a git repository, and is mainly written in JSON. "
"To get them: "
(pre
"git clone https://projects.feuforeve.fr/flora-generator-data.git")
"A mirror of the repository is also hosted on " (a ((href "https://github.com/Feufochmar/flora-generator-data")) "GitHub") ". " (br)
"The file structures are documented in the " (code "README.md") " file. "))
(section
(h3 "Code")
(p "The code of the generator is available along with the code of this website in a git repository. "
"It is released under the terms of the GNU General Public License version 2 or any later version (GPLv2+). "
"To get it: "
(pre
"git clone https://projects.feuforeve.fr/feuforeve.v4.git")
"The code is written in " (a ((href "http://racket-lang.org/")) "Racket") ". "))
(section
(h3 "Previous versions")
(p "The code of previous versions of the generator and of this website are also present in git repositories. " (br)
"Fourth version (using Racket): "
(pre
"git clone https://projects.feuforeve.fr/feuforeve.v3.git")
"Third version (using Guile): "
(pre
"git clone https://github.com/Feufochmar/feuforeve.dynamic.git")
"The code of the older versions are not available online anymore. "))
)))
; TODO: move this elsewhere
; Get the ordinal of a given number
(define (ordinal N)
(cond
((and (not (eq? 11 (modulo N 100))) (eq? 1 (modulo N 10))) (string-append (number->string N) "st"))
((and (not (eq? 12 (modulo N 100))) (eq? 2 (modulo N 10))) (string-append (number->string N) "nd"))
((and (not (eq? 13 (modulo N 100))) (eq? 3 (modulo N 10))) (string-append (number->string N) "rd"))
(#t (string-append (number->string N) "th"))))
; Generator page
; TODO: decide on how to present it - may change from previous version.
(define pages:floraverse-character-generator
(pages:template
#:title "Floraverse Character Generator"
#:author "MechaMaskedOwl"
#:content
(lambda (param)
(let* ((chr (flora-generator-character-generate *FloraGen*))
(birthday (character-birthday chr))
)
`(article
(p "WIP")
(p "Born on " ,(ordinal (date+sign-day birthday)) " of " ,(date+sign-month-name birthday) ". " (br)
"Astrological sign: "
(img ((src ,(string-append "/data/flora-generator-data/" (date+sign-sign-symbol birthday)))
(width "16")
(height "16")
))
" " ,(date+sign-sign-name birthday)
)
)))))
; Calendar Tool
(define pages:floraverse-calendar
(pages:template
#:title "Floraverse Calendar"
#:author "MechaMaskedOwl"
#:content
(lambda (param)
(define today (current-date))
(define today-flora (calendar-get-date (flora-generator-calendar *FloraGen*) (date-month today) (date-day today)))
(define req-date (weblet-parameter-ref param 'date #f))
(define split-date (and req-date (string-split req-date "-")))
(define req-month (and split-date (eq? 3 (length split-date)) (cadr split-date)))
(define req-day (and split-date (eq? 3 (length split-date)) (caddr split-date)))
(define match-month (weblet-parameter-ref param 'month #f))
(define match-day (weblet-parameter-ref param 'day #f))
(define month (or (and req-month (string->number req-month))
(and match-month (string->number match-month))))
(define day (or (and req-day (string->number req-day))
(and match-day (string->number match-day))))
(define req-flora
(with-handlers ([exn:fail? (lambda (v) #f)])
(calendar-get-date (flora-generator-calendar *FloraGen*) month day)))
(define (show-date d+s)
`(p
"The YYYY-" ,(number->string (date+sign-month-number d+s)) "-" ,(number->string (date+sign-day d+s)) " "
"is the " ,(ordinal (date+sign-day d+s)) " of " ,(date+sign-month-name d+s) ". " (br)
"This day is under the astrological sign of " ,(date+sign-sign-name d+s) ". " (br)
(img ((src ,(string-append "/data/flora-generator-data/" (date+sign-sign-symbol d+s)))
(width "64")
(height "64")
))))
`(article
,(if req-flora
`(section
(h3 ,(string-append "YYYY-" (number->string month) "-" (number->string day)))
,(show-date req-flora))
"")
(section
(h3 "Today")
,(show-date today-flora))
(section
(h3 "Get the date in Floraverse")
(form ((action "/Floraverse/Calendar"))
(label "Pick a date:"
(input ((name "date")
(type "date")
(value ,(string-append
(number->string (date-year today)) "-"
(number->string (date-month today)) "-"
(number->string (date-day today)))))))
(button "Get Floraverse date")))
))))