From 68c4a9fceb04eb843eee4247a79838fab40279ee Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sun, 6 Sep 2020 21:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E5=AD=97=E4=BD=93=E6=97=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=BC=95=E6=93=8E=E8=87=AA=E5=B8=A6=E5=AD=97?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/toolfunc.lua | 49 ++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index de92160b..94c38233 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -2,23 +2,42 @@ local gc=love.graphics local int=math.floor local format=string.format -local fontData=love.filesystem.newFile("font.ttf") -local newFont=gc.setNewFont -local setNewFont=gc.setFont -local fontCache,currentFontSize={} -function setFont(s) - local f=fontCache[s] - if s~=currentFontSize then - if f then - setNewFont(f) - else - f=newFont(fontData,s) - fontCache[s]=f - setNewFont(f) +do + local newFont=gc.setNewFont + local setNewFont=gc.setFont + local fontCache,currentFontSize={} + if love.filesystem.getInfo("font.ttf")then + local fontData=love.filesystem.newFile("font.ttf") + function setFont(s) + local f=fontCache[s] + if s~=currentFontSize then + if f then + setNewFont(f) + else + f=newFont(fontData,s) + fontCache[s]=f + setNewFont(f) + end + currentFontSize=s + end + return f + end + else + function setFont(s) + local f=fontCache[s] + if s~=currentFontSize then + if f then + setNewFont(f) + else + f=newFont(s) + fontCache[s]=f + setNewFont(f) + end + currentFontSize=s + end + return f end - currentFontSize=s end - return f end function toTime(s)