diff --git a/src/engine.clj b/src/engine.clj index eb1471c..3701efa 100644 --- a/src/engine.clj +++ b/src/engine.clj @@ -40,7 +40,6 @@ (if (rl/window-ready?) (println "Warning: Existing raylib window open, ignoring!") (do - (reset! texture-cache {}) (rl/set-trace-log-level! rl/log-warning) (rl/init-window! width height title) (rl/set-target-fps! 30) @@ -66,10 +65,13 @@ (w/watch! (merge (watch-fn config @game-state) {:error t})))))))) (try (when unload + (doseq [[_ tex] @texture-cache] + (rl/unload-texture! tex)) (unload @game-state)) (catch Throwable t (report-exception! t))) (rl/close-window!) + (reset! texture-cache {}) (reset! last-error nil) (reset! game-state nil) (reset! game-config nil))))) diff --git a/src/game.clj b/src/game.clj index 8f6719d..e656be1 100644 --- a/src/game.clj +++ b/src/game.clj @@ -264,10 +264,7 @@ (defn watch-game [config game] {}) -(defn unload-game [game] - (doseq [[_ tex] (:tilemaps game)] - (rl/unload-texture! tex)) - (reset! texture-cache {})) +(defn unload-game [game]) (defn -main [& _args] (e/run-game! diff --git a/src/sprite_atlas.clj b/src/sprite_atlas.clj index 7ade459..c459910 100644 --- a/src/sprite_atlas.clj +++ b/src/sprite_atlas.clj @@ -31,6 +31,13 @@ :atlas-pos [0 0] :drag-delta [0 0]})) +(defn- get-selection-rect [{ax :x ay :y} {bx :x by :y}] + (let [start-x (min ax bx) + start-y (min ay by) + end-x (max ax bx) + end-y (max ay by)] + {:x start-x :y start-y :w (- end-x start-x) :h (- end-y start-y)})) + (defn handle-input [_ game] (update-as-> [g game] (when (rl/key-pressed? rl/key-r) @@ -50,11 +57,13 @@ (assoc g :zoom (zoom-to-fit (:atlas g)))) (when (rl/mouse-button-pressed? rl/mouse-button-left) - (assoc g - :drag-start-pos (rl/get-mouse-position) - :current-mouse-pos (rl/get-mouse-position) - :drag-mode :selecting - :selected-cells #{})) + (cond-> (assoc g + :drag-start-pos (rl/get-mouse-position) + :current-mouse-pos (rl/get-mouse-position) + :drag-mode :selecting) + + (not (rl/key-down? rl/key-left-shift)) + (assoc :selected-cells #{}))) (when (rl/mouse-button-released? rl/mouse-button-left) (-> g (assoc :selected-sprite (get-selection-rect (:drag-start-pos g) (:current-mouse-pos g))) @@ -76,13 +85,6 @@ (assoc g :zoom new-scale :atlas-pos [(- mx (* k (- mx ax))) (- my (* k (- my ay)))])))))) -(defn- get-selection-rect [{ax :x ay :y} {bx :x by :y}] - (let [start-x (min ax bx) - start-y (min ay by) - end-x (max ax bx) - end-y (max ay by)] - {:x start-x :y start-y :w (- end-x start-x) :h (- end-y start-y)})) - (defn update-sprite-atlas [_ game] (update-as-> [g game] (handle-input {} g) @@ -169,8 +171,7 @@ :atlas-pos (:atlas-pos game) #_#_:drag-delta (:drag-delta game)}) -(defn unload-sprite-atlas [game] - (rl/unload-texture! (:atlas game))) +(defn unload-sprite-atlas [game]) (defn -main [& _args] (engine/run-game!