整理代码(user670升级的cmd小程序)

This commit is contained in:
MrZ626
2021-03-08 02:07:48 +08:00
parent df0be2468e
commit d034be1aff

View File

@@ -25,6 +25,8 @@ function scene.sceneInit()
BG.set("none") BG.set("none")
end end
-- command_help_messages format: -- command_help_messages format:
-- command_help_messages is a table -- command_help_messages is a table
-- key: the command -- key: the command
@@ -56,7 +58,7 @@ local command_help_messages={
"print() can be used to print text into this window." "print() can be used to print text into this window."
} }
}, },
["exit"]={ exit={
description="Return to the previous menu.", description="Return to the previous menu.",
details={ details={
"Return to the previous menu.", "Return to the previous menu.",
@@ -206,103 +208,105 @@ local command_help_list={
local command_help_page_size=10 local command_help_page_size=10
local commands={ local commands={}
--Basic commands --Basic commands
help=function(arg) function commands.help(arg)
if command_help_messages[arg] then -- help [command] if command_help_messages[arg]then -- help [command]
for i,v in pairs(command_help_messages[arg]["details"]) do for _,v in pairs(command_help_messages[arg].details)do
log(v) log(v)
end
return
end end
if tonumber(arg) then return
arg=int(tonumber(arg)) end
else if tonumber(arg)then
arg=1 arg=int(tonumber(arg))
end -- help or help [page] else
local total_pages=math.ceil(#command_help_list/command_help_page_size) arg=1
if arg<=0 or arg>total_pages then end -- help or help [page]
log("Invalid page number. Must be between 1 and "..total_pages.." (inclusive).") local total_pages=math.ceil(#command_help_list/command_help_page_size)
return if arg<=0 or arg>total_pages then
end log("Invalid page number. Must be between 1 and "..total_pages.." (inclusive).")
log("Use help [page] to view more commands,") return
log("or help [command_name] for more info on a command.") end
log("") log"Use help [page] to view more commands,"
log("Page "..arg.." of "..total_pages) log"or help [command_name] for more info on a command."
for i=(arg-1)*10+1,math.min(arg*10,#command_help_list) do log""
local _c=command_help_list[i] log("Page "..arg.." of "..total_pages)
log("".._c.." - "..command_help_messages[_c]["description"]) for i=(arg-1)*10+1,math.min(arg*10,#command_help_list)do
end local _c=command_help_list[i]
end, log("".._c.." - "..command_help_messages[_c].description)
shutdown=function(arg)os.execute("shutdown "..arg)end, end
cls=function()outputBox:clear()end, end
echo=log, function commands.shutdown(arg)os.execute("shutdown "..arg)end
exit=backScene, function commands.cls()outputBox:clear()end
quit=backScene, commands.echo=log
bye=backScene, commands.exit=backScene
commands.quit=backScene
commands.bye=backScene
--Game commands --Game commands
fn=function(n) function commands.fn(n)
if tonumber(n)then if tonumber(n)then
n=int(tonumber(n)) n=int(tonumber(n))
if n>=1 and n<=12 then if n>=1 and n<=12 then
love.keypressed("f"..n) love.keypressed("f"..n)
return return
end
end
log"Usage: fn [1~12]"
end
function commands.scrinfo()for _,v in next,SCR.info()do log(v)end end
function commands.wireframe(bool)
if bool=="true"or bool=="false"then
gc.setWireframe(bool=="true")
log("Wireframe: "..(gc.isWireframe()and"on"or"off"))
else
log"Usage: wireframe [true|false]"
end
end
function commands.gammacorrect(bool)
if bool=="true"or bool=="false"then
love._setGammaCorrect(bool=="true")
log("GammaCorrect: "..(gc.isGammaCorrect()and"on"or"off"))
else
log"Usage: gammacorrect [true|false]"
end
end
function commands.rmwtm(password)
if password==(14^2*10)..(2*11)then
_G["\100\114\97\119\70\87\77"]=NULL
log("\68\69\86\58\87\97\116\101\114\109\97\114\107\32\82\101\109\111\118\101\100")
SFX.play("clear")
else
log"Usage: None."
end
end
function commands.unlockall(bool)
if bool=="sure"then
for name,M in next,MODES do
if type(name)=="string"and not RANKS[name]and M.x then
RANKS[name]=M.score and 0 or 6
end end
end end
log"Usage: fn [1~12]" FILE.save(RANKS,"conf/unlock")
end, log("\68\69\86\58\85\78\76\79\67\75\65\76\76")
scrinfo=function()for _,v in next,SCR.info()do log(v)end end, SFX.play("clear_2")
wireframe=function(bool) else
if bool=="true"or bool=="false"then log"Are you sure to unlock all modes?"
gc.setWireframe(bool=="true") log"Type: unlockall sure"
log("Wireframe: "..(gc.isWireframe()and"on"or"off")) end
else end
log"Usage: wireframe [true|false]" function commands.play(m)--marathon_bfmax can only played here
end if MODES[m]then
end, loadGame(m)
gammacorrect=function(bool) elseif m then
if bool=="true"or bool=="false"then log("No mode called "..m)
love._setGammaCorrect(bool=="true") else
log("GammaCorrect: "..(gc.isGammaCorrect()and"on"or"off")) log"Usage: play [modeName]"
else end
log"Usage: gammacorrect [true|false]" end
end
end,
rmwtm=function(password)
if password=="196022"then
_G["\100\114\97\119\70\87\77"]=NULL
log("\68\69\86\58\87\97\116\101\114\109\97\114\107\32\82\101\109\111\118\101\100")
SFX.play("clear")
else
log"Usage: None."
end
end,
unlockall=function(bool)
if bool=="sure"then
for name,M in next,MODES do
if type(name)=="string"and not RANKS[name]and M.x then
RANKS[name]=M.score and 0 or 6
end
end
FILE.save(RANKS,"conf/unlock")
log("\68\69\86\58\85\78\76\79\67\75\65\76\76")
SFX.play("clear_2")
else
log"Are you sure to unlock all modes?"
log"Type: unlockall sure"
end
end,
play=function(m)--marathon_bfmax can only played here
if MODES[m]then
loadGame(m)
elseif m then
log("No mode called "..m)
else
log"Usage: play [modeName]"
end
end,
}
function scene.keyDown(k) function scene.keyDown(k)
if k=="return"then if k=="return"then
local input=inputBox.value local input=inputBox.value