forked from pyrex/chameleonic
Compare commits
10 Commits
e878717c31
...
sprintf
Author | SHA1 | Date | |
---|---|---|---|
e028209adf
|
|||
ce3fc83221
|
|||
3e2229be65
|
|||
46f1339e19
|
|||
f86e52d3bd
|
|||
e6c35dbeda
|
|||
3516d2855e
|
|||
2264349e72
|
|||
93c154f876
|
|||
3494c48e74
|
@ -38,6 +38,39 @@ function cycle(tbl,period)
|
||||
return tbl[t()%period*#tbl\period+1]
|
||||
end
|
||||
|
||||
-- fake sprintf function
|
||||
-- %~ for literal "%"
|
||||
-- %v for param
|
||||
-- %! for tostring(param)
|
||||
-- which dumps tables
|
||||
function fmt(f, ...)
|
||||
local out, i = "", 0
|
||||
for s in all(split(f,"%")) do
|
||||
if i == 0 then
|
||||
-- before first format directive
|
||||
out ..= s
|
||||
i = 1
|
||||
else
|
||||
local m = s[1]
|
||||
if m == "~" then
|
||||
out ..= "%"
|
||||
else
|
||||
local p = select(i,...)
|
||||
i+=1
|
||||
if m == "v" then
|
||||
out ..= p
|
||||
elseif m == "!" then
|
||||
out ..= tostring(p)
|
||||
else
|
||||
assert(false, tostr(m).."is not a formatting directive")
|
||||
end
|
||||
end
|
||||
out ..=sub(s,2)
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
mnames={}
|
||||
function names(root)
|
||||
local n=mnames[root]
|
||||
@ -246,14 +279,12 @@ function kbd:release(i)
|
||||
end
|
||||
|
||||
function tostring(any)
|
||||
if type(any)=="table" then
|
||||
if (type(any)!="table") return tostr(any)
|
||||
local str = "{ "
|
||||
for k,v in pairs(any) do
|
||||
str=str..tostring(k).."->"..tostring(v).." "
|
||||
str..=tostring(k).."->"..tostring(v).." "
|
||||
end
|
||||
return str.."}"
|
||||
end
|
||||
return tostr(any)
|
||||
end
|
||||
|
||||
-->8
|
||||
@ -269,7 +300,7 @@ function title:draw()
|
||||
print("pyrex",32,73,7)
|
||||
print("[nyeogmi]",62,73,7)
|
||||
print("kistaro",32,79,7)
|
||||
local lvlstr = "⬅️ "..start_level.." ➡️"
|
||||
local lvlstr = fmt("⬅️ %v ➡️",start_level)
|
||||
print(lvlstr,50,91,1)
|
||||
print(lvlstr,51,90,blinkcol)
|
||||
end
|
||||
@ -439,8 +470,7 @@ function level:recollide_reanchor()
|
||||
not self:mcoll(mx1,my0) and
|
||||
not self:mcoll(mx1,my1)
|
||||
) then
|
||||
local key="GEOM"..mx0..","..my0..","..dx..","..dy
|
||||
anch_new[key]= {
|
||||
anch_new[fmt("GEOM%v,%v,%v,%v",mx0,my0,dx,dy)]= {
|
||||
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
|
||||
}
|
||||
end
|
||||
@ -448,10 +478,9 @@ function level:recollide_reanchor()
|
||||
end
|
||||
|
||||
for _,cr in pairs(self._crates) do
|
||||
local key="CRATE"..cr.id..","..dx..","..dy
|
||||
local mx0,my0=cr.mx,cr.my
|
||||
local mx1,my1=mx0+dx,my0+dy
|
||||
anch_new[key]={
|
||||
anch_new[fmt("CRATE%v,%v,%v",cr.id,dx,dy)]={
|
||||
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
|
||||
}
|
||||
end
|
||||
@ -1059,7 +1088,7 @@ function rope:draw(artificial_px,artificial_py)
|
||||
if (anch.ady>0) y-=1
|
||||
end
|
||||
rectfill(x-1,y-1,x+1,y+1,12)
|
||||
print("ax="..n1.ax..",ay="..n1.ay,72,sy)
|
||||
print(fmt("ax=%v,ay=%v",n1.ax,n1.ay),72,sy)
|
||||
sy+=7
|
||||
|
||||
local n0=n1.prev
|
||||
@ -1834,7 +1863,7 @@ function debugmouse:draw3()
|
||||
if (c == " ") spr(50,x,y)
|
||||
print(c,x,y,15)
|
||||
local px, py = mid(0,x,89), mid(0, y > 111 and y - 12 or y + 6, 117)
|
||||
print("("..x..", "..y..")\n["..(x\8)..", "..(y\8).."]",px,py,15)
|
||||
print(fmt("(%v, %v)\n[%v, %v]",x,y,x\8,y\8),px,py,15)
|
||||
pal()
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user