From 03cf9b79e00bfe4f79f44e7948508b200d4b856a Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Thu, 24 Jul 2014 08:09:48 +0100 Subject: [PATCH] Now working nicely on tablets; iPhones and some Android phones are still getting the 'tablet' stylesheet instead of the 'phone' stylesheet, but it's not critical. --- README.md | 4 +- project.clj | 6 +- resources/public/css/phone.css | 144 ++++++++++++++++ resources/public/css/standard.css | 34 ++-- resources/public/css/tablet.css | 160 ++++++++++++++++++ resources/public/docs/mw-engine/uberdoc.html | 2 +- resources/public/docs/mw-ui/uberdoc.html | 103 +++++++++-- .../img/heightmaps/life_gosperglidergun.png | Bin 0 -> 198 bytes resources/public/img/threelines.png | Bin 0 -> 260 bytes resources/public/img/tiles/black.png | Bin 0 -> 169 bytes resources/public/img/tiles/white.png | Bin 0 -> 164 bytes resources/rulesets/life.txt | 33 ++++ resources/templates/base.html | 3 +- resources/templates/docs.html | 23 ++- war-resources | 1 + 15 files changed, 476 insertions(+), 37 deletions(-) create mode 100644 resources/public/css/phone.css create mode 100644 resources/public/css/tablet.css create mode 100644 resources/public/img/heightmaps/life_gosperglidergun.png create mode 100644 resources/public/img/threelines.png create mode 100644 resources/public/img/tiles/black.png create mode 100644 resources/public/img/tiles/white.png create mode 100644 resources/rulesets/life.txt create mode 120000 war-resources diff --git a/README.md b/README.md index 8c3d29f..a8e1f0a 100644 --- a/README.md +++ b/README.md @@ -153,5 +153,5 @@ Have fun! Copyright © 2014 [Simon Brooke](mailto:simon@journeyman.cc) -Distributed under the terms of the [GNU General Public License v2] -(http://www.gnu.org/licenses/gpl-2.0.html) \ No newline at end of file +Distributed under the terms of the +[GNU General Public License v2](http://www.gnu.org/licenses/gpl-2.0.html) \ No newline at end of file diff --git a/project.clj b/project.clj index 67a49b3..1028b1f 100644 --- a/project.clj +++ b/project.clj @@ -19,7 +19,11 @@ [lein-marginalia "0.7.1"]] :ring {:handler mw-ui.handler/app :init mw-ui.handler/init - :destroy mw-ui.handler/destroy} + :destroy mw-ui.handler/destroy + :resources-path "resources" + :war-resources-path "war-resources" + :uberwar-name "microworld.war" + } :profiles {:uberjar {:aot :all} :production {:ring {:open-browser? false diff --git a/resources/public/css/phone.css b/resources/public/css/phone.css new file mode 100644 index 0000000..6b32ce8 --- /dev/null +++ b/resources/public/css/phone.css @@ -0,0 +1,144 @@ +body { + font-family: sans-serif; + font-size: larger; +} + +/* ids generally in document order */ +/* Overall container div, holds all content of page. Yes, I know it shouldn't have fixed width */ +#main-container{ + clear: both; + width:100%; +} + +/* footer of the document */ +#footer { + display: none; +} + +#header { + width:100%; + padding: 0.25em 5% 0.25em 5%; + background-color: black; + color: white; +} + +#header h1 { + background-color: transparent; +} + +#nav{ + margin: 0; + padding: 0; + position: fixed; + z-index: 149; + background:rgba(40,40,40,0.8); +} + +#nav:hover #nav-menu { + display: inline; +} + +#nav-icon { + padding: 0.25em; +} + +#nav-menu { + display: none; +} + +#nav ul li { + padding: 0; + margin: 0; + display: inline; +} + +#nav ul li a { + color: white; + text-decoration: none; + font-weight: bold; + padding: 0.1em 0.75em; + margin: 0; +} +#nav ul li.active a { background: silver;} +li.nav-item a:hover { background: rgb( 240, 240, 240) } +li.nav-item a:active { background: gray; color: white; } + +.error { + background-color: red; + color: white; +} + +.widget { + margin: 0; + padding: 0.25em 1em; + border: thin solid white; +} + +.world { + font-size: 8pt; +} + +div.error { + width: 100%; +} + +form { + width: 100%; + background-color: silver; + border: thin solid silver; +} + +h1 { + font-size: 300%; +} + +h1, h2, h3, h4, h5 { + background-color: black; + color: white; +} + +p, pre, ul, ol, dl, h1, h2, h3, h4, h5 { + width: 100%; + padding: 0.25em 1em; +} + +input { + background-color: white; +} + +input.submit { + background-color: green; +} + +input.required:after { + content: " \*"; + color: red; +} + +label { + min-width: 35%; +} + +label, input { + padding: 0.25em 1em; + margin: 0 0.5em; +} + +label { + border-right: thin solid gray; +} + +menu li { + display: inline; +} + +menu li::before { + content: "|| "; +} + + +div.world table, div.world tr td { + padding: 0; + margin: 0; + border: none; +} diff --git a/resources/public/css/standard.css b/resources/public/css/standard.css index 8f2fed2..1a8c13d 100644 --- a/resources/public/css/standard.css +++ b/resources/public/css/standard.css @@ -29,29 +29,25 @@ body { #header { width:100%; - padding: 2em 10% 0.25em 10%; + padding: 2em 0 0.25em 0; background-color: black; color: white; } -#header h1 { - background-color: transparent; -} - -#header-logo { - float: left; - padding-right: 2.5em; -} - - #nav{ margin: 0; + padding: 0; width: 100%; position: fixed; z-index: 149; background:rgba(40,40,40,0.8); } +/* only needed for fly-out menu effect on tablet and phone stylesheets */ +#nav-icon { + display: none; +} + #nav ul li { padding: 0; margin: 0; @@ -65,6 +61,7 @@ body { padding: 0.1em 0.75em; margin: 0; } + #nav ul li.active a { background: silver;} li.nav-item a:hover { background: rgb( 240, 240, 240) } li.nav-item a:active { background: gray; color: white; } @@ -103,7 +100,7 @@ h1, h2, h3, h4, h5 { color: white; } -p, pre, ul, ol, dl, h1, h2, h3, h4, h5 { +p, pre, ul, ol, dl, menu, h1, h2, h3, h4, h5 { padding: 0.25em 10%; } @@ -133,4 +130,17 @@ label { border-right: thin solid gray; } +menu li { + display: inline; +} + +menu li::before { + content: "|| "; +} + +div.world table, div.world tr td { + padding: 0; + margin: 0; + border: none; +} diff --git a/resources/public/css/tablet.css b/resources/public/css/tablet.css new file mode 100644 index 0000000..6a7e71d --- /dev/null +++ b/resources/public/css/tablet.css @@ -0,0 +1,160 @@ +body { + font-family: sans-serif; +} + +/* ids generally in document order */ +/* Overall container div, holds all content of page. Yes, I know it shouldn't have fixed width */ +#main-container{ + clear: both; + width:100%; +} + +/* footer of the document */ +#footer { + clear: both; + font-size: smaller; + padding: 0 2em; + text-align: center; + color:white; + background:rgba(196,196,196,0.95); + width: 100%; + margin: 0; + bottom:0; + position:fixed; + z-index:150; + _position:absolute; + _top:expression(eval(document.documentElement.scrollTop+ + (document.documentElement.clientHeight-this.offsetHeight))); +} + +#footer:hover #credits { + font-size: normal; +} + +#header { + width:100%; + padding: 0.25em 5% 0.25em 5%; + background-color: black; + color: white; +} + +#header h1 { + background-color: transparent; +} + +#nav{ + margin: 0; + padding: 0; + position: fixed; + z-index: 149; + background:rgba(40,40,40,0.8); +} + +#nav:hover #nav-menu { + display: inline; +} + +#nav-icon { + padding: 0.25em; +} + +#nav-menu { + display: none; +} + +#nav ul li { + padding: 0; + margin: 0; + display: inline; +} + +#nav ul li a { + color: white; + text-decoration: none; + font-weight: bold; + padding: 0.1em 0.75em; + margin: 0; +} +#nav ul li.active a { background: silver;} +li.nav-item a:hover { background: rgb( 240, 240, 240) } +li.nav-item a:active { background: gray; color: white; } + +.error { + background-color: red; + color: white; +} + +.widget { + margin: 0; + padding: 0.25em 1em; + border: thin solid white; +} + +.world { + font-size: 8pt; +} + +div.error { + width: 100%; +} + +form { + width: 100%; + background-color: silver; + border: thin solid silver; +} + +h1 { + font-size: 300%; +} + +h1, h2, h3, h4, h5 { + background-color: black; + color: white; +} + +p, pre, ul, ol, dl, h1, h2, h3, h4, h5 { + width: 100%; + padding: 0.25em 1em; +} + +input { + background-color: white; +} + +input.submit { + background-color: green; +} + +input.required:after { + content: " \*"; + color: red; +} + +label { + min-width: 35%; +} + +label, input { + padding: 0.25em 1em; + margin: 0 0.5em; +} + +label { + border-right: thin solid gray; +} + +menu li { + display: inline; +} + +menu li::before { + content: "|| "; +} + + +div.world table, div.world tr td { + padding: 0; + margin: 0; + border: none; +} diff --git a/resources/public/docs/mw-engine/uberdoc.html b/resources/public/docs/mw-engine/uberdoc.html index 469fa5a..08d1adb 100644 --- a/resources/public/docs/mw-engine/uberdoc.html +++ b/resources/public/docs/mw-engine/uberdoc.html @@ -3029,7 +3029,7 @@ net.brehaut.ClojureTools = (function (SH) { }; })(SyntaxHighlighter); mw-engine -- Marginalia

