Feature complete for version 1; some refactoring still needed.

This commit is contained in:
Simon Brooke 2014-07-24 18:44:04 +01:00
parent a0f59ac2dd
commit 98e43dbe8f
10 changed files with 190 additions and 84 deletions

View file

@ -28,7 +28,7 @@
[cell]
(let [state (:state cell)]
[:td {:class (format-css-class state) :title (format-mouseover cell)}
[:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))}
[:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))}
[:img {:alt (:state cell) :src (format-image-path state)}]]]))
(defn render-world-row
@ -63,19 +63,16 @@
(map render-world-row w2)))
[:p (str "Generation " generation)]]))
(defn render-world
"Render the world implied by the session as a complete HTML page."
[]
(html
[:html
[:head
[:title "MicroWorld demo"]
[:link {:media "only screen and (max-device-width: 480px)" :href "css/phone.css" :type "text/css" :rel "stylesheet"}]
[:link {:media "only screen and (min-device-width: 481px) and (max-device-width: 1024px)" :href "css/tablet.css" :type "text/css" :rel "stylesheet"}]
[:link {:media "screen and (min-device-width: 1025px)" :href "css/standard.css" :type "text/css" :rel "stylesheet"}]
[:link {:media "print" :href "css/print.css" :type "text/css" :rel "stylesheet"}]
[:link {:href "css/states.css" :type "text/css" :rel "stylesheet"}]
[:meta {:http-equiv "refresh" :content "5"}]]
[:body
(render-world-table)
]]))
(defn render-inspector
[cell table]
[:table {:class "music-ruled"}
[:tr
[:td {:colspan 2 :style "text-align: center;"}
[:img {:src (str "img/tiles/" (name (:state cell)) ".png")
:width 64
:height 64}]]]
[:tr [:th "Key"][:th "Value"]]
(map #(vector :tr (vector :th %)(vector :td (cell %))) (keys cell))])

View file

@ -1,18 +1,43 @@
(ns mw-ui.routes.home
(:use clojure.walk
compojure.core
[mw-engine.utils :as engine-utils]
[mw-ui.routes.rules :as rules]
[mw-ui.routes.params :as params])
(:require [hiccup.core :refer [html]]
[mw-ui.layout :as layout]
[mw-ui.util :as util]
[mw-ui.render-world :as world]
[noir.session :as session]))
[noir.session :as session]
[ring.util.response :as response]))
(defn home-page []
(layout/render "trusted-content.html" {:title "Welcome to MicroWorld"
:content (util/md->html "/md/mw-ui.md")}))
(defn inspect-page [request]
(let [params (keywordize-keys (:params request))
xs (:x params)
ys (:y params)
x (if (not (empty? xs)) (read-string xs) 0)
y (if (not (empty? ys)) (read-string ys) 0)
world (session/get :world)
cell (engine-utils/get-cell world x y)
state (:state params)]
(cond state
(do
(session/put! :world (engine-utils/set-property world cell :state (keyword state)))
(response/redirect "world"))
true
(layout/render "inspector.html"
{:title (format "Inspect cell at %d, %d" x y)
:content (html (world/render-inspector cell world))
:cell cell
:x (:x cell)
:y (:y cell)
:states (util/list-resources
"/img/tiles" #"([0-9a-z-_]+).png")}))))
(defn world-page []
(layout/render "trusted-content.html"
{:title "Watch your world grow"
@ -43,8 +68,8 @@
(defn docs-page []
(layout/render "docs.html" {:title "Documentation"
:parser (util/md->html "/md/mw-parser.md" )
:states (util/list-resources "resources/public/img/tiles" #"([0-9a-z-_]+).png")
:lessons (util/list-resources "resources/public/md/lesson-plans" #"([0-9a-z-_]+).md")
:states (util/list-resources "/img/tiles" #"([0-9a-z-_]+).png")
:lessons (util/list-resources "/md/lesson-plans" #"([0-9a-z-_]+).md")
:components ["mw-engine" "mw-parser" "mw-ui"]}))
(defroutes home-routes
@ -56,4 +81,7 @@
(GET "/md" request (md-page request))
(POST "/params" request (params/params-page request))
(GET "/rules" request (rules/rules-page request))
(POST "/rules" request (rules/rules-page request)))
(POST "/rules" request (rules/rules-page request))
(GET "/inspect" request (inspect-page request))
(POST "/inspect" request (inspect-page request))
)