暂时使用未完成的MES模块替换LOG模块
This commit is contained in:
@@ -50,7 +50,7 @@ function BGM.init(list)
|
||||
Sources[list[i]]:setLooping(true)
|
||||
Sources[list[i]]:setVolume(0)
|
||||
else
|
||||
LOG.print("No BGM file: "..list[i],5,'warn')
|
||||
MES.new("No BGM file: "..list[i],5)
|
||||
end
|
||||
if not skip and i~=count then
|
||||
coroutine.yield()
|
||||
|
||||
@@ -21,7 +21,7 @@ function FILE.load(name)
|
||||
return s
|
||||
end
|
||||
end
|
||||
LOG.print(name.." "..text.loadError,'error')
|
||||
MES.new(name.." "..text.loadError)
|
||||
end
|
||||
end
|
||||
function FILE.save(data,name,mode)
|
||||
@@ -30,13 +30,13 @@ function FILE.save(data,name,mode)
|
||||
if mode:find'l'then
|
||||
data=TABLE.dump(data)
|
||||
if not data then
|
||||
LOG.print(name.." "..text.saveError.."dump error",'error')
|
||||
MES.new(name.." "..text.saveError.."dump error")
|
||||
return
|
||||
end
|
||||
else
|
||||
data=JSON.encode(data)
|
||||
if not data then
|
||||
LOG.print(name.." "..text.saveError.."json error",'error')
|
||||
MES.new(name.." "..text.saveError.."json error")
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -50,11 +50,11 @@ function FILE.save(data,name,mode)
|
||||
F:flush()F:close()
|
||||
if success then
|
||||
if not mode:find'q'then
|
||||
LOG.print(text.saveDone,'message')
|
||||
MES.new(text.saveDone)
|
||||
end
|
||||
else
|
||||
LOG.print(text.saveError..(mes or"unknown error"),'error')
|
||||
LOG.print(debug.traceback(),'error')
|
||||
MES.new(text.saveError..(mes or"unknown error"))
|
||||
MES.new(debug.traceback())
|
||||
end
|
||||
end
|
||||
function FILE.clear(path)
|
||||
|
||||
@@ -11,7 +11,6 @@ ADRAW=require"Zframework.aDraw"
|
||||
|
||||
SCR= require"Zframework.screen"
|
||||
COLOR= require"Zframework.color"
|
||||
LOG= require"Zframework.log"
|
||||
SCN= require"Zframework.scene"
|
||||
WS= require"Zframework.websocket"
|
||||
|
||||
@@ -31,6 +30,7 @@ BG= require"Zframework.background"
|
||||
WIDGET= require"Zframework.widget"
|
||||
TEXT= require"Zframework.text"
|
||||
SYSFX= require"Zframework.sysFX"
|
||||
MES= require"Zframework.message"
|
||||
|
||||
IMG= require"Zframework.image"
|
||||
BGM= require"Zframework.bgm"
|
||||
@@ -208,7 +208,7 @@ local function noDevkeyPressed(key)
|
||||
if key=="f1"then
|
||||
PROFILE.switch()
|
||||
elseif key=="f2"then
|
||||
LOG.print(("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s"):format(SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num),'message')
|
||||
MES.new(("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s"):format(SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num))
|
||||
elseif key=="f3"then
|
||||
for _=1,8 do
|
||||
local P=PLY_ALIVE[rnd(#PLY_ALIVE)]
|
||||
@@ -218,7 +218,7 @@ local function noDevkeyPressed(key)
|
||||
end
|
||||
end
|
||||
elseif key=="f4"and not kb.isDown("lalt","ralt")then
|
||||
LOG.copy()
|
||||
MES.new.copy()
|
||||
elseif key=="f5"then
|
||||
print(WIDGET.isFocus()or"no widget selected")
|
||||
elseif key=="f6"then
|
||||
@@ -226,15 +226,15 @@ local function noDevkeyPressed(key)
|
||||
elseif key=="f7"and love._openConsole then
|
||||
love._openConsole()
|
||||
elseif key=="f8"then
|
||||
devMode=nil LOG.print("DEBUG OFF",.2)
|
||||
devMode=nil MES.new("DEBUG OFF",.2)
|
||||
elseif key=="f9"then
|
||||
devMode=1 LOG.print("DEBUG 1")
|
||||
devMode=1 MES.new("DEBUG 1")
|
||||
elseif key=="f10"then
|
||||
devMode=2 LOG.print("DEBUG 2")
|
||||
devMode=2 MES.new("DEBUG 2")
|
||||
elseif key=="f11"then
|
||||
devMode=3 LOG.print("DEBUG 3")
|
||||
devMode=3 MES.new("DEBUG 3")
|
||||
elseif key=="f12"then
|
||||
devMode=4 LOG.print("DEBUG 4")
|
||||
devMode=4 MES.new("DEBUG 4")
|
||||
elseif devMode==2 then
|
||||
local W=WIDGET.sel
|
||||
if W then
|
||||
@@ -263,7 +263,7 @@ function love.keypressed(key)
|
||||
return
|
||||
elseif key=="f8"then
|
||||
devMode=1
|
||||
LOG.print("DEBUG ON",.2)
|
||||
MES.new("DEBUG ON",.2)
|
||||
elseif key=="f11"then
|
||||
if kb.isDown("lctrl","rctrl")then
|
||||
_G["\100\114\97\119\70\87\77"]=NULL
|
||||
@@ -294,13 +294,13 @@ end
|
||||
|
||||
function love.joystickadded(JS)
|
||||
ins(joysticks,JS)
|
||||
LOG.print("Joystick added",'message')
|
||||
MES.new("Joystick added")
|
||||
end
|
||||
function love.joystickremoved(JS)
|
||||
local i=TABLE.find(joysticks,JS)
|
||||
if i then
|
||||
rem(joysticks,i)
|
||||
LOG.print("Joystick removed",'message')
|
||||
MES.new("Joystick removed")
|
||||
end
|
||||
end
|
||||
local keyMirror={
|
||||
@@ -359,7 +359,7 @@ function love.lowmemory()
|
||||
if TIME()-lastGCtime>6.26 then
|
||||
collectgarbage()
|
||||
lastGCtime=TIME()
|
||||
LOG.print("[auto GC] low MEM 设备内存过低",'warn')
|
||||
MES.new("[auto GC] low MEM 设备内存过低")
|
||||
end
|
||||
end
|
||||
function love.resize(w,h)
|
||||
@@ -519,7 +519,7 @@ function love.run()
|
||||
local love=love
|
||||
|
||||
local VOC,BG,SYSFX=VOC,BG,SYSFX
|
||||
local TASK,LOG,TEXT=TASK,LOG,TEXT
|
||||
local TASK,TEXT=TASK,TEXT
|
||||
|
||||
local TEXTURE,TIME=TEXTURE,TIME
|
||||
local SETTING,VERSION=SETTING,VERSION
|
||||
@@ -570,7 +570,7 @@ function love.run()
|
||||
if SCN.update then SCN.update(dt)end
|
||||
if SCN.swapping then SCN.swapUpdate()end
|
||||
TEXT.update()
|
||||
LOG.update(dt)
|
||||
MES.update(dt)
|
||||
|
||||
--DRAW
|
||||
if not MINI()then
|
||||
@@ -597,9 +597,8 @@ function love.run()
|
||||
gc_setColor(1,1,1)
|
||||
gc_draw(ms.isDown(1)and cursor_holdImg or cursorImg,mx,my,nil,nil,nil,8,8)
|
||||
end
|
||||
gc_replaceTransform(SCR.xOy_ul)
|
||||
LOG.draw()
|
||||
gc_replaceTransform(SCR.origin)
|
||||
MES.draw()
|
||||
--Draw power info.
|
||||
if SETTING.powerInfo then
|
||||
gc_setColor(1,1,1)
|
||||
|
||||
@@ -118,8 +118,8 @@ function json.encode(val)
|
||||
local a,b=pcall(encode,val)
|
||||
if a then
|
||||
return b
|
||||
elseif LOG then
|
||||
LOG.print(text.jsonError..": "..(b or"uknErr"),'warn')
|
||||
elseif MES.new then
|
||||
MES.new(text.jsonError..": "..(b or"uknErr"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -348,8 +348,8 @@ function json.decode(str)
|
||||
local a,b=pcall(decode,str)
|
||||
if a then
|
||||
return b
|
||||
elseif LOG then
|
||||
LOG.print(text.jsonError..": "..(b or"uknErr"),'warn')
|
||||
elseif MES.new then
|
||||
MES.new(text.jsonError..": "..(b or"uknErr"))
|
||||
end
|
||||
end
|
||||
return json
|
||||
@@ -4,7 +4,7 @@ return function(name,libName)
|
||||
if r1 and r2 then
|
||||
return r2
|
||||
else
|
||||
LOG.print("Cannot load "..name..": "..(r2 or r3),'warn')
|
||||
MES.new("Cannot load "..name..": "..(r2 or r3))
|
||||
end
|
||||
elseif SYSTEM=="Android"then
|
||||
local fs=love.filesystem
|
||||
@@ -17,25 +17,25 @@ return function(name,libName)
|
||||
if success then
|
||||
libFunc,mes2=package.loadlib(SAVEDIR.."/lib/"..libName.Android,libName.libFunc)
|
||||
if libFunc then
|
||||
LOG.print(name.." lib loaded",'message')
|
||||
MES.new(name.." lib loaded")
|
||||
break
|
||||
else
|
||||
LOG.print("Cannot load "..name..": "..mes2,'error')
|
||||
MES.new("Cannot load "..name..": "..mes2)
|
||||
end
|
||||
else
|
||||
LOG.print(("Write %s-%s to saving failed: %s"):format(name,platform[i],mes2),'error')
|
||||
MES.new(("Write %s-%s to saving failed: %s"):format(name,platform[i],mes2))
|
||||
end
|
||||
else
|
||||
LOG.print(("Read %s-%s to saving failed: %s"):format(name,platform[i],mes1),'error')
|
||||
MES.new(("Read %s-%s to saving failed: %s"):format(name,platform[i],mes1))
|
||||
end
|
||||
end
|
||||
if not libFunc then
|
||||
LOG.print("Cannot load "..name,'error')
|
||||
MES.new("Cannot load "..name)
|
||||
return
|
||||
end
|
||||
return libFunc()
|
||||
else
|
||||
LOG.print("No "..name.." for "..SYSTEM,'error')
|
||||
MES.new("No "..name.." for "..SYSTEM)
|
||||
return
|
||||
end
|
||||
return true
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
local utf8=require"utf8"
|
||||
local gc=love.graphics
|
||||
local gc_setColor,gc_print=gc.setColor,gc.print
|
||||
local int,min=math.floor,math.min
|
||||
local ins,rem=table.insert,table.remove
|
||||
local setFont=setFont
|
||||
|
||||
local mesList={}
|
||||
local mesHistory={
|
||||
"Version: "..VERSION.string,
|
||||
os.date("Launched at %Y/%m/%d %H:%M"),
|
||||
}
|
||||
local LOG={}
|
||||
function LOG.update(dt)
|
||||
if mesList[1]then
|
||||
for i=#mesList,1,-1 do
|
||||
local M=mesList[i]
|
||||
if M.blink>0 then
|
||||
M.blink=M.blink-1
|
||||
else
|
||||
M.time=M.time-dt
|
||||
if M.time<=0 then
|
||||
rem(mesList,i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function LOG.draw()
|
||||
if mesList[1]then
|
||||
setFont(20)
|
||||
for i=1,#mesList do
|
||||
local M=mesList[i]
|
||||
M.rgba[4]=M.blink>0 and int(M.blink/3)%2 or min(M.time*60/26,1)
|
||||
gc_setColor(M.rgba)
|
||||
gc_print(M.text,10+(20-min(M.time*60,20))^1.5/4,25*i)
|
||||
end
|
||||
end
|
||||
end
|
||||
function LOG.print(text,T)--text,type/time
|
||||
local color=COLOR.Z
|
||||
local his,time
|
||||
if T=='message'then
|
||||
color=COLOR.N
|
||||
his,time=true,4
|
||||
elseif T=='warn'then
|
||||
color=COLOR.Y
|
||||
his,time=true,4
|
||||
elseif T=='error'then
|
||||
color=COLOR.R
|
||||
his,time=true,5
|
||||
elseif type(T)=='number'then
|
||||
time=T
|
||||
end
|
||||
text=tostring(text)
|
||||
assert(utf8.len(text),"Error UTF-8 coding")
|
||||
if his then ins(mesHistory,SCN.cur..": "..text)end
|
||||
ins(mesList,{text=text,rgba={color[1],color[2],color[3],nil},blink=30,time=time or 3})
|
||||
end
|
||||
function LOG.copy()
|
||||
love.system.setClipboardText(table.concat(mesHistory,"\n"))
|
||||
LOG.print("Log copied",'message')
|
||||
end
|
||||
return LOG
|
||||
70
Zframework/message.lua
Normal file
70
Zframework/message.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
local gc=love.graphics
|
||||
local gc_push,gc_pop=gc.push,gc.pop
|
||||
local gc_replaceTransform=gc.replaceTransform
|
||||
local gc_translate,gc_setColor,gc_draw=gc.translate,gc.setColor,gc.draw
|
||||
|
||||
local ins,rem=table.insert,table.remove
|
||||
|
||||
local mesList={}
|
||||
|
||||
local MES={}
|
||||
|
||||
function MES.new(...)
|
||||
local icon,str,time=...
|
||||
if type(icon)~='userdata'then
|
||||
icon,str,time=false,icon,str
|
||||
else
|
||||
end
|
||||
local t=gc.newText(getFont(30),str)
|
||||
local w=math.max(t:getWidth()+(icon and 45 or 5),200)
|
||||
local L={w+20,48,
|
||||
{'setCL',.5,.5,.5,.7},
|
||||
{'fRect',0,0,w+20,48},
|
||||
{'setCL',.9,.9,.9},
|
||||
{'setLW',2},
|
||||
{'dRect',1,1,w+18,46},
|
||||
{'setCL',1,1,1},
|
||||
}
|
||||
if icon then
|
||||
ins(L,{'draw',icon,4,4,nil,40/icon:getWidth(),40/icon:getHeight()})
|
||||
end
|
||||
ins(L,{'draw',t,icon and 50 or 10,2})
|
||||
|
||||
ins(mesList,{
|
||||
startTime=.5,
|
||||
endTime=.5,
|
||||
time=time or 3,
|
||||
canvas=DOGC(L),
|
||||
})
|
||||
end
|
||||
|
||||
function MES.update(dt)
|
||||
for i=#mesList,1,-1 do
|
||||
local m=mesList[i]
|
||||
if m.startTime>0 then
|
||||
m.startTime=m.startTime-dt
|
||||
elseif m.time>0 then
|
||||
m.time=m.time-dt
|
||||
elseif m.endTime>0 then
|
||||
m.endTime=m.endTime-dt
|
||||
else
|
||||
rem(mesList,i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MES.draw()
|
||||
gc_push('transform')
|
||||
if #mesList>0 then
|
||||
gc_translate(0,25)
|
||||
for i=1,#mesList do
|
||||
local m=mesList[i]
|
||||
gc_setColor(1,1,1,2*(m.endTime-m.startTime))
|
||||
gc_draw(m.canvas,40-80*(m.endTime+m.startTime))
|
||||
gc_translate(0,52)
|
||||
end
|
||||
gc_replaceTransform(SCR.xOy)
|
||||
end
|
||||
gc_pop()
|
||||
end
|
||||
return MES
|
||||
@@ -141,10 +141,10 @@ function profile.switch()
|
||||
profile.stop()
|
||||
love.system.setClipboardText(PROFILE.report())
|
||||
PROFILE.reset()
|
||||
LOG.print("profile report copied!",'message')
|
||||
MES.new("profile report copied!")
|
||||
else
|
||||
PROFILE.start()
|
||||
LOG.print("profile start!",'message')
|
||||
MES.new("profile start!")
|
||||
end
|
||||
switch=not switch
|
||||
end
|
||||
|
||||
@@ -150,7 +150,7 @@ function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
|
||||
S.time,S.mid,S.draw=s[1],s[2],s[3]
|
||||
end
|
||||
else
|
||||
LOG.print("No Scene: "..tar,'warn')
|
||||
MES.new("No Scene: "..tar)
|
||||
end
|
||||
end
|
||||
function SCN.go(tar,style)--Normal scene swapping, can back
|
||||
@@ -158,7 +158,7 @@ function SCN.go(tar,style)--Normal scene swapping, can back
|
||||
SCN.push()
|
||||
SCN.swapTo(tar,style)
|
||||
else
|
||||
LOG.print("No Scene: "..tar,'warn')
|
||||
MES.new("No Scene: "..tar)
|
||||
end
|
||||
end
|
||||
function SCN.back()
|
||||
|
||||
@@ -17,7 +17,7 @@ function SFX.init(list)
|
||||
if love.filesystem.getInfo(N)then
|
||||
Sources[list[i]]={love.audio.newSource(N,'static')}
|
||||
else
|
||||
LOG.print("No SFX file: "..N,.1)
|
||||
MES.new("No SFX file: "..N,.1)
|
||||
end
|
||||
if not skip and i~=count then
|
||||
coroutine.yield()
|
||||
|
||||
@@ -52,18 +52,18 @@ function THEME.set(theme)
|
||||
elseif theme=='xmas'then
|
||||
BG.setDefault('snow')
|
||||
BGM.setDefault('xmas')
|
||||
LOG.print("==============")
|
||||
LOG.print("Merry Christmas!")
|
||||
LOG.print("==============")
|
||||
MES.new("==============")
|
||||
MES.new("Merry Christmas!")
|
||||
MES.new("==============")
|
||||
elseif theme=='birth'then
|
||||
BG.setDefault('firework')
|
||||
BGM.setDefault('magicblock')
|
||||
elseif theme=='sprfes'then
|
||||
BG.setDefault('firework')
|
||||
BGM.setDefault("spring festival")
|
||||
LOG.print(" ★☆☆★")
|
||||
LOG.print("新年快乐!")
|
||||
LOG.print(" ★☆☆★")
|
||||
MES.new(" ★☆☆★")
|
||||
MES.new("新年快乐!")
|
||||
MES.new(" ★☆☆★")
|
||||
elseif theme=='zday1'then
|
||||
BG.setDefault('lanterns')
|
||||
BGM.setDefault("empty")
|
||||
|
||||
@@ -45,7 +45,7 @@ function VOC.init(list)
|
||||
|
||||
if n==1 then
|
||||
if not loadVoiceFile(list[i],list[i])then
|
||||
LOG.print("No VOICE file: "..list[i],.1)
|
||||
MES.new("No VOICE file: "..list[i],.1)
|
||||
end
|
||||
end
|
||||
if not Source[list[i]][1]then Source[list[i]]=nil end
|
||||
|
||||
@@ -349,7 +349,7 @@ function WS.update(dt)
|
||||
ws.pongTimer=1
|
||||
else
|
||||
ws.status='dead'
|
||||
LOG.print(text.wsFailed..": "..(mes=="timeout"and text.netTimeout or mes),'warn')
|
||||
MES.new(text.wsFailed..": "..(mes=="timeout"and text.netTimeout or mes))
|
||||
end
|
||||
end
|
||||
elseif ws.status=='running'then
|
||||
|
||||
@@ -617,7 +617,7 @@ function selector:reset()
|
||||
self.selText=self.list[i]
|
||||
else
|
||||
self.hide=true
|
||||
LOG.print("Selector "..self.name.." dead, disp= "..tostring(V),'warn')
|
||||
MES.new("Selector "..self.name.." dead, disp= "..tostring(V))
|
||||
end
|
||||
end
|
||||
function selector:isAbove(x,y)
|
||||
@@ -771,7 +771,7 @@ function inputBox:addText(str)
|
||||
if type(str)=='string'then
|
||||
self.value=self.value..str
|
||||
else
|
||||
LOG.print("inputBox "..self.name.." dead, addText("..type(str)..")",'warn')
|
||||
MES.new("inputBox "..self.name.." dead, addText("..type(str)..")")
|
||||
end
|
||||
end
|
||||
function inputBox:clear()
|
||||
|
||||
Reference in New Issue
Block a user