language模块完全排除外部数据
This commit is contained in:
@@ -1,52 +1,3 @@
|
|||||||
local langList={
|
|
||||||
require"parts/language/lang_zh",
|
|
||||||
require"parts/language/lang_zh2",
|
|
||||||
require"parts/language/lang_en",
|
|
||||||
require"parts/language/lang_fr",
|
|
||||||
require"parts/language/lang_sp",
|
|
||||||
require"parts/language/lang_symbol",
|
|
||||||
require"parts/language/lang_yygq",
|
|
||||||
--Add new language file to LANG folder. Attention, new language won't show in-game when you add language
|
|
||||||
}
|
|
||||||
local publicText={
|
|
||||||
block={
|
|
||||||
"Z","S","J","L","T","O","I",
|
|
||||||
"Z5","S5","Q","P","F","E",
|
|
||||||
"T5","U","V","W","X",
|
|
||||||
"J5","L5","R","Y","N","H","I5"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
local publicWidgetText={
|
|
||||||
calculator={
|
|
||||||
_1="1",_2="2",_3="3",
|
|
||||||
_4="4",_5="5",_6="6",
|
|
||||||
_7="7",_8="8",_9="9",
|
|
||||||
_0="0",["."]=".",e="e",
|
|
||||||
["+"]="+",["-"]="-",["*"]="*",["/"]="/",
|
|
||||||
["<"]="<",["="]="=",
|
|
||||||
play="-->",
|
|
||||||
},
|
|
||||||
staff={},
|
|
||||||
history={
|
|
||||||
prev="↑",
|
|
||||||
next="↓",
|
|
||||||
},
|
|
||||||
lang={
|
|
||||||
zh="中文",
|
|
||||||
zh2="全中文",
|
|
||||||
en="English",
|
|
||||||
fr="Français",
|
|
||||||
sp="Español",
|
|
||||||
symbol="?????",
|
|
||||||
yygq="就这?",
|
|
||||||
},
|
|
||||||
custom_field={
|
|
||||||
b0="",b1="",b2="",b3="",b4="",b5="",b6="",b7="",
|
|
||||||
b8="",b9="",b10="",b11="",b12="",b13="",b14="",b15="",b16="",
|
|
||||||
b17="[ ]",b18="N",b19="B",b20="_",b21="_",b22="_",b23="_",b24="_",
|
|
||||||
},
|
|
||||||
mg_cubefield={},
|
|
||||||
}
|
|
||||||
local function langFallback(T0,T)
|
local function langFallback(T0,T)
|
||||||
for k,v in next,T0 do
|
for k,v in next,T0 do
|
||||||
if type(v)=="table"and not v.refuseCopy then--refuseCopy: just copy pointer, not contents
|
if type(v)=="table"and not v.refuseCopy then--refuseCopy: just copy pointer, not contents
|
||||||
@@ -58,43 +9,53 @@ local function langFallback(T0,T)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local tipMeta={__call=function(L)return L[math.random(#L)]end}
|
local tipMeta={__call=function(L)return L[math.random(#L)]end}
|
||||||
for i=1,#langList do
|
|
||||||
local L=langList[i]
|
|
||||||
|
|
||||||
--Set public text
|
local langList={}
|
||||||
for key,list in next,publicText do
|
local publicText,publicWidgetText={},{}
|
||||||
L[key]=list
|
|
||||||
end
|
|
||||||
|
|
||||||
--Set public widget text
|
|
||||||
for key,list in next,publicWidgetText do
|
|
||||||
local WT=L.WidgetText
|
|
||||||
if not WT[key]then WT[key]={}end
|
|
||||||
for k,v in next,list do
|
|
||||||
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(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
|
|
||||||
|
|
||||||
local LANG={}
|
local LANG={}
|
||||||
function LANG.getLen()
|
|
||||||
return #langList
|
--Must call before 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()
|
||||||
|
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
|
||||||
|
if not WT[key]then WT[key]={}end
|
||||||
|
for k,v in next,list do
|
||||||
|
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
|
end
|
||||||
|
|
||||||
function LANG.set(l)
|
function LANG.set(l)
|
||||||
text=langList[l]
|
text=langList[l]
|
||||||
WIDGET.setLang(text.WidgetText)
|
WIDGET.setLang(text.WidgetText)
|
||||||
@@ -102,4 +63,5 @@ function LANG.set(l)
|
|||||||
drawableText[s]:set(text[s])
|
drawableText[s]:set(text[s])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return LANG
|
return LANG
|
||||||
@@ -39,6 +39,8 @@ local SCN={
|
|||||||
|
|
||||||
function SCN.add(name,scene)
|
function SCN.add(name,scene)
|
||||||
scenes[name]=scene
|
scenes[name]=scene
|
||||||
|
if not scene.widgetList then scene.widgetList={}end
|
||||||
|
setmetatable(scene.widgetList,WIDGET.indexMeta)
|
||||||
end
|
end
|
||||||
|
|
||||||
function SCN.swapUpdate()
|
function SCN.swapUpdate()
|
||||||
@@ -76,7 +78,7 @@ function SCN.init(s,org)
|
|||||||
SCN.gamepadUp=S.gamepadUp
|
SCN.gamepadUp=S.gamepadUp
|
||||||
SCN.socketRead=S.socketRead
|
SCN.socketRead=S.socketRead
|
||||||
if S.sceneInit then S.sceneInit(org)end
|
if S.sceneInit then S.sceneInit(org)end
|
||||||
WIDGET.set(s)
|
WIDGET.set(S.widgetList)
|
||||||
end
|
end
|
||||||
function SCN.push(tar,style)
|
function SCN.push(tar,style)
|
||||||
if not SCN.swapping then
|
if not SCN.swapping then
|
||||||
|
|||||||
@@ -810,7 +810,7 @@ function WIDGET.lnk_pressKey(k) return function() love.keypressed(k) end end
|
|||||||
function WIDGET.lnk_goScene(t,s) return function() SCN.go(t,s) end end
|
function WIDGET.lnk_goScene(t,s) return function() SCN.go(t,s) end end
|
||||||
function WIDGET.lnk_swapScene(t,s) return function() SCN.swapTo(t,s) end end
|
function WIDGET.lnk_swapScene(t,s) return function() SCN.swapTo(t,s) end end
|
||||||
|
|
||||||
local indexMeta={
|
WIDGET.indexMeta={
|
||||||
__index=function(L,k)
|
__index=function(L,k)
|
||||||
for i=1,#L do
|
for i=1,#L do
|
||||||
if L[i].name==k then
|
if L[i].name==k then
|
||||||
@@ -819,16 +819,7 @@ local indexMeta={
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
function WIDGET.init(sceneName,list)
|
function WIDGET.set(list)
|
||||||
local L={}
|
|
||||||
for i=1,#list do
|
|
||||||
ins(L,list[i])
|
|
||||||
end
|
|
||||||
setmetatable(L,indexMeta)
|
|
||||||
widgetList[sceneName]=L
|
|
||||||
end
|
|
||||||
function WIDGET.set(sceneName)
|
|
||||||
local list=widgetList[sceneName]
|
|
||||||
kb.setTextInput(false)
|
kb.setTextInput(false)
|
||||||
WIDGET.sel=nil
|
WIDGET.sel=nil
|
||||||
WIDGET.active=list or NONE
|
WIDGET.active=list or NONE
|
||||||
@@ -840,10 +831,12 @@ function WIDGET.set(sceneName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function WIDGET.setLang(lang)
|
function WIDGET.setLang(widgetText)
|
||||||
for S,L in next,widgetList do
|
for S,L in next,SCN.scenes do
|
||||||
for _,W in next,L do
|
if widgetText[S]then
|
||||||
W.text=lang[S][W.name]
|
for _,W in next,L.widgetList do
|
||||||
|
W.text=widgetText[S][W.name]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
56
main.lua
56
main.lua
@@ -109,6 +109,58 @@ VOC.set{
|
|||||||
"welcome_voc",
|
"welcome_voc",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--Initialize language lib
|
||||||
|
LANG.setLangList{
|
||||||
|
require"parts/language/lang_zh",
|
||||||
|
require"parts/language/lang_zh2",
|
||||||
|
require"parts/language/lang_en",
|
||||||
|
require"parts/language/lang_fr",
|
||||||
|
require"parts/language/lang_sp",
|
||||||
|
require"parts/language/lang_symbol",
|
||||||
|
require"parts/language/lang_yygq",
|
||||||
|
--Add new language file to LANG folder. Attention, new language won't show in-game when you add language
|
||||||
|
}
|
||||||
|
LANG.setPublicText{
|
||||||
|
block={
|
||||||
|
"Z","S","J","L","T","O","I",
|
||||||
|
"Z5","S5","Q","P","F","E",
|
||||||
|
"T5","U","V","W","X",
|
||||||
|
"J5","L5","R","Y","N","H","I5"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
LANG.setPublicWidgetText{
|
||||||
|
calculator={
|
||||||
|
_1="1",_2="2",_3="3",
|
||||||
|
_4="4",_5="5",_6="6",
|
||||||
|
_7="7",_8="8",_9="9",
|
||||||
|
_0="0",["."]=".",e="e",
|
||||||
|
["+"]="+",["-"]="-",["*"]="*",["/"]="/",
|
||||||
|
["<"]="<",["="]="=",
|
||||||
|
play="-->",
|
||||||
|
},
|
||||||
|
custom_field={
|
||||||
|
b0="",b1="",b2="",b3="",b4="",b5="",b6="",b7="",
|
||||||
|
b8="",b9="",b10="",b11="",b12="",b13="",b14="",b15="",b16="",
|
||||||
|
b17="[ ]",b18="N",b19="B",b20="_",b21="_",b22="_",b23="_",b24="_",
|
||||||
|
},
|
||||||
|
lang={
|
||||||
|
zh="中文",
|
||||||
|
zh2="全中文",
|
||||||
|
en="English",
|
||||||
|
fr="Français",
|
||||||
|
sp="Español",
|
||||||
|
symbol="?????",
|
||||||
|
yygq="就这?",
|
||||||
|
},
|
||||||
|
staff={},
|
||||||
|
history={
|
||||||
|
prev="↑",
|
||||||
|
next="↓",
|
||||||
|
},
|
||||||
|
mg_cubefield={},
|
||||||
|
}
|
||||||
|
LANG.init()
|
||||||
|
|
||||||
--Load shader files from SOURCE ONLY
|
--Load shader files from SOURCE ONLY
|
||||||
SHADER={}
|
SHADER={}
|
||||||
for _,v in next,love.filesystem.getDirectoryItems("parts/shaders")do
|
for _,v in next,love.filesystem.getDirectoryItems("parts/shaders")do
|
||||||
@@ -134,9 +186,7 @@ end
|
|||||||
for _,v in next,fs.getDirectoryItems("parts/scenes")do
|
for _,v in next,fs.getDirectoryItems("parts/scenes")do
|
||||||
if fs.getRealDirectory("parts/scenes/"..v)~=SAVEDIR then
|
if fs.getRealDirectory("parts/scenes/"..v)~=SAVEDIR then
|
||||||
local sceneName=v:sub(1,-5)
|
local sceneName=v:sub(1,-5)
|
||||||
local scene=require("parts/scenes/"..sceneName)
|
SCN.add(sceneName,require("parts/scenes/"..sceneName))
|
||||||
SCN.add(sceneName,scene)
|
|
||||||
if scene.widgetList then WIDGET.init(sceneName,scene.widgetList)end
|
|
||||||
else
|
else
|
||||||
LOG.print("Dangerous file : %SAVE%/parts/scenes/"..v)
|
LOG.print("Dangerous file : %SAVE%/parts/scenes/"..v)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user