30 lines
1.2 KiB
Fennel
30 lines
1.2 KiB
Fennel
(local {: putpixel : make-canvas} (require :editor.tiledraw))
|
|
(local tiles (require :game.tiles))
|
|
|
|
; converted from http://pixeljoint.com/forum/forum_posts.asp?TID=12795 (db16)
|
|
; maybe check out https://lospec.com/palette-list ?
|
|
(local pal [[1 0 1] [4 2 3] [3 3 6] [4 4 4] [8 4 3] [3 6 2] [13 4 4] [7 7 6]
|
|
[5 7 12] [13 7 2] [8 9 10] [6 10 2] [13 10 9] [6 12 12] [13 13 5] [13 14 13]])
|
|
(fn gs-to-rgb [color] (icollect [_ v (ipairs (or color [0 0 0]))] (* v 0x11)))
|
|
|
|
(fn spritegen-for-size [w h]
|
|
(fn [tile]
|
|
(when tile (make-canvas w h (fn [canvas]
|
|
(love.graphics.clear 0 0 0 0)
|
|
(for [y 0 (- h 1)]
|
|
(for [x 0 (- w 1)]
|
|
(let [ibyte (+ (* y w) x 1)
|
|
byte (string.byte (tile:sub ibyte ibyte))
|
|
mask (bit.band (bit.rshift byte 4) 0xf)
|
|
color (bit.band byte 0xf)
|
|
rgb (if (= mask 0) (gs-to-rgb (. pal (+ color 1))) [255 0 255])]
|
|
(when (= mask 0) (putpixel x y rgb))))))))))
|
|
|
|
(local tile-to-sprite (spritegen-for-size 16 16))
|
|
|
|
(fn spritegen-for-style [name]
|
|
(let [{: tilew : tileh} (tiles.style name)]
|
|
(spritegen-for-size tilew tileh)))
|
|
|
|
{: tile-to-sprite : spritegen-for-size : spritegen-for-style : pal : gs-to-rgb}
|