bgm模块新增瞬间开/关功能
字符串扩展模块不再直接修改全局的string,需要外部自己补充
This commit is contained in:
@@ -107,8 +107,9 @@ function BGM.init(list)
|
||||
LOG("No BGM: "..name,5)
|
||||
end
|
||||
end
|
||||
function BGM.play(name)
|
||||
function BGM.play(name,args)
|
||||
name=name or BGM.default
|
||||
args=args or""
|
||||
if not _tryLoad(name)then return end
|
||||
if volume==0 then
|
||||
BGM.nowPlay=name
|
||||
@@ -118,14 +119,24 @@ function BGM.init(list)
|
||||
if name and SourceObjList[name].source then
|
||||
if BGM.nowPlay~=name then
|
||||
if BGM.nowPlay then
|
||||
TASK.new(task_fadeOut,BGM.playing)
|
||||
if not STRING.sArg(args,'-so')then
|
||||
TASK.new(task_fadeOut,BGM.playing)
|
||||
else
|
||||
BGM.playing:pause()
|
||||
end
|
||||
end
|
||||
TASK.removeTask_iterate(check_curFadeOut,task_fadeOut,SourceObjList[name].source)
|
||||
TASK.removeTask_code(task_fadeIn)
|
||||
|
||||
TASK.new(task_fadeIn,SourceObjList[name].source)
|
||||
BGM.nowPlay=name
|
||||
BGM.playing=SourceObjList[name].source
|
||||
if not STRING.sArg(args,'-si')then
|
||||
BGM.playing:setVolume(0)
|
||||
TASK.new(task_fadeIn,BGM.playing)
|
||||
else
|
||||
BGM.playing:setVolume(volume)
|
||||
BGM.playing:play()
|
||||
end
|
||||
BGM.lastPlayed=BGM.nowPlay
|
||||
BGM.playing:seek(0)
|
||||
BGM.playing:play()
|
||||
@@ -148,10 +159,15 @@ function BGM.init(list)
|
||||
BGM.playing:play()
|
||||
end
|
||||
end
|
||||
function BGM.stop()
|
||||
function BGM.stop(args)
|
||||
args=args or""
|
||||
TASK.removeTask_code(task_fadeIn)
|
||||
if BGM.nowPlay then
|
||||
TASK.new(task_fadeOut,BGM.playing)
|
||||
if not STRING.sArg(args,'-s')then
|
||||
if BGM.nowPlay then
|
||||
TASK.new(task_fadeOut,BGM.playing)
|
||||
end
|
||||
else
|
||||
BGM.playing:pause()
|
||||
end
|
||||
BGM.nowPlay,BGM.playing=nil
|
||||
end
|
||||
|
||||
@@ -7,10 +7,10 @@ function FILE.load(name,args)
|
||||
assert(F:open'r','open error')
|
||||
local s=F:read()F:close()
|
||||
local mode=
|
||||
args:sArg'-luaon'and'luaon'or
|
||||
args:sArg'-lua'and'lua'or
|
||||
args:sArg'-json'and'json'or
|
||||
args:sArg'-string'and'string'or
|
||||
STRING.sArg(args,'-luaon')and'luaon'or
|
||||
STRING.sArg(args,'-lua')and'lua'or
|
||||
STRING.sArg(args,'-json')and'json'or
|
||||
STRING.sArg(args,'-string')and'string'or
|
||||
s:sub(1,6)=='return{'and'luaon'or
|
||||
(s:sub(1,1)=='['and s:sub(-1)==']'or s:sub(1,1)=='{'and s:sub(-1)=='}')and'json'or
|
||||
'string'
|
||||
@@ -48,12 +48,12 @@ function FILE.load(name,args)
|
||||
end
|
||||
function FILE.save(data,name,args)
|
||||
if not args then args=''end
|
||||
if args:sArg'-d'and fs.getInfo(name)then
|
||||
if STRING.sArg(args,'-d')and fs.getInfo(name)then
|
||||
error('duplicate')
|
||||
end
|
||||
|
||||
if type(data)=='table'then
|
||||
if args:sArg'-luaon'then
|
||||
if STRING.sArg(args,'-luaon')then
|
||||
data=TABLE.dump(data)
|
||||
if not data then
|
||||
error('encode error')
|
||||
|
||||
@@ -18,7 +18,7 @@ function FONT.rawset(s)
|
||||
end
|
||||
function FONT.load(fonts)
|
||||
for name,path in next,fonts do
|
||||
assert(love.filesystem.getInfo(path),("Font file $1($2) not exist!"):repD(name,path))
|
||||
assert(love.filesystem.getInfo(path),STRING.repD("Font file $1($2) not exist!",name,path))
|
||||
fontFiles[name]=love.filesystem.newFile(path)
|
||||
fontCache[name]={}
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ local find,sub,gsub,upper=string.find,string.sub,string.gsub,string.upper
|
||||
local char,byte=string.char,string.byte
|
||||
|
||||
--"Replace dollars", replace all $n with ...
|
||||
function string.repD(str,...)
|
||||
function STRING.repD(str,...)
|
||||
local l={...}
|
||||
for i=#l,1,-1 do
|
||||
str=gsub(str,'$'..i,l[i])
|
||||
@@ -15,7 +15,7 @@ function string.repD(str,...)
|
||||
end
|
||||
|
||||
--"Scan arg", scan if str has the arg (format of str is like "-json -q", arg is like "-q")
|
||||
function string.sArg(str,switch)
|
||||
function STRING.sArg(str,switch)
|
||||
if find(str.." ",switch.." ")then
|
||||
return true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user