Mercurial > vba-clojure
diff clojure/com/aurellem/vbm.clj @ 88:65c2854c5875
can now save moves and states and am ready to continue past the title
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 10 Mar 2012 15:36:26 -0600 |
parents | e8855121f413 |
children | 718abf3bec8a |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/vbm.clj Sat Mar 10 14:48:17 2012 -0600 1.2 +++ b/clojure/com/aurellem/vbm.clj Sat Mar 10 15:36:26 2012 -0600 1.3 @@ -3,6 +3,11 @@ 1.4 (:import org.apache.commons.io.FileUtils) 1.5 (:use com.aurellem.gb-driver)) 1.6 1.7 +;;;;;;;;;;;;; read vbm file 1.8 + 1.9 +(def ^:dynamic *moves-cache* 1.10 + (File. "/home/r/proj/pokemon-escape/moves/")) 1.11 + 1.12 (defn buttons [mask] 1.13 (loop [buttons [] 1.14 masks (seq (dissoc button-code :listen))] 1.15 @@ -29,7 +34,7 @@ 1.16 pending vbm-masks] 1.17 (if (empty? pending) fixed 1.18 (let [mask (first pending)] 1.19 - (if (not= 0x0000 (bit-and mask (button-code :reset))) 1.20 + (if (not= 0x0000 (bit-and mask (button-code :restart))) 1.21 (recur (conj fixed mask 0x0000 0x0000) (next pending)) 1.22 (recur (conj fixed mask) (next pending))))))) 1.23 1.24 @@ -42,10 +47,6 @@ 1.25 1.26 (defn vbm-buttons [#^File vbm] 1.27 (map buttons (vbm-masks vbm))) 1.28 - 1.29 -(defn play-vbm [#^File vbm] 1.30 - (restart!) 1.31 - (dorun (map step (vbm-masks vbm)))) 1.32 1.33 (defn convert-buttons 1.34 "To write a vbm file, we must remove the last two buttons after any 1.35 @@ -59,6 +60,16 @@ 1.36 (recur (conj fixed mask) (drop 3 pending)) 1.37 (recur (conj fixed mask) (next pending))))))) 1.38 1.39 +(defn moves->filename [frame] 1.40 + (File. *moves-cache* (format "%07d.vbm" frame))) 1.41 + 1.42 +(defn read-moves [frame] 1.43 + (let [target (moves->filename frame)] 1.44 + (if (.exists target) 1.45 + (vbm-buttons target)))) 1.46 +;;;;;;;;;;;;;; write moves to vbm file 1.47 + 1.48 + 1.49 (def vbm-header 1.50 (byte-array 1.51 (map 1.52 @@ -95,5 +106,21 @@ 1.53 vbm-trailer))] 1.54 contents)) 1.55 1.56 -(defn write-vbm [buttons #^File out] 1.57 - (clojure.java.io/copy (buttons->vbm-bytes buttons) out)) 1.58 +(defn write-moves! [moves] 1.59 + (let [target (moves->filename (count moves))] 1.60 + (clojure.java.io/copy (buttons->vbm-bytes moves) target) 1.61 + target)) 1.62 + 1.63 +;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.64 + 1.65 +(use 'clojure.java.shell) 1.66 + 1.67 + 1.68 +(defn play-vbm [#^File vbm] 1.69 + (.delete yellow-save-file) 1.70 + (if (.exists vbm) 1.71 + (sh "/home/r/bin/vba-linux" 1.72 + (str "--playmovie=" (.getCanonicalPath vbm)) 1.73 + (.getCanonicalPath yellow-rom-image))) 1.74 + nil) 1.75 +