Improvements...III

This commit is contained in:
asciibene 2022-04-14 23:43:11 -04:00
parent ae1bb53004
commit 602c3f947c
3 changed files with 89 additions and 15 deletions

View File

@ -3,3 +3,10 @@
graphed is a simple tool to create _ascii art_
It is very rudimentary for now...
## Changelog
- Version 0.2
- *WIP*
- Version 0.1
- added file write/load
-

View File

@ -2,13 +2,11 @@
nc = require("nocurses")
dofile("simplefuncs.lua")
-- Misc nc funcs ============================
COLORS={"BLACK","RED","GREEN","YELLOW","BLUE","MAGENTA","CYAN","WHITE"}
MSIZE_X=32 -- Map
MSIZE_Y=24 ---- size
PL_GLYPH="@"
VER=0.08
-- MAKE Map matrix -------------
VER=0.10
-- -------------- START FUNC -----------
function start()
nc.setcurshape("BAR")
@ -17,7 +15,7 @@ function start()
map=mkmat()
mapcolors=mkmat()
p=mkpointer()
nc.clrscr()
-- Now main loop
main()
end
@ -33,7 +31,12 @@ function drawmap()
end
-- XXX draw last info line XXX
nc.gotoxy(0,MSIZE_Y+1)
print("X:"..p.x.." | ".." Y:"..p.y.." ")
print("X:"..p.x.." | ".." Y:"..p.y.." ")
if mesg_string~=nil then
nc.gotoxy(1,1)
print(mesg_string)
mesg_string=nil
end
end
function drawmap_fg() -- Draw map foreground
@ -42,18 +45,20 @@ function drawmap_fg() -- Draw map foreground
print(p.glyph)
nc.setfontcolor("WHITE")
end
----------- main func -----
-- end drawmap--> main func ---------VVVVVVVVV
function main()
printul("Graphed")
print("version "..VER)
printul("Graphed -- 'Graphical Editor' --")
printcol("http://asciibene.tx0.org/","YELLOW")
printcol("version "..VER,"CYAN")
while exitbool~=true do
if await_cmd()~=0 then
drawmap()
drawmap_fg()
end
end
end
nc.clrscr()
printul("Goodbye...")
end
@ -64,17 +69,25 @@ function await_cmd()
k=string.char(nc.getch())
if k=="h" and p.x>1 then
movep(-1,0)
elseif k=="j" and p.y<=MSIZE_Y then
elseif k=="j" and p.y<MSIZE_Y then
movep(0,1)
elseif k=="k" and p.y>1 then
movep(0,-1)
elseif k=="l" and p.x<MSIZE_X then
movep(1,0)
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)
elseif k=="q" then
exitbool=true
elseif k=="t" then
showmesg("This is a test")
elseif k=="g" then
mesg_string="This is a test"
elseif k=="c" then
changep()
elseif k=="." then
map[p.x][p.y]=p.glyph
@ -84,18 +97,49 @@ function await_cmd()
write()
elseif k=="?" then
help()
elseif k=="o" then
-- TODO OPTIONS -----
elseif k=="s" then
changesize()
else
return 0
end
end
-- TODO make load func TODO
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
function help()
nc.clrscr()
nc.setfontcolor("BLUE")
printul("graphed commands")
print("g -> change current glyph")
print("c -> change current glyph")
print(". -> place current glyph on screen")
print("x -> delete glyph under cursor")
-- TODO
@ -105,6 +149,20 @@ function help()
nc.setfontcolor("WHITE")
end
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
function write()
nc.clrscr()
print("Enter Filename")
@ -117,9 +175,10 @@ function write()
end
fp:write("\n")
end
fp:close()
nc.clrscr()
showmesg("wrote to file:'"..fn.."'. Press enter")
mesg_string="Wrote to file : "..fn
end
function movep(dx,dy)
@ -136,5 +195,7 @@ function changep()
p.glyph=c
end
-- -------------------------------------------
-- To write a ephemeral message that gets erased after any input (unlike 'press enter') messages then set 'mesg_string' to any value
-- ------------------------------------------
start()

View File

@ -6,6 +6,12 @@ function printul(s)
nc.setunderline(false)
end
function printcol(str,col)
nc.setfontcolor(col)
print(str)
nc.setfontcolor("WHITE")
end
function mkmat()
local mt
mt = {} -- create the matrix