mw-engine

0.1.0-SNAPSHOT


Cellular automaton world builder.

-

dependencies

org.clojure/clojure
1.5.1
org.clojure/math.combinatorics
0.0.7
org.clojure/tools.trace
0.7.8
net.mikera/imagez
0.3.1
fivetonine/collage
0.2.0



(this space intentionally left almost blank)
 

Functions to transform a world and run rules.

+

dependencies

org.clojure/clojure
1.5.1
org.clojure/math.combinatorics
0.0.7
org.clojure/tools.trace
0.7.8
net.mikera/imagez
0.3.1
fivetonine/collage
0.2.1



(this space intentionally left almost blank)
 

Functions to transform a world and run rules.

(ns mw-engine.core
   (:require [mw-engine.world :as world]
diff --git a/resources/public/docs/mw-ui/uberdoc.html b/resources/public/docs/mw-ui/uberdoc.html
index 0d35bfd..4057037 100644
--- a/resources/public/docs/mw-ui/uberdoc.html
+++ b/resources/public/docs/mw-ui/uberdoc.html
@@ -3029,7 +3029,7 @@ net.brehaut.ClojureTools = (function (SH) {
   };
 })(SyntaxHighlighter);
 mw-ui -- Marginalia

mw-ui

0.1.0-SNAPSHOT


Web-based user interface for MicroWorld

-

dependencies

org.clojure/clojure
1.6.0
mw-engine
0.1.0-SNAPSHOT
mw-parser
0.1.0-SNAPSHOT
lib-noir
0.8.4
ring-server
0.3.1
selmer
0.6.8
com.taoensso/timbre
3.2.1
com.taoensso/tower
2.0.2
markdown-clj
0.9.44
environ
0.5.0
noir-exception
0.2.2



(this space intentionally left almost blank)
 
+

dependencies

org.clojure/clojure
1.6.0
mw-engine
0.1.0-SNAPSHOT
mw-parser
0.1.0-SNAPSHOT
lib-noir
0.8.4
ring-server
0.3.1
selmer
0.6.8
com.taoensso/timbre
3.2.1
com.taoensso/tower
2.0.2
markdown-clj
0.9.44
environ
0.5.0
noir-exception
0.2.2



(this space intentionally left almost blank)
 
(ns mw-ui.handler
   (:require [compojure.core :refer [defroutes]]
             [mw-ui.routes.home :refer [home-routes]]
@@ -3151,7 +3151,7 @@ net.brehaut.ClojureTools = (function (SH) {
   (let [world (or (session/get :world)
                   (engine/transform-world
                    (heightmap/apply-heightmap
-                     "resources/public/img/20x20/hill.png"
+                     "resources/public/img/heightmaps/small_hill.png"
                      ;; "resources/public/img/heightmaps/great_britain_and_ireland_small.png")
                    rules/init-rules))
         rules (or (session/get :rules) 
@@ -3212,23 +3212,36 @@ net.brehaut.ClojureTools = (function (SH) {
   (.stop @server)
   (reset! server nil))
 
(ns mw-ui.routes.home
-  (:use compojure.core
-        [mw-ui.routes.rules :as rules])
+  (:use clojure.walk
+        compojure.core
+        [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]))
(defn home-page []
-  (layout/render "home.html" {:title "Welcome to MicroWorld" 
+  (layout/render "trusted-content.html" {:title "Welcome to MicroWorld" 
                               :content (util/md->html "/md/mw-ui.md")}))
(defn world-page []
-  (layout/render "world.html" {:title "Watch your world grow" 
-                               :content (html (world/render-world-table)) 
-                               :seconds (or (session/get :seconds) 5) 
-                               :maybe-refresh "refresh"}))
+ (layout/render "trusted-content.html" + {:title "Watch your world grow" + :world-selected "active" + :content (html (world/render-world-table)) + :pause (or (session/get :pause) 5) + :maybe-refresh "refresh"}))
(defn about-page []
-  (layout/render "about.html" {:title "About MicroWorld" :content (util/md->html "/md/about.md")}))
+ (layout/render "trusted-content.html" + {:title "About MicroWorld" + :about-selected "active" + :content (util/md->html "/md/about.md")}))
+
(defn md-page [request]
+  (let [params (keywordize-keys (:params request))
+        content (or (:content params) "missing.md")]
+    (layout/render "trusted-content.html" 
+                   {:title "Welcome to MicroWorld" 
+                    :content (util/md->html (str "/md/" content))})))
(defn list-states []
   (sort
     (filter #(not (nil? %)) 
@@ -3236,16 +3249,72 @@ net.brehaut.ClojureTools = (function (SH) {
                  (file-seq (clojure.java.io/file "resources/public/img/tiles"))))))
(defn docs-page []
   (layout/render "docs.html" {:title "Documentation"
-                              :parser (util/md->html "/md/mw-parser.md")
-                              :states (list-states)
+                              :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")
                               :components ["mw-engine" "mw-parser" "mw-ui"]}))
(defroutes home-routes
   (GET "/" [] (home-page))
   (GET "/about" [] (about-page))
   (GET "/docs"  [] (docs-page))
   (GET "/world"  [] (world-page))
+  (GET "/params" [] (params/params-page))
+  (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)))
 
+
(ns mw-ui.routes.params
+  (:use clojure.walk
+        compojure.core)
+  (:require [hiccup.core :refer [html]]
+            [mw-engine.heightmap :as heightmap]
+            [mw-parser.bulk :as compiler]
+            [mw-ui.layout :as layout]
+            [mw-ui.util :as util]
+            [mw-ui.render-world :as world]
+            [noir.session :as session]))
+
(defn- send-params []
+  {:title "Choose your world"
+   :heightmaps (util/list-resources "resources/public/img/heightmaps" #"([0-9a-z-_]+).png")
+   :pause (or (session/get :pause) 5)
+   :rulesets (util/list-resources "resources/rulesets" #"([0-9a-z-_]+).txt")
+   })

Handler for params request. If no request passed, show empty params form. + If request is passed, put parameters from request into session and show + the world page.

+
(defn params-page 
+  ([]
+    (layout/render "params.html" (send-params)))
+  ([request]
+    (try
+      (let [params (keywordize-keys (:form-params request))
+            map (:heightmap params)
+            pause (:pause params)
+            rulefile (:ruleset params)
+            rulepath (str "resources/rulesets/" rulefile ".txt")]
+        (if (not (= map "")) 
+          (session/put! :world 
+                        (heightmap/apply-heightmap 
+                          (str "resources/public/img/heightmaps/" map ".png"))))
+        (if (not (= rulefile ""))
+          (do
+            (session/put! :rule-text (slurp rulepath))
+            (session/put! :rules (compiler/compile-file rulepath))))
+        (if (not (= pause ""))
+          (session/put! :pause pause))
+        (layout/render "params.html" 
+                       (merge (send-params) 
+                              {:r rulefile
+                               :h map
+                               :message "Your parameters are saved, now look at your world"})))
+      (catch Exception e
+        (let [params (keywordize-keys (:form-params request))]
+          (layout/render "params.html" 
+                         (merge (send-params)
+                                {:title "Choose your world" 
+                                 :r (:ruleset params)
+                                 :h (:heightmap params)
+                                 :message "Your paramters are not saved"
+                                 :error (str (.getName (.getClass e)) ": " (.getMessage e) "; " params)})))))))
 
(ns mw-ui.routes.rules
   (:use clojure.walk
         compojure.core)
@@ -3298,5 +3367,11 @@ net.brehaut.ClojureTools = (function (SH) {
   [filename]
   (->>
     (io/slurp-resource filename)
-    (md/md-to-html-string)))
 
\ No newline at end of file diff --git a/resources/public/img/heightmaps/life_gosperglidergun.png b/resources/public/img/heightmaps/life_gosperglidergun.png new file mode 100644 index 0000000000000000000000000000000000000000..c48b7414573bae67d62b5ced79a5b23fc89c8455 GIT binary patch literal 198 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSoB=)|uE&lY`~UwxkhfZ1b`y|d zO!9VjVd!9$^#G|T@Q5sCVBi)4Va7{$>;3=**-JcqUD@xki*s7YRr=q%2NZJlba4!^ zIGxPl%FH96CF-ld6RIH0;e2?R63a3_SFsa3yxhKLU5rFD1g3Rnu?4Ws(hXj|Xs5Dp h_hC0y5M=9RU}*mpHY3qC?>5jl22WQ%mvv4FO#mlBGfe;h literal 0 HcmV?d00001 diff --git a/resources/public/img/threelines.png b/resources/public/img/threelines.png new file mode 100644 index 0000000000000000000000000000000000000000..f26babbf65472cdd7d749f2d8c2f8158b863c17a GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^hCr;r!3HG5U4{IC6kC$Fy9>jA5L~c#`DCC7XMsm# zF#`j)FbFd;%$g$s6l5>)^mS#w$1X0+B;@iiOA9D8(bL5-B;xSfn;Ur>6a-oyT0fRs z^GL|&kcI&vM zG%zR%ZQL5>*>e9{pYNLbdz=Ca_bzEZ*ST8b^>U_P&c-t=90LD)Zrs~#r_{2bKVz+- xu!6%Gv5iYbRz6Gafk-RZ`Ds4>{zbl&sjyLACU)wCB%tFMJYD@<);T3K0RR#2UAq7P literal 0 HcmV?d00001 diff --git a/resources/public/img/tiles/black.png b/resources/public/img/tiles/black.png new file mode 100644 index 0000000000000000000000000000000000000000..9e48aa6029940260a66393f364dd700d7610fea3 GIT binary patch literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1SFYWcSQjy&H|6fVg?3oVGw3ym^DWND9B#o z>FdgVk6oNoLN)e)a0F0Dvcxr_#5q4VH#M(>!MP|ku_QG`p**uBL&4qCHz2%`PaLR7 z+0(@_#Nu>vLP81FdgVk6oNol7avJw>Y4XWQl7;iF1B#Zfaf$gL6@8Vo7R>LV0FMhJw4NZ$Nk>pEyvF zoTrOph{fsTKmY&RGw*EZY-BQ6RT=Vm#k0V(Q?l6@<}6@VRm_Oq0aVH0>FVdQ&MBb@ E0EZeZX#fBK literal 0 HcmV?d00001 diff --git a/resources/rulesets/life.txt b/resources/rulesets/life.txt new file mode 100644 index 0000000..d290d6d --- /dev/null +++ b/resources/rulesets/life.txt @@ -0,0 +1,33 @@ +# Conway's Game of Life is the classic cellular automaton. + +;; see http://en.wikipedia.org/wiki/Conway's_Game_of_Life + +;; This ruleset works with any strictly black and white map, but the maps which +;; are designed to work with it have names starting 'life'. + +;; The universe of the Game of Life is an infinite two-dimensional orthogonal +;; grid of square cells, each of which is in one of two possible states, alive +;; or dead. Every cell interacts with its eight neighbours, which are the +;; cells that are horizontally, vertically, or diagonally adjacent. At each +;; step in time, the following transitions occur: + +;; Any live cell with fewer than two live neighbours dies, as if caused by +;; under-population. + +if state is black and fewer than 2 neighbours are black then state should be white + +;; Any live cell with two or three live neighbours lives on to the next generation. + +;; Any live cell with more than three live neighbours dies, as if by overcrowding. + +if state is black and more than 3 neighbours are black then state should be white + +;; Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. + +if state is not black and 3 neighbours are black then state should be black + +# Initialisation rules + +if state is new and altitude is more than 127 then state should be black + +if state is new then state should be white diff --git a/resources/templates/base.html b/resources/templates/base.html index 55ad0ca..611a3d0 100644 --- a/resources/templates/base.html +++ b/resources/templates/base.html @@ -20,7 +20,8 @@ {% endblock %} \ No newline at end of file diff --git a/war-resources b/war-resources new file mode 120000 index 0000000..4c5ab1b --- /dev/null +++ b/war-resources @@ -0,0 +1 @@ +resources/public/ \ No newline at end of file