comparison clojure/com/aurellem/run/bootstrap_0.clj @ 323:92ee94945327

created functions to set the cursor to any position in any list
author Robert McIntyre <rlm@mit.edu>
date Wed, 04 Apr 2012 00:56:53 -0500
parents d604bd3c122c
children 7876781520ea
comparison
equal deleted inserted replaced
322:d604bd3c122c 323:92ee94945327
335 "up-4" "down-4" 335 "up-4" "down-4"
336 "up-5" "down-5" 336 "up-5" "down-5"
337 "up-6"])))) 337 "up-6"]))))
338 338
339 339
340 340 ;; turns out that these addresses are the cursor position
341 (def item-cursor-offset-address 52262) 341 ;; for all lists in the game (start list, pokemon list, shop
342 (def item-screen-offset-address 52278) 342 ;; lists, inventory lists, battle list, basically
343 343 ;; everything!)
344 (defn item-offset 344
345 (def list-cursor-offset-address 52262)
346 (def list-screen-offset-address 52278)
347
348 (defn list-offset
345 ([^SaveState state] 349 ([^SaveState state]
346 (let [mem (memory state)] 350 (let [mem (memory state)]
347 (+ (aget mem item-screen-offset-address) 351 (+ (aget mem item-screen-offset-address)
348 (aget mem item-cursor-offset-address)))) 352 (aget mem item-cursor-offset-address))))
349 ([] (item-offset @current-state))) 353 ([] (item-offset @current-state)))
354
350 355
351 356
352 (defn exp-item-selection [] 357 (defn exp-item-selection []
353 (clojure.pprint/pprint 358 (clojure.pprint/pprint
354 (apply memory-compare 359 (apply memory-compare
364 (defn item-quantity-selected 369 (defn item-quantity-selected
365 ([^SaveState state] 370 ([^SaveState state]
366 (aget (memory state) item-quantity-selected-address)) 371 (aget (memory state) item-quantity-selected-address))
367 ([] (item-quantity-selected @current-state))) 372 ([] (item-quantity-selected @current-state)))
368 373
369 374 (defn set-cursor-relative
375 "Assumes the arrow keys currently control the cursor.
376 Moves the cursor n steps relative to its current
377 position."
378 [n script]
379 (let [key (if (< 0 n) ↓ ↑)]
380 (multiple-times
381 n (partial repeat-until-different
382 key list-offset) script)))
383
384 (defn set-cursor
385 "Assumes the arrow keys currently control the cursor. Sets
386 the cursor to the desired position. Works for any menu
387 that uses a cursor including the start menu, item menu,
388 pokemon menu, and battle menu."
389 [n [moves state :as script]]
390 (let [current-position (list-offset state)
391 difference (- n current-position)]
392 (println difference)
393 (set-cursor-relative difference script)))
394
370 (defn buy-item 395 (defn buy-item
371 "Assumes that the main item-screen is up, and buys 396 "Assumes that the main item-screen is up, and buys
372 quantity of the nth item in the list, assuming that you 397 quantity of the nth item in the list, assuming that you
373 have enough money." 398 have enough money."
374 [n quantity script] 399 [n quantity script]