 
 (def current-fill-style (atom nil)) ;one of [:empty :crossed :filled nil]
 
+(def base-cell (atom nil))
+(def last-cell (atom nil))
+
+(def board (atom nil))
+
+(def drag-type (atom :rect)) ; possible values :rect, :by-one
+
+
+(defn range-inc [a b]
+  (range (min a b) (inc (max a b))))
+
+(defn attr-int [cell attribute]
+  (js/parseInt (attr cell attribute) 10))
+
+;;; Board functions
+
+(defn init-board! [board width height]
+  (let [state (->> (repeat width :empty)
+                   vec
+                   (repeat height)
+                   vec)]
+    (reset! board state)))
+
+(defn change-cell-in-board! [board x y new-state]
+  (swap! board assoc-in [y x] new-state))
+
+(defn update-region-of-board! [board [from-x from-y] [to-x to-y] new-state]
+  (let [cells-to-change (for [x (range-inc from-x to-x)
+                              y (range-inc from-y to-y)]
+                          [y x])
+        new-board (reduce #(assoc-in %1 %2 new-state) @board cells-to-change)]
+    (reset! board new-board)))
+
+
 (defn pad [nums beg end value]
   (-> []
       (into (repeat beg value))

(defn ^:export init []
  (when (and js/document
             (aget js/document "getElementById"))
    (dommy/prepend! (sel1 :#puzzle-view) (create-template (nonojure.random/generate-puzzle 8 10)))
    (add-handlers)))

(ns nonojure.puzzleview
  (:require
   [dommy.utils :as utils]
   [dommy.core :as dommy :refer [listen! attr]]
   [jayq.util :refer [log]])
  (:use-macros
   [dommy.macros :only [node sel sel1]]))
