graphed/main.lua

198 lines
4.2 KiB
Lua
Raw Normal View History

2022-04-11 17:05:37 -04:00
-- Paint in your terminal
nc = require("nocurses")
2022-04-12 21:51:29 -04:00
dofile("simplefuncs.lua")
2022-04-11 17:05:37 -04:00
-- Misc nc funcs ============================
2022-04-12 21:51:29 -04:00
COLORS={"BLACK","RED","GREEN","YELLOW","BLUE","MAGENTA","CYAN","WHITE"}
MSIZE_X=32 -- Map
2022-04-11 17:05:37 -04:00
MSIZE_Y=24 ---- size
PL_GLYPH="@"
2022-04-14 23:43:11 -04:00
VER=0.10
2022-04-11 17:05:37 -04:00
-- -------------- START FUNC -----------
function start()
2022-04-11 23:02:57 -04:00
nc.setcurshape("BAR")
2022-04-11 17:05:37 -04:00
nc.clrscr()
-- Make X functions
map=mkmat()
2022-04-12 21:51:29 -04:00
mapcolors=mkmat()
2022-04-11 17:05:37 -04:00
p=mkpointer()
2022-04-14 23:43:11 -04:00
nc.clrscr()
2022-04-11 17:05:37 -04:00
-- Now main loop
main()
end
-- ----------------END START FUNC -------------
-- ====== DRAW MAP FUNC=========
function drawmap()
for ix=1,MSIZE_X do
for iy=1,MSIZE_Y do
nc.gotoxy(ix,iy)
print(map[ix][iy])
end
end
2022-04-11 23:02:57 -04:00
-- XXX draw last info line XXX
nc.gotoxy(0,MSIZE_Y+1)
2022-04-14 23:43:11 -04:00
print("X:"..p.x.." | ".." Y:"..p.y.." ")
if mesg_string~=nil then
nc.gotoxy(1,1)
print(mesg_string)
mesg_string=nil
end
2022-04-11 17:05:37 -04:00
end
function drawmap_fg() -- Draw map foreground
2022-04-12 21:51:29 -04:00
nc.setfontcolor("RED")
2022-04-11 17:05:37 -04:00
nc.gotoxy(p.x,p.y)
print(p.glyph)
2022-04-12 21:51:29 -04:00
nc.setfontcolor("WHITE")
2022-04-11 17:05:37 -04:00
end
2022-04-14 23:43:11 -04:00
-- end drawmap--> main func ---------VVVVVVVVV
2022-04-12 21:51:29 -04:00
function main()
2022-04-14 23:43:11 -04:00
printul("Graphed -- 'Graphical Editor' --")
printcol("http://asciibene.tx0.org/","YELLOW")
printcol("version "..VER,"CYAN")
2022-04-11 17:05:37 -04:00
while exitbool~=true do
2022-04-12 21:51:29 -04:00
if await_cmd()~=0 then
2022-04-11 17:05:37 -04:00
drawmap()
drawmap_fg()
2022-04-14 23:43:11 -04:00
end
2022-04-11 17:05:37 -04:00
end
nc.clrscr()
printul("Goodbye...")
2022-04-14 23:43:11 -04:00
2022-04-11 17:05:37 -04:00
end
-- END OF MAKE FUNCS ========== MAKE =====
function await_cmd()
local k
k=string.char(nc.getch())
2022-04-12 21:51:29 -04:00
if k=="h" and p.x>1 then
2022-04-11 17:05:37 -04:00
movep(-1,0)
2022-04-14 23:43:11 -04:00
elseif k=="j" and p.y<MSIZE_Y then
2022-04-11 17:05:37 -04:00
movep(0,1)
2022-04-12 21:51:29 -04:00
elseif k=="k" and p.y>1 then
2022-04-11 17:05:37 -04:00
movep(0,-1)
2022-04-12 21:51:29 -04:00
elseif k=="l" and p.x<MSIZE_X then
2022-04-14 23:43:11 -04:00
movep(1,0)
elseif k=="H" and p.x>3 then
movep(-3,0)
elseif k=="J" and p.y<MSIZE_Y-3 then
movep(0,3)
elseif k=="K" and p.y>3 then
movep(0,-3)
elseif k=="L" and p.x<MSIZE_X-3 then
movep(3,0)
2022-04-11 17:05:37 -04:00
elseif k=="q" then
exitbool=true
elseif k=="t" then
2022-04-14 23:43:11 -04:00
mesg_string="This is a test"
elseif k=="c" then
2022-04-11 23:02:57 -04:00
changep()
elseif k=="." then
2022-04-12 21:51:29 -04:00
map[p.x][p.y]=p.glyph
2022-04-11 23:02:57 -04:00
elseif k=="x" then
2022-04-12 21:51:29 -04:00
map[p.x][p.y]=" "
elseif k=="w" then
write()
elseif k=="?" then
help()
2022-04-14 23:43:11 -04:00
elseif k=="o" then
-- TODO OPTIONS -----
elseif k=="s" then
changesize()
2022-04-11 23:02:57 -04:00
else
return 0
2022-04-11 17:05:37 -04:00
end
2022-04-11 23:02:57 -04:00
end
2022-04-14 23:43:11 -04:00
function loadf(fn)
local tbl
fp=io.open(fn,"r")
ftxt={}
i=1
for i=1,MSIZE_Y do
ftxt[i]=io.read("l")
end
-- XXX This func is garbage XXX
-- initialze table
for ix=1,MSIZE_X do
for iy=1,MSIZE_Y do
tbl[ix]={}
tbl[ix][iy]=0
end
end
-- Read file
for ix=1,MSIZE_X do
for iy=1,MSIZE_Y do
end
end
return tbl
end
2022-04-11 23:02:57 -04:00
2022-04-12 21:51:29 -04:00
function help()
nc.clrscr()
nc.setfontcolor("BLUE")
printul("graphed commands")
2022-04-14 23:43:11 -04:00
print("c -> change current glyph")
2022-04-12 21:51:29 -04:00
print(". -> place current glyph on screen")
print("x -> delete glyph under cursor")
-- TODO
nc.setfontcolor("RED")
print("Press enter...")
nc.wait()
nc.setfontcolor("WHITE")
end
2022-04-14 23:43:11 -04:00
function changesize()
nc.clrscr()
print("Enter y size(lines)")
yin=io.read("l")
print("Enter y size(lines)")
xin=io.read("l")
MSIZE_X=tonumber(xin)
MSIZE_Y=tonumber(yin)
end
2022-04-12 21:51:29 -04:00
function write()
nc.clrscr()
print("Enter Filename")
fn=io.read("l")
fp=io.open(fn,"w+")
for i=1,MSIZE_Y do
for ii=1,MSIZE_X do
cc=map[ii][i]
fp:write(cc)
end
fp:write("\n")
end
2022-04-14 23:43:11 -04:00
2022-04-12 21:51:29 -04:00
fp:close()
nc.clrscr()
2022-04-14 23:43:11 -04:00
mesg_string="Wrote to file : "..fn
2022-04-11 17:05:37 -04:00
end
function movep(dx,dy)
p.x=p.x+dx
p.y=p.y+dy
2022-04-11 23:02:57 -04:00
end
function changep()
local c
showmesg("Press Enter and a new char:")
while c==nil do
c=string.char(nc.getch())
end
p.glyph=c
2022-04-11 17:05:37 -04:00
end
2022-04-14 23:43:11 -04:00
-- -------------------------------------------
-- To write a ephemeral message that gets erased after any input (unlike 'press enter') messages then set 'mesg_string' to any value
2022-04-11 17:05:37 -04:00
-- ------------------------------------------
start()