From 657bc2b4e06e138d7fd2e644c7b636ceaa8f1eff Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Fri, 26 Nov 2021 14:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8A=A0=E8=BD=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=97=B6=E5=80=99=E4=BC=9A=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=BA=94=E7=94=A8=E8=AF=AD=E8=A8=80=E6=B2=A1?= =?UTF-8?q?=E6=B3=95=E5=BC=B9=E5=87=BA=E6=B6=88=E6=81=AF=E8=80=8C=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gameFuncs.lua | 69 ++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 41e3484a..322a3ea1 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -15,41 +15,46 @@ local playSFX=SFX.play --System -function loadFile(name,args) - if not args then args=''end - local res,mes=pcall(FILE.load,name,args) - if res then - return mes - else - if mes:find'open error'then - MES.new('error',text.loadError_open:repD(name)) - elseif mes:find'unknown mode'then - MES.new('error',text.loadError_errorMode:repD(name,args)) - elseif mes:find'no file'then - if not args:sArg'-canSkip'then - MES.new('error',text.loadError_noFile:repD(name)) - end - elseif mes then - MES.new('error',text.loadError_other:repD(name,mes)) +do--function loadFile(name,args), function saveFile(data,name,args) + local t=setmetatable({},{__index=function()return"'$1' loading failed: $2"end}) + function loadFile(name,args) + local text=text or t + if not args then args=''end + local res,mes=pcall(FILE.load,name,args) + if res then + return mes else - MES.new('error',text.loadError_unknown:repD(name)) + if mes:find'open error'then + MES.new('error',text.loadError_open:repD(name,"")) + elseif mes:find'unknown mode'then + MES.new('error',text.loadError_errorMode:repD(name,args)) + elseif mes:find'no file'then + if not args:sArg'-canSkip'then + MES.new('error',text.loadError_noFile:repD(name,"")) + end + elseif mes then + MES.new('error',text.loadError_other:repD(name,mes)) + else + MES.new('error',text.loadError_unknown:repD(name,"")) + end end end -end -function saveFile(data,name,args) - local res,mes=pcall(FILE.save,data,name,args) - if res then - return mes - else - MES.new('error', - mes:find'duplicate'and - text.saveError_duplicate:repD(name)or - mes:find'encode error'and - text.saveError_encode:repD(name)or - mes and - text.saveError_other:repD(name,mes)or - text.saveError_unknown:repD(name) - ) + function saveFile(data,name,args) + local text=text or t + local res,mes=pcall(FILE.save,data,name,args) + if res then + return mes + else + MES.new('error', + mes:find'duplicate'and + text.saveError_duplicate:repD(name)or + mes:find'encode error'and + text.saveError_encode:repD(name)or + mes and + text.saveError_other:repD(name,mes)or + text.saveError_unknown:repD(name) + ) + end end end function isSafeFile(file,mes)