整理Zframework代码
给所有模块进行更合理的分类 解除部分模块之间的依赖 修复image和bgm模块两个一般不会触发的小问题 close #209
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -1,6 +1,5 @@
|
||||
local gc=love.graphics
|
||||
local abs=math.abs
|
||||
local SCR=SCR
|
||||
|
||||
local scenes={}
|
||||
|
||||
|
||||
2
main.lua
2
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)
|
||||
|
||||
Reference in New Issue
Block a user