屏蔽词典敏感词

词典场景代码简化(无需性能场景,更易读)
This commit is contained in:
MrZ626
2021-10-25 13:01:34 +08:00
parent 007982c481
commit d3b117a23f
2 changed files with 29 additions and 18 deletions

View File

@@ -16,7 +16,7 @@ return{
{"To New Players",
"guide newbie noob",
"help",
"To new players that want to get better at the game:\n\tTwo principles:\n\t1. find a version with good controls (e.g. Techmino, Tetr.io, Tetris Online, Jstris, Tetr.js). Do not use those version used for programming practice.\n\t2. Build foundations in your skills (stable Tetrises using next queue to aid decisions), don't go for fancy T-Spins from the start.\n\n\tTwo main techniques:\n\t1. familiarize yourself with spawn locations of pieces, and the controls to move the piece into each location\n\t2. Plan ahead of where to put the pieces\nWe recommend that you read this article titled \"Words to newbies from a Tetris Pro\" (Click \"Open URL\". In Simplified Chinese)",
"To new players that want to get better at the game:\n\tTwo principles:\n\t1. find a version with good controls (e.g. Techmino, Tetr.io, Tetris Online, Jstris, Tetr.js). Do not use those version used for programming practice.\n\t2. Build foundations in your skills (stable Techrashes using next queue to aid decisions), don't go for fancy T-Spins from the start.\n\n\tTwo main techniques:\n\t1. familiarize yourself with spawn locations of pieces, and the controls to move the piece into each location\n\t2. Plan ahead of where to put the pieces\nWe recommend that you read this article titled \"Words to newbies from a Tetris Pro\" (Click \"Open URL\". In Simplified Chinese)",
"https://bilibili.com/read/cv2352939",
},
{"Hard Drop Wiki",
@@ -332,7 +332,7 @@ return{
{"Tetris",
"tetris",
"term",
"The name of the game (and its trademark). Also the name for clearing 4 lines at one time in official games.\nCoined from Tetra (greek for \"four\") and Tennis (favorite sport of Alexey Pajitnov, the creator of Tetris).",
"The name of the game (and its trademark). Also the name for clearing 4 lines at one time in official games.\nCoined from Tetra (greek for \"four\") and Tennis (favorite sport of the creator of Tetris).",--Thanks to Alexey Pajitnov!
},
{"All Clear",
"pc perfectclear ac allclear",

View File

@@ -11,7 +11,6 @@ local scene={}
local dict--Dict list
local result--Result Lable
local url
local lastTickInput
local waiting--Searching animation timer
@@ -31,10 +30,22 @@ local typeColor={
english=COLOR.B,
name=COLOR.lV,
}
local function _scanDict(D)
local c=CHAR.zChan.thinking
for i=1,#D do
local O=D[i]
O.title,O[1]=O[1]:gsub("[Tt]etris",c)
O.keywords,O[2]=O[2]
O.type,O[3]=O[3]
O.content,O[4]=O[4]:gsub("[Tt]etris",c)
O.url,O[5]=O[5]
end
end
local function _getList()return result[1]and result or dict end
local function _clearResult()
TABLE.cut(result)
selected,scrollPos=1,0
selected=1
scrollPos=0
waiting,lastSearch=0,false
copyButton.hide=false
end
@@ -43,7 +54,7 @@ local function _search()
_clearResult()
local first
for i=1,#dict do
local pos=find(dict[i][2],input,nil,true)
local pos=find(dict[i].keywords,input,nil,true)
if pos==1 and not first then
ins(result,1,dict[i])
first=true
@@ -54,16 +65,17 @@ local function _search()
if #result>0 then
SFX.play('reach')
end
url=_getList()[selected][5]
lastSearch=input
end
function scene.sceneInit()
dict=require("parts.language.dict_"..(SETTING.locale:find'zh'and'zh'or'en'))
if dict[1][1]then
_scanDict(dict)
end
inputBox:clear()
result={}
url=dict[1][5]
waiting=0
selected=1
@@ -99,7 +111,7 @@ function scene.keyDown(key)
elseif key=="right"or key=="pagedown"then
for _=1,12 do scene.keyDown("down")end
elseif key=="link"then
love.system.openURL(url)
love.system.openURL(_getList()[selected].url)
elseif key=="delete"then
if inputBox:hasText()then
_clearResult()
@@ -116,7 +128,7 @@ function scene.keyDown(key)
end
elseif key=="c"and love.keyboard.isDown("lctrl","rctrl")or key=="cC"then
local t=_getList()[selected]
t=t[1]..":\n"..t[4]..(t[5]and"\n[ "..t[5].." ]\n"or"\n")..text.dictNote
t=t.title..":\n"..t.content..(t.url and"\n[ "..t.url.." ]\n"or"\n")..text.dictNote
love.system.setClipboardText(t)
copyButton.hide=true
MES.new('info',text.copyDone)
@@ -124,7 +136,6 @@ function scene.keyDown(key)
else
return
end
url=_getList()[selected][5]
end
function scene.update(dt)
@@ -150,7 +161,7 @@ end
function scene.draw()
local list=_getList()
gc.setColor(COLOR.Z)
local t=list[selected][4]
local t=list[selected].content
setFont(
#t>900 and 15 or
#t>600 and 20 or
@@ -169,12 +180,12 @@ function scene.draw()
i=i+scrollPos
local item=list[i]
gc.setColor(COLOR.D)
gc.print(item[1],29,y-1)
gc.print(item[1],29,y+1)
gc.print(item[1],31,y-1)
gc.print(item[1],31,y+1)
gc.setColor(typeColor[item[3]])
gc.print(item[1],30,y)
gc.print(item.title,29,y-1)
gc.print(item.title,29,y+1)
gc.print(item.title,31,y-1)
gc.print(item.title,31,y+1)
gc.setColor(typeColor[item.type])
gc.print(item.title,30,y)
end
gc.setLineWidth(2)
@@ -195,7 +206,7 @@ scene.widgetList={
WIDGET.newText{name="title", x=100,y=15,font=70,align='L'},
inputBox,
copyButton,
WIDGET.newKey{name="link", x=1150,y=655,w=200,h=80,font=35,code=pressKey"link",hideF=function()return not url end},
WIDGET.newKey{name="link", x=1150,y=655,w=200,h=80,font=35,code=pressKey"link",hideF=function()return not _getList()[selected].url end},
WIDGET.newKey{name="up", x=1130,y=460,w=60,h=90,font=35,fText="",code=pressKey"up",hide=not MOBILE},
WIDGET.newKey{name="down", x=1130,y=560,w=60,h=90,font=35,fText="",code=pressKey"down",hide=not MOBILE},
WIDGET.newKey{name="pageup", x=1210,y=460,w=80,h=90,font=35,fText="↑↑",code=pressKey"pageup",hide=not MOBILE},