commit b235bda44c31e862494f9db41196791569034e8a Author: Daniel Ziltener Date: Fri Apr 30 07:54:07 2021 +0200 In the beginning there was darkness diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f9e036e --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +deps: ~/.cache/chicken-install/awful-sse/awful.sse.so ~/.cache/chicken-install/mini-kanren/mini-kanren.so + +~/.cache/chicken-install/awful-sse/awful.sse.so: + chicken-install -s awful-sse + +~/.cache/chicken-install/mini-kanren/mini-kanren.so: + chicken-install -s mini-kanren diff --git a/coinage.scm b/coinage.scm new file mode 100644 index 0000000..286a401 --- /dev/null +++ b/coinage.scm @@ -0,0 +1,120 @@ +(import (scheme base) + (chicken port) + (chicken irregex) + (chicken time posix) + srfi-123 + srfi-69 + srfi-48 + srfi-18 + intarweb + spiffy + awful + (awful sse) + sxml-transforms) + +;; Game +(define games (make-hash-table)) + +(define (init-game-table) + (let ((game (make-hash-table))) + game)) + +;; Webserver stuff + (define (add-sse-resource! sse-path sse-proc vhost-root-path client-path) + (add-resource! sse-path + (or vhost-root-path (root-path)) + (lambda (#!optional given-path) + (let ((accept (header-values 'accept + (request-headers (current-request))))) + ;; If client's EventSource (JS code) requested SSE page... + (if (memq 'text/event-stream accept) + ;;...complete handshake & keep connection alive with 'sse-proc'. + (lambda () + (with-headers '((content-type text/event-stream) + (cache-control no-cache) + (connection keep-alive)) + (lambda () + (write-logged-response) + (sse-proc)))) + (redirect-to client-path)))) + 'GET + #f)) + +(define (pagescript sse-path color) + #<#EOF + eventsource ssevent from #{sse-path} + + on unlockMessage as string + if it is "#{color}" + set #board.data-locked to 'false' + end + end + + end +EOF + ) + +(define (render-sxml sxml) + (with-output-to-string + (lambda () + (SXML->HTML sxml)))) + +(define (board sse-path color) + (let () + `(div (@ (id "content") + (class "row")) + (div (@ (id "leftbank") + (class "col-2 m-0"))) + (div (@ (id "board") + (data-locked ,(if (eqv? color "white") "true" "false")) + (class "col-8 m-0 p-0"))) + (div (@ (id "rightbank") + (class "col-2 m-0")))))) + +(define (game-proc code) + (print "Returning sse-proc") + (lambda () + (let loop () + (send-sse-data (render-positions) + id: (seconds->string) event: "boardChange") + (thread-sleep! 2) + (loop)))) + +(define (init-game code) + (let ((game (or (and (hash-table-exists? games code) + (~ games code)) + #f)) + (sse-path (string-append "/sse-" code)) + (sse-proc (game-proc code))) + (print "Game:" game) + (if game + (board sse-path "white") + (let ((game (init-game-table))) + (print "Initialized game to " game ", adding SSE resource.") + (set! (~ game 'sse-proc) (add-sse-resource! sse-path sse-proc #f sse-path)) + (set! (~ game 'code) code) + (set! (~ games code) game) + (board sse-path "yellow"))))) + +(define-page "/start-game" + (lambda () + (let ((gamecode ($ 'gamecode as-string))) + (init-game gamecode)))) + +(define-page "/" + (lambda () + (lambda () + (send-static-file "resources/html/coinage.html"))) + no-template: #t) + +(define-page "/css/coinage.css" + (lambda () + (lambda () + (send-static-file "resources/css/coinage.css")))) + +(define-page (irregex "/images/.*") + (lambda (file) + (print "Trying to fetch file " file "...") + (lambda () + (print "Fetching " file "...") + (send-static-file (string-append "resources" file))))) diff --git a/resources/css/coinage.css b/resources/css/coinage.css new file mode 100644 index 0000000..43b2b13 --- /dev/null +++ b/resources/css/coinage.css @@ -0,0 +1,9 @@ +html { + scrollbar-width: none; + overflow: hidden; +} + +html::-webkit-scrollbar { + width: 0 !important; + display: none; +} diff --git a/resources/html/coinage.html b/resources/html/coinage.html new file mode 100644 index 0000000..8aad117 --- /dev/null +++ b/resources/html/coinage.html @@ -0,0 +1,47 @@ + + + + + CoinAge Online + + + + + +
+
+
+ + Seems like it works. You clicked coordinates + + + + +

Welcome to Coin Age!

+

Please enter a code to join a match:

+ + +
+ + + + +
+ + diff --git a/resources/images/board.svg b/resources/images/board.svg new file mode 100644 index 0000000..a2dc21e --- /dev/null +++ b/resources/images/board.svg @@ -0,0 +1,955 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/images/coinage.png b/resources/images/coinage.png new file mode 100644 index 0000000..339bff4 Binary files /dev/null and b/resources/images/coinage.png differ diff --git a/resources/images/white-coin-1.png b/resources/images/white-coin-1.png new file mode 100644 index 0000000..56727c1 Binary files /dev/null and b/resources/images/white-coin-1.png differ diff --git a/resources/images/white-coin-2.png b/resources/images/white-coin-2.png new file mode 100644 index 0000000..9a11ce1 Binary files /dev/null and b/resources/images/white-coin-2.png differ diff --git a/resources/images/white-coin-3.png b/resources/images/white-coin-3.png new file mode 100644 index 0000000..fc42802 Binary files /dev/null and b/resources/images/white-coin-3.png differ diff --git a/resources/images/white-coin-4.png b/resources/images/white-coin-4.png new file mode 100644 index 0000000..644c4d3 Binary files /dev/null and b/resources/images/white-coin-4.png differ diff --git a/resources/images/yellow-coin-1.png b/resources/images/yellow-coin-1.png new file mode 100644 index 0000000..f5e8c86 Binary files /dev/null and b/resources/images/yellow-coin-1.png differ diff --git a/resources/images/yellow-coin-2.png b/resources/images/yellow-coin-2.png new file mode 100644 index 0000000..6f85193 Binary files /dev/null and b/resources/images/yellow-coin-2.png differ diff --git a/resources/images/yellow-coin-3.png b/resources/images/yellow-coin-3.png new file mode 100644 index 0000000..9ea1e00 Binary files /dev/null and b/resources/images/yellow-coin-3.png differ diff --git a/resources/images/yellow-coin-4.png b/resources/images/yellow-coin-4.png new file mode 100644 index 0000000..d3e74fc Binary files /dev/null and b/resources/images/yellow-coin-4.png differ