整理代码,lang模块功能特化

This commit is contained in:
MrZ626
2020-12-09 00:49:30 +08:00
parent d4075c6fa9
commit 123e453bd2
2 changed files with 16 additions and 18 deletions

View File

@@ -12,23 +12,30 @@ local tipMeta={__call=function(L)return L[math.random(#L)]end}
local langList={}
local publicText,publicWidgetText={},{}
local function lang_set(l)
text=langList[l]
WIDGET.setLang(text.WidgetText)
for _,s in next,drawableTextLoad do
drawableText[s]:set(text[s])
end
end
local LANG={}
--Must call before LANG.init
--Call these before call LANG.init()
function LANG.setLangList(list)langList=list end
function LANG.setPublicText(L)publicText=L end
function LANG.setPublicWidgetText(L)publicWidgetText=L end
function LANG.init()
function LANG.init()--Attention, calling this will DESTORY ALL METHODS, only left LANG.set()!
for i=1,#langList do
local L=langList[i]
--Set public text
for key,list in next,publicText do
L[key]=list
end
--Set public widget text
for key,list in next,publicWidgetText do
local WT=L.WidgetText
@@ -37,31 +44,24 @@ function LANG.init()
WT[key][k]=v
end
end
--Fallback to other language, default zh
if i>1 then
langFallback(langList[L.fallback or 1],L)
end
--Metatable:__call for table:getTip
if type(rawget(L,"getTip"))=="table"then
setmetatable(L.getTip,tipMeta)
end
--set global name for all back button
for _,v in next,L.WidgetText do
v.back=L.back
end
end
LANG.init=nil
end
function LANG.set(l)
text=langList[l]
WIDGET.setLang(text.WidgetText)
for _,s in next,drawableTextLoad do
drawableText[s]:set(text[s])
end
LANG.init,LANG.setLangList,LANG.setPublicText,LANG.setPublicWidgetText=nil
LANG.set=lang_set
end
return LANG

View File

@@ -3,12 +3,10 @@ local kb=love.keyboard
local int,abs=math.floor,math.abs
local max,min=math.max,math.min
local sub,format=string.sub,string.format
local ins=table.insert
local Timer=love.timer.getTime
local setFont,mStr=setFont,mStr
local widgetList={}
local WIDGET={}
local widgetMetatable={
__tostring=function(self)