简化LOG.print的功能和使用

This commit is contained in:
MrZ626
2021-05-14 11:35:34 +08:00
parent c6115e3417
commit 5697a201ef
25 changed files with 112 additions and 121 deletions

View File

@@ -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,COLOR.O)
LOG.print("No BGM file: "..list[i],5,'warn')
end
if not skip and i~=count then
coroutine.yield()

View File

@@ -21,7 +21,7 @@ function FILE.load(name)
return s
end
end
LOG.print(name.." "..text.loadError,COLOR.R)
LOG.print(name.." "..text.loadError,'error')
end
end
function FILE.save(data,name,mode)
@@ -50,7 +50,7 @@ function FILE.save(data,name,mode)
F:flush()F:close()
if success then
if not mode:find'q'then
LOG.print(text.saveDone,COLOR.G)
LOG.print(text.saveDone,'message')
end
else
LOG.print(text.saveError..(mes or"unknown error"),'error')

View File

@@ -204,7 +204,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))
LOG.print(("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s"):format(SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num),'message')
elseif key=="f3"then
for _=1,8 do
local P=PLY_ALIVE[rnd(#PLY_ALIVE)]
@@ -217,11 +217,11 @@ local function noDevkeyPressed(key)
elseif key=="f5"then if WIDGET.sel then print(WIDGET.sel)end
elseif key=="f6"then for k,v in next,_G do print(k,v)end
elseif key=="f7"then if love._openConsole then love._openConsole()end
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.Y)
elseif key=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.Y)
elseif key=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.Y)
elseif key=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.Y)
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.Y)
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF")
elseif key=="f9"then devMode=1 LOG.print("DEBUG 1")
elseif key=="f10"then devMode=2 LOG.print("DEBUG 2")
elseif key=="f11"then devMode=3 LOG.print("DEBUG 3")
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4")
elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
elseif devMode==2 then
if WIDGET.sel then
@@ -251,7 +251,7 @@ function love.keypressed(key)
return
elseif key=="f8"then
devMode=1
LOG.print("DEBUG ON",COLOR.Y)
LOG.print("DEBUG ON")
elseif key=="f11"then
switchFullscreen()
elseif not SCN.swapping then
@@ -278,12 +278,13 @@ end
function love.joystickadded(JS)
ins(joysticks,JS)
LOG.print("Joystick added",'message')
end
function love.joystickremoved(JS)
local i=TABLE.find(joysticks,JS)
if i then
rem(joysticks,i)
LOG.print("Joystick removed",COLOR.Y)
LOG.print("Joystick removed",'message')
end
end
local keyMirror={

View File

@@ -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',COLOR.R)
LOG.print("Cannot load "..name..": "..(r2 or r3),'warn')
end
elseif SYSTEM=="Android"then
local fs=love.filesystem
@@ -12,35 +12,35 @@ return function(name,libName)
local libFunc=package.loadlib(SAVEDIR.."/lib/"..libName.Android,libName.libFunc)
if libFunc then
LOG.print(name.." lib loaded",'warn',COLOR.G)
LOG.print(name.." lib loaded",'message')
else
for i=1,#platform do
local soFile=fs.read('data',"libAndroid/"..platform[i].."/"..libName.Android)
local soFile,_,_,mes1=fs.read('data',"libAndroid/"..platform[i].."/"..libName.Android)
if soFile then
local success,message=fs.write("lib/"..libName.Android,soFile)
local success,mes2=fs.write("lib/"..libName.Android,soFile)
if success then
libFunc,message=package.loadlib(SAVEDIR.."/lib/"..libName.Android,libName.libFunc)
libFunc,mes2=package.loadlib(SAVEDIR.."/lib/"..libName.Android,libName.libFunc)
if libFunc then
LOG.print(name.." lib loaded",'warn',COLOR.G)
LOG.print(name.." lib loaded",'message')
break
else
LOG.print("Cannot load "..name..": "..message,'warn',COLOR.R)
LOG.print("Cannot load "..name..": "..mes2,'error')
end
else
LOG.print("Write "..name.."-"..platform[i].." to saving failed: "..message,'warn',COLOR.R)
LOG.print(("Write %s-%s to saving failed: %s"):format(name,platform[i],mes2),'error')
end
else
LOG.print("Read "..name.."-"..platform[i].." failed",'warn',COLOR.R)
LOG.print(("Read %s-%s to saving failed: %s"):format(name,platform[i],mes1),'error')
end
end
if not libFunc then
LOG.print("Cannot load "..name,'warn',COLOR.R)
LOG.print("Cannot load "..name,'error')
return
end
end
return libFunc()
else
LOG.print("No "..name.." for "..SYSTEM,'warn',COLOR.R)
LOG.print("No "..name.." for "..SYSTEM,'error')
return
end
return true

View File

@@ -35,36 +35,26 @@ function LOG.draw()
end
end
end
function LOG.print(text,T,C)--text,type/time/color,color
local time
local his
if T=='warn'then
C=C or COLOR.Y
his=true
time=180
function LOG.print(text,T)--text,type/time/color,color
local color=COLOR.Z
local time,his
if T=='message'then
color=COLOR.N
his,time=true,180
elseif T=='warn'then
color=COLOR.Y
his,time=true,180
elseif T=='error'then
C=C or COLOR.R
his=true
time=210
elseif T=='message'then
C=C or COLOR.N
his=true
color=COLOR.R
his,time=true,210
elseif type(T)=='number'then
C=C or COLOR.Z
time=T
elseif type(T)=='table'then
C=T
elseif not C then
C=COLOR.Z
end
if his then
ins(debugMesHistory,SCN.cur..": "..tostring(text))
end
ins(debugMesList,{text=tostring(text),r=C[1],g=C[2],b=C[3],blink=30,time=time or 120})
if his then ins(debugMesHistory,SCN.cur..": "..tostring(text))end
ins(debugMesList,{text=tostring(text),r=color[1],g=color[2],b=color[3],blink=30,time=time or 120})
end
function LOG.copy()
local str=table.concat(debugMesHistory,"\n")
love.system.setClipboardText(str)
LOG.print("Log copied",COLOR.B)
love.system.setClipboardText(table.concat(debugMesHistory,"\n"))
LOG.print("Log copied",'message')
end
return LOG

View File

@@ -141,10 +141,10 @@ function profile.switch()
profile.stop()
love.system.setClipboardText(PROFILE.report())
PROFILE.reset()
LOG.print("profile report copied!")
LOG.print("profile report copied!",'message')
else
PROFILE.start()
LOG.print("profile start!")
LOG.print("profile start!",'message')
end
switch=not switch
end

View File

@@ -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,5,COLOR.O)
LOG.print("No SFX file: "..N,5)
end
if not skip and i~=count then
coroutine.yield()

View File

@@ -48,15 +48,15 @@ function THEME.set(theme)
elseif theme=='xmas'then
BG.setDefault('snow')
BGM.setDefault('xmas')
LOG.print("==============",COLOR.R)
LOG.print("Merry Christmas!",COLOR.Z)
LOG.print("==============",COLOR.R)
LOG.print("==============")
LOG.print("Merry Christmas!")
LOG.print("==============")
elseif theme=='sprfes'then
BG.setDefault('firework')
BGM.setDefault("spring festival")
LOG.print(" ★☆☆★",COLOR.R)
LOG.print("新年快乐!",COLOR.Z)
LOG.print(" ★☆☆★",COLOR.R)
LOG.print(" ★☆☆★")
LOG.print("新年快乐!")
LOG.print(" ★☆☆★")
elseif theme=='zday1'then
BG.setDefault('lanterns')
BGM.setDefault("empty")

View File

@@ -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],5,COLOR.O)
LOG.print("No VOICE file: "..list[i],5)
end
end
if not Source[list[i]][1]then Source[list[i]]=nil end