TIC-80 icon indicating copy to clipboard operation
TIC-80 copied to clipboard

Add colorkey return value to remap callback for map()

Open sorucoder opened this issue 1 year ago • 5 comments

For the purpose of using custom transparency on certain tiles, or make a tile opaque.

sorucoder avatar Jul 20 '22 10:07 sorucoder

I guess you can do it using flags

BuoYancYdabl avatar Jul 21 '22 12:07 BuoYancYdabl

I don't understand where we can get this color from?

nesbox avatar Jul 26 '22 09:07 nesbox

Why does there need to be an input? The remap callback could just be:

-- (tile, x, y) -> tile, colorkey, flip, rotate
local function remap(tile,x,y)
    local colorkey = math.random(0,15)
    return tile, colorkey, false, false
end

map(0, 0, 30, 17, 0, 0, -1, 1, remap)

Or if you want an input, just pass through what was provided to map:

-- (tile, x, y) -> tile, colorkey, flip, rotate
local function remap(tile, colorkey, x, y)
    colorkey = math.random(0,15)
    return tile, colorkey, false, false
end

map(0, 0, 30, 17, 0, 0, -1, 1, remap) -- the colorkey passed to "remap" will be -1

sorucoder avatar Jul 27 '22 07:07 sorucoder

I got it, thanks. Let's try adding this, of course if it won't break compatibility.

nesbox avatar Jul 28 '22 09:07 nesbox

Thought: I think we should consider map is/was (originally?) intended just meant to be a simple "easy to get started" helper (no?), it doesn't need to do everything under the sun. If someone wants to write a custom map function it's just a few lines of code...

Other than that thought, no other real objections to this - seems a useful utility - I just think it can be done easily enough without needing to be part of the core. :)

  • I don't think there are any binary compatibility issues with this since WASM doesn't implement remap yet...
  • Obviously we can't add a middle param though, it would have to be the last param for backwards compatibility

joshgoebel avatar Jul 28 '22 12:07 joshgoebel