From 64ab0b9dd9231eba77d83e2684f0c42551ba8a70 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 10 Aug 2014 18:31:31 +0100 Subject: [PATCH] Moved some display stuff from ui to engine. Not certain this was the right decision... --- src/mw_engine/display.clj | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/mw_engine/display.clj diff --git a/src/mw_engine/display.clj b/src/mw_engine/display.clj new file mode 100644 index 0000000..f77a983 --- /dev/null +++ b/src/mw_engine/display.clj @@ -0,0 +1,38 @@ +(ns mw-engine.display + (:use mw-engine.utils + mw-engine.world) + (:require [hiccup.core :refer [html]])) + +(defn format-css-class [state] + "Format this `state`, assumed to be a keyword indicating a state in the + world, into a CSS class" + (subs (str state) 1)) + +(defn format-image-path + "Render this `state`, assumed to be a keyword indicating a state in the + world, into a path which should recover the corresponding image file." + [state] + (format "img/tiles/%s.png" (format-css-class state))) + +(defn format-mouseover [cell] + (str cell)) + +(defn render-cell + "Render this world cell as a Hiccup table cell." + [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))} + [:img {:alt (:state cell) :width 32 :height 32 :src (format-image-path state)}]]])) + +(defn render-world-row + "Render this world `row` as a Hiccup table row." + [row] + (apply vector (cons :tr (map render-cell row)))) + +(defn render-world-table + "Render this `world` as a Hiccup table." + [world] + (apply vector + (cons :table + (map render-world-row world)))