diff --git a/Zframework/bgm.lua b/Zframework/bgm.lua index 37b4dde3..e8bddb11 100644 --- a/Zframework/bgm.lua +++ b/Zframework/bgm.lua @@ -24,8 +24,24 @@ function BGM.init(list) function BGM.getList()return simpList end local count=#simpList function BGM.getCount()return count end - function BGM.loadAll()for name in next,Sources do load(name)end end + local function load(name) + if type(Sources[name])=='string'then + if love.filesystem.getInfo(Sources[name])then + Sources[name]=love.audio.newSource(Sources[name],'stream') + Sources[name]:setLooping(true) + Sources[name]:setVolume(0) + return true + else + MES.new('warn',"No BGM file: "..Sources[name],5) + end + elseif Sources[name]then + return true + elseif name then + MES.new('warn',"No BGM: "..name,5) + end + end + function BGM.loadAll()for name in next,Sources do load(name)end end local function fadeOut(src) while true do coroutine.yield() @@ -51,22 +67,6 @@ function BGM.init(list) local function removeCurFadeOut(task,code,src) return task.code==code and task.args[1]==src end - local function load(name) - if type(Sources[name])=='string'then - if love.filesystem.getInfo(Sources[name])then - Sources[name]=love.audio.newSource(Sources[name],'stream') - Sources[name]:setLooping(true) - Sources[name]:setVolume(0) - return true - else - MES.new('warn',"No BGM file: "..Sources[name],5) - end - elseif Sources[name]then - return true - elseif name then - MES.new('warn',"No BGM: "..name,5) - end - end function BGM.play(name) if not name then name=BGM.default end if not load(name)then return end diff --git a/Zframework/doGC.lua b/Zframework/doGC.lua deleted file mode 100644 index f41131a8..00000000 --- a/Zframework/doGC.lua +++ /dev/null @@ -1,72 +0,0 @@ -local gc=love.graphics -local cmds={ - origin="origin", - move="translate", - scale="scale", - rotate="rotate", - shear="shear", - clear="clear", - - setCL="setColor", - setCM="setColorMask", - setLW="setLineWidth", - setLS="setLineStyle", - setLJ="setLineJoin", - - print="print", - setFT=setFont, - mText=GC.str, - mDraw=GC.draw, - mOutDraw=GC.outDraw, - - draw="draw", - line="line", - fRect=function(...)gc.rectangle('fill',...)end, - dRect=function(...)gc.rectangle('line',...)end, - fCirc=function(...)gc.circle('fill',...)end, - dCirc=function(...)gc.circle('line',...)end, - fElps=function(...)gc.ellipse('fill',...)end, - dElps=function(...)gc.ellipse('line',...)end, - fPoly=function(...)gc.polygon('fill',...)end, - dPoly=function(...)gc.polygon('line',...)end, - - dPie=function(...)gc.arc('line',...)end, - dArc=function(...)gc.arc('line','open',...)end, - dBow=function(...)gc.arc('line','closed',...)end, - fPie=function(...)gc.arc('fill',...)end, - fArc=function(...)gc.arc('fill','open',...)end, - fBow=function(...)gc.arc('fill','closed',...)end, -} -local sizeLimit=gc.getSystemLimits().texturesize -return function(L) - gc.push() - ::REPEAT_tryAgain:: - local success,canvas=pcall(gc.newCanvas,math.min(L[1],sizeLimit),math.min(L[2],sizeLimit)) - if not success then - sizeLimit=math.floor(sizeLimit*.8) - goto REPEAT_tryAgain - end - gc.setCanvas(canvas) - gc.origin() - gc.setColor(1,1,1) - gc.setLineWidth(1) - for i=3,#L do - local cmd=L[i][1] - if type(cmd)=='boolean'and cmd then - table.remove(L[i],1) - cmd=L[i][1] - end - if type(cmd)=='string'then - local func=cmds[cmd] - if type(func)=='string'then func=gc[func]end - if func then - func(unpack(L[i],2)) - else - error("No gc command: "..cmd) - end - end - end - gc.setCanvas() - gc.pop() - return canvas -end \ No newline at end of file diff --git a/Zframework/gcExtend.lua b/Zframework/gcExtend.lua index c1679335..3b1afe96 100644 --- a/Zframework/gcExtend.lua +++ b/Zframework/gcExtend.lua @@ -1,7 +1,5 @@ local gc=love.graphics -local setColor=gc.setColor -local printf=gc.printf -local draw=gc.draw +local setColor,printf,draw=gc.setColor,gc.printf,gc.draw local GC={} function GC.str(obj,x,y)printf(obj,x-626,y,1252,'center')end function GC.simpX(obj,x,y)draw(obj,x-obj:getWidth()*.5,y)end @@ -97,7 +95,7 @@ do--function GC.DO(L) setLJ="setLineJoin", print="print", - setFT=setFont, + setFT=function(...)setFont(...)end, mText=GC.str, mDraw=GC.draw, mOutDraw=GC.outDraw, diff --git a/Zframework/image.lua b/Zframework/image.lua index fa69c7da..e00fbb6a 100644 --- a/Zframework/image.lua +++ b/Zframework/image.lua @@ -12,7 +12,7 @@ function IMG.init(list) elseif type(list[name])=='string'then self[name]=love.graphics.newImage(list[name]) else - MES.new('warn',"No BGM: "..name,5) + MES.new('warn',"No IMG: "..name,5) self[name]=null end return self[name] diff --git a/Zframework/init.lua b/Zframework/init.lua index cfea58f9..31f24a0b 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -3,44 +3,63 @@ EDITING="" LOADED=false ERRDATA={} -SCR= require'Zframework.screen' +--Pure lua modules (basic) COLOR= require'Zframework.color' -SCN= require'Zframework.scene' -WS= require'Zframework.websocket' +TABLE= require'Zframework.tableExtend' +STRING= require'Zframework.stringExtend' +PROFILE=require'Zframework.profile' +JSON= require'Zframework.json' +do--Add pcall & MES for JSON lib + local encode,decode=JSON.encode,JSON.decode + JSON.encode=function(val) + local a,b=pcall(encode,val) + if a then + return b + elseif MES then + MES.traceback() + end + end + JSON.decode=function(str) + local a,b=pcall(decode,str) + if a then + return b + elseif MES then + MES.traceback() + end + end +end -require'Zframework.setFont' +--Pure lua modules (complex) +LOADLIB=require'Zframework.loadLib' +TASK= require'Zframework.task' +WS= require'Zframework.websocket' +LANG= require'Zframework.languages' +THEME= require'Zframework.theme' + +--Love-based modules (basic) +FILE= require'Zframework.file' +WHEELMOV=require'Zframework.wheelScroll' +SCR= require'Zframework.screen' +SCN= require'Zframework.scene' +LIGHT= require'Zframework.light' + +--Love-based modules (complex) GC=require'Zframework.gcExtend' mStr=GC.str mText=GC.simpX mDraw=GC.draw - -LOADLIB=require'Zframework.loadLib' -WHEELMOV=require'Zframework.wheelScroll' - -JSON= require'Zframework.json' -TABLE= require'Zframework.tableExtend' -STRING= require'Zframework.stringExtend' - -VIB= require'Zframework.vibrate' -SFX= require'Zframework.sfx' - -LIGHT= require'Zframework.light' -BG= require'Zframework.background' -WIDGET= require'Zframework.widget' +require'Zframework.setFont' TEXT= require'Zframework.text' SYSFX= require'Zframework.sysFX' MES= require'Zframework.message' - +BG= require'Zframework.background' +WIDGET= require'Zframework.widget' +VIB= require'Zframework.vibrate' +SFX= require'Zframework.sfx' IMG= require'Zframework.image' BGM= require'Zframework.bgm' VOC= require'Zframework.voice' -LANG= require'Zframework.languages' -TASK= require'Zframework.task' -FILE= require'Zframework.file' -PROFILE=require'Zframework.profile' -THEME= require'Zframework.theme' - local ms,kb=love.mouse,love.keyboard local gc=love.graphics diff --git a/Zframework/json.lua b/Zframework/json.lua index d3783ce8..7970a87b 100644 --- a/Zframework/json.lua +++ b/Zframework/json.lua @@ -29,7 +29,7 @@ local json = {} -- Encode ------------------------------------------------------------------------------- -local encode +local _encode local escape_char_map = { ["\\"] = "\\", @@ -70,7 +70,7 @@ local function encode_table(val, stack) end if n ~= #val then error("invalid table: sparse array") end -- Encode - for _, v in ipairs(val) do ins(res, encode(v, stack)) end + for _, v in ipairs(val) do ins(res, _encode(v, stack)) end stack[val] = nil return "[" .. table.concat(res, ",") .. "]" @@ -80,7 +80,7 @@ local function encode_table(val, stack) if type(k) ~= 'string' then error("invalid table: mixed or invalid key types") end - ins(res, encode(k, stack) .. ":" .. encode(v, stack)) + ins(res, _encode(k, stack) .. ":" .. _encode(v, stack)) end stack[val] = nil return "{" .. table.concat(res, ",") .. "}" @@ -107,21 +107,14 @@ local type_func_map = { ['boolean'] = tostring } -encode = function(val, stack) +_encode = function(val, stack) local t = type(val) local f = type_func_map[t] if f then return f(val, stack) end error("unexpected type '" .. t .. "'") end -function json.encode(val) - local a,b=pcall(encode,val) - if a then - return b - elseif MES then - MES.traceback() - end -end +json.encode=_encode ------------------------------------------------------------------------------- -- Decode @@ -335,7 +328,7 @@ function parse(str, idx) decode_error(str, idx, "unexpected character '" .. chr .. "'") end -local function decode(str) +function json.decode(str) if type(str) ~= 'string' then error("expected argument of type string, got " .. type(str)) end @@ -344,12 +337,4 @@ local function decode(str) if idx <= #str then decode_error(str, idx, "trailing garbage") end return res end -function json.decode(str) - local a,b=pcall(decode,str) - if a then - return b - elseif MES then - MES.traceback() - end -end return json \ No newline at end of file diff --git a/Zframework/scene.lua b/Zframework/scene.lua index 367ff5e5..d35a6555 100644 --- a/Zframework/scene.lua +++ b/Zframework/scene.lua @@ -1,6 +1,5 @@ local gc=love.graphics local abs=math.abs -local SCR=SCR local scenes={} diff --git a/main.lua b/main.lua index 606fd686..a44c88dd 100644 --- a/main.lua +++ b/main.lua @@ -37,7 +37,7 @@ love.setDeprecationOutput(false) love.keyboard.setKeyRepeat(true) love.keyboard.setTextInput(false) love.mouse.setVisible(false) -if SYSTEM=='Android'then +if SYSTEM=='Android'or SYSTEM=='iOS'then local w,h,f=love.window.getMode() f.resizable=false love.window.setMode(w,h,f)