Add checks and error messages for some invalid custom mode data (#1049)
This commit is contained in:
@@ -99,6 +99,7 @@ function DATA.pasteBoard(str)-- Paste [str] data to [page] board
|
|||||||
|
|
||||||
local fX,fY=1,1-- *ptr for Field(r*10+(c-1))
|
local fX,fY=1,1-- *ptr for Field(r*10+(c-1))
|
||||||
local p=1
|
local p=1
|
||||||
|
local lineLimit=126
|
||||||
while true do
|
while true do
|
||||||
local b=byte(str,p)-- 1byte
|
local b=byte(str,p)-- 1byte
|
||||||
|
|
||||||
@@ -120,13 +121,13 @@ function DATA.pasteBoard(str)-- Paste [str] data to [page] board
|
|||||||
fX=fX+1
|
fX=fX+1
|
||||||
else
|
else
|
||||||
fY=fY+1
|
fY=fY+1
|
||||||
if fY>126 then break end
|
if fY>lineLimit then break end
|
||||||
fX=1
|
fX=1
|
||||||
end
|
end
|
||||||
p=p+1
|
p=p+1
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, F
|
return true, F, #str>lineLimit*10
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@@ -213,9 +214,26 @@ function DATA.pasteQuestArgs(str)
|
|||||||
if #str<4 then return end
|
if #str<4 then return end
|
||||||
local ENV={}
|
local ENV={}
|
||||||
ENV.holdCount= str:byte(1)-48
|
ENV.holdCount= str:byte(1)-48
|
||||||
|
if ENV.holdCount<0 or ENV.holdCount>6 then
|
||||||
|
-- hold count invalid
|
||||||
|
if ENV.holdCount>=7 and ENV.holdCount<=9 then
|
||||||
|
-- hold count clearly intended to be a number, set to 6
|
||||||
|
ENV.holdCount=6
|
||||||
|
MES.new('warn',text.customDataInvalidHold1)
|
||||||
|
else
|
||||||
|
-- hold count is a random character, reset to 1
|
||||||
|
ENV.holdCount=1
|
||||||
|
MES.new('warn',text.customDataInvalidHold2)
|
||||||
|
end
|
||||||
|
end
|
||||||
ENV.ospin= str:byte(2)~=90
|
ENV.ospin= str:byte(2)~=90
|
||||||
ENV.missionKill=str:byte(3)~=90
|
ENV.missionKill=str:byte(3)~=90
|
||||||
ENV.sequence= str:sub(4)
|
ENV.sequence= str:sub(4)
|
||||||
|
-- hard coding list of generators because there is no other way to obtain it
|
||||||
|
if not TABLE.find({'bag','bagES','his','hisPool','c2','bagP1inf','rnd','mess','reverb','loop','fixed'}, ENV.sequence) then
|
||||||
|
MES.new('warn',text.customDataInvalidSequence)
|
||||||
|
ENV.sequence='bag'
|
||||||
|
end
|
||||||
return true,ENV
|
return true,ENV
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,13 @@ return {
|
|||||||
dataCorrupted="Data corrupted",
|
dataCorrupted="Data corrupted",
|
||||||
pasteWrongPlace="Did you paste in the wrong place?",
|
pasteWrongPlace="Did you paste in the wrong place?",
|
||||||
noFile="File missing",
|
noFile="File missing",
|
||||||
|
|
||||||
|
-- data validation for custom game data import
|
||||||
|
customDataInvalidHold1="Invalid Hold queue length in custom mode data. Resetting to 6.",
|
||||||
|
customDataInvalidHold2="Invalid Hold queue length in custom mode data. Resetting to 1.",
|
||||||
|
customDataInvalidSequence="Invalid sequence mode in custom mode data. Resetting to bag.",
|
||||||
|
customDataBoardLineLimit="One or more fields in the data exceeded height limit (126 lines).\nParts exceeding the limit have been removed.",
|
||||||
|
customDataSingleBoardLineLimit="Field data exceeded height limit (126 lines).\nParts exceeding the limit have been removed.",
|
||||||
|
|
||||||
nowPlaying="Now playing:",
|
nowPlaying="Now playing:",
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,13 @@ return {
|
|||||||
dataCorrupted="数据损坏",
|
dataCorrupted="数据损坏",
|
||||||
pasteWrongPlace="提醒:可能粘贴错地方了",
|
pasteWrongPlace="提醒:可能粘贴错地方了",
|
||||||
noFile="找不到文件",
|
noFile="找不到文件",
|
||||||
|
|
||||||
|
-- data validation for custom game data import
|
||||||
|
customDataInvalidHold1="自定义模式数据中的 Hold 数量错误。重置为 6。",
|
||||||
|
customDataInvalidHold2="自定义模式数据中的 Hold 数量错误。重置为 1。",
|
||||||
|
customDataInvalidSequence="自定义模式数据中的序列模式不存在。重置为 bag。",
|
||||||
|
customDataBoardLineLimit="数据中一个或多个自定义场地的高度超过限制(126 行)。超出限制的部分已被移除。",
|
||||||
|
customDataSingleBoardLineLimit="数据中自定义场地的高度超过限制(126 行)。超出限制的部分已被移除。",
|
||||||
|
|
||||||
nowPlaying="正在播放:",
|
nowPlaying="正在播放:",
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ function scene.keyDown(key,isRep)
|
|||||||
elseif key=='v' and kb.isDown('lctrl','rctrl') or key=='cV' then
|
elseif key=='v' and kb.isDown('lctrl','rctrl') or key=='cV' then
|
||||||
local str=sys.getClipboardText()
|
local str=sys.getClipboardText()
|
||||||
local args=str:sub((str:find(":") or 0)+1):split("!")
|
local args=str:sub((str:find(":") or 0)+1):split("!")
|
||||||
|
local flagHasBoardWithLineLimit=false
|
||||||
repeat
|
repeat
|
||||||
if #args<4 then break end-- goto THROW_fail
|
if #args<4 then break end-- goto THROW_fail
|
||||||
local success,env=DATA.pasteQuestArgs(args[1])
|
local success,env=DATA.pasteQuestArgs(args[1])
|
||||||
@@ -210,15 +211,22 @@ function scene.keyDown(key,isRep)
|
|||||||
TABLE.cut(CUSTOMGAME_LOCAL.field)
|
TABLE.cut(CUSTOMGAME_LOCAL.field)
|
||||||
CUSTOMGAME_LOCAL.field[1]=DATA.newBoard()
|
CUSTOMGAME_LOCAL.field[1]=DATA.newBoard()
|
||||||
for i=4,#args do
|
for i=4,#args do
|
||||||
|
|
||||||
if args[i]:find("%S") then
|
if args[i]:find("%S") then
|
||||||
local success,F=DATA.pasteBoard(args[i])
|
local success, F, flagBoardLineLimit=DATA.pasteBoard(args[i])
|
||||||
if success then
|
if success then
|
||||||
|
if flagBoardLineLimit then
|
||||||
|
flagHasBoardWithLineLimit=true
|
||||||
|
end
|
||||||
CUSTOMGAME_LOCAL.field[i-3]=F
|
CUSTOMGAME_LOCAL.field[i-3]=F
|
||||||
else
|
else
|
||||||
if i<#args then break end-- goto THROW_fail
|
if i<#args then break end-- goto THROW_fail
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if flagHasBoardWithLineLimit then
|
||||||
|
MES.new('warn', text.customDataBoardLineLimit)
|
||||||
|
end
|
||||||
MES.new('check',text.importSuccess)
|
MES.new('check',text.importSuccess)
|
||||||
return
|
return
|
||||||
until true
|
until true
|
||||||
|
|||||||
@@ -237,9 +237,12 @@ function scene.keyDown(key)
|
|||||||
end
|
end
|
||||||
str=str:sub(p+1)
|
str=str:sub(p+1)
|
||||||
end
|
end
|
||||||
local success,F=DATA.pasteBoard(str)
|
local success,F, flagBoardLineLimit=DATA.pasteBoard(str)
|
||||||
if success then
|
if success then
|
||||||
FIELD[page]=F
|
FIELD[page]=F
|
||||||
|
if flagBoardLineLimit then
|
||||||
|
MES.new('warn', text.customDataSingleBoardLineLimit)
|
||||||
|
end
|
||||||
MES.new('check',text.importSuccess)
|
MES.new('check',text.importSuccess)
|
||||||
else
|
else
|
||||||
MES.new('error',text.dataCorrupted)
|
MES.new('error',text.dataCorrupted)
|
||||||
|
|||||||
Reference in New Issue
Block a user