record-types.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. (define (make-game-file level-list file-id)
  2. (vector make-game-file level-list file-id))
  3. (define (game-file? o)
  4. (and (vector? o)
  5. (>= (vector-length o) 1)
  6. (eq? (vector-ref o 0) make-game-file)))
  7. (define (game-file-level-list game-file)
  8. (vector-ref game-file 1))
  9. (define (game-file-id game-file)
  10. (vector-ref game-file 2))
  11. (define (make-level rows cols data move-history game-file levnum)
  12. (vector make-level rows cols data move-history game-file levnum))
  13. (define (level? o)
  14. (and (vector? o)
  15. (>= (vector-length o) 1)
  16. (eq? (vector-ref o 0) make-level)))
  17. (define (level-rows level)
  18. (vector-ref level 1))
  19. (define (level-cols level)
  20. (vector-ref level 2))
  21. (define (level-data level)
  22. (vector-ref level 3))
  23. (define (level-move-history level)
  24. (vector-ref level 4))
  25. (define (level-move-history-set! level new-h)
  26. (vector-set! level 4 new-h))
  27. (define (level-game-file level)
  28. (vector-ref level 5))
  29. (define (level-number level)
  30. (vector-ref level 6))
  31. (define (make-tile row col type)
  32. (vector make-tile row col type))
  33. (define (tile? o)
  34. (and (vector? o)
  35. (>= (vector-length o) 1)
  36. (eq? (vector-ref o 0) make-tile)))
  37. (define (tile-row tile)
  38. (vector-ref tile 1))
  39. (define (tile-col tile)
  40. (vector-ref tile 2))
  41. (define (tile-type tile)
  42. (vector-ref tile 3))
  43. (define (make-global-state current-level-state in-menu current-progress-tracker current-event-handler)
  44. (vector make-global-state current-level-state in-menu current-progress-tracker current-event-handler))
  45. (define (global-state? o)
  46. (and (vector? o)
  47. (>= (vector-length o) 1)
  48. (eq? (vector-ref o 0) make-global-state)))
  49. (define (global-level global-state)
  50. (vector-ref global-state 1))
  51. (define (global-level-set! global-state new-level)
  52. (vector-set! global-state 1 new-level))
  53. (define (global-menu global-state)
  54. (vector-ref global-state 2))
  55. (define (global-menu-set! global-state new-menu)
  56. (vector-set! global-state 2 new-menu))
  57. (define (global-progress global-state)
  58. (vector-ref global-state 3))
  59. (define (global-progress-set! global-state new-progress)
  60. (vector-set! global-state 3 new-progress))
  61. (define (global-event-handler global-state)
  62. (vector-ref global-state 4))
  63. (define (make-menu items top-item cursor callback undo-callback)
  64. ;; items is a vector of cons - key value pairs, the value which gets sent to the callback
  65. (vector make-menu items top-item cursor callback undo-callback))
  66. (define (menu? o)
  67. (and (vector? o)
  68. (>= (vector-length o) 1)
  69. (eq? (vector-ref o 0) make-menu)))
  70. (define (menu-items menu)
  71. (vector-ref menu 1))
  72. (define (menu-top-item menu)
  73. (vector-ref menu 2))
  74. (define (menu-top-item-set! menu new-val)
  75. (vector-set! menu 2 new-val))
  76. (define (menu-cursor menu)
  77. (vector-ref menu 3))
  78. (define (menu-cursor-set! menu new-val)
  79. (vector-set! menu 3 new-val))
  80. (define (menu-callback menu)
  81. (vector-ref menu 4))
  82. (define (menu-undo-callback menu)
  83. (vector-ref menu 5))