-- Necklace of the Eye v5.2 roguelike frontend -- Copyright (C) 2010-2012 Zeno Rogue, see COPYING for details -- table utilities function table.copy(t) local t2 = {} for k,v in pairs(t) do t2[k] = v end return t2 end function table.merge(t2, t) for k,v in pairs(t) do t2[k] = v end return t2 end -- directions and keys for them -- direction 0 is right, and then we go anti-clockwise dofile(commondir.."sdlkeys.noe") numpad = {256+9, 256+8, 256+7, 256+4, 256+1, 256+2, 256+3} numpad[0] = 256+6 numberkeys = {"9", "8", "7", "4", "1", "2", "3"} numberkeys[0] = "6" arrowkeys = {SDLK_PAGEUP, SDLK_UP, SDLK_HOME, SDLK_LEFT, SDLK_END, SDLK_DOWN, SDLK_PAGEDOWN} arrowkeys[0] = SDLK_RIGHT arrowkeys.ktype = 4 vikeytab = {"u", "k", "y", "h", "b", "j", "n"} vikeytab[0] = "l" vikeytab.ktype = 8 pseudovikeytab = {"i", "u", "y", "h", "b", "n", "m"} pseudovikeytab[0] = "j" pseudovikeytab.ktype = 8 leftkeytab = {"e", "w", "q", "a", "z", "x", "c"} leftkeytab[0] = "d" leftkeytab.ktype = 8 wasdkeytab = {"u", "w", "y", "a", "b", "s", "n"} wasdkeytab[0] = "d" wasdkeytab.ktype = 4 -- ascii value function av(x) return string.byte(x,1) end function avf(x) return string.byte(x,1) end -- identity for scrcopy function eq(C) return C end -- translate vector to direction, for use in mouse support do local dirtab = {3, 2, 1, 4, 0, 0, 5, 6, 7} function vectodir(x, y, mzero) max = math.max(math.abs(x), math.abs(y)) if max*2 > mzero then dx = 5 if x > max/2 then dx = dx + 1 end if x < -max/2 then dx = dx - 1 end if y > max/2 then dx = dx + 3 end if y < -max/2 then dx = dx - 3 end return dirtab[dx] end return -1 end end function cellshade(x) if x == 0 then return 0 end return tilemerge(tileshade(gba(x)), gp2(x)) end function celltrans(x) return gp2(x) end function celltransorshade(x) local ba = gba(x) if av(gch(x)) == 0 then return x elseif ba <= 0 then return gp2(x) else return tilemerge(tileshade(ba), gp2(x)) end end function cellblack(x) return tilerecolor(gp2(x), 0) end function cellblacknb(x) return tilerecolor(x, 0) end function getline(y) local s = "" for x=0, conssize.x-1 do s = s .. gch(scrget(S,x,y)) end return s end function mround(x) return math.floor(x + 0.5) end function renewscreen(S, x, y) if S then local oldsize = scrgetsize(S) if oldsize.x ~= x or oldsize.y ~= y then scrsetsize(S, x, y) end return S else S = newscreen(x, y) return S end end function fixchr(ev) if ev.symbol >= 1 and ev.symbol < 128 then ev.chr = ev.symbol else ev.chr = 0 end end function assignkey(ev, ch) if type(ch) == "number" then ev.symbol = ch ev.chr = 0 else ev.symbol = av(ch) if ev.type == evKeyDown then ev.chr = av(ch) else ev.chr = 0 end end end function checkkey(ev, ch) if type(ch) == "number" then return ev.symbol == ch else return ev.chr == av(ch) end end function getlayerX(val) return function(x) return getlayer(x, val) end end -- old 'tileshade', 'tilefill', and 'tilerecolor' functions function tilefill(x) return tilealpha(x, 0xFFFFFF) end function tileshade(x) return tilealpha(x, 0x808080) end function tilerecolor(x, y) return tilecol(x, y, recDefault) end spIWall = spIWallL + spIWallR spWall = spWallN + spWallE + spWallS + spWallW function tiletransform(t1, dx,dy, sx,sy) return tilexf(t1,dx,dy,sx,sy,0,0) end function tilemerge3(a,b,c) return tilemerge(tilemerge(a,b),c) end function tilemerge4(a,b,c,d) return tilemerge(tilemerge3(a,b,c),d) end vgaorig = {} for i=0,15 do vgaorig[i] = vgaget(i) end function vgareset() for i=0,15 do vgaset(i, vgaorig[i]) end end