34 lines
1.1 KiB
Fennel
34 lines
1.1 KiB
Fennel
(local tiledraw (require :editor.tiledraw))
|
|
|
|
(fn map-bitxy-tile [x y]
|
|
(when (and (>= x 0) (< x 16) (>= y 0) (< y 16))
|
|
(local ibyte (if (< x 8) y (+ y 16)))
|
|
(local ibit
|
|
(if (= x 0) 7
|
|
(< x 8) (- x 1)
|
|
(- x 8)))
|
|
(values ibyte ibit 1)))
|
|
|
|
(fn map-bitxy-portrait [x y]
|
|
(local quadrant (+ (if (>= x 16) 2 0) (if (>= y 16) 1 0)))
|
|
(local tilex
|
|
(if (or (= x 0) (= x 30)) 0
|
|
(or (= x 1) (= x 31)) 15
|
|
(< x 16) (- x 1)
|
|
(- x 15)))
|
|
(local tiley (% y 16))
|
|
(local (ibyte ibit) (map-bitxy-tile tilex tiley))
|
|
(values (+ ibyte (* quadrant 32)) ibit 1))
|
|
|
|
{:map-bitxy (fn [self x y w] (if (> w 16) (map-bitxy-portrait x y) (map-bitxy-tile x y)))
|
|
:pixel-color (fn [self b _ ibit]
|
|
(if (= ibit 7) (tiledraw.pal-from-bit (= b 1))
|
|
(= b 1) [255 255 255]
|
|
[0 0 0]))
|
|
:draw-off (fn [self] (set self.bit nil))
|
|
:draw-on (fn [self b] (when (= self.bit nil) (set self.bit (if (= b 1) 0 1))))
|
|
:draw-bits (fn [self] self.bit)
|
|
:pixel-storage-divisor #8
|
|
}
|
|
|