adjust games to use find-relevant-directories instead of

working directly with collections

also some Rackety
This commit is contained in:
Robby Findler 2013-06-19 20:53:14 -05:00
parent 28e23fa65a
commit 9df3aa6a94

View File

@ -4,24 +4,19 @@
(define-struct game (file name set icon)) (define-struct game (file name set icon))
(define gamedirs (define (get-game gamedir)
(filter directory-exists? (define-values (base name dir?) (split-path gamedir))
(map (λ (x) (build-path x "games")) (define game (path-element->string name))
(current-library-collection-paths)))) (define info (with-handlers ([exn:fail? (lambda (x) #f)])
(get-info (list "games" game))))
(define (get-game gamedir game) (define main (and info (info 'game (lambda () #f))))
(let* ([game (path-element->string game)] (define (gamefile f) (build-path gamedir f))
[info (with-handlers ([exn:fail? (lambda (x) #f)]) (and main
(get-info (list "games" game)))] (make-game
[main (and info (info 'game (lambda () #f)))] (gamefile main)
[gamefile (lambda (f) (build-path gamedir game f))]) (info 'name (λ () (string-titlecase (regexp-replace* #rx"-" game " "))))
(and main (info 'game-set (λ () "Other Games"))
(make-game (info 'game-icon (λ () (gamefile (format "~a.png" game)))))))
(gamefile main)
(info 'name (lambda ()
(string-titlecase (regexp-replace* #rx"-" game " "))))
(info 'game-set (lambda () "Other Games"))
(info 'game-icon (lambda () (gamefile (format "~a.png" game))))))))
(define (run-game game) (define (run-game game)
(define c (make-custodian)) (define c (make-custodian))
@ -51,15 +46,12 @@
(run)))))) (run))))))
(define games (define games
(apply (for/list ([gamedir (in-list (find-relevant-directories '(game)))])
append (get-game gamedir)))
(for/list ([gamedir (in-list gamedirs)])
(filter values (map (λ (x) (get-game gamedir x))
(directory-list gamedir))))))
(define game-sets (define game-sets
(let ([ht (make-hash)]) (let ([ht (make-hash)])
(for ([g games]) (for ([g (in-list games)])
(let ([set (game-set g)]) (let ([set (game-set g)])
(hash-set! ht set (cons g (hash-ref ht set '()))))) (hash-set! ht set (cons g (hash-ref ht set '())))))
(sort (hash-map ht cons) (sort (hash-map ht cons)
@ -79,7 +71,7 @@
(send f stretchable-width #f) (send f stretchable-width #f)
(send f stretchable-height #f) (send f stretchable-height #f)
(for ([set game-sets]) (for ([set (in-list game-sets)])
(define set-name (car set)) (define set-name (car set))
(define games (cdr set)) (define games (cdr set))
(define panel (define panel
@ -102,7 +94,7 @@
(lambda () (lambda ()
(message-box (message-box
"Oops" "Oops"
"There aren't actually any preferences. This is just a test for Mac OS X" "There aren't actually any preferences."
f f
'(ok)))) '(ok))))