From b9ee9d138ab1a2f685a4cc1d824588d996a6c405 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 27 Dec 2016 14:32:23 +0000 Subject: [PATCH] Preparation to work client-side. --- buildall.sh | 16 ++++++++++++---- project.clj | 4 ++-- src/cljc/microworld/engine/core.cljc | 7 +++++-- src/cljc/microworld/engine/heightmap.cljc | 15 +++++++-------- test/microworld/engine/heightmap_test.clj | 6 +++--- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/buildall.sh b/buildall.sh index 0eabd8e..205c897 100755 --- a/buildall.sh +++ b/buildall.sh @@ -72,7 +72,7 @@ if [ $# -lt 1 ] then cat <<-EOF 1>&2 Usage: - -archive Create a tar archive of the current state of the source. + -archive Create a tar archive of the current state of the source. -build Build all components and commit to master. -email [ADDRESS] Your email address, to be recorded in the build signature. -fullname [NAME] Your full name, to be recorded in the build signature. @@ -93,6 +93,8 @@ do # 'build' is the expected normal case. trial="FALSE"; ;; + -d|-docker) + docker="TRUE";; -e|-email) shift; email=$1;; @@ -126,7 +128,7 @@ do shift done -echo "Trial: ${trial}; email: ${email}; fullname ${fullname}; release: ${release}; webapps: $webappsdir" +echo "Trial: ${trial}; docker: ${docker}; email: ${email}; fullname ${fullname}; release: ${release}; webapps: $webappsdir" ls mw-* > /dev/null 2>&1 if [ $? -ne 0 ] @@ -200,12 +202,18 @@ do # probably deploy it to local Tomcat for test if [ "${dir}" = "mw-ui" -a "${webappsdir}" != "" ] then - lein ring uberwar + lein ring uberwar sudo cp target/microworld.war "${webappsdir}" echo "Deployed new WAR file to local Tomcat at ${webappsdir}" fi - # Then unset manifest properties prior to committing. + if [ "${dir}" = "mw-ui" -a "${docker}" = "TRUE" ] + then + lein docker build + lein docker push + fi + + # Then unset manifest properties prior to committing. cat project.clj > ${tmp}/project.bak.2 setup-build-sig sed -f ${tmp}/manifest.sed ${tmp}/project.bak.2 > project.clj diff --git a/project.clj b/project.clj index 436a5a1..fec5988 100644 --- a/project.clj +++ b/project.clj @@ -10,6 +10,7 @@ } :jvm-opts ["-Xmx4g"] :source-paths ["src/clj" "src/cljc"] + :resource-paths ["resources"] :license {:name "GNU General Public License v2" :url "http://www.gnu.org/licenses/gpl-2.0.html"} :plugins [[lein-marginalia "0.7.1"]] @@ -18,5 +19,4 @@ [org.clojure/tools.trace "0.7.8"] [org.clojure/tools.namespace "0.2.10"] [hiccup "1.0.5"] - [net.mikera/imagez "0.11.0"] - [fivetonine/collage "0.2.1"]]) + [net.mikera/imagez "0.11.0"]]) diff --git a/src/cljc/microworld/engine/core.cljc b/src/cljc/microworld/engine/core.cljc index 87ccd76..a15d37b 100644 --- a/src/cljc/microworld/engine/core.cljc +++ b/src/cljc/microworld/engine/core.cljc @@ -56,8 +56,10 @@ "Apply a single `rule` to a `cell`. What this is about is that I want to be able, for debugging purposes, to tag a cell with the rule text of the rule which fired (and especially so when an exception is thrown. So a rule may be either - an ifn, or a list (ifn source-text). This function deals with despatching - on those two possibilities. `world` is also passed in in order to be able + an ifn, a list (ifn source-text), or a list (ifn {:rule source-text :clojure + generated-function}. + This function deals with despatching on those three possibilities. `world` + is also passed in in order to be able to access neighbours." ([world cell rule] (cond @@ -66,6 +68,7 @@ ([world cell rule source] (let [result (apply rule (list cell world))] (cond + (and result source (map? source)) (merge result source) (and result source) (merge result {:rule source}) true result)))) diff --git a/src/cljc/microworld/engine/heightmap.cljc b/src/cljc/microworld/engine/heightmap.cljc index 81891bf..cec789f 100644 --- a/src/cljc/microworld/engine/heightmap.cljc +++ b/src/cljc/microworld/engine/heightmap.cljc @@ -2,8 +2,7 @@ :author "Simon Brooke"} microworld.engine.heightmap (:import [java.awt.image BufferedImage]) - (:require [fivetonine.collage.util :as collage :only [load-image]] - [mikera.image.core :as imagez :only [filter-image get-pixels]] + (:require [mikera.image.core :as imagez :only [filter-image get-pixels]] [mikera.image.filters :as filters] [microworld.engine.utils :refer [abs get-int get-neighbours map-world]] [microworld.engine.world :refer [make-world]])) @@ -107,15 +106,15 @@ * `imagepath` a file path or URL which indicates an (ideally greyscale) image file." ([world imagepath] (let [heightmap (imagez/filter-image - (filters/grayscale) - (collage/load-image imagepath))] + (imagez/load-image-resource imagepath) + (filters/grayscale))] (map-world (map-world world tag-altitude (list heightmap)) tag-gradient))) ([imagepath] (let [heightmap (imagez/filter-image - (filters/grayscale) - (collage/load-image imagepath)) + (imagez/load-image-resource imagepath) + (filters/grayscale)) world (make-world (.getWidth heightmap) (.getHeight heightmap))] (map-world (map-world world tag-altitude (list heightmap)) @@ -132,6 +131,6 @@ intensity of the corresponding cell of the image." [world imagepath property] (let [heightmap (imagez/filter-image - (filters/grayscale) - (collage/load-image imagepath))] + (imagez/load-image-resource imagepath) + (filters/grayscale))] (map-world world tag-property (list property heightmap)))) diff --git a/test/microworld/engine/heightmap_test.clj b/test/microworld/engine/heightmap_test.clj index 3f80776..87ea5b8 100644 --- a/test/microworld/engine/heightmap_test.clj +++ b/test/microworld/engine/heightmap_test.clj @@ -7,7 +7,7 @@ (deftest apply-heightmap-test (testing "Heightmap functionality" - (let [world (apply-heightmap (as-file "resources/heightmaps/test9x9.png")) + (let [world (apply-heightmap "heightmaps/test9x9.png") altitudes (map #(:altitude %) (flatten world)) gradients (map #(:gradient %) (flatten world))] (is (= (count world) 9) "World should be 9x9") @@ -22,7 +22,7 @@ (is (> (apply + gradients) 0) "At least some gradients must be positive, none should be negative")) ;; alternate means of making the world, same tests. - (let [world (apply-heightmap (world/make-world 9 9) (as-file "resources/heightmaps/test9x9.png")) + (let [world (apply-heightmap (world/make-world 9 9) "heightmaps/test9x9.png") altitudes (map #(:altitude %) (flatten world)) gradients (map #(:gradient %) (flatten world))] (is (= (count world) 9) "World should be 9x9") @@ -42,7 +42,7 @@ (deftest apply-valuemap-test (testing "Valuemap functionality" - (let [image (as-file "resources/heightmaps/test9x9.png") + (let [image "heightmaps/test9x9.png" world (apply-valuemap (apply-heightmap image) image :arbitrary) altitudes (map #(:altitude %) (flatten world)) arbitraries (map #(:arbitrary %) (flatten world))]