Files
ascii/tools/scredit.lua
T
JailDoctor 5b82b260ab - [NEW] F1, F2 i F3 per al zoom i fullscreen
- [NEW] [tools/scredit.lua] C per a borrar pantalla en el caracter seleccionar, F per a flood fill
2026-05-18 09:04:04 +02:00

165 lines
3.6 KiB
Lua

ind = 22
function init()
mode(1)
map = {}
col = {}
for i=0,1199 do
map[i] = 32
col[i] = 0x0f
end
map[ind] = 65
sel_col = 0x0f
sel_chr = 65
end
blink=30
function update()
if btn(KEY_TAB) then
draw_picker()
update_picker()
else
draw_map()
--update_map()
end
end
function draw_picker()
for y=0,15 do
for x=0,15 do
poke(x+y*40, x+y*16)
poke(1200+x+y*40, sel_col)
end
end
for i=0,15 do
poke(1840+i, i<<4)
poke(1880+i, i<<4)
poke(640+i, 32)
poke(680+i, 32)
end
poke(1840, 15) poke(1880, 15)
poke(640+(sel_col&0xf), 203)
poke(680+(sel_col>>4), 203)
local mx, my = mousex(), mousey()
if mx<16 then
if my<16 then
poke(1200+(mx+my*40), 0x4e)
print(mx+my*40, 16, 13)
elseif my>=16 then
poke(mx+my*40, 144)
end
end
end
function update_picker()
local mx, my = mousex(), mousey()
if mousebutton(1) then
if mx<16 then
if my<16 then
sel_chr = mx+my*16
else
if my == 16 then
sel_col = (sel_col & 0xf0) + mx
elseif my == 17 then
sel_col = (sel_col & 0x0f) + (mx << 4)
end
end
end
end
end
local W, H = 40, 30
function flood_fill(x, y)
-- índice inicial
local idx0 = x + y * W
local target_chr = map[idx0]
local target_col = col[idx0]
-- Si ya está pintado con lo que queremos, no hacemos nada
if target_chr == sel_chr and target_col == sel_col then
return
end
-- Pila para DFS iterativo
local stack = {}
local sp = 1
stack[sp] = {x = x, y = y}
while sp > 0 do
local p = stack[sp]
sp = sp - 1
local px, py = p.x, p.y
-- Comprobación de límites
if px >= 0 and px < W and py >= 0 and py < H then
local idx = px + py * W
-- ¿Coincide con el color original?
if map[idx] == target_chr and col[idx] == target_col then
-- Pintar
map[idx] = sel_chr
col[idx] = sel_col
-- Añadir vecinos
sp = sp + 1; stack[sp] = {x = px+1, y = py}
sp = sp + 1; stack[sp] = {x = px-1, y = py}
sp = sp + 1; stack[sp] = {x = px, y = py+1}
sp = sp + 1; stack[sp] = {x = px, y = py-1}
end
end
end
end
function draw_map()
for i=0,1199 do
poke(i, map[i])
poke(1200+i, col[i])
end
local mx, my = mousex(), mousey()
if mousebutton(1) then
map[mx+my*40] = sel_chr
col[mx+my*40] = sel_col
end
if btn(KEY_SPACE) then
sel_chr = peek(mx+my*40)
sel_col = peek(1200+mx+my*40)
end
if btnp(KEY_UP) then for i=40,1199 do map[i-40]=map[i]col[i-40]=col[i] end end
if btnp(KEY_DOWN) then for i=1159,0,-1 do map[i+40]=map[i]col[i+40]=col[i] end end
if btnp(KEY_LEFT) then for i=0,1198 do map[i]=map[i+1]col[i]=col[i+1] end end
if btnp(KEY_RIGHT) then for i=1199,1,-1 do map[i]=map[i-1]col[i]=col[i-1] end end
blink = blink - 1
if blink < 30 then
if blink==0 then blink = 60 end
local mx, my = mousex(), mousey()
local c = peek(1200+(mx+my*40))
poke(1200+(mx+my*40), c~0xff)
end
if btn(KEY_S) then
fileout("scr.bin", 0, 2400);
elseif btn(KEY_L) then
filein("scr.bin", 0, 2400);
for i=0,1199 do
map[i] = peek(i)
col[i] = peek(1200+i)
end
elseif btn(KEY_C) then
for y=0,29 do
for x=0,39 do
map[x+y*40] = sel_chr
col[x+y*40] = sel_col
end
end
elseif btn(KEY_F) then
flood_fill(mousex(),mousey())
end
end