├── README.md └── src ├── app ├── MyApp.lua └── views │ └── MainScene.lua ├── cocos ├── 3d │ └── 3dConstants.lua ├── cocos2d │ ├── Cocos2d.lua │ ├── Cocos2dConstants.lua │ ├── DeprecatedCocos2dClass.lua │ ├── DeprecatedCocos2dEnum.lua │ ├── DeprecatedCocos2dFunc.lua │ ├── DeprecatedOpenglEnum.lua │ ├── DrawPrimitives.lua │ ├── Opengl.lua │ ├── OpenglConstants.lua │ ├── bitExtend.lua │ ├── deprecated.lua │ ├── functions.lua │ ├── json.lua │ ├── luaj.lua │ └── luaoc.lua ├── cocosbuilder │ ├── CCBReaderLoad.lua │ └── DeprecatedCocosBuilderClass.lua ├── cocosdenshion │ ├── AudioEngine.lua │ ├── DeprecatedCocosDenshionClass.lua │ └── DeprecatedCocosDenshionFunc.lua ├── cocostudio │ ├── CocoStudio.lua │ ├── DeprecatedCocoStudioClass.lua │ ├── DeprecatedCocoStudioFunc.lua │ └── StudioConstants.lua ├── controller │ └── ControllerConstants.lua ├── extension │ ├── DeprecatedExtensionClass.lua │ ├── DeprecatedExtensionEnum.lua │ ├── DeprecatedExtensionFunc.lua │ └── ExtensionConstants.lua ├── framework │ ├── audio.lua │ ├── components │ │ └── event.lua │ ├── device.lua │ ├── display.lua │ ├── extends │ │ ├── LayerEx.lua │ │ ├── MenuEx.lua │ │ ├── NodeEx.lua │ │ ├── SpriteEx.lua │ │ ├── UICheckBox.lua │ │ ├── UIEditBox.lua │ │ ├── UIListView.lua │ │ ├── UIPageView.lua │ │ ├── UIScrollView.lua │ │ ├── UISlider.lua │ │ ├── UITextField.lua │ │ └── UIWidget.lua │ ├── init.lua │ ├── package_support.lua │ └── transition.lua ├── init.lua ├── network │ ├── DeprecatedNetworkClass.lua │ ├── DeprecatedNetworkEnum.lua │ ├── DeprecatedNetworkFunc.lua │ └── NetworkConstants.lua ├── physics3d │ └── physics3d-constants.lua ├── spine │ └── SpineConstants.lua └── ui │ ├── DeprecatedUIEnum.lua │ ├── DeprecatedUIFunc.lua │ ├── GuiConstants.lua │ └── experimentalUIConstants.lua ├── config.lua ├── luasocket ├── ltn12.lua ├── mime.lua ├── socket.lua └── socket │ ├── ftp.lua │ ├── headers.lua │ ├── http.lua │ ├── mbox.lua │ ├── smtp.lua │ ├── tp.lua │ └── url.lua ├── main.lua ├── network └── NetMgr.lua └── packages └── mvc ├── AppBase.lua ├── ViewBase.lua └── init.lua /README.md: -------------------------------------------------------------------------------- 1 | # cocos_lua_tcp 2 | 这是一个cocos2d-x lua 项目下的异步非阻塞 TCP socket的示例代码,从连接到序列化全部交由lua完成实现,有详细注释 3 | 4 | 需要手动导入lpack进入cocos2d-x引擎中 5 | 6 | 核心代码在 src/network/NetMgr.lua 7 | 8 | This is a sample code for an asynchronous TCP socket under the cocos2d-x lua project, from connection to serialization, 9 | all done by lua, with detailed comments 10 | 11 | Need to manually import lpack into the cocos2d-x engine 12 | 13 | the main codes is under src/network/NetMgr.lua 14 | -------------------------------------------------------------------------------- /src/app/MyApp.lua: -------------------------------------------------------------------------------- 1 | 2 | local MyApp = class("MyApp", cc.load("mvc").AppBase) 3 | 4 | function MyApp:onCreate() 5 | math.randomseed(os.time()) 6 | end 7 | 8 | return MyApp 9 | -------------------------------------------------------------------------------- /src/app/views/MainScene.lua: -------------------------------------------------------------------------------- 1 | 2 | local MainScene = class("MainScene", cc.load("mvc").ViewBase) 3 | 4 | function MainScene:onCreate() 5 | print("============== test start =============") 6 | 7 | -- 尝试连接 127.0.0.1:19810 8 | cc.NetMgr:getInstance():connect("127.0.0.1", "19810") 9 | end 10 | 11 | return MainScene 12 | -------------------------------------------------------------------------------- /src/cocos/3d/3dConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Terrain then 2 | return 3 | end 4 | 5 | cc.Terrain.CrackFixedType = 6 | { 7 | SKIRT = 0, 8 | INCREASE_LOWER = 1, 9 | } 10 | 11 | cc.Animate3DQuality = 12 | { 13 | QUALITY_NONE = 0, 14 | QUALITY_LOW = 1, 15 | QUALITY_HIGH = 2, 16 | } 17 | -------------------------------------------------------------------------------- /src/cocos/cocos2d/Opengl.lua: -------------------------------------------------------------------------------- 1 | 2 | if not gl then return end 3 | 4 | --Create functions 5 | function gl.createTexture() 6 | local retTable = {} 7 | retTable.texture_id = gl._createTexture() 8 | return retTable 9 | end 10 | 11 | function gl.createBuffer() 12 | local retTable = {} 13 | retTable.buffer_id = gl._createBuffer() 14 | return retTable 15 | end 16 | 17 | function gl.createRenderbuffer() 18 | local retTable = {} 19 | retTable.renderbuffer_id = gl._createRenderuffer() 20 | return retTable 21 | end 22 | 23 | function gl.createFramebuffer( ) 24 | local retTable = {} 25 | retTable.framebuffer_id = gl._createFramebuffer() 26 | return retTable 27 | end 28 | 29 | function gl.createProgram() 30 | local retTable = {} 31 | retTable.program_id = gl._createProgram() 32 | return retTable 33 | end 34 | 35 | function gl.createShader(shaderType) 36 | local retTable = {} 37 | retTable.shader_id = gl._createShader(shaderType) 38 | return retTable 39 | end 40 | 41 | --Delete Fun 42 | function gl.deleteTexture(texture) 43 | local texture_id = 0 44 | if "number" == type(texture) then 45 | texture_id = texture 46 | elseif "table" == type(texture) then 47 | texture_id = texture.texture_id 48 | end 49 | gl._deleteTexture(texture_id) 50 | end 51 | 52 | function gl.deleteBuffer(buffer) 53 | local buffer_id = 0 54 | if "number" == type(buffer) then 55 | buffer_id = buffer 56 | elseif "table" == type(buffer) then 57 | buffer_id = buffer.buffer_id 58 | end 59 | gl._deleteBuffer(buffer_id) 60 | end 61 | 62 | function gl.deleteRenderbuffer(buffer) 63 | local renderbuffer_id = 0 64 | if "number" == type(buffer) then 65 | renderbuffer_id = buffer 66 | elseif "table" == type(buffer) then 67 | renderbuffer_id = buffer.renderbuffer_id 68 | end 69 | gl._deleteRenderbuffer(renderbuffer_id) 70 | end 71 | 72 | function gl.deleteFramebuffer(buffer) 73 | local framebuffer_id = 0 74 | if "number" == type(buffer) then 75 | framebuffer_id = buffer 76 | elseif "table" == type(buffer) then 77 | framebuffer_id = buffer.framebuffer_id 78 | end 79 | gl._deleteFramebuffer(framebuffer_id) 80 | end 81 | 82 | function gl.deleteProgram( program ) 83 | local program_id = 0 84 | if "number" == type(buffer) then 85 | program_id = program 86 | elseif "table" == type(program) then 87 | program_id = program.program_id 88 | end 89 | 90 | gl._deleteProgram(program_id) 91 | end 92 | 93 | function gl.deleteShader(shader) 94 | local shader_id = 0 95 | if "number" == type(shader) then 96 | shader_id = shader 97 | elseif "table" == type(shader) then 98 | shader_id = shader.shader_id 99 | end 100 | 101 | gl._deleteShader(shader_id) 102 | end 103 | 104 | --Bind Related 105 | function gl.bindTexture(target, texture) 106 | local texture_id = 0 107 | if "number" == type(texture) then 108 | texture_id = texture 109 | elseif "table" == type(texture) then 110 | texture_id = texture.texture_id 111 | end 112 | 113 | gl._bindTexture(target,texture_id) 114 | end 115 | 116 | function gl.bindBuffer( target,buffer ) 117 | local buffer_id = 0 118 | if "number" == type(buffer) then 119 | buffer_id = buffer 120 | elseif "table" == type(buffer) then 121 | buffer_id = buffer.buffer_id 122 | end 123 | 124 | gl._bindBuffer(target, buffer_id) 125 | end 126 | 127 | function gl.bindRenderBuffer(target, buffer) 128 | local buffer_id = 0 129 | 130 | if "number" == type(buffer) then 131 | buffer_id = buffer; 132 | elseif "table" == type(buffer) then 133 | buffer_id = buffer.buffer_id 134 | end 135 | 136 | gl._bindRenderbuffer(target, buffer_id) 137 | end 138 | 139 | function gl.bindFramebuffer(target, buffer) 140 | local buffer_id = 0 141 | 142 | if "number" == type(buffer) then 143 | buffer_id = buffer 144 | elseif "table" == type(buffer) then 145 | buffer_id = buffer.buffer_id 146 | end 147 | 148 | gl._bindFramebuffer(target, buffer_id) 149 | end 150 | 151 | --Uniform related 152 | function gl.getUniform(program, location) 153 | local program_id = 0 154 | local location_id = 0 155 | 156 | if "number" == type(program) then 157 | program_id = program 158 | else 159 | program_id = program.program_id 160 | end 161 | 162 | if "number" == type(location) then 163 | location_id = location 164 | else 165 | location_id = location.location_id 166 | end 167 | 168 | return gl._getUniform(program_id, location_id) 169 | end 170 | 171 | --shader related 172 | function gl.compileShader(shader) 173 | gl._compileShader( shader.shader_id) 174 | end 175 | 176 | function gl.shaderSource(shader, source) 177 | gl._shaderSource(shader.shader_id, source) 178 | end 179 | 180 | function gl.getShaderParameter(shader, e) 181 | return gl._getShaderParameter(shader.shader_id,e) 182 | end 183 | 184 | function gl.getShaderInfoLog( shader ) 185 | return gl._getShaderInfoLog(shader.shader_id) 186 | end 187 | 188 | --program related 189 | function gl.attachShader( program, shader ) 190 | local program_id = 0 191 | 192 | if "number" == type(program) then 193 | program_id = program 194 | elseif "table" == type(program) then 195 | program_id = program.program_id 196 | end 197 | 198 | gl._attachShader(program_id, shader.shader_id) 199 | end 200 | 201 | function gl.linkProgram( program ) 202 | local program_id = 0 203 | 204 | if "number" == type(program) then 205 | program_id = program 206 | elseif "table" == type(program) then 207 | program_id = program.program_id 208 | end 209 | 210 | gl._linkProgram(program_id) 211 | end 212 | 213 | function gl.getProgramParameter(program, e) 214 | local program_id = 0 215 | 216 | if "number" == type(program) then 217 | program_id = program 218 | elseif "table" == type(program) then 219 | program_id = program.program_id 220 | end 221 | 222 | return gl._getProgramParameter(program_id, e) 223 | end 224 | 225 | function gl.useProgram(program) 226 | local program_id = 0 227 | if "number" == type(program) then 228 | program_id = program 229 | elseif "table" == type(program) then 230 | program_id = program.program_id 231 | end 232 | 233 | gl._useProgram (program_id) 234 | end 235 | 236 | function gl.getAttribLocation(program, name ) 237 | local program_id = 0 238 | 239 | if "number" == type(program) then 240 | program_id = program 241 | elseif "table" == type(program) then 242 | program_id = program.program_id 243 | end 244 | 245 | return gl._getAttribLocation(program_id, name) 246 | end 247 | 248 | function gl.getUniformLocation( program, name ) 249 | local program_id = 0 250 | 251 | if "number" == type(program) then 252 | program_id = program 253 | elseif "table" == type(program) then 254 | program_id = program.program_id 255 | end 256 | 257 | return gl._getUniformLocation(program_id,name) 258 | end 259 | 260 | function gl.getActiveAttrib( program, index ) 261 | local program_id = 0 262 | if "number" == type(program) then 263 | program_id = program 264 | elseif "table" == type(program) then 265 | program_id = program.program_id 266 | end 267 | 268 | return gl._getActiveAttrib(program_id, index); 269 | end 270 | 271 | function gl.getActiveUniform( program, index ) 272 | local program_id = 0 273 | 274 | if "number" == type(program) then 275 | program_id = program 276 | elseif "table" == type(program) then 277 | program_id = program.program_id 278 | end 279 | 280 | return gl._getActiveUniform(program_id, index) 281 | end 282 | 283 | function gl.getAttachedShaders(program) 284 | local program_id = 0 285 | 286 | if "number" == type(program) then 287 | program_id = program 288 | elseif "table" == type(program) then 289 | program_id = program.program_id 290 | end 291 | 292 | return gl._getAttachedShaders(program_id) 293 | end 294 | 295 | function gl.glNodeCreate() 296 | return cc.GLNode:create() 297 | end 298 | -------------------------------------------------------------------------------- /src/cocos/cocos2d/bitExtend.lua: -------------------------------------------------------------------------------- 1 | -- bit operation 2 | 3 | bit = bit or {} 4 | bit.data32 = {} 5 | 6 | for i=1,32 do 7 | bit.data32[i]=2^(32-i) 8 | end 9 | 10 | function bit._b2d(arg) 11 | local nr=0 12 | for i=1,32 do 13 | if arg[i] ==1 then 14 | nr=nr+bit.data32[i] 15 | end 16 | end 17 | return nr 18 | end 19 | 20 | function bit._d2b(arg) 21 | arg = arg >= 0 and arg or (0xFFFFFFFF + arg + 1) 22 | local tr={} 23 | for i=1,32 do 24 | if arg >= bit.data32[i] then 25 | tr[i]=1 26 | arg=arg-bit.data32[i] 27 | else 28 | tr[i]=0 29 | end 30 | end 31 | return tr 32 | end 33 | 34 | function bit._and(a,b) 35 | local op1=bit._d2b(a) 36 | local op2=bit._d2b(b) 37 | local r={} 38 | 39 | for i=1,32 do 40 | if op1[i]==1 and op2[i]==1 then 41 | r[i]=1 42 | else 43 | r[i]=0 44 | end 45 | end 46 | return bit._b2d(r) 47 | 48 | end 49 | 50 | function bit._rshift(a,n) 51 | local op1=bit._d2b(a) 52 | n = n <= 32 and n or 32 53 | n = n >= 0 and n or 0 54 | 55 | for i=32, n+1, -1 do 56 | op1[i] = op1[i-n] 57 | end 58 | for i=1, n do 59 | op1[i] = 0 60 | end 61 | 62 | return bit._b2d(op1) 63 | end 64 | 65 | function bit._not(a) 66 | local op1=bit._d2b(a) 67 | local r={} 68 | 69 | for i=1,32 do 70 | if op1[i]==1 then 71 | r[i]=0 72 | else 73 | r[i]=1 74 | end 75 | end 76 | return bit._b2d(r) 77 | end 78 | 79 | function bit._or(a,b) 80 | local op1=bit._d2b(a) 81 | local op2=bit._d2b(b) 82 | local r={} 83 | 84 | for i=1,32 do 85 | if op1[i]==1 or op2[i]==1 then 86 | r[i]=1 87 | else 88 | r[i]=0 89 | end 90 | end 91 | return bit._b2d(r) 92 | end 93 | 94 | bit.band = bit.band or bit._and 95 | bit.rshift = bit.rshift or bit._rshift 96 | bit.bnot = bit.bnot or bit._not 97 | -------------------------------------------------------------------------------- /src/cocos/cocos2d/deprecated.lua: -------------------------------------------------------------------------------- 1 | 2 | function schedule(node, callback, delay) 3 | local delay = cc.DelayTime:create(delay) 4 | local sequence = cc.Sequence:create(delay, cc.CallFunc:create(callback)) 5 | local action = cc.RepeatForever:create(sequence) 6 | node:runAction(action) 7 | return action 8 | end 9 | 10 | function performWithDelay(node, callback, delay) 11 | local delay = cc.DelayTime:create(delay) 12 | local sequence = cc.Sequence:create(delay, cc.CallFunc:create(callback)) 13 | node:runAction(sequence) 14 | return sequence 15 | end 16 | -------------------------------------------------------------------------------- /src/cocos/cocos2d/luaj.lua: -------------------------------------------------------------------------------- 1 | 2 | local luaj = {} 3 | 4 | local callJavaStaticMethod = LuaJavaBridge.callStaticMethod 5 | 6 | local function checkArguments(args, sig) 7 | if type(args) ~= "table" then args = {} end 8 | if sig then return args, sig end 9 | 10 | sig = {"("} 11 | for i, v in ipairs(args) do 12 | local t = type(v) 13 | if t == "number" then 14 | sig[#sig + 1] = "F" 15 | elseif t == "boolean" then 16 | sig[#sig + 1] = "Z" 17 | elseif t == "function" then 18 | sig[#sig + 1] = "I" 19 | else 20 | sig[#sig + 1] = "Ljava/lang/String;" 21 | end 22 | end 23 | sig[#sig + 1] = ")V" 24 | 25 | return args, table.concat(sig) 26 | end 27 | 28 | function luaj.callStaticMethod(className, methodName, args, sig) 29 | local args, sig = checkArguments(args, sig) 30 | --echoInfo("luaj.callStaticMethod(\"%s\",\n\t\"%s\",\n\targs,\n\t\"%s\"", className, methodName, sig) 31 | return callJavaStaticMethod(className, methodName, args, sig) 32 | end 33 | 34 | return luaj 35 | -------------------------------------------------------------------------------- /src/cocos/cocos2d/luaoc.lua: -------------------------------------------------------------------------------- 1 | 2 | local luaoc = {} 3 | 4 | local callStaticMethod = LuaObjcBridge.callStaticMethod 5 | 6 | function luaoc.callStaticMethod(className, methodName, args) 7 | local ok, ret = callStaticMethod(className, methodName, args) 8 | if not ok then 9 | local msg = string.format("luaoc.callStaticMethod(\"%s\", \"%s\", \"%s\") - error: [%s] ", 10 | className, methodName, tostring(args), tostring(ret)) 11 | if ret == -1 then 12 | print(msg .. "INVALID PARAMETERS") 13 | elseif ret == -2 then 14 | print(msg .. "CLASS NOT FOUND") 15 | elseif ret == -3 then 16 | print(msg .. "METHOD NOT FOUND") 17 | elseif ret == -4 then 18 | print(msg .. "EXCEPTION OCCURRED") 19 | elseif ret == -5 then 20 | print(msg .. "INVALID METHOD SIGNATURE") 21 | else 22 | print(msg .. "UNKNOWN") 23 | end 24 | end 25 | return ok, ret 26 | end 27 | 28 | return luaoc 29 | -------------------------------------------------------------------------------- /src/cocos/cocosbuilder/CCBReaderLoad.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.CCBReader then 2 | return 3 | end 4 | 5 | ccb = ccb or {} 6 | 7 | function CCBReaderLoad(strFilePath,proxy,owner) 8 | if nil == proxy then 9 | return nil 10 | end 11 | 12 | local ccbReader = proxy:createCCBReader() 13 | local node = ccbReader:load(strFilePath) 14 | local rootName = "" 15 | --owner set in readCCBFromFile is proxy 16 | if nil ~= owner then 17 | --Callbacks 18 | local ownerCallbackNames = ccbReader:getOwnerCallbackNames() 19 | local ownerCallbackNodes = ccbReader:getOwnerCallbackNodes() 20 | local ownerCallbackControlEvents = ccbReader:getOwnerCallbackControlEvents() 21 | local i = 1 22 | for i = 1,table.getn(ownerCallbackNames) do 23 | local callbackName = ownerCallbackNames[i] 24 | local callbackNode = tolua.cast(ownerCallbackNodes[i],"cc.Node") 25 | 26 | if "function" == type(owner[callbackName]) then 27 | proxy:setCallback(callbackNode, owner[callbackName], ownerCallbackControlEvents[i]) 28 | else 29 | print("Warning: Cannot find owner's lua function:" .. ":" .. callbackName .. " for ownerVar selector") 30 | end 31 | 32 | end 33 | 34 | --Variables 35 | local ownerOutletNames = ccbReader:getOwnerOutletNames() 36 | local ownerOutletNodes = ccbReader:getOwnerOutletNodes() 37 | 38 | for i = 1, table.getn(ownerOutletNames) do 39 | local outletName = ownerOutletNames[i] 40 | local outletNode = tolua.cast(ownerOutletNodes[i],"cc.Node") 41 | owner[outletName] = outletNode 42 | end 43 | end 44 | 45 | local nodesWithAnimationManagers = ccbReader:getNodesWithAnimationManagers() 46 | local animationManagersForNodes = ccbReader:getAnimationManagersForNodes() 47 | 48 | for i = 1 , table.getn(nodesWithAnimationManagers) do 49 | local innerNode = tolua.cast(nodesWithAnimationManagers[i], "cc.Node") 50 | local animationManager = tolua.cast(animationManagersForNodes[i], "cc.CCBAnimationManager") 51 | local documentControllerName = animationManager:getDocumentControllerName() 52 | if "" == documentControllerName then 53 | 54 | end 55 | if nil ~= ccb[documentControllerName] then 56 | ccb[documentControllerName]["mAnimationManager"] = animationManager 57 | end 58 | 59 | --Callbacks 60 | local documentCallbackNames = animationManager:getDocumentCallbackNames() 61 | local documentCallbackNodes = animationManager:getDocumentCallbackNodes() 62 | local documentCallbackControlEvents = animationManager:getDocumentCallbackControlEvents() 63 | 64 | for i = 1,table.getn(documentCallbackNames) do 65 | local callbackName = documentCallbackNames[i] 66 | local callbackNode = tolua.cast(documentCallbackNodes[i],"cc.Node") 67 | if "" ~= documentControllerName and nil ~= ccb[documentControllerName] then 68 | if "function" == type(ccb[documentControllerName][callbackName]) then 69 | proxy:setCallback(callbackNode, ccb[documentControllerName][callbackName], documentCallbackControlEvents[i]) 70 | else 71 | print("Warning: Cannot found lua function [" .. documentControllerName .. ":" .. callbackName .. "] for docRoot selector") 72 | end 73 | end 74 | end 75 | 76 | --Variables 77 | local documentOutletNames = animationManager:getDocumentOutletNames() 78 | local documentOutletNodes = animationManager:getDocumentOutletNodes() 79 | 80 | for i = 1, table.getn(documentOutletNames) do 81 | local outletName = documentOutletNames[i] 82 | local outletNode = tolua.cast(documentOutletNodes[i],"cc.Node") 83 | 84 | if nil ~= ccb[documentControllerName] then 85 | ccb[documentControllerName][outletName] = tolua.cast(outletNode, proxy:getNodeTypeName(outletNode)) 86 | end 87 | end 88 | --[[ 89 | if (typeof(controller.onDidLoadFromCCB) == "function") 90 | controller.onDidLoadFromCCB(); 91 | ]]-- 92 | --Setup timeline callbacks 93 | local keyframeCallbacks = animationManager:getKeyframeCallbacks() 94 | 95 | for i = 1 , table.getn(keyframeCallbacks) do 96 | local callbackCombine = keyframeCallbacks[i] 97 | local beignIndex,endIndex = string.find(callbackCombine,":") 98 | local callbackType = tonumber(string.sub(callbackCombine,1,beignIndex - 1)) 99 | local callbackName = string.sub(callbackCombine,endIndex + 1, -1) 100 | --Document callback 101 | 102 | if 1 == callbackType and nil ~= ccb[documentControllerName] then 103 | local callfunc = cc.CallFunc:create(ccb[documentControllerName][callbackName]) 104 | animationManager:setCallFuncForLuaCallbackNamed(callfunc, callbackCombine); 105 | elseif 2 == callbackType and nil ~= owner then --Owner callback 106 | local callfunc = cc.CallFunc:create(owner[callbackName])--need check 107 | animationManager:setCallFuncForLuaCallbackNamed(callfunc, callbackCombine) 108 | end 109 | end 110 | --start animation 111 | local autoPlaySeqId = animationManager:getAutoPlaySequenceId() 112 | if -1 ~= autoPlaySeqId then 113 | animationManager:runAnimationsForSequenceIdTweenDuration(autoPlaySeqId, 0) 114 | end 115 | end 116 | 117 | return node 118 | end 119 | 120 | 121 | local function CCBuilderReaderLoad(strFilePath,proxy,owner) 122 | print("\n********** \n".."CCBuilderReaderLoad(strFilePath,proxy,owner)".." was deprecated please use ".. "CCBReaderLoad(strFilePath,proxy,owner)" .. " instead.\n**********") 123 | return CCBReaderLoad(strFilePath,proxy,owner) 124 | end 125 | rawset(_G,"CCBuilderReaderLoad",CCBuilderReaderLoad) -------------------------------------------------------------------------------- /src/cocos/cocosbuilder/DeprecatedCocosBuilderClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.CCBProxy then 2 | return 3 | end 4 | -- This is the DeprecatedCocosBuilderClass 5 | 6 | DeprecatedCocosBuilderClass = {} or DeprecatedCocosBuilderClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --CCBReader class will be Deprecated,begin 14 | function DeprecatedCocosBuilderClass.CCBReader() 15 | deprecatedTip("CCBReader","cc.BReader") 16 | return cc.BReader 17 | end 18 | _G["CCBReader"] = DeprecatedCocosBuilderClass.CCBReader() 19 | --CCBReader class will be Deprecated,end 20 | 21 | --CCBAnimationManager class will be Deprecated,begin 22 | function DeprecatedCocosBuilderClass.CCBAnimationManager() 23 | deprecatedTip("CCBAnimationManager","cc.BAnimationManager") 24 | return cc.BAnimationManager 25 | end 26 | _G["CCBAnimationManager"] = DeprecatedCocosBuilderClass.CCBAnimationManager() 27 | --CCBAnimationManager class will be Deprecated,end 28 | 29 | --CCBProxy class will be Deprecated,begin 30 | function DeprecatedCocosBuilderClass.CCBProxy() 31 | deprecatedTip("CCBProxy","cc.CCBProxy") 32 | return cc.CCBProxy 33 | end 34 | _G["CCBProxy"] = DeprecatedCocosBuilderClass.CCBProxy() 35 | --CCBProxy class will be Deprecated,end 36 | -------------------------------------------------------------------------------- /src/cocos/cocosdenshion/AudioEngine.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.SimpleAudioEngine then 2 | return 3 | end 4 | --Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects. 5 | local M = {} 6 | 7 | function M.stopAllEffects() 8 | cc.SimpleAudioEngine:getInstance():stopAllEffects() 9 | end 10 | 11 | function M.getMusicVolume() 12 | return cc.SimpleAudioEngine:getInstance():getMusicVolume() 13 | end 14 | 15 | function M.isMusicPlaying() 16 | return cc.SimpleAudioEngine:getInstance():isMusicPlaying() 17 | end 18 | 19 | function M.getEffectsVolume() 20 | return cc.SimpleAudioEngine:getInstance():getEffectsVolume() 21 | end 22 | 23 | function M.setMusicVolume(volume) 24 | cc.SimpleAudioEngine:getInstance():setMusicVolume(volume) 25 | end 26 | 27 | function M.stopEffect(handle) 28 | cc.SimpleAudioEngine:getInstance():stopEffect(handle) 29 | end 30 | 31 | function M.stopMusic(isReleaseData) 32 | local releaseDataValue = false 33 | if nil ~= isReleaseData then 34 | releaseDataValue = isReleaseData 35 | end 36 | cc.SimpleAudioEngine:getInstance():stopMusic(releaseDataValue) 37 | end 38 | 39 | function M.playMusic(filename, isLoop) 40 | local loopValue = false 41 | if nil ~= isLoop then 42 | loopValue = isLoop 43 | end 44 | cc.SimpleAudioEngine:getInstance():playMusic(filename, loopValue) 45 | end 46 | 47 | function M.pauseAllEffects() 48 | cc.SimpleAudioEngine:getInstance():pauseAllEffects() 49 | end 50 | 51 | function M.preloadMusic(filename) 52 | cc.SimpleAudioEngine:getInstance():preloadMusic(filename) 53 | end 54 | 55 | function M.resumeMusic() 56 | cc.SimpleAudioEngine:getInstance():resumeMusic() 57 | end 58 | 59 | function M.playEffect(filename, isLoop) 60 | local loopValue = false 61 | if nil ~= isLoop then 62 | loopValue = isLoop 63 | end 64 | return cc.SimpleAudioEngine:getInstance():playEffect(filename, loopValue) 65 | end 66 | 67 | function M.rewindMusic() 68 | cc.SimpleAudioEngine:getInstance():rewindMusic() 69 | end 70 | 71 | function M.willPlayMusic() 72 | return cc.SimpleAudioEngine:getInstance():willPlayMusic() 73 | end 74 | 75 | function M.unloadEffect(filename) 76 | cc.SimpleAudioEngine:getInstance():unloadEffect(filename) 77 | end 78 | 79 | function M.preloadEffect(filename) 80 | cc.SimpleAudioEngine:getInstance():preloadEffect(filename) 81 | end 82 | 83 | function M.setEffectsVolume(volume) 84 | cc.SimpleAudioEngine:getInstance():setEffectsVolume(volume) 85 | end 86 | 87 | function M.pauseEffect(handle) 88 | cc.SimpleAudioEngine:getInstance():pauseEffect(handle) 89 | end 90 | 91 | function M.resumeAllEffects(handle) 92 | cc.SimpleAudioEngine:getInstance():resumeAllEffects() 93 | end 94 | 95 | function M.pauseMusic() 96 | cc.SimpleAudioEngine:getInstance():pauseMusic() 97 | end 98 | 99 | function M.resumeEffect(handle) 100 | cc.SimpleAudioEngine:getInstance():resumeEffect(handle) 101 | end 102 | 103 | function M.getInstance() 104 | return cc.SimpleAudioEngine:getInstance() 105 | end 106 | 107 | function M.destroyInstance() 108 | return cc.SimpleAudioEngine:destroyInstance() 109 | end 110 | 111 | AudioEngine = M 112 | -------------------------------------------------------------------------------- /src/cocos/cocosdenshion/DeprecatedCocosDenshionClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.SimpleAudioEngine then 2 | return 3 | end 4 | -- This is the DeprecatedCocosDenshionClass 5 | 6 | DeprecatedCocosDenshionClass = {} or DeprecatedCocosDenshionClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --SimpleAudioEngine class will be Deprecated,begin 14 | function DeprecatedCocosDenshionClass.SimpleAudioEngine() 15 | deprecatedTip("SimpleAudioEngine","cc.SimpleAudioEngine") 16 | return cc.SimpleAudioEngine 17 | end 18 | _G["SimpleAudioEngine"] = DeprecatedCocosDenshionClass.SimpleAudioEngine() 19 | --SimpleAudioEngine class will be Deprecated,end 20 | -------------------------------------------------------------------------------- /src/cocos/cocosdenshion/DeprecatedCocosDenshionFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.SimpleAudioEngine then 2 | return 3 | end 4 | --tip 5 | local function deprecatedTip(old_name,new_name) 6 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 7 | end 8 | 9 | --functions of SimpleAudioEngine will be deprecated begin 10 | local SimpleAudioEngineDeprecated = { } 11 | function SimpleAudioEngineDeprecated.sharedEngine() 12 | deprecatedTip("SimpleAudioEngine:sharedEngine","SimpleAudioEngine:getInstance") 13 | return cc.SimpleAudioEngine:getInstance() 14 | end 15 | SimpleAudioEngine.sharedEngine = SimpleAudioEngineDeprecated.sharedEngine 16 | 17 | function SimpleAudioEngineDeprecated.playBackgroundMusic(self,...) 18 | deprecatedTip("SimpleAudioEngine:playBackgroundMusic","SimpleAudioEngine:playMusic") 19 | return self:playMusic(...) 20 | end 21 | SimpleAudioEngine.playBackgroundMusic = SimpleAudioEngineDeprecated.playBackgroundMusic 22 | --functions of SimpleAudioEngine will be deprecated end 23 | -------------------------------------------------------------------------------- /src/cocos/cocostudio/CocoStudio.lua: -------------------------------------------------------------------------------- 1 | if nil == ccs then 2 | return 3 | end 4 | 5 | if not json then 6 | require "cocos.cocos2d.json" 7 | end 8 | 9 | require "cocos.cocostudio.StudioConstants" 10 | 11 | function ccs.sendTriggerEvent(event) 12 | local triggerObjArr = ccs.TriggerMng.getInstance():get(event) 13 | 14 | if nil == triggerObjArr then 15 | return 16 | end 17 | 18 | for i = 1, table.getn(triggerObjArr) do 19 | local triObj = triggerObjArr[i] 20 | if nil ~= triObj and triObj:detect() then 21 | triObj:done() 22 | end 23 | end 24 | end 25 | 26 | function ccs.registerTriggerClass(className, createFunc) 27 | ccs.TInfo.new(className,createFunc) 28 | end 29 | 30 | ccs.TInfo = class("TInfo") 31 | ccs.TInfo._className = "" 32 | ccs.TInfo._fun = nil 33 | 34 | function ccs.TInfo:ctor(c,f) 35 | -- @param {String|ccs.TInfo}c 36 | -- @param {Function}f 37 | if nil ~= f then 38 | self._className = c 39 | self._fun = f 40 | else 41 | self._className = c._className 42 | self._fun = c._fun 43 | end 44 | 45 | ccs.ObjectFactory.getInstance():registerType(self) 46 | end 47 | 48 | ccs.ObjectFactory = class("ObjectFactory") 49 | ccs.ObjectFactory._typeMap = nil 50 | ccs.ObjectFactory._instance = nil 51 | 52 | function ccs.ObjectFactory:ctor() 53 | self._typeMap = {} 54 | end 55 | 56 | function ccs.ObjectFactory.getInstance() 57 | if nil == ccs.ObjectFactory._instance then 58 | ccs.ObjectFactory._instance = ccs.ObjectFactory.new() 59 | end 60 | 61 | return ccs.ObjectFactory._instance 62 | end 63 | 64 | function ccs.ObjectFactory.destroyInstance() 65 | ccs.ObjectFactory._instance = nil 66 | end 67 | 68 | function ccs.ObjectFactory:createObject(classname) 69 | local obj = nil 70 | local t = self._typeMap[classname] 71 | if nil ~= t then 72 | obj = t._fun() 73 | end 74 | 75 | return obj 76 | end 77 | 78 | function ccs.ObjectFactory:registerType(t) 79 | self._typeMap[t._className] = t 80 | end 81 | 82 | ccs.TriggerObj = class("TriggerObj") 83 | ccs.TriggerObj._cons = {} 84 | ccs.TriggerObj._acts = {} 85 | ccs.TriggerObj._enable = false 86 | ccs.TriggerObj._id = 0 87 | ccs.TriggerObj._vInt = {} 88 | 89 | function ccs.TriggerObj.extend(target) 90 | local t = tolua.getpeer(target) 91 | if not t then 92 | t = {} 93 | tolua.setpeer(target, t) 94 | end 95 | setmetatable(t, TriggerObj) 96 | return target 97 | end 98 | 99 | function ccs.TriggerObj:ctor() 100 | self:init() 101 | end 102 | 103 | function ccs.TriggerObj:init() 104 | self._id = 0 105 | self._enable = true 106 | self._cons = {} 107 | self._acts = {} 108 | self._vInt = {} 109 | end 110 | 111 | function ccs.TriggerObj:detect() 112 | if (not self._enable) or (table.getn(self._cons) == 0) then 113 | return true 114 | end 115 | 116 | local ret = true 117 | local obj = nil 118 | for i = 1 , table.getn(self._cons) do 119 | obj = self._cons[i] 120 | if nil ~= obj and nil ~= obj.detect then 121 | ret = ret and obj:detect() 122 | end 123 | end 124 | return ret 125 | end 126 | 127 | function ccs.TriggerObj:done() 128 | if (not self._enable) or (table.getn(self._acts) == 0) then 129 | return 130 | end 131 | 132 | local obj = nil 133 | for i = 1, table.getn(self._acts) do 134 | obj = self._acts[i] 135 | if nil ~= obj and obj.done then 136 | obj:done() 137 | end 138 | end 139 | end 140 | 141 | function ccs.TriggerObj:removeAll() 142 | local obj = nil 143 | for i=1, table.getn(self._cons) do 144 | obj = self._cons[i] 145 | if nil ~= obj then 146 | obj:removeAll() 147 | end 148 | end 149 | self._cons = {} 150 | 151 | for i=1, table.getn(self._acts) do 152 | obj = self._acts[i] 153 | if nil ~= obj then 154 | obj:removeAll() 155 | end 156 | end 157 | self._acts = {} 158 | end 159 | 160 | function ccs.TriggerObj:serialize(jsonValue) 161 | self._id = jsonValue["id"] 162 | local count = 0 163 | 164 | --condition 165 | local cons = jsonValue["conditions"] 166 | if nil ~= cons then 167 | count = table.getn(cons) 168 | for i = 1, count do 169 | local subDict = cons[i] 170 | local className = subDict["classname"] 171 | if nil ~= className then 172 | local obj = ccs.ObjectFactory.getInstance():createObject(className) 173 | assert(nil ~= obj, string.format("class named %s can not implement!",className)) 174 | obj:serialize(subDict) 175 | obj:init() 176 | table.insert(self._cons, obj) 177 | end 178 | end 179 | end 180 | 181 | local actions = jsonValue["actions"] 182 | if nil ~= actions then 183 | count = table.getn(actions) 184 | for i = 1,count do 185 | local subAction = actions[i] 186 | local className = subAction["classname"] 187 | if nil ~= className then 188 | local act = ccs.ObjectFactory.getInstance():createObject(className) 189 | assert(nil ~= act ,string.format("class named %s can not implement!",className)) 190 | act:serialize(subAction) 191 | act:init() 192 | table.insert(self._acts,act) 193 | end 194 | end 195 | end 196 | 197 | local events = jsonValue["events"] 198 | if nil ~= events then 199 | count = table.getn(events) 200 | for i = 1, count do 201 | local subEveent = events[i] 202 | local eventID = subEveent["id"] 203 | if eventID >= 0 then 204 | table.insert(self._vInt,eventID) 205 | end 206 | end 207 | end 208 | end 209 | 210 | function ccs.TriggerObj:getId() 211 | return self._id 212 | end 213 | 214 | function ccs.TriggerObj:setEnable(enable) 215 | self._enable = enable 216 | end 217 | 218 | function ccs.TriggerObj:getEvents() 219 | return self._vInt 220 | end 221 | 222 | ccs.TriggerMng = class("TriggerMng") 223 | ccs.TriggerMng._eventTriggers = nil 224 | ccs.TriggerMng._triggerObjs = nil 225 | ccs.TriggerMng._movementDispatches = nil 226 | ccs.TriggerMng._instance = nil 227 | 228 | function ccs.TriggerMng:ctor() 229 | self._triggerObjs = {} 230 | self._movementDispatches = {} 231 | self._eventTriggers = {} 232 | end 233 | 234 | function ccs.TriggerMng.getInstance() 235 | if ccs.TriggerMng._instance == nil then 236 | ccs.TriggerMng._instance = ccs.TriggerMng.new() 237 | end 238 | 239 | return ccs.TriggerMng._instance 240 | end 241 | 242 | function ccs.TriggerMng.destroyInstance() 243 | if ccs.TriggerMng._instance ~= nil then 244 | ccs.TriggerMng._instance:removeAll() 245 | ccs.TriggerMng._instance = nil 246 | end 247 | end 248 | 249 | function ccs.TriggerMng:triggerMngVersion() 250 | return "1.0.0.0" 251 | end 252 | 253 | function ccs.TriggerMng:parse(jsonStr) 254 | local parseTable = json.decode(jsonStr,1) 255 | if nil == parseTable then 256 | return 257 | end 258 | 259 | local count = table.getn(parseTable) 260 | for i = 1, count do 261 | local subDict = parseTable[i] 262 | local triggerObj = ccs.TriggerObj.new() 263 | triggerObj:serialize(subDict) 264 | local events = triggerObj:getEvents() 265 | for j = 1, table.getn(events) do 266 | local event = events[j] 267 | self:add(event, triggerObj) 268 | end 269 | 270 | self._triggerObjs[triggerObj:getId()] = triggerObj 271 | end 272 | end 273 | 274 | function ccs.TriggerMng:get(event) 275 | return self._eventTriggers[event] 276 | end 277 | 278 | function ccs.TriggerMng:getTriggerObj(id) 279 | return self._triggerObjs[id] 280 | end 281 | 282 | function ccs.TriggerMng:add(event,triggerObj) 283 | local eventTriggers = self._eventTriggers[event] 284 | if nil == eventTriggers then 285 | eventTriggers = {} 286 | end 287 | 288 | local exist = false 289 | for i = 1, table.getn(eventTriggers) do 290 | if eventTriggers[i] == triggers then 291 | exist = true 292 | break 293 | end 294 | end 295 | 296 | if not exist then 297 | table.insert(eventTriggers,triggerObj) 298 | self._eventTriggers[event] = eventTriggers 299 | end 300 | end 301 | 302 | function ccs.TriggerMng:removeAll( ) 303 | for k in pairs(self._eventTriggers) do 304 | local triObjArr = self._eventTriggers[k] 305 | for j = 1, table.getn(triObjArr) do 306 | local obj = triObjArr[j] 307 | obj:removeAll() 308 | end 309 | end 310 | self._eventTriggers = {} 311 | end 312 | 313 | function ccs.TriggerMng:remove(event, obj) 314 | 315 | if nil ~= obj then 316 | return self:removeObjByEvent(event, obj) 317 | end 318 | 319 | assert(event >= 0,"event must be larger than 0") 320 | if nil == self._eventTriggers then 321 | return false 322 | end 323 | 324 | local triObjects = self._eventTriggers[event] 325 | if nil == triObjects then 326 | return false 327 | end 328 | 329 | for i = 1, table.getn(triObjects) do 330 | local triObject = triggers[i] 331 | if nil ~= triObject then 332 | triObject:remvoeAll() 333 | end 334 | end 335 | 336 | self._eventTriggers[event] = nil 337 | return true 338 | end 339 | 340 | function ccs.TriggerMng:removeObjByEvent(event, obj) 341 | assert(event >= 0,"event must be larger than 0") 342 | if nil == self._eventTriggers then 343 | return false 344 | end 345 | 346 | local triObjects = self._eventTriggers[event] 347 | if nil == triObjects then 348 | return false 349 | end 350 | 351 | for i = 1,table.getn(triObjects) do 352 | local triObject = triObjects[i] 353 | if nil ~= triObject and triObject == obj then 354 | triObject:remvoeAll() 355 | table.remove(triObjects, i) 356 | return true 357 | end 358 | end 359 | end 360 | 361 | function ccs.TriggerMng:removeTriggerObj(id) 362 | local obj = self.getTriggerObj(id) 363 | 364 | if nil == obj then 365 | return false 366 | end 367 | 368 | local events = obj:getEvents() 369 | for i = 1, table.getn(events) do 370 | self:remove(events[i],obj) 371 | end 372 | 373 | return true 374 | end 375 | 376 | function ccs.TriggerMng:isEmpty() 377 | return (not (nil == self._eventTriggers)) or table.getn(self._eventTriggers) <= 0 378 | end 379 | 380 | function __onParseConfig(configType,jasonStr) 381 | if configType == cc.ConfigType.COCOSTUDIO then 382 | ccs.TriggerMng.getInstance():parse(jasonStr) 383 | end 384 | end 385 | 386 | function ccs.AnimationInfo(_name, _startIndex, _endIndex) 387 | assert(nil ~= _name and type(_name) == "string" and _startIndex ~= nil and type(_startIndex) == "number" and _endIndex ~= nil and type(_endIndex) == "number", "ccs.AnimationInfo() - invalid input parameters") 388 | return { name = _name, startIndex = _startIndex, endIndex = _endIndex} 389 | end 390 | -------------------------------------------------------------------------------- /src/cocos/cocostudio/DeprecatedCocoStudioClass.lua: -------------------------------------------------------------------------------- 1 | if nil == ccs then 2 | return 3 | end 4 | -- This is the DeprecatedExtensionClass 5 | 6 | DeprecatedExtensionClass = {} or DeprecatedExtensionClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --CCArmature class will be Deprecated,begin 14 | function DeprecatedExtensionClass.CCArmature() 15 | deprecatedTip("CCArmature","ccs.Armature") 16 | return ccs.Armature 17 | end 18 | _G["CCArmature"] = DeprecatedExtensionClass.CCArmature() 19 | --CCArmature class will be Deprecated,end 20 | 21 | --CCArmatureAnimation class will be Deprecated,begin 22 | function DeprecatedExtensionClass.CCArmatureAnimation() 23 | deprecatedTip("CCArmatureAnimation","ccs.ArmatureAnimation") 24 | return ccs.ArmatureAnimation 25 | end 26 | _G["CCArmatureAnimation"] = DeprecatedExtensionClass.CCArmatureAnimation() 27 | --CCArmatureAnimation class will be Deprecated,end 28 | 29 | --CCSkin class will be Deprecated,begin 30 | function DeprecatedExtensionClass.CCSkin() 31 | deprecatedTip("CCSkin","ccs.Skin") 32 | return ccs.Skin 33 | end 34 | _G["CCSkin"] = DeprecatedExtensionClass.CCSkin() 35 | --CCSkin class will be Deprecated,end 36 | 37 | --CCBone class will be Deprecated,begin 38 | function DeprecatedExtensionClass.CCBone() 39 | deprecatedTip("CCBone","ccs.Bone") 40 | return ccs.Bone 41 | end 42 | _G["CCBone"] = DeprecatedExtensionClass.CCBone() 43 | --CCBone class will be Deprecated,end 44 | 45 | --CCArmatureDataManager class will be Deprecated,begin 46 | function DeprecatedExtensionClass.CCArmatureDataManager() 47 | deprecatedTip("CCArmatureDataManager","ccs.ArmatureDataManager") 48 | return ccs.ArmatureDataManager 49 | end 50 | _G["CCArmatureDataManager"] = DeprecatedExtensionClass.CCArmatureDataManager() 51 | --CCArmatureDataManager class will be Deprecated,end 52 | 53 | --CCBatchNode class will be Deprecated,begin 54 | function DeprecatedExtensionClass.CCBatchNode() 55 | deprecatedTip("CCBatchNode","ccs.BatchNode") 56 | return ccs.BatchNode 57 | end 58 | _G["CCBatchNode"] = DeprecatedExtensionClass.CCBatchNode() 59 | --CCBatchNode class will be Deprecated,end 60 | 61 | --CCTween class will be Deprecated,begin 62 | function DeprecatedExtensionClass.CCTween() 63 | deprecatedTip("CCTween","ccs.Tween") 64 | return ccs.Tween 65 | end 66 | _G["CCTween"] = DeprecatedExtensionClass.CCTween() 67 | --CCTween class will be Deprecated,end 68 | 69 | --CCBaseData class will be Deprecated,begin 70 | function DeprecatedExtensionClass.CCBaseData() 71 | deprecatedTip("CCBaseData","ccs.BaseData") 72 | return ccs.BaseData 73 | end 74 | _G["CCBaseData"] = DeprecatedExtensionClass.CCBaseData() 75 | --CCBaseData class will be Deprecated,end 76 | 77 | --CCDisplayManager class will be Deprecated,begin 78 | function DeprecatedExtensionClass.CCDisplayManager() 79 | deprecatedTip("CCDisplayManager","ccs.DisplayManager") 80 | return ccs.DisplayManager 81 | end 82 | _G["CCDisplayManager"] = DeprecatedExtensionClass.CCDisplayManager() 83 | --CCDisplayManager class will be Deprecated,end 84 | 85 | --UIHelper class will be Deprecated,begin 86 | function DeprecatedExtensionClass.UIHelper() 87 | deprecatedTip("UIHelper","ccs.UIHelper") 88 | return ccs.UIHelper 89 | end 90 | _G["UIHelper"] = DeprecatedExtensionClass.UIHelper() 91 | --UIHelper class will be Deprecated,end 92 | 93 | --UILayout class will be Deprecated,begin 94 | function DeprecatedExtensionClass.UILayout() 95 | deprecatedTip("UILayout","ccs.UILayout") 96 | return ccs.UILayout 97 | end 98 | _G["UILayout"] = DeprecatedExtensionClass.UILayout() 99 | --UILayout class will be Deprecated,end 100 | 101 | --UIWidget class will be Deprecated,begin 102 | function DeprecatedExtensionClass.UIWidget() 103 | deprecatedTip("UIWidget","ccs.UIWidget") 104 | return ccs.UIWidget 105 | end 106 | _G["UIWidget"] = DeprecatedExtensionClass.UIWidget() 107 | --UIWidget class will be Deprecated,end 108 | 109 | --UILayer class will be Deprecated,begin 110 | function DeprecatedExtensionClass.UILayer() 111 | deprecatedTip("UILayer","ccs.UILayer") 112 | return ccs.UILayer 113 | end 114 | _G["UILayer"] = DeprecatedExtensionClass.UILayer() 115 | --UILayer class will be Deprecated,end 116 | 117 | --UIButton class will be Deprecated,begin 118 | function DeprecatedExtensionClass.UIButton() 119 | deprecatedTip("UIButton","ccs.UIButton") 120 | return ccs.UIButton 121 | end 122 | _G["UIButton"] = DeprecatedExtensionClass.UIButton() 123 | --UIButton class will be Deprecated,end 124 | 125 | --UICheckBox class will be Deprecated,begin 126 | function DeprecatedExtensionClass.UICheckBox() 127 | deprecatedTip("UICheckBox","ccs.UICheckBox") 128 | return ccs.UICheckBox 129 | end 130 | _G["UICheckBox"] = DeprecatedExtensionClass.UICheckBox() 131 | --UICheckBox class will be Deprecated,end 132 | 133 | --UIImageView class will be Deprecated,begin 134 | function DeprecatedExtensionClass.UIImageView() 135 | deprecatedTip("UIImageView","ccs.UIImageView") 136 | return ccs.UIImageView 137 | end 138 | _G["UIImageView"] = DeprecatedExtensionClass.UIImageView() 139 | --UIImageView class will be Deprecated,end 140 | 141 | --UILabel class will be Deprecated,begin 142 | function DeprecatedExtensionClass.UILabel() 143 | deprecatedTip("UILabel","ccs.UILabel") 144 | return ccs.UILabel 145 | end 146 | _G["UILabel"] = DeprecatedExtensionClass.UILabel() 147 | --UILabel class will be Deprecated,end 148 | 149 | --UILabelAtlas class will be Deprecated,begin 150 | function DeprecatedExtensionClass.UILabelAtlas() 151 | deprecatedTip("UILabelAtlas","ccs.UILabelAtlas") 152 | return ccs.UILabelAtlas 153 | end 154 | _G["UILabelAtlas"] = DeprecatedExtensionClass.UILabelAtlas() 155 | --UILabelAtlas class will be Deprecated,end 156 | 157 | --UILabelBMFont class will be Deprecated,begin 158 | function DeprecatedExtensionClass.UILabelBMFont() 159 | deprecatedTip("UILabelBMFont","ccs.UILabelBMFont") 160 | return ccs.UILabelBMFont 161 | end 162 | _G["UILabelBMFont"] = DeprecatedExtensionClass.UILabelBMFont() 163 | --UILabelBMFont class will be Deprecated,end 164 | 165 | --UILoadingBar class will be Deprecated,begin 166 | function DeprecatedExtensionClass.UILoadingBar() 167 | deprecatedTip("UILoadingBar","ccs.UILoadingBar") 168 | return ccs.UILoadingBar 169 | end 170 | _G["UILoadingBar"] = DeprecatedExtensionClass.UILoadingBar() 171 | --UILoadingBar class will be Deprecated,end 172 | 173 | --UISlider class will be Deprecated,begin 174 | function DeprecatedExtensionClass.UISlider() 175 | deprecatedTip("UISlider","ccs.UISlider") 176 | return ccs.UISlider 177 | end 178 | _G["UISlider"] = DeprecatedExtensionClass.UISlider() 179 | --UISlider class will be Deprecated,end 180 | 181 | --UITextField class will be Deprecated,begin 182 | function DeprecatedExtensionClass.UITextField() 183 | deprecatedTip("UITextField","ccs.UITextField") 184 | return ccs.UITextField 185 | end 186 | _G["UITextField"] = DeprecatedExtensionClass.UITextField() 187 | --UITextField class will be Deprecated,end 188 | 189 | --UIScrollView class will be Deprecated,begin 190 | function DeprecatedExtensionClass.UIScrollView() 191 | deprecatedTip("UIScrollView","ccs.UIScrollView") 192 | return ccs.UIScrollView 193 | end 194 | _G["UIScrollView"] = DeprecatedExtensionClass.UIScrollView() 195 | --UIScrollView class will be Deprecated,end 196 | 197 | --UIPageView class will be Deprecated,begin 198 | function DeprecatedExtensionClass.UIPageView() 199 | deprecatedTip("UIPageView","ccs.UIPageView") 200 | return ccs.UIPageView 201 | end 202 | _G["UIPageView"] = DeprecatedExtensionClass.UIPageView() 203 | --UIPageView class will be Deprecated,end 204 | 205 | --UIListView class will be Deprecated,begin 206 | function DeprecatedExtensionClass.UIListView() 207 | deprecatedTip("UIListView","ccs.UIListView") 208 | return ccs.UIListView 209 | end 210 | _G["UIListView"] = DeprecatedExtensionClass.UIListView() 211 | --UIListView class will be Deprecated,end 212 | 213 | --UILayoutParameter class will be Deprecated,begin 214 | function DeprecatedExtensionClass.UILayoutParameter() 215 | deprecatedTip("UILayoutParameter","ccs.UILayoutParameter") 216 | return ccs.UILayoutParameter 217 | end 218 | _G["UILayoutParameter"] = DeprecatedExtensionClass.UILayoutParameter() 219 | --UILayoutParameter class will be Deprecated,end 220 | 221 | --UILinearLayoutParameter class will be Deprecated,begin 222 | function DeprecatedExtensionClass.UILinearLayoutParameter() 223 | deprecatedTip("UILinearLayoutParameter","ccs.UILinearLayoutParameter") 224 | return ccs.UILinearLayoutParameter 225 | end 226 | _G["UILinearLayoutParameter"] = DeprecatedExtensionClass.UILinearLayoutParameter() 227 | --UILinearLayoutParameter class will be Deprecated,end 228 | 229 | --UIRelativeLayoutParameter class will be Deprecated,begin 230 | function DeprecatedExtensionClass.UIRelativeLayoutParameter() 231 | deprecatedTip("UIRelativeLayoutParameter","ccs.UIRelativeLayoutParameter") 232 | return ccs.UIRelativeLayoutParameter 233 | end 234 | _G["UIRelativeLayoutParameter"] = DeprecatedExtensionClass.UIRelativeLayoutParameter() 235 | --UIRelativeLayoutParameter class will be Deprecated,end 236 | 237 | --CCComController class will be Deprecated,begin 238 | function DeprecatedExtensionClass.CCComController() 239 | deprecatedTip("CCComController","ccs.ComController") 240 | return ccs.CCComController 241 | end 242 | _G["CCComController"] = DeprecatedExtensionClass.CCComController() 243 | --CCComController class will be Deprecated,end 244 | 245 | --CCComAudio class will be Deprecated,begin 246 | function DeprecatedExtensionClass.CCComAudio() 247 | deprecatedTip("CCComAudio","ccs.ComAudio") 248 | return ccs.ComAudio 249 | end 250 | _G["CCComAudio"] = DeprecatedExtensionClass.CCComAudio() 251 | --CCComAudio class will be Deprecated,end 252 | 253 | --CCComAttribute class will be Deprecated,begin 254 | function DeprecatedExtensionClass.CCComAttribute() 255 | deprecatedTip("CCComAttribute","ccs.ComAttribute") 256 | return ccs.ComAttribute 257 | end 258 | _G["CCComAttribute"] = DeprecatedExtensionClass.CCComAttribute() 259 | --CCComAttribute class will be Deprecated,end 260 | 261 | --CCComRender class will be Deprecated,begin 262 | function DeprecatedExtensionClass.CCComRender() 263 | deprecatedTip("CCComRender","ccs.ComRender") 264 | return ccs.ComRender 265 | end 266 | _G["CCComRender"] = DeprecatedExtensionClass.CCComRender() 267 | --CCComRender class will be Deprecated,end 268 | 269 | --ActionManager class will be Deprecated,begin 270 | function DeprecatedExtensionClass.ActionManager() 271 | deprecatedTip("ActionManager","ccs.ActionManagerEx") 272 | return ccs.ActionManagerEx 273 | end 274 | _G["ActionManager"] = DeprecatedExtensionClass.ActionManager() 275 | --CCComRender class will be Deprecated,end 276 | 277 | --SceneReader class will be Deprecated,begin 278 | function DeprecatedExtensionClass.SceneReader() 279 | deprecatedTip("SceneReader","ccs.SceneReader") 280 | return ccs.SceneReader 281 | end 282 | _G["SceneReader"] = DeprecatedExtensionClass.SceneReader() 283 | --SceneReader class will be Deprecated,end 284 | 285 | --GUIReader class will be Deprecated,begin 286 | function DeprecatedExtensionClass.GUIReader() 287 | deprecatedTip("GUIReader","ccs.GUIReader") 288 | return ccs.GUIReader 289 | end 290 | _G["GUIReader"] = DeprecatedExtensionClass.GUIReader() 291 | --GUIReader class will be Deprecated,end 292 | 293 | --UIRootWidget class will be Deprecated,begin 294 | function DeprecatedExtensionClass.UIRootWidget() 295 | deprecatedTip("UIRootWidget","ccs.UIRootWidget") 296 | return ccs.UIRootWidget 297 | end 298 | _G["UIRootWidget"] = DeprecatedExtensionClass.UIRootWidget() 299 | --UIRootWidget class will be Deprecated,end 300 | 301 | --ActionObject class will be Deprecated,begin 302 | function DeprecatedExtensionClass.ActionObject() 303 | deprecatedTip("ActionObject","ccs.ActionObject") 304 | return ccs.ActionObject 305 | end 306 | _G["ActionObject"] = DeprecatedExtensionClass.ActionObject() 307 | --ActionObject class will be Deprecated,end -------------------------------------------------------------------------------- /src/cocos/cocostudio/DeprecatedCocoStudioFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == ccs then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of GUIReader will be deprecated begin 11 | local GUIReaderDeprecated = { } 12 | function GUIReaderDeprecated.shareReader() 13 | deprecatedTip("GUIReader:shareReader","ccs.GUIReader:getInstance") 14 | return ccs.GUIReader:getInstance() 15 | end 16 | GUIReader.shareReader = GUIReaderDeprecated.shareReader 17 | 18 | function GUIReaderDeprecated.purgeGUIReader() 19 | deprecatedTip("GUIReader:purgeGUIReader","ccs.GUIReader:destroyInstance") 20 | return ccs.GUIReader:destroyInstance() 21 | end 22 | GUIReader.purgeGUIReader = GUIReaderDeprecated.purgeGUIReader 23 | --functions of GUIReader will be deprecated end 24 | 25 | --functions of SceneReader will be deprecated begin 26 | local SceneReaderDeprecated = { } 27 | function SceneReaderDeprecated.sharedSceneReader() 28 | deprecatedTip("SceneReader:sharedSceneReader","ccs.SceneReader:getInstance") 29 | return ccs.SceneReader:getInstance() 30 | end 31 | SceneReader.sharedSceneReader = SceneReaderDeprecated.sharedSceneReader 32 | 33 | function SceneReaderDeprecated.purgeSceneReader(self) 34 | deprecatedTip("SceneReader:purgeSceneReader","ccs.SceneReader:destroyInstance") 35 | return self:destroyInstance() 36 | end 37 | SceneReader.purgeSceneReader = SceneReaderDeprecated.purgeSceneReader 38 | --functions of SceneReader will be deprecated end 39 | 40 | 41 | --functions of ccs.GUIReader will be deprecated begin 42 | local CCSGUIReaderDeprecated = { } 43 | function CCSGUIReaderDeprecated.purgeGUIReader() 44 | deprecatedTip("ccs.GUIReader:purgeGUIReader","ccs.GUIReader:destroyInstance") 45 | return ccs.GUIReader:destroyInstance() 46 | end 47 | ccs.GUIReader.purgeGUIReader = CCSGUIReaderDeprecated.purgeGUIReader 48 | --functions of ccs.GUIReader will be deprecated end 49 | 50 | --functions of ccs.ActionManagerEx will be deprecated begin 51 | local CCSActionManagerExDeprecated = { } 52 | function CCSActionManagerExDeprecated.destroyActionManager() 53 | deprecatedTip("ccs.ActionManagerEx:destroyActionManager","ccs.ActionManagerEx:destroyInstance") 54 | return ccs.ActionManagerEx:destroyInstance() 55 | end 56 | ccs.ActionManagerEx.destroyActionManager = CCSActionManagerExDeprecated.destroyActionManager 57 | --functions of ccs.ActionManagerEx will be deprecated end 58 | 59 | --functions of ccs.SceneReader will be deprecated begin 60 | local CCSSceneReaderDeprecated = { } 61 | function CCSSceneReaderDeprecated.destroySceneReader(self) 62 | deprecatedTip("ccs.SceneReader:destroySceneReader","ccs.SceneReader:destroyInstance") 63 | return self:destroyInstance() 64 | end 65 | ccs.SceneReader.destroySceneReader = CCSSceneReaderDeprecated.destroySceneReader 66 | --functions of ccs.SceneReader will be deprecated end 67 | 68 | --functions of CCArmatureDataManager will be deprecated begin 69 | local CCArmatureDataManagerDeprecated = { } 70 | function CCArmatureDataManagerDeprecated.sharedArmatureDataManager() 71 | deprecatedTip("CCArmatureDataManager:sharedArmatureDataManager","ccs.ArmatureDataManager:getInstance") 72 | return ccs.ArmatureDataManager:getInstance() 73 | end 74 | CCArmatureDataManager.sharedArmatureDataManager = CCArmatureDataManagerDeprecated.sharedArmatureDataManager 75 | 76 | function CCArmatureDataManagerDeprecated.purge() 77 | deprecatedTip("CCArmatureDataManager:purge","ccs.ArmatureDataManager:destoryInstance") 78 | return ccs.ArmatureDataManager:destoryInstance() 79 | end 80 | CCArmatureDataManager.purge = CCArmatureDataManagerDeprecated.purge 81 | --functions of CCArmatureDataManager will be deprecated end 82 | -------------------------------------------------------------------------------- /src/cocos/cocostudio/StudioConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == ccs then 2 | return 3 | end 4 | 5 | ccs.MovementEventType = { 6 | start = 0, 7 | complete = 1, 8 | loopComplete = 2, 9 | } 10 | 11 | ccs.InnerActionType = { 12 | LoopAction = 0, 13 | NoLoopAction = 1, 14 | SingleFrame = 2, 15 | } 16 | -------------------------------------------------------------------------------- /src/cocos/controller/ControllerConstants.lua: -------------------------------------------------------------------------------- 1 | 2 | cc = cc or {} 3 | 4 | cc.ControllerKey = 5 | { 6 | JOYSTICK_LEFT_X = 1000, 7 | JOYSTICK_LEFT_Y = 1001, 8 | JOYSTICK_RIGHT_X = 1002, 9 | JOYSTICK_RIGHT_Y = 1003, 10 | 11 | BUTTON_A = 1004, 12 | BUTTON_B = 1005, 13 | BUTTON_C = 1006, 14 | BUTTON_X = 1007, 15 | BUTTON_Y = 1008, 16 | BUTTON_Z = 1009, 17 | 18 | BUTTON_DPAD_UP = 1010, 19 | BUTTON_DPAD_DOWN = 1011, 20 | BUTTON_DPAD_LEFT = 1012, 21 | BUTTON_DPAD_RIGHT = 1013, 22 | BUTTON_DPAD_CENTER = 1014, 23 | 24 | BUTTON_LEFT_SHOULDER = 1015, 25 | BUTTON_RIGHT_SHOULDER = 1016, 26 | 27 | AXIS_LEFT_TRIGGER = 1017, 28 | AXIS_RIGHT_TRIGGER = 1018, 29 | 30 | BUTTON_LEFT_THUMBSTICK = 1019, 31 | BUTTON_RIGHT_THUMBSTICK = 1020, 32 | 33 | BUTTON_START = 1021, 34 | BUTTON_SELECT = 1022, 35 | 36 | BUTTON_PAUSE = 1023, 37 | KEY_MAX = 1024, 38 | } 39 | -------------------------------------------------------------------------------- /src/cocos/extension/DeprecatedExtensionClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | -- This is the DeprecatedExtensionClass 6 | DeprecatedExtensionClass = {} or DeprecatedExtensionClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --CCControl class will be Deprecated,begin 14 | function DeprecatedExtensionClass.CCControl() 15 | deprecatedTip("CCControl","cc.Control") 16 | return cc.Control 17 | end 18 | _G["CCControl"] = DeprecatedExtensionClass.CCControl() 19 | --CCControl class will be Deprecated,end 20 | 21 | --CCScrollView class will be Deprecated,begin 22 | function DeprecatedExtensionClass.CCScrollView() 23 | deprecatedTip("CCScrollView","cc.ScrollView") 24 | return cc.ScrollView 25 | end 26 | _G["CCScrollView"] = DeprecatedExtensionClass.CCScrollView() 27 | --CCScrollView class will be Deprecated,end 28 | 29 | --CCTableView class will be Deprecated,begin 30 | function DeprecatedExtensionClass.CCTableView() 31 | deprecatedTip("CCTableView","cc.TableView") 32 | return cc.TableView 33 | end 34 | _G["CCTableView"] = DeprecatedExtensionClass.CCTableView() 35 | --CCTableView class will be Deprecated,end 36 | 37 | --CCControlPotentiometer class will be Deprecated,begin 38 | function DeprecatedExtensionClass.CCControlPotentiometer() 39 | deprecatedTip("CCControlPotentiometer","cc.ControlPotentiometer") 40 | return cc.ControlPotentiometer 41 | end 42 | _G["CCControlPotentiometer"] = DeprecatedExtensionClass.CCControlPotentiometer() 43 | --CCControlPotentiometer class will be Deprecated,end 44 | 45 | --CCControlStepper class will be Deprecated,begin 46 | function DeprecatedExtensionClass.CCControlStepper() 47 | deprecatedTip("CCControlStepper","cc.ControlStepper") 48 | return cc.ControlStepper 49 | end 50 | _G["CCControlStepper"] = DeprecatedExtensionClass.CCControlStepper() 51 | --CCControlStepper class will be Deprecated,end 52 | 53 | --CCControlHuePicker class will be Deprecated,begin 54 | function DeprecatedExtensionClass.CCControlHuePicker() 55 | deprecatedTip("CCControlHuePicker","cc.ControlHuePicker") 56 | return cc.ControlHuePicker 57 | end 58 | _G["CCControlHuePicker"] = DeprecatedExtensionClass.CCControlHuePicker() 59 | --CCControlHuePicker class will be Deprecated,end 60 | 61 | --CCControlSlider class will be Deprecated,begin 62 | function DeprecatedExtensionClass.CCControlSlider() 63 | deprecatedTip("CCControlSlider","cc.ControlSlider") 64 | return cc.ControlSlider 65 | end 66 | _G["CCControlSlider"] = DeprecatedExtensionClass.CCControlSlider() 67 | --CCControlSlider class will be Deprecated,end 68 | 69 | --CCControlSaturationBrightnessPicker class will be Deprecated,begin 70 | function DeprecatedExtensionClass.CCControlSaturationBrightnessPicker() 71 | deprecatedTip("CCControlSaturationBrightnessPicker","cc.ControlSaturationBrightnessPicker") 72 | return cc.ControlSaturationBrightnessPicker 73 | end 74 | _G["CCControlSaturationBrightnessPicker"] = DeprecatedExtensionClass.CCControlSaturationBrightnessPicker() 75 | --CCControlSaturationBrightnessPicker class will be Deprecated,end 76 | 77 | --CCControlSwitch class will be Deprecated,begin 78 | function DeprecatedExtensionClass.CCControlSwitch() 79 | deprecatedTip("CCControlSwitch","cc.ControlSwitch") 80 | return cc.ControlSwitch 81 | end 82 | _G["CCControlSwitch"] = DeprecatedExtensionClass.CCControlSwitch() 83 | --CCControlSwitch class will be Deprecated,end 84 | 85 | --CCControlButton class will be Deprecated,begin 86 | function DeprecatedExtensionClass.CCControlButton() 87 | deprecatedTip("CCControlButton","cc.ControlButton") 88 | return cc.ControlButton 89 | end 90 | _G["CCControlButton"] = DeprecatedExtensionClass.CCControlButton() 91 | --CCControlButton class will be Deprecated,end 92 | 93 | --CCControlColourPicker class will be Deprecated,begin 94 | function DeprecatedExtensionClass.CCControlColourPicker() 95 | deprecatedTip("CCControlColourPicker","cc.ControlColourPicker") 96 | return cc.ControlColourPicker 97 | end 98 | _G["CCControlColourPicker"] = DeprecatedExtensionClass.CCControlColourPicker() 99 | --CCControlColourPicker class will be Deprecated,end 100 | 101 | 102 | if nil == ccui then 103 | return 104 | end 105 | 106 | --CCEditBox class will be Deprecated,begin 107 | function DeprecatedExtensionClass.CCEditBox() 108 | deprecatedTip("CCEditBox","ccui.EditBox") 109 | return ccui.EditBox 110 | end 111 | _G["CCEditBox"] = DeprecatedExtensionClass.CCEditBox() 112 | 113 | function DeprecatedExtensionClass.CCUIEditBox() 114 | deprecatedTip("cc.EditBox","ccui.EditBox") 115 | return ccui.EditBox 116 | end 117 | _G["cc"]["EditBox"] = DeprecatedExtensionClass.CCUIEditBox() 118 | 119 | --CCEditBox class will be Deprecated,end 120 | 121 | --CCScale9Sprite class will be Deprecated,begin 122 | function DeprecatedExtensionClass.CCScale9Sprite() 123 | deprecatedTip("CCScale9Sprite","ccui.Scale9Sprite") 124 | return ccui.Scale9Sprite 125 | end 126 | _G["CCScale9Sprite"] = DeprecatedExtensionClass.CCScale9Sprite() 127 | 128 | function DeprecatedExtensionClass.UIScale9Sprite() 129 | deprecatedTip("cc.Scale9Sprite","ccui.Scale9Sprite") 130 | return ccui.Scale9Sprite 131 | end 132 | _G["cc"]["Scale9Sprite"] = DeprecatedExtensionClass.UIScale9Sprite() 133 | --CCScale9Sprite class will be Deprecated,end 134 | 135 | -------------------------------------------------------------------------------- /src/cocos/extension/DeprecatedExtensionEnum.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | _G.kCCControlStepperPartMinus = cc.CONTROL_STEPPER_PART_MINUS 6 | _G.kCCControlStepperPartPlus = cc.CONTROL_STEPPER_PART_PLUS 7 | _G.kCCControlStepperPartNone = cc.CONTROL_STEPPER_PART_NONE 8 | 9 | _G.CCControlEventTouchDown = cc.CONTROL_EVENTTYPE_TOUCH_DOWN 10 | _G.CCControlEventTouchDragInside = cc.CONTROL_EVENTTYPE_DRAG_INSIDE 11 | _G.CCControlEventTouchDragOutside = cc.CONTROL_EVENTTYPE_DRAG_OUTSIDE 12 | _G.CCControlEventTouchDragEnter = cc.CONTROL_EVENTTYPE_DRAG_ENTER 13 | _G.CCControlEventTouchDragExit = cc.CONTROL_EVENTTYPE_DRAG_EXIT 14 | _G.CCControlEventTouchUpInside = cc.CONTROL_EVENTTYPE_TOUCH_UP_INSIDE 15 | _G.CCControlEventTouchUpOutside = cc.CONTROL_EVENTTYPE_TOUCH_UP_OUTSIDE 16 | _G.CCControlEventTouchCancel = cc.CONTROL_EVENTTYPE_TOUCH_CANCEL 17 | _G.CCControlEventValueChanged = cc.CONTROL_EVENTTYPE_VALUE_CHANGED 18 | _G.CCControlStateNormal = cc.CONTROL_STATE_NORMAL 19 | _G.CCControlStateHighlighted = cc.CONTROL_STATE_HIGH_LIGHTED 20 | _G.CCControlStateDisabled = cc.CONTROL_STATE_DISABLED 21 | _G.CCControlStateSelected = cc.CONTROL_STATE_SELECTED 22 | 23 | _G.kCCScrollViewDirectionHorizontal = cc.SCROLLVIEW_DIRECTION_HORIZONTAL 24 | _G.kCCScrollViewDirectionVertical = cc.SCROLLVIEW_DIRECTION_VERTICAL 25 | _G.kCCTableViewFillTopDown = cc.TABLEVIEW_FILL_TOPDOWN 26 | _G.kCCTableViewFillBottomUp = cc.TABLEVIEW_FILL_BOTTOMUP 27 | -------------------------------------------------------------------------------- /src/cocos/extension/DeprecatedExtensionFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of CCControl will be deprecated end 11 | local CCControlDeprecated = { } 12 | function CCControlDeprecated.addHandleOfControlEvent(self,func,controlEvent) 13 | deprecatedTip("addHandleOfControlEvent","registerControlEventHandler") 14 | print("come in addHandleOfControlEvent") 15 | self:registerControlEventHandler(func,controlEvent) 16 | end 17 | CCControl.addHandleOfControlEvent = CCControlDeprecated.addHandleOfControlEvent 18 | --functions of CCControl will be deprecated end 19 | 20 | --Enums of CCTableView will be deprecated begin 21 | CCTableView.kTableViewScroll = cc.SCROLLVIEW_SCRIPT_SCROLL 22 | CCTableView.kTableViewZoom = cc.SCROLLVIEW_SCRIPT_ZOOM 23 | CCTableView.kTableCellTouched = cc.TABLECELL_TOUCHED 24 | CCTableView.kTableCellSizeForIndex = cc.TABLECELL_SIZE_FOR_INDEX 25 | CCTableView.kTableCellSizeAtIndex = cc.TABLECELL_SIZE_AT_INDEX 26 | CCTableView.kNumberOfCellsInTableView = cc.NUMBER_OF_CELLS_IN_TABLEVIEW 27 | --Enums of CCTableView will be deprecated end 28 | 29 | --Enums of CCScrollView will be deprecated begin 30 | CCScrollView.kScrollViewScroll = cc.SCROLLVIEW_SCRIPT_SCROLL 31 | CCScrollView.kScrollViewZoom = cc.SCROLLVIEW_SCRIPT_ZOOM 32 | --Enums of CCScrollView will be deprecated end 33 | -------------------------------------------------------------------------------- /src/cocos/extension/ExtensionConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Control then 2 | return 3 | end 4 | 5 | cc.CONTROL_STATE_NORMAL = 1 6 | cc.CONTROL_STATE_HIGH_LIGHTED = 2 7 | cc.CONTROL_STATE_DISABLED = 4 8 | cc.CONTROL_STATE_SELECTED = 8 9 | 10 | cc.CONTROL_STEPPER_PART_MINUS = 0 11 | cc.CONTROL_STEPPER_PART_PLUS = 1 12 | cc.CONTROL_STEPPER_PART_NONE = 2 13 | 14 | cc.TABLEVIEW_FILL_TOPDOWN = 0 15 | cc.TABLEVIEW_FILL_BOTTOMUP = 1 16 | 17 | cc.SCROLLVIEW_SCRIPT_SCROLL = 0 18 | cc.SCROLLVIEW_SCRIPT_ZOOM = 1 19 | cc.TABLECELL_TOUCHED = 2 20 | cc.TABLECELL_HIGH_LIGHT = 3 21 | cc.TABLECELL_UNHIGH_LIGHT = 4 22 | cc.TABLECELL_WILL_RECYCLE = 5 23 | cc.TABLECELL_SIZE_FOR_INDEX = 6 24 | cc.TABLECELL_SIZE_AT_INDEX = 7 25 | cc.NUMBER_OF_CELLS_IN_TABLEVIEW = 8 26 | 27 | cc.SCROLLVIEW_DIRECTION_NONE = -1 28 | cc.SCROLLVIEW_DIRECTION_HORIZONTAL = 0 29 | cc.SCROLLVIEW_DIRECTION_VERTICAL = 1 30 | cc.SCROLLVIEW_DIRECTION_BOTH = 2 31 | 32 | cc.CONTROL_EVENTTYPE_TOUCH_DOWN = 1 33 | cc.CONTROL_EVENTTYPE_DRAG_INSIDE = 2 34 | cc.CONTROL_EVENTTYPE_DRAG_OUTSIDE = 4 35 | cc.CONTROL_EVENTTYPE_DRAG_ENTER = 8 36 | cc.CONTROL_EVENTTYPE_DRAG_EXIT = 16 37 | cc.CONTROL_EVENTTYPE_TOUCH_UP_INSIDE = 32 38 | cc.CONTROL_EVENTTYPE_TOUCH_UP_OUTSIDE = 64 39 | cc.CONTROL_EVENTTYPE_TOUCH_CANCEL = 128 40 | cc.CONTROL_EVENTTYPE_VALUE_CHANGED = 256 41 | 42 | cc.EDITBOX_INPUT_MODE_ANY = 0 43 | cc.EDITBOX_INPUT_MODE_EMAILADDR = 1 44 | cc.EDITBOX_INPUT_MODE_NUMERIC = 2 45 | cc.EDITBOX_INPUT_MODE_PHONENUMBER = 3 46 | cc.EDITBOX_INPUT_MODE_URL = 4 47 | cc.EDITBOX_INPUT_MODE_DECIMAL = 5 48 | cc.EDITBOX_INPUT_MODE_SINGLELINE = 6 49 | 50 | cc.EDITBOX_INPUT_FLAG_PASSWORD = 0 51 | cc.EDITBOX_INPUT_FLAG_SENSITIVE = 1 52 | cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_WORD = 2 53 | cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_SENTENCE = 3 54 | cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_ALL_CHARACTERS = 4 55 | 56 | cc.KEYBOARD_RETURNTYPE_DEFAULT = 0 57 | cc.KEYBOARD_RETURNTYPE_DONE = 1 58 | cc.KEYBOARD_RETURNTYPE_SEND = 2 59 | cc.KEYBOARD_RETURNTYPE_SEARCH = 3 60 | cc.KEYBOARD_RETURNTYPE_GO = 4 61 | 62 | cc.ASSETSMANAGER_CREATE_FILE = 0 63 | cc.ASSETSMANAGER_NETWORK = 1 64 | cc.ASSETSMANAGER_NO_NEW_VERSION = 2 65 | cc.ASSETSMANAGER_UNCOMPRESS = 3 66 | 67 | cc.ASSETSMANAGER_PROTOCOL_PROGRESS = 0 68 | cc.ASSETSMANAGER_PROTOCOL_SUCCESS = 1 69 | cc.ASSETSMANAGER_PROTOCOL_ERROR = 2 70 | 71 | -------------------------------------------------------------------------------- /src/cocos/framework/audio.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local audio = {} 26 | 27 | local engine = cc.SimpleAudioEngine:getInstance() 28 | 29 | function audio.getMusicVolume() 30 | local volume = engine:getMusicVolume() 31 | if DEBUG > 1 then 32 | printf("[audio] getMusicVolume() - volume: %0.2f", volume) 33 | end 34 | return volume 35 | end 36 | 37 | function audio.setMusicVolume(volume) 38 | volume = checknumber(volume) 39 | if DEBUG > 1 then 40 | printf("[audio] setMusicVolume() - volume: %0.2f", volume) 41 | end 42 | engine:setMusicVolume(volume) 43 | end 44 | 45 | function audio.preloadMusic(filename) 46 | assert(filename, "audio.preloadMusic() - invalid filename") 47 | if DEBUG > 1 then 48 | printf("[audio] preloadMusic() - filename: %s", tostring(filename)) 49 | end 50 | engine:preloadMusic(filename) 51 | end 52 | 53 | function audio.playMusic(filename, isLoop) 54 | assert(filename, "audio.playMusic() - invalid filename") 55 | if type(isLoop) ~= "boolean" then isLoop = true end 56 | 57 | audio.stopMusic() 58 | if DEBUG > 1 then 59 | printf("[audio] playMusic() - filename: %s, isLoop: %s", tostring(filename), tostring(isLoop)) 60 | end 61 | engine:playMusic(filename, isLoop) 62 | end 63 | 64 | function audio.stopMusic(isReleaseData) 65 | isReleaseData = checkbool(isReleaseData) 66 | if DEBUG > 1 then 67 | printf("[audio] stopMusic() - isReleaseData: %s", tostring(isReleaseData)) 68 | end 69 | engine:stopMusic(isReleaseData) 70 | end 71 | 72 | function audio.pauseMusic() 73 | if DEBUG > 1 then 74 | printf("[audio] pauseMusic()") 75 | end 76 | engine:pauseMusic() 77 | end 78 | 79 | function audio.resumeMusic() 80 | if DEBUG > 1 then 81 | printf("[audio] resumeMusic()") 82 | end 83 | engine:resumeMusic() 84 | end 85 | 86 | function audio.rewindMusic() 87 | if DEBUG > 1 then 88 | printf("[audio] rewindMusic()") 89 | end 90 | engine:rewindMusic() 91 | end 92 | 93 | function audio.isMusicPlaying() 94 | local ret = engine:isMusicPlaying() 95 | if DEBUG > 1 then 96 | printf("[audio] isMusicPlaying() - ret: %s", tostring(ret)) 97 | end 98 | return ret 99 | end 100 | 101 | function audio.getSoundsVolume() 102 | local volume = engine:getEffectsVolume() 103 | if DEBUG > 1 then 104 | printf("[audio] getSoundsVolume() - volume: %0.1f", volume) 105 | end 106 | return volume 107 | end 108 | 109 | function audio.setSoundsVolume(volume) 110 | volume = checknumber(volume) 111 | if DEBUG > 1 then 112 | printf("[audio] setSoundsVolume() - volume: %0.1f", volume) 113 | end 114 | engine:setEffectsVolume(volume) 115 | end 116 | 117 | function audio.playSound(filename, isLoop) 118 | if not filename then 119 | printError("audio.playSound() - invalid filename") 120 | return 121 | end 122 | if type(isLoop) ~= "boolean" then isLoop = false end 123 | if DEBUG > 1 then 124 | printf("[audio] playSound() - filename: %s, isLoop: %s", tostring(filename), tostring(isLoop)) 125 | end 126 | return engine:playEffect(filename, isLoop) 127 | end 128 | 129 | function audio.pauseSound(handle) 130 | if not handle then 131 | printError("audio.pauseSound() - invalid handle") 132 | return 133 | end 134 | if DEBUG > 1 then 135 | printf("[audio] pauseSound() - handle: %s", tostring(handle)) 136 | end 137 | engine:pauseEffect(handle) 138 | end 139 | 140 | function audio.pauseAllSounds() 141 | if DEBUG > 1 then 142 | printf("[audio] pauseAllSounds()") 143 | end 144 | engine:pauseAllEffects() 145 | end 146 | 147 | function audio.resumeSound(handle) 148 | if not handle then 149 | printError("audio.resumeSound() - invalid handle") 150 | return 151 | end 152 | if DEBUG > 1 then 153 | printf("[audio] resumeSound() - handle: %s", tostring(handle)) 154 | end 155 | engine:resumeEffect(handle) 156 | end 157 | 158 | function audio.resumeAllSounds() 159 | if DEBUG > 1 then 160 | printf("[audio] resumeAllSounds()") 161 | end 162 | engine:resumeAllEffects() 163 | end 164 | 165 | function audio.stopSound(handle) 166 | if not handle then 167 | printError("audio.stopSound() - invalid handle") 168 | return 169 | end 170 | if DEBUG > 1 then 171 | printf("[audio] stopSound() - handle: %s", tostring(handle)) 172 | end 173 | engine:stopEffect(handle) 174 | end 175 | 176 | function audio.stopAllSounds() 177 | if DEBUG > 1 then 178 | printf("[audio] stopAllSounds()") 179 | end 180 | engine:stopAllEffects() 181 | end 182 | audio.stopAllEffects = audio.stopAllSounds 183 | 184 | function audio.preloadSound(filename) 185 | if not filename then 186 | printError("audio.preloadSound() - invalid filename") 187 | return 188 | end 189 | if DEBUG > 1 then 190 | printf("[audio] preloadSound() - filename: %s", tostring(filename)) 191 | end 192 | engine:preloadEffect(filename) 193 | end 194 | 195 | function audio.unloadSound(filename) 196 | if not filename then 197 | printError("audio.unloadSound() - invalid filename") 198 | return 199 | end 200 | if DEBUG > 1 then 201 | printf("[audio] unloadSound() - filename: %s", tostring(filename)) 202 | end 203 | engine:unloadEffect(filename) 204 | end 205 | 206 | return audio 207 | -------------------------------------------------------------------------------- /src/cocos/framework/components/event.lua: -------------------------------------------------------------------------------- 1 | 2 | local Event = class("Event") 3 | 4 | local EXPORTED_METHODS = { 5 | "addEventListener", 6 | "dispatchEvent", 7 | "removeEventListener", 8 | "removeEventListenersByTag", 9 | "removeEventListenersByEvent", 10 | "removeAllEventListeners", 11 | "hasEventListener", 12 | "dumpAllEventListeners", 13 | } 14 | 15 | function Event:init_() 16 | self.target_ = nil 17 | self.listeners_ = {} 18 | self.nextListenerHandleIndex_ = 0 19 | end 20 | 21 | function Event:bind(target) 22 | self:init_() 23 | cc.setmethods(target, self, EXPORTED_METHODS) 24 | self.target_ = target 25 | end 26 | 27 | function Event:unbind(target) 28 | cc.unsetmethods(target, EXPORTED_METHODS) 29 | self:init_() 30 | end 31 | 32 | function Event:on(eventName, listener, tag) 33 | assert(type(eventName) == "string" and eventName ~= "", 34 | "Event:addEventListener() - invalid eventName") 35 | eventName = string.upper(eventName) 36 | if self.listeners_[eventName] == nil then 37 | self.listeners_[eventName] = {} 38 | end 39 | 40 | self.nextListenerHandleIndex_ = self.nextListenerHandleIndex_ + 1 41 | local handle = tostring(self.nextListenerHandleIndex_) 42 | tag = tag or "" 43 | self.listeners_[eventName][handle] = {listener, tag} 44 | 45 | if DEBUG > 1 then 46 | printInfo("%s [Event] addEventListener() - event: %s, handle: %s, tag: \"%s\"", 47 | tostring(self.target_), eventName, handle, tostring(tag)) 48 | end 49 | 50 | return self.target_, handle 51 | end 52 | 53 | Event.addEventListener = Event.on 54 | 55 | function Event:dispatchEvent(event) 56 | event.name = string.upper(tostring(event.name)) 57 | local eventName = event.name 58 | if DEBUG > 1 then 59 | printInfo("%s [Event] dispatchEvent() - event %s", tostring(self.target_), eventName) 60 | end 61 | 62 | if self.listeners_[eventName] == nil then return end 63 | event.target = self.target_ 64 | event.stop_ = false 65 | event.stop = function(self) 66 | self.stop_ = true 67 | end 68 | 69 | for handle, listener in pairs(self.listeners_[eventName]) do 70 | if DEBUG > 1 then 71 | printInfo("%s [Event] dispatchEvent() - dispatching event %s to listener %s", tostring(self.target_), eventName, handle) 72 | end 73 | -- listener[1] = listener 74 | -- listener[2] = tag 75 | event.tag = listener[2] 76 | listener[1](event) 77 | if event.stop_ then 78 | if DEBUG > 1 then 79 | printInfo("%s [Event] dispatchEvent() - break dispatching for event %s", tostring(self.target_), eventName) 80 | end 81 | break 82 | end 83 | end 84 | 85 | return self.target_ 86 | end 87 | 88 | function Event:removeEventListener(handleToRemove) 89 | for eventName, listenersForEvent in pairs(self.listeners_) do 90 | for handle, _ in pairs(listenersForEvent) do 91 | if handle == handleToRemove then 92 | listenersForEvent[handle] = nil 93 | if DEBUG > 1 then 94 | printInfo("%s [Event] removeEventListener() - remove listener [%s] for event %s", tostring(self.target_), handle, eventName) 95 | end 96 | return self.target_ 97 | end 98 | end 99 | end 100 | 101 | return self.target_ 102 | end 103 | 104 | function Event:removeEventListenersByTag(tagToRemove) 105 | for eventName, listenersForEvent in pairs(self.listeners_) do 106 | for handle, listener in pairs(listenersForEvent) do 107 | -- listener[1] = listener 108 | -- listener[2] = tag 109 | if listener[2] == tagToRemove then 110 | listenersForEvent[handle] = nil 111 | if DEBUG > 1 then 112 | printInfo("%s [Event] removeEventListener() - remove listener [%s] for event %s", tostring(self.target_), handle, eventName) 113 | end 114 | end 115 | end 116 | end 117 | 118 | return self.target_ 119 | end 120 | 121 | function Event:removeEventListenersByEvent(eventName) 122 | self.listeners_[string.upper(eventName)] = nil 123 | if DEBUG > 1 then 124 | printInfo("%s [Event] removeAllEventListenersForEvent() - remove all listeners for event %s", tostring(self.target_), eventName) 125 | end 126 | return self.target_ 127 | end 128 | 129 | function Event:removeAllEventListeners() 130 | self.listeners_ = {} 131 | if DEBUG > 1 then 132 | printInfo("%s [Event] removeAllEventListeners() - remove all listeners", tostring(self.target_)) 133 | end 134 | return self.target_ 135 | end 136 | 137 | function Event:hasEventListener(eventName) 138 | eventName = string.upper(tostring(eventName)) 139 | local t = self.listeners_[eventName] 140 | for _, __ in pairs(t) do 141 | return true 142 | end 143 | return false 144 | end 145 | 146 | function Event:dumpAllEventListeners() 147 | print("---- Event:dumpAllEventListeners() ----") 148 | for name, listeners in pairs(self.listeners_) do 149 | printf("-- event: %s", name) 150 | for handle, listener in pairs(listeners) do 151 | printf("-- listener: %s, handle: %s", tostring(listener[1]), tostring(handle)) 152 | end 153 | end 154 | return self.target_ 155 | end 156 | 157 | return Event 158 | -------------------------------------------------------------------------------- /src/cocos/framework/device.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local device = {} 26 | 27 | device.platform = "unknown" 28 | device.model = "unknown" 29 | 30 | local app = cc.Application:getInstance() 31 | local target = app:getTargetPlatform() 32 | if target == cc.PLATFORM_OS_WINDOWS then 33 | device.platform = "windows" 34 | elseif target == cc.PLATFORM_OS_MAC then 35 | device.platform = "mac" 36 | elseif target == cc.PLATFORM_OS_ANDROID then 37 | device.platform = "android" 38 | elseif target == cc.PLATFORM_OS_IPHONE or target == cc.PLATFORM_OS_IPAD then 39 | device.platform = "ios" 40 | local director = cc.Director:getInstance() 41 | local view = director:getOpenGLView() 42 | local framesize = view:getFrameSize() 43 | local w, h = framesize.width, framesize.height 44 | if w == 640 and h == 960 then 45 | device.model = "iphone 4" 46 | elseif w == 640 and h == 1136 then 47 | device.model = "iphone 5" 48 | elseif w == 750 and h == 1334 then 49 | device.model = "iphone 6" 50 | elseif w == 1242 and h == 2208 then 51 | device.model = "iphone 6 plus" 52 | elseif w == 768 and h == 1024 then 53 | device.model = "ipad" 54 | elseif w == 1536 and h == 2048 then 55 | device.model = "ipad retina" 56 | end 57 | elseif target == cc.PLATFORM_OS_WINRT then 58 | device.platform = "winrt" 59 | elseif target == cc.PLATFORM_OS_WP8 then 60 | device.platform = "wp8" 61 | end 62 | 63 | local language_ = app:getCurrentLanguage() 64 | if language_ == cc.LANGUAGE_CHINESE then 65 | language_ = "cn" 66 | elseif language_ == cc.LANGUAGE_FRENCH then 67 | language_ = "fr" 68 | elseif language_ == cc.LANGUAGE_ITALIAN then 69 | language_ = "it" 70 | elseif language_ == cc.LANGUAGE_GERMAN then 71 | language_ = "gr" 72 | elseif language_ == cc.LANGUAGE_SPANISH then 73 | language_ = "sp" 74 | elseif language_ == cc.LANGUAGE_RUSSIAN then 75 | language_ = "ru" 76 | elseif language_ == cc.LANGUAGE_KOREAN then 77 | language_ = "kr" 78 | elseif language_ == cc.LANGUAGE_JAPANESE then 79 | language_ = "jp" 80 | elseif language_ == cc.LANGUAGE_HUNGARIAN then 81 | language_ = "hu" 82 | elseif language_ == cc.LANGUAGE_PORTUGUESE then 83 | language_ = "pt" 84 | elseif language_ == cc.LANGUAGE_ARABIC then 85 | language_ = "ar" 86 | else 87 | language_ = "en" 88 | end 89 | 90 | device.language = language_ 91 | device.writablePath = cc.FileUtils:getInstance():getWritablePath() 92 | device.directorySeparator = "/" 93 | device.pathSeparator = ":" 94 | if device.platform == "windows" then 95 | device.directorySeparator = "\\" 96 | device.pathSeparator = ";" 97 | end 98 | 99 | printInfo("# device.platform = " .. device.platform) 100 | printInfo("# device.model = " .. device.model) 101 | printInfo("# device.language = " .. device.language) 102 | printInfo("# device.writablePath = " .. device.writablePath) 103 | printInfo("# device.directorySeparator = " .. device.directorySeparator) 104 | printInfo("# device.pathSeparator = " .. device.pathSeparator) 105 | printInfo("#") 106 | 107 | return device 108 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/LayerEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Layer = cc.Layer 26 | 27 | function Layer:onTouch(callback, isMultiTouches, swallowTouches) 28 | if type(isMultiTouches) ~= "boolean" then isMultiTouches = false end 29 | if type(swallowTouches) ~= "boolean" then swallowTouches = false end 30 | 31 | self:registerScriptTouchHandler(function(state, ...) 32 | local args = {...} 33 | local event = {name = state} 34 | if isMultiTouches then 35 | args = args[1] 36 | local points = {} 37 | for i = 1, #args, 3 do 38 | local x, y, id = args[i], args[i + 1], args[i + 2] 39 | points[id] = {x = x, y = y, id = id} 40 | end 41 | event.points = points 42 | else 43 | event.x = args[1] 44 | event.y = args[2] 45 | end 46 | return callback( event ) 47 | end, isMultiTouches, 0, swallowTouches) 48 | self:setTouchEnabled(true) 49 | return self 50 | end 51 | 52 | function Layer:removeTouch() 53 | self:unregisterScriptTouchHandler() 54 | self:setTouchEnabled(false) 55 | return self 56 | end 57 | 58 | function Layer:onKeypad(callback) 59 | self:registerScriptKeypadHandler(callback) 60 | self:setKeyboardEnabled(true) 61 | return self 62 | end 63 | 64 | function Layer:removeKeypad() 65 | self:unregisterScriptKeypadHandler() 66 | self:setKeyboardEnabled(false) 67 | return self 68 | end 69 | 70 | function Layer:onAccelerate(callback) 71 | self:registerScriptAccelerateHandler(callback) 72 | self:setAccelerometerEnabled(true) 73 | return self 74 | end 75 | 76 | function Layer:removeAccelerate() 77 | self:unregisterScriptAccelerateHandler() 78 | self:setAccelerometerEnabled(false) 79 | return self 80 | end 81 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/MenuEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Menu = cc.Menu 26 | local MenuItem = cc.MenuItem 27 | 28 | function MenuItem:onClicked(callback) 29 | self:registerScriptTapHandler(callback) 30 | return self 31 | end 32 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/NodeEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Node = cc.Node 26 | 27 | function Node:add(child, zorder, tag) 28 | if tag then 29 | self:addChild(child, zorder, tag) 30 | elseif zorder then 31 | self:addChild(child, zorder) 32 | else 33 | self:addChild(child) 34 | end 35 | return self 36 | end 37 | 38 | function Node:addTo(parent, zorder, tag) 39 | if tag then 40 | parent:addChild(self, zorder, tag) 41 | elseif zorder then 42 | parent:addChild(self, zorder) 43 | else 44 | parent:addChild(self) 45 | end 46 | return self 47 | end 48 | 49 | function Node:removeSelf() 50 | self:removeFromParent() 51 | return self 52 | end 53 | 54 | function Node:align(anchorPoint, x, y) 55 | self:setAnchorPoint(anchorPoint) 56 | return self:move(x, y) 57 | end 58 | 59 | function Node:show() 60 | self:setVisible(true) 61 | return self 62 | end 63 | 64 | function Node:hide() 65 | self:setVisible(false) 66 | return self 67 | end 68 | 69 | function Node:move(x, y) 70 | if y then 71 | self:setPosition(x, y) 72 | else 73 | self:setPosition(x) 74 | end 75 | return self 76 | end 77 | 78 | function Node:moveTo(args) 79 | transition.moveTo(self, args) 80 | return self 81 | end 82 | 83 | function Node:moveBy(args) 84 | transition.moveBy(self, args) 85 | return self 86 | end 87 | 88 | function Node:fadeIn(args) 89 | transition.fadeIn(self, args) 90 | return self 91 | end 92 | 93 | function Node:fadeOut(args) 94 | transition.fadeOut(self, args) 95 | return self 96 | end 97 | 98 | function Node:fadeTo(args) 99 | transition.fadeTo(self, args) 100 | return self 101 | end 102 | 103 | function Node:rotate(rotation) 104 | self:setRotation(rotation) 105 | return self 106 | end 107 | 108 | function Node:rotateTo(args) 109 | transition.rotateTo(self, args) 110 | return self 111 | end 112 | 113 | function Node:rotateBy(args) 114 | transition.rotateBy(self, args) 115 | return self 116 | end 117 | 118 | function Node:scaleTo(args) 119 | transition.scaleTo(self, args) 120 | return self 121 | end 122 | 123 | function Node:onUpdate(callback) 124 | self:scheduleUpdateWithPriorityLua(callback, 0) 125 | return self 126 | end 127 | 128 | Node.scheduleUpdate = Node.onUpdate 129 | 130 | function Node:onNodeEvent(eventName, callback) 131 | if "enter" == eventName then 132 | self.onEnterCallback_ = callback 133 | elseif "exit" == eventName then 134 | self.onExitCallback_ = callback 135 | elseif "enterTransitionFinish" == eventName then 136 | self.onEnterTransitionFinishCallback_ = callback 137 | elseif "exitTransitionStart" == eventName then 138 | self.onExitTransitionStartCallback_ = callback 139 | elseif "cleanup" == eventName then 140 | self.onCleanupCallback_ = callback 141 | end 142 | self:enableNodeEvents() 143 | end 144 | 145 | function Node:enableNodeEvents() 146 | if self.isNodeEventEnabled_ then 147 | return self 148 | end 149 | 150 | self:registerScriptHandler(function(state) 151 | if state == "enter" then 152 | self:onEnter_() 153 | elseif state == "exit" then 154 | self:onExit_() 155 | elseif state == "enterTransitionFinish" then 156 | self:onEnterTransitionFinish_() 157 | elseif state == "exitTransitionStart" then 158 | self:onExitTransitionStart_() 159 | elseif state == "cleanup" then 160 | self:onCleanup_() 161 | end 162 | end) 163 | self.isNodeEventEnabled_ = true 164 | 165 | return self 166 | end 167 | 168 | function Node:disableNodeEvents() 169 | self:unregisterScriptHandler() 170 | self.isNodeEventEnabled_ = false 171 | return self 172 | end 173 | 174 | 175 | function Node:onEnter() 176 | end 177 | 178 | function Node:onExit() 179 | end 180 | 181 | function Node:onEnterTransitionFinish() 182 | end 183 | 184 | function Node:onExitTransitionStart() 185 | end 186 | 187 | function Node:onCleanup() 188 | end 189 | 190 | function Node:onEnter_() 191 | self:onEnter() 192 | if not self.onEnterCallback_ then 193 | return 194 | end 195 | self:onEnterCallback_() 196 | end 197 | 198 | function Node:onExit_() 199 | self:onExit() 200 | if not self.onExitCallback_ then 201 | return 202 | end 203 | self:onExitCallback_() 204 | end 205 | 206 | function Node:onEnterTransitionFinish_() 207 | self:onEnterTransitionFinish() 208 | if not self.onEnterTransitionFinishCallback_ then 209 | return 210 | end 211 | self:onEnterTransitionFinishCallback_() 212 | end 213 | 214 | function Node:onExitTransitionStart_() 215 | self:onExitTransitionStart() 216 | if not self.onExitTransitionStartCallback_ then 217 | return 218 | end 219 | self:onExitTransitionStartCallback_() 220 | end 221 | 222 | function Node:onCleanup_() 223 | self:onCleanup() 224 | if not self.onCleanupCallback_ then 225 | return 226 | end 227 | self:onCleanupCallback_() 228 | end 229 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/SpriteEx.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Sprite = cc.Sprite 26 | 27 | function Sprite:playAnimationOnce(animation, args) 28 | local actions = {} 29 | 30 | local showDelay = args.showDelay 31 | if showDelay then 32 | self:setVisible(false) 33 | actions[#actions + 1] = cc.DelayTime:create(showDelay) 34 | actions[#actions + 1] = cc.Show:create() 35 | end 36 | 37 | local delay = args.delay or 0 38 | if delay > 0 then 39 | actions[#actions + 1] = cc.DelayTime:create(delay) 40 | end 41 | 42 | actions[#actions + 1] = cc.Animate:create(animation) 43 | 44 | if args.removeSelf then 45 | actions[#actions + 1] = cc.RemoveSelf:create() 46 | end 47 | 48 | if args.onComplete then 49 | actions[#actions + 1] = cc.CallFunc:create(args.onComplete) 50 | end 51 | 52 | local action 53 | if #actions > 1 then 54 | action = cc.Sequence:create(actions) 55 | else 56 | action = actions[1] 57 | end 58 | self:runAction(action) 59 | return action 60 | end 61 | 62 | function Sprite:playAnimationForever(animation) 63 | local animate = cc.Animate:create(animation) 64 | local action = cc.RepeatForever:create(animate) 65 | self:runAction(action) 66 | return action 67 | end 68 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UICheckBox.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local CheckBox = ccui.CheckBox 27 | 28 | function CheckBox:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "selected" 33 | else 34 | event.name = "unselected" 35 | end 36 | event.target = sender 37 | callback(event) 38 | end) 39 | return self 40 | end 41 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UIEditBox.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local EditBox = ccui.EditBox 27 | 28 | function EditBox:onEditHandler(callback) 29 | self:registerScriptEditBoxHandler(function(name, sender) 30 | local event = {} 31 | event.name = name 32 | event.target = sender 33 | callback(event) 34 | end) 35 | return self 36 | end 37 | 38 | function EditBox:removeEditHandler() 39 | self:unregisterScriptEditBoxHandler() 40 | return self 41 | end 42 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UIListView.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local ListView = ccui.ListView 27 | 28 | function ListView:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "ON_SELECTED_ITEM_START" 33 | else 34 | event.name = "ON_SELECTED_ITEM_END" 35 | end 36 | event.target = sender 37 | callback(event) 38 | end) 39 | return self 40 | end 41 | 42 | function ListView:onScroll(callback) 43 | self:addScrollViewEventListener(function(sender, eventType) 44 | local event = {} 45 | if eventType == 0 then 46 | event.name = "SCROLL_TO_TOP" 47 | elseif eventType == 1 then 48 | event.name = "SCROLL_TO_BOTTOM" 49 | elseif eventType == 2 then 50 | event.name = "SCROLL_TO_LEFT" 51 | elseif eventType == 3 then 52 | event.name = "SCROLL_TO_RIGHT" 53 | elseif eventType == 4 then 54 | event.name = "SCROLLING" 55 | elseif eventType == 5 then 56 | event.name = "BOUNCE_TOP" 57 | elseif eventType == 6 then 58 | event.name = "BOUNCE_BOTTOM" 59 | elseif eventType == 7 then 60 | event.name = "BOUNCE_LEFT" 61 | elseif eventType == 8 then 62 | event.name = "BOUNCE_RIGHT" 63 | elseif eventType == 9 then 64 | event.name = "CONTAINER_MOVED" 65 | elseif eventType == 10 then 66 | event.name = "AUTOSCROLL_ENDED" 67 | end 68 | event.target = sender 69 | callback(event) 70 | end) 71 | return self 72 | end 73 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UIPageView.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local PageView = ccui.PageView 27 | 28 | function PageView:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "TURNING" 33 | end 34 | event.target = sender 35 | callback(event) 36 | end) 37 | return self 38 | end 39 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UIScrollView.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local ScrollView = ccui.ScrollView 27 | 28 | function ScrollView:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "SCROLL_TO_TOP" 33 | elseif eventType == 1 then 34 | event.name = "SCROLL_TO_BOTTOM" 35 | elseif eventType == 2 then 36 | event.name = "SCROLL_TO_LEFT" 37 | elseif eventType == 3 then 38 | event.name = "SCROLL_TO_RIGHT" 39 | elseif eventType == 4 then 40 | event.name = "SCROLLING" 41 | elseif eventType == 5 then 42 | event.name = "BOUNCE_TOP" 43 | elseif eventType == 6 then 44 | event.name = "BOUNCE_BOTTOM" 45 | elseif eventType == 7 then 46 | event.name = "BOUNCE_LEFT" 47 | elseif eventType == 8 then 48 | event.name = "BOUNCE_RIGHT" 49 | elseif eventType == 9 then 50 | event.name = "CONTAINER_MOVED" 51 | elseif eventType == 10 then 52 | event.name = "AUTOSCROLL_ENDED" 53 | end 54 | event.target = sender 55 | callback(event) 56 | end) 57 | return self 58 | end 59 | 60 | ScrollView.onScroll = ScrollView.onEvent 61 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UISlider.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local Slider = ccui.Slider 27 | 28 | function Slider:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "ON_PERCENTAGE_CHANGED" 33 | end 34 | event.target = sender 35 | callback(event) 36 | end) 37 | return self 38 | end 39 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UITextField.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2014-2017 Chukong Technologies Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ]] 25 | 26 | local TextField = ccui.TextField 27 | 28 | function TextField:onEvent(callback) 29 | self:addEventListener(function(sender, eventType) 30 | local event = {} 31 | if eventType == 0 then 32 | event.name = "ATTACH_WITH_IME" 33 | elseif eventType == 1 then 34 | event.name = "DETACH_WITH_IME" 35 | elseif eventType == 2 then 36 | event.name = "INSERT_TEXT" 37 | elseif eventType == 3 then 38 | event.name = "DELETE_BACKWARD" 39 | end 40 | event.target = sender 41 | callback(event) 42 | end) 43 | return self 44 | end 45 | -------------------------------------------------------------------------------- /src/cocos/framework/extends/UIWidget.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local Widget = ccui.Widget 26 | 27 | function Widget:onTouch(callback) 28 | self:addTouchEventListener(function(sender, state) 29 | local event = {x = 0, y = 0} 30 | if state == 0 then 31 | event.name = "began" 32 | elseif state == 1 then 33 | event.name = "moved" 34 | elseif state == 2 then 35 | event.name = "ended" 36 | else 37 | event.name = "cancelled" 38 | end 39 | event.target = sender 40 | callback(event) 41 | end) 42 | return self 43 | end 44 | -------------------------------------------------------------------------------- /src/cocos/framework/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | if type(DEBUG) ~= "number" then DEBUG = 0 end 26 | 27 | -- load framework 28 | printInfo("") 29 | printInfo("# DEBUG = " .. DEBUG) 30 | printInfo("#") 31 | 32 | device = require("cocos.framework.device") 33 | display = require("cocos.framework.display") 34 | audio = require("cocos.framework.audio") 35 | transition = require("cocos.framework.transition") 36 | 37 | require("cocos.framework.extends.NodeEx") 38 | require("cocos.framework.extends.SpriteEx") 39 | require("cocos.framework.extends.LayerEx") 40 | require("cocos.framework.extends.MenuEx") 41 | 42 | if ccui then 43 | require("cocos.framework.extends.UIWidget") 44 | require("cocos.framework.extends.UICheckBox") 45 | require("cocos.framework.extends.UIEditBox") 46 | require("cocos.framework.extends.UIListView") 47 | require("cocos.framework.extends.UIPageView") 48 | require("cocos.framework.extends.UIScrollView") 49 | require("cocos.framework.extends.UISlider") 50 | require("cocos.framework.extends.UITextField") 51 | end 52 | 53 | require("cocos.framework.package_support") 54 | 55 | -- register the build-in packages 56 | cc.register("event", require("cocos.framework.components.event")) 57 | 58 | -- export global variable 59 | local __g = _G 60 | cc.exports = {} 61 | setmetatable(cc.exports, { 62 | __newindex = function(_, name, value) 63 | rawset(__g, name, value) 64 | end, 65 | 66 | __index = function(_, name) 67 | return rawget(__g, name) 68 | end 69 | }) 70 | 71 | -- disable create unexpected global variable 72 | function cc.disable_global() 73 | setmetatable(__g, { 74 | __newindex = function(_, name, value) 75 | error(string.format("USE \" cc.exports.%s = value \" INSTEAD OF SET GLOBAL VARIABLE", name), 0) 76 | end 77 | }) 78 | end 79 | 80 | if CC_DISABLE_GLOBAL then 81 | cc.disable_global() 82 | end 83 | -------------------------------------------------------------------------------- /src/cocos/framework/package_support.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | -- Cocos2d-Lua core functions 26 | cc.loaded_packages = {} 27 | local loaded_packages = cc.loaded_packages 28 | 29 | function cc.register(name, package) 30 | cc.loaded_packages[name] = package 31 | end 32 | 33 | function cc.load(...) 34 | local names = {...} 35 | assert(#names > 0, "cc.load() - invalid package names") 36 | 37 | local packages = {} 38 | for _, name in ipairs(names) do 39 | assert(type(name) == "string", string.format("cc.load() - invalid package name \"%s\"", tostring(name))) 40 | if not loaded_packages[name] then 41 | local packageName = string.format("packages.%s.init", name) 42 | local cls = require(packageName) 43 | assert(cls, string.format("cc.load() - package class \"%s\" load failed", packageName)) 44 | loaded_packages[name] = cls 45 | 46 | if DEBUG > 1 then 47 | printInfo("cc.load() - load module \"packages.%s.init\"", name) 48 | end 49 | end 50 | packages[#packages + 1] = loaded_packages[name] 51 | end 52 | return unpack(packages) 53 | end 54 | 55 | local load_ = cc.load 56 | local bind_ 57 | bind_ = function(target, ...) 58 | local t = type(target) 59 | assert(t == "table" or t == "userdata", string.format("cc.bind() - invalid target, expected is object, actual is %s", t)) 60 | local names = {...} 61 | assert(#names > 0, "cc.bind() - package names expected") 62 | 63 | load_(...) 64 | if not target.components_ then target.components_ = {} end 65 | for _, name in ipairs(names) do 66 | assert(type(name) == "string" and name ~= "", string.format("cc.bind() - invalid package name \"%s\"", name)) 67 | if not target.components_[name] then 68 | local cls = loaded_packages[name] 69 | for __, depend in ipairs(cls.depends or {}) do 70 | if not target.components_[depend] then 71 | bind_(target, depend) 72 | end 73 | end 74 | local component = cls:create() 75 | target.components_[name] = component 76 | component:bind(target) 77 | end 78 | end 79 | 80 | return target 81 | end 82 | cc.bind = bind_ 83 | 84 | function cc.unbind(target, ...) 85 | if not target.components_ then return end 86 | 87 | local names = {...} 88 | assert(#names > 0, "cc.unbind() - invalid package names") 89 | 90 | for _, name in ipairs(names) do 91 | assert(type(name) == "string" and name ~= "", string.format("cc.unbind() - invalid package name \"%s\"", name)) 92 | local component = target.components_[name] 93 | assert(component, string.format("cc.unbind() - component \"%s\" not found", tostring(name))) 94 | component:unbind(target) 95 | target.components_[name] = nil 96 | end 97 | return target 98 | end 99 | 100 | function cc.setmethods(target, component, methods) 101 | for _, name in ipairs(methods) do 102 | local method = component[name] 103 | target[name] = function(__, ...) 104 | return method(component, ...) 105 | end 106 | end 107 | end 108 | 109 | function cc.unsetmethods(target, methods) 110 | for _, name in ipairs(methods) do 111 | target[name] = nil 112 | end 113 | end 114 | -------------------------------------------------------------------------------- /src/cocos/framework/transition.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | local transition = {} 26 | 27 | local ACTION_EASING = {} 28 | ACTION_EASING["BACKIN"] = {cc.EaseBackIn, 1} 29 | ACTION_EASING["BACKINOUT"] = {cc.EaseBackInOut, 1} 30 | ACTION_EASING["BACKOUT"] = {cc.EaseBackOut, 1} 31 | ACTION_EASING["BOUNCE"] = {cc.EaseBounce, 1} 32 | ACTION_EASING["BOUNCEIN"] = {cc.EaseBounceIn, 1} 33 | ACTION_EASING["BOUNCEINOUT"] = {cc.EaseBounceInOut, 1} 34 | ACTION_EASING["BOUNCEOUT"] = {cc.EaseBounceOut, 1} 35 | ACTION_EASING["ELASTIC"] = {cc.EaseElastic, 2, 0.3} 36 | ACTION_EASING["ELASTICIN"] = {cc.EaseElasticIn, 2, 0.3} 37 | ACTION_EASING["ELASTICINOUT"] = {cc.EaseElasticInOut, 2, 0.3} 38 | ACTION_EASING["ELASTICOUT"] = {cc.EaseElasticOut, 2, 0.3} 39 | ACTION_EASING["EXPONENTIALIN"] = {cc.EaseExponentialIn, 1} 40 | ACTION_EASING["EXPONENTIALINOUT"] = {cc.EaseExponentialInOut, 1} 41 | ACTION_EASING["EXPONENTIALOUT"] = {cc.EaseExponentialOut, 1} 42 | ACTION_EASING["IN"] = {cc.EaseIn, 2, 1} 43 | ACTION_EASING["INOUT"] = {cc.EaseInOut, 2, 1} 44 | ACTION_EASING["OUT"] = {cc.EaseOut, 2, 1} 45 | ACTION_EASING["RATEACTION"] = {cc.EaseRateAction, 2, 1} 46 | ACTION_EASING["SINEIN"] = {cc.EaseSineIn, 1} 47 | ACTION_EASING["SINEINOUT"] = {cc.EaseSineInOut, 1} 48 | ACTION_EASING["SINEOUT"] = {cc.EaseSineOut, 1} 49 | 50 | local actionManager = cc.Director:getInstance():getActionManager() 51 | 52 | function transition.newEasing(action, easingName, more) 53 | local key = string.upper(tostring(easingName)) 54 | local easing 55 | if ACTION_EASING[key] then 56 | local cls, count, default = unpack(ACTION_EASING[key]) 57 | if count == 2 then 58 | easing = cls:create(action, more or default) 59 | else 60 | easing = cls:create(action) 61 | end 62 | end 63 | return easing or action 64 | end 65 | 66 | function transition.create(action, args) 67 | args = checktable(args) 68 | if args.easing then 69 | if type(args.easing) == "table" then 70 | action = transition.newEasing(action, unpack(args.easing)) 71 | else 72 | action = transition.newEasing(action, args.easing) 73 | end 74 | end 75 | 76 | local actions = {} 77 | local delay = checknumber(args.delay) 78 | if delay > 0 then 79 | actions[#actions + 1] = cc.DelayTime:create(delay) 80 | end 81 | actions[#actions + 1] = action 82 | 83 | local onComplete = args.onComplete 84 | if type(onComplete) ~= "function" then onComplete = nil end 85 | if onComplete then 86 | actions[#actions + 1] = cc.CallFunc:create(onComplete) 87 | end 88 | 89 | if args.removeSelf then 90 | actions[#actions + 1] = cc.RemoveSelf:create() 91 | end 92 | 93 | if #actions > 1 then 94 | return transition.sequence(actions) 95 | else 96 | return actions[1] 97 | end 98 | end 99 | 100 | function transition.execute(target, action, args) 101 | assert(not tolua.isnull(target), "transition.execute() - target is not cc.Node") 102 | local action = transition.create(action, args) 103 | target:runAction(action) 104 | return action 105 | end 106 | 107 | function transition.moveTo(target, args) 108 | assert(not tolua.isnull(target), "transition.moveTo() - target is not cc.Node") 109 | local x = args.x or target:getPositionX() 110 | local y = args.y or target:getPositionY() 111 | local action = cc.MoveTo:create(args.time, cc.p(x, y)) 112 | return transition.execute(target, action, args) 113 | end 114 | 115 | function transition.moveBy(target, args) 116 | assert(not tolua.isnull(target), "transition.moveBy() - target is not cc.Node") 117 | local x = args.x or 0 118 | local y = args.y or 0 119 | local action = cc.MoveBy:create(args.time, cc.p(x, y)) 120 | return transition.execute(target, action, args) 121 | end 122 | 123 | function transition.fadeIn(target, args) 124 | assert(not tolua.isnull(target), "transition.fadeIn() - target is not cc.Node") 125 | local action = cc.FadeIn:create(args.time) 126 | return transition.execute(target, action, args) 127 | end 128 | 129 | function transition.fadeOut(target, args) 130 | assert(not tolua.isnull(target), "transition.fadeOut() - target is not cc.Node") 131 | local action = cc.FadeOut:create(args.time) 132 | return transition.execute(target, action, args) 133 | end 134 | 135 | function transition.fadeTo(target, args) 136 | assert(not tolua.isnull(target), "transition.fadeTo() - target is not cc.Node") 137 | local opacity = checkint(args.opacity) 138 | if opacity < 0 then 139 | opacity = 0 140 | elseif opacity > 255 then 141 | opacity = 255 142 | end 143 | local action = cc.FadeTo:create(args.time, opacity) 144 | return transition.execute(target, action, args) 145 | end 146 | 147 | function transition.scaleTo(target, args) 148 | assert(not tolua.isnull(target), "transition.scaleTo() - target is not cc.Node") 149 | local action 150 | if args.scale then 151 | action = cc.ScaleTo:create(checknumber(args.time), checknumber(args.scale)) 152 | elseif args.scaleX or args.scaleY then 153 | local scaleX, scaleY 154 | if args.scaleX then 155 | scaleX = checknumber(args.scaleX) 156 | else 157 | scaleX = target:getScaleX() 158 | end 159 | if args.scaleY then 160 | scaleY = checknumber(args.scaleY) 161 | else 162 | scaleY = target:getScaleY() 163 | end 164 | action = cc.ScaleTo:create(checknumber(args.time), scaleX, scaleY) 165 | end 166 | return transition.execute(target, action, args) 167 | end 168 | 169 | function transition.rotateTo(target, args) 170 | assert(not tolua.isnull(target), "transition.rotateTo() - target is not cc.Node") 171 | local rotation = args.rotation or target:getRotation() 172 | local action = cc.RotateTo:create(args.time, rotation) 173 | return transition.execute(target, action, args) 174 | end 175 | 176 | function transition.rotateBy(target, args) 177 | assert(not tolua.isnull(target), "transition.rotateTo() - target is not cc.Node") 178 | local rotation = args.rotation or 0 179 | local action = cc.RotateBy:create(args.time, rotation) 180 | return transition.execute(target, action, args) 181 | end 182 | 183 | function transition.sequence(actions) 184 | if #actions < 1 then return end 185 | if #actions < 2 then return actions[1] end 186 | return cc.Sequence:create(actions) 187 | end 188 | 189 | function transition.removeAction(action) 190 | if not tolua.isnull(action) then 191 | actionManager:removeAction(action) 192 | end 193 | end 194 | 195 | function transition.stopTarget(target) 196 | if not tolua.isnull(target) then 197 | actionManager:removeAllActionsFromTarget(target) 198 | end 199 | end 200 | 201 | function transition.pauseTarget(target) 202 | if not tolua.isnull(target) then 203 | actionManager:pauseTarget(target) 204 | end 205 | end 206 | 207 | function transition.resumeTarget(target) 208 | if not tolua.isnull(target) then 209 | actionManager:resumeTarget(target) 210 | end 211 | end 212 | 213 | return transition 214 | -------------------------------------------------------------------------------- /src/cocos/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2014-2017 Chukong Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | ]] 24 | 25 | require "cocos.cocos2d.Cocos2d" 26 | require "cocos.cocos2d.Cocos2dConstants" 27 | require "cocos.cocos2d.functions" 28 | 29 | __G__TRACKBACK__ = function(msg) 30 | local msg = debug.traceback(msg, 3) 31 | print(msg) 32 | return msg 33 | end 34 | 35 | -- opengl 36 | require "cocos.cocos2d.Opengl" 37 | require "cocos.cocos2d.OpenglConstants" 38 | -- audio 39 | require "cocos.cocosdenshion.AudioEngine" 40 | -- cocosstudio 41 | if nil ~= ccs then 42 | require "cocos.cocostudio.CocoStudio" 43 | end 44 | -- ui 45 | if nil ~= ccui then 46 | require "cocos.ui.GuiConstants" 47 | require "cocos.ui.experimentalUIConstants" 48 | end 49 | 50 | -- extensions 51 | require "cocos.extension.ExtensionConstants" 52 | -- network 53 | require "cocos.network.NetworkConstants" 54 | -- Spine 55 | if nil ~= sp then 56 | require "cocos.spine.SpineConstants" 57 | end 58 | 59 | require "cocos.cocos2d.deprecated" 60 | require "cocos.cocos2d.DrawPrimitives" 61 | 62 | -- Lua extensions 63 | require "cocos.cocos2d.bitExtend" 64 | 65 | -- CCLuaEngine 66 | require "cocos.cocos2d.DeprecatedCocos2dClass" 67 | require "cocos.cocos2d.DeprecatedCocos2dEnum" 68 | require "cocos.cocos2d.DeprecatedCocos2dFunc" 69 | require "cocos.cocos2d.DeprecatedOpenglEnum" 70 | 71 | -- register_cocostudio_module 72 | if nil ~= ccs then 73 | require "cocos.cocostudio.DeprecatedCocoStudioClass" 74 | require "cocos.cocostudio.DeprecatedCocoStudioFunc" 75 | end 76 | 77 | 78 | -- register_cocosbuilder_module 79 | require "cocos.cocosbuilder.DeprecatedCocosBuilderClass" 80 | 81 | -- register_cocosdenshion_module 82 | require "cocos.cocosdenshion.DeprecatedCocosDenshionClass" 83 | require "cocos.cocosdenshion.DeprecatedCocosDenshionFunc" 84 | 85 | -- register_extension_module 86 | require "cocos.extension.DeprecatedExtensionClass" 87 | require "cocos.extension.DeprecatedExtensionEnum" 88 | require "cocos.extension.DeprecatedExtensionFunc" 89 | 90 | -- register_network_module 91 | require "cocos.network.DeprecatedNetworkClass" 92 | require "cocos.network.DeprecatedNetworkEnum" 93 | require "cocos.network.DeprecatedNetworkFunc" 94 | 95 | -- register_ui_module 96 | if nil ~= ccui then 97 | require "cocos.ui.DeprecatedUIEnum" 98 | require "cocos.ui.DeprecatedUIFunc" 99 | end 100 | 101 | -- cocosbuilder 102 | require "cocos.cocosbuilder.CCBReaderLoad" 103 | 104 | -- physics3d 105 | require "cocos.physics3d.physics3d-constants" 106 | 107 | if CC_USE_FRAMEWORK then 108 | require "cocos.framework.init" 109 | end 110 | -------------------------------------------------------------------------------- /src/cocos/network/DeprecatedNetworkClass.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | -- This is the DeprecatedNetworkClass 5 | 6 | DeprecatedNetworkClass = {} or DeprecatedNetworkClass 7 | 8 | --tip 9 | local function deprecatedTip(old_name,new_name) 10 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 11 | end 12 | 13 | --WebSocket class will be Deprecated,begin 14 | function DeprecatedNetworkClass.WebSocket() 15 | deprecatedTip("WebSocket","cc.WebSocket") 16 | return cc.WebSocket 17 | end 18 | _G["WebSocket"] = DeprecatedNetworkClass.WebSocket() 19 | --WebSocket class will be Deprecated,end 20 | -------------------------------------------------------------------------------- /src/cocos/network/DeprecatedNetworkEnum.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | 5 | _G.kWebSocketScriptHandlerOpen = cc.WEBSOCKET_OPEN 6 | _G.kWebSocketScriptHandlerMessage = cc.WEBSOCKET_MESSAGE 7 | _G.kWebSocketScriptHandlerClose = cc.WEBSOCKET_CLOSE 8 | _G.kWebSocketScriptHandlerError = cc.WEBSOCKET_ERROR 9 | 10 | _G.kStateConnecting = cc.WEBSOCKET_STATE_CONNECTING 11 | _G.kStateOpen = cc.WEBSOCKET_STATE_OPEN 12 | _G.kStateClosing = cc.WEBSOCKET_STATE_CLOSING 13 | _G.kStateClosed = cc.WEBSOCKET_STATE_CLOSED 14 | -------------------------------------------------------------------------------- /src/cocos/network/DeprecatedNetworkFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of WebSocket will be deprecated begin 11 | local targetPlatform = CCApplication:getInstance():getTargetPlatform() 12 | if (kTargetIphone == targetPlatform) or (kTargetIpad == targetPlatform) or (kTargetAndroid == targetPlatform) or (kTargetWindows == targetPlatform) then 13 | local WebSocketDeprecated = { } 14 | function WebSocketDeprecated.sendTextMsg(self, string) 15 | deprecatedTip("WebSocket:sendTextMsg","WebSocket:sendString") 16 | return self:sendString(string) 17 | end 18 | WebSocket.sendTextMsg = WebSocketDeprecated.sendTextMsg 19 | 20 | function WebSocketDeprecated.sendBinaryMsg(self, table,tablesize) 21 | deprecatedTip("WebSocket:sendBinaryMsg","WebSocket:sendString") 22 | string.char(unpack(table)) 23 | return self:sendString(string.char(unpack(table))) 24 | end 25 | WebSocket.sendBinaryMsg = WebSocketDeprecated.sendBinaryMsg 26 | end 27 | --functions of WebSocket will be deprecated end 28 | -------------------------------------------------------------------------------- /src/cocos/network/NetworkConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.XMLHttpRequest then 2 | return 3 | end 4 | 5 | cc.WEBSOCKET_OPEN = 0 6 | cc.WEBSOCKET_MESSAGE = 1 7 | cc.WEBSOCKET_CLOSE = 2 8 | cc.WEBSOCKET_ERROR = 3 9 | 10 | cc.WEBSOCKET_STATE_CONNECTING = 0 11 | cc.WEBSOCKET_STATE_OPEN = 1 12 | cc.WEBSOCKET_STATE_CLOSING = 2 13 | cc.WEBSOCKET_STATE_CLOSED = 3 14 | 15 | cc.XMLHTTPREQUEST_RESPONSE_STRING = 0 16 | cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER = 1 17 | cc.XMLHTTPREQUEST_RESPONSE_BLOB = 2 18 | cc.XMLHTTPREQUEST_RESPONSE_DOCUMENT = 3 19 | cc.XMLHTTPREQUEST_RESPONSE_JSON = 4 20 | -------------------------------------------------------------------------------- /src/cocos/physics3d/physics3d-constants.lua: -------------------------------------------------------------------------------- 1 | if nil == cc.Physics3DComponent then 2 | return 3 | end 4 | 5 | cc.Physics3DComponent.PhysicsSyncFlag = 6 | { 7 | NONE = 0, 8 | NODE_TO_PHYSICS = 1, 9 | PHYSICS_TO_NODE = 2, 10 | NODE_AND_NODE = 3, 11 | } 12 | 13 | cc.Physics3DObject.PhysicsObjType = 14 | { 15 | UNKNOWN = 0, 16 | RIGID_BODY = 1, 17 | } -------------------------------------------------------------------------------- /src/cocos/spine/SpineConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == sp then 2 | return 3 | end 4 | 5 | sp.EventType = 6 | { 7 | ANIMATION_START = 0, 8 | ANIMATION_INTERRUPT = 1, 9 | ANIMATION_END = 2, 10 | ANIMATION_COMPLETE = 3, 11 | ANIMATION_DISPOSE = 4, 12 | ANIMATION_EVENT = 5, 13 | } 14 | -------------------------------------------------------------------------------- /src/cocos/ui/DeprecatedUIEnum.lua: -------------------------------------------------------------------------------- 1 | if nil == ccui then 2 | return 3 | end 4 | 5 | LAYOUT_COLOR_NONE = ccui.LayoutBackGroundColorType.none 6 | LAYOUT_COLOR_SOLID = ccui.LayoutBackGroundColorType.solid 7 | LAYOUT_COLOR_GRADIENT = ccui.LayoutBackGroundColorType.gradient 8 | 9 | LAYOUT_ABSOLUTE = ccui.LayoutType.ABSOLUTE 10 | LAYOUT_LINEAR_VERTICAL = ccui.LayoutType.VERTICAL 11 | LAYOUT_LINEAR_HORIZONTAL = ccui.LayoutType.HORIZONTAL 12 | LAYOUT_RELATIVE = ccui.LayoutType.RELATIVE 13 | 14 | BRIGHT_NONE = ccui.BrightStyle.none 15 | BRIGHT_NORMAL = ccui.BrightStyle.normal 16 | BRIGHT_HIGHLIGHT = ccui.BrightStyle.highlight 17 | 18 | UI_TEX_TYPE_LOCAL = ccui.TextureResType.localType 19 | UI_TEX_TYPE_PLIST = ccui.TextureResType.plistType 20 | 21 | TOUCH_EVENT_BEGAN = ccui.TouchEventType.began 22 | TOUCH_EVENT_MOVED = ccui.TouchEventType.moved 23 | TOUCH_EVENT_ENDED = ccui.TouchEventType.ended 24 | TOUCH_EVENT_CANCELED = ccui.TouchEventType.canceled 25 | 26 | SIZE_ABSOLUTE = ccui.SizeType.absolute 27 | SIZE_PERCENT = ccui.SizeType.percent 28 | 29 | POSITION_ABSOLUTE = ccui.PositionType.absolute 30 | POSITION_PERCENT = ccui.PositionType.percent 31 | 32 | CHECKBOX_STATE_EVENT_SELECTED = ccui.CheckBoxEventType.selected 33 | CHECKBOX_STATE_EVENT_UNSELECTED = ccui.CheckBoxEventType.unselected 34 | 35 | CHECKBOX_STATE_EVENT_SELECTED = ccui.CheckBoxEventType.selected 36 | CHECKBOX_STATE_EVENT_UNSELECTED = ccui.CheckBoxEventType.unselected 37 | 38 | LoadingBarTypeLeft = ccui.LoadingBarDirection.LEFT 39 | LoadingBarTypeRight = ccui.LoadingBarDirection.RIGHT 40 | 41 | LoadingBarTypeRight = ccui.SliderEventType.percent_changed 42 | 43 | TEXTFIELD_EVENT_ATTACH_WITH_IME = ccui.TextFiledEventType.attach_with_ime 44 | TEXTFIELD_EVENT_DETACH_WITH_IME = ccui.TextFiledEventType.detach_with_ime 45 | TEXTFIELD_EVENT_INSERT_TEXT = ccui.TextFiledEventType.insert_text 46 | TEXTFIELD_EVENT_DELETE_BACKWARD = ccui.TextFiledEventType.delete_backward 47 | 48 | SCROLLVIEW_EVENT_SCROLL_TO_TOP = ccui.ScrollViewDir.none 49 | SCROLLVIEW_DIR_VERTICAL = ccui.ScrollViewDir.vertical 50 | SCROLLVIEW_DIR_HORIZONTAL = ccui.ScrollViewDir.horizontal 51 | SCROLLVIEW_DIR_BOTH = ccui.ScrollViewDir.both 52 | 53 | SCROLLVIEW_EVENT_SCROLL_TO_TOP = ccui.ScrollviewEventType.scrollToTop 54 | SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM = ccui.ScrollviewEventType.scrollToBottom 55 | SCROLLVIEW_EVENT_SCROLL_TO_LEFT = ccui.ScrollviewEventType.scrollToLeft 56 | SCROLLVIEW_EVENT_SCROLL_TO_RIGHT = ccui.ScrollviewEventType.scrollToRight 57 | SCROLLVIEW_EVENT_SCROLLING = ccui.ScrollviewEventType.scrolling 58 | SCROLLVIEW_EVENT_BOUNCE_TOP = ccui.ScrollviewEventType.bounceTop 59 | SCROLLVIEW_EVENT_BOUNCE_BOTTOM = ccui.ScrollviewEventType.bounceBottom 60 | SCROLLVIEW_EVENT_BOUNCE_LEFT = ccui.ScrollviewEventType.bounceLeft 61 | SCROLLVIEW_EVENT_BOUNCE_RIGHT = ccui.ScrollviewEventType.bounceRight 62 | SCROLLVIEW_EVENT_CONTAINER_MOVED = ccui.ScrollviewEventType.containerMoved 63 | SCROLLVIEW_EVENT_AUTOSCROLL_ENDED = ccui.ScrollviewEventType.autoscrollEnded 64 | 65 | PAGEVIEW_EVENT_TURNING = ccui.PageViewEventType.turning 66 | 67 | PAGEVIEW_TOUCHLEFT = ccui.PVTouchDir.touch_left 68 | PAGEVIEW_TOUCHRIGHT = ccui.PVTouchDir.touch_right 69 | 70 | LISTVIEW_DIR_NONE = ccui.ListViewDirection.none 71 | LISTVIEW_DIR_VERTICAL = ccui.ListViewDirection.vertical 72 | LISTVIEW_DIR_HORIZONTAL = ccui.ListViewDirection.horizontal 73 | 74 | LISTVIEW_MOVE_DIR_NONE = ccui.ListViewMoveDirection.none 75 | LISTVIEW_MOVE_DIR_UP = ccui.ListViewMoveDirection.up 76 | LISTVIEW_MOVE_DIR_DOWN = ccui.ListViewMoveDirection.down 77 | LISTVIEW_MOVE_DIR_LEFT = ccui.ListViewMoveDirection.left 78 | LISTVIEW_MOVE_DIR_RIGHT = ccui.ListViewMoveDirection.right 79 | 80 | LISTVIEW_EVENT_INIT_CHILD = ccui.ListViewEventType.init_child 81 | LISTVIEW_EVENT_UPDATE_CHILD = ccui.ListViewEventType.update_child 82 | 83 | LAYOUT_PARAMETER_NONE = ccui.LayoutParameterType.none 84 | LAYOUT_PARAMETER_LINEAR = ccui.LayoutParameterType.linear 85 | LAYOUT_PARAMETER_RELATIVE = ccui.LayoutParameterType.relative 86 | 87 | ccui.LoadingBarType = ccui.LoadingBarDirection 88 | ccui.LoadingBarType.left = ccui.LoadingBarDirection.LEFT 89 | ccui.LoadingBarType.right = ccui.LoadingBarDirection.RIGHT 90 | 91 | ccui.LayoutType.absolute = ccui.LayoutType.ABSOLUTE 92 | ccui.LayoutType.linearVertical = ccui.LayoutType.VERTICAL 93 | ccui.LayoutType.linearHorizontal = ccui.LayoutType.HORIZONTAL 94 | ccui.LayoutType.relative = ccui.LayoutType.RELATIVE 95 | 96 | ccui.ListViewEventType.onsSelectedItem = ccui.ListViewEventType.ONSELECTEDITEM_START 97 | -------------------------------------------------------------------------------- /src/cocos/ui/DeprecatedUIFunc.lua: -------------------------------------------------------------------------------- 1 | if nil == ccui then 2 | return 3 | end 4 | 5 | --tip 6 | local function deprecatedTip(old_name,new_name) 7 | print("\n********** \n"..old_name.." was deprecated please use ".. new_name .. " instead.\n**********") 8 | end 9 | 10 | --functions of ccui.Text will be deprecated begin 11 | local TextDeprecated = { } 12 | function TextDeprecated.setText(self, str) 13 | deprecatedTip("ccui.Text:setText","ccui.Text:setString") 14 | return self:setString(str) 15 | end 16 | ccui.Text.setText = TextDeprecated.setText 17 | 18 | function TextDeprecated.getStringValue(self) 19 | deprecatedTip("ccui.Text:getStringValue","ccui.Text:getString") 20 | return self:getString() 21 | end 22 | ccui.Text.getStringValue = TextDeprecated.getStringValue 23 | 24 | --functions of ccui.Text will be deprecated begin 25 | 26 | --functions of ccui.TextAtlas will be deprecated begin 27 | local TextAtlasDeprecated = { } 28 | function TextAtlasDeprecated.setStringValue(self, str) 29 | deprecatedTip("ccui.TextAtlas:setStringValue","ccui.TextAtlas:setString") 30 | return self:setString(str) 31 | end 32 | ccui.TextAtlas.setStringValue = TextAtlasDeprecated.setStringValue 33 | 34 | function TextAtlasDeprecated.getStringValue(self) 35 | deprecatedTip("ccui.TextAtlas:getStringValue","ccui.TextAtlas:getString") 36 | return self:getString() 37 | end 38 | ccui.TextAtlas.getStringValue = TextAtlasDeprecated.getStringValue 39 | --functions of ccui.TextAtlas will be deprecated begin 40 | 41 | 42 | --functions of ccui.TextBMFont will be deprecated begin 43 | local TextBMFontDeprecated = { } 44 | function TextBMFontDeprecated.setText(self, str) 45 | deprecatedTip("ccui.TextBMFont:setText","ccui.TextBMFont:setString") 46 | return self:setString(str) 47 | end 48 | ccui.TextBMFont.setText = TextBMFontDeprecated.setText 49 | 50 | function TextBMFontDeprecated.getStringValue(self) 51 | deprecatedTip("ccui.Text:getStringValue","ccui.TextBMFont:getString") 52 | return self:getString() 53 | end 54 | ccui.Text.getStringValue = TextBMFontDeprecated.getStringValue 55 | --functions of ccui.TextBMFont will be deprecated begin 56 | 57 | --functions of cc.ShaderCache will be deprecated begin 58 | local ShaderCacheDeprecated = { } 59 | function ShaderCacheDeprecated.getProgram(self,strShader) 60 | deprecatedTip("cc.ShaderCache:getProgram","cc.ShaderCache:getGLProgram") 61 | return self:getGLProgram(strShader) 62 | end 63 | cc.ShaderCache.getProgram = ShaderCacheDeprecated.getProgram 64 | --functions of ccui.TextBMFont will be deprecated begin 65 | 66 | --functions of ccui.Widget will be deprecated begin 67 | local UIWidgetDeprecated = { } 68 | function UIWidgetDeprecated.getLeftInParent(self) 69 | deprecatedTip("ccui.Widget:getLeftInParent","ccui.Widget:getLeftBoundary") 70 | return self:getLeftBoundary() 71 | end 72 | ccui.Widget.getLeftInParent = UIWidgetDeprecated.getLeftInParent 73 | 74 | function UIWidgetDeprecated.getBottomInParent(self) 75 | deprecatedTip("ccui.Widget:getBottomInParent","ccui.Widget:getBottomBoundary") 76 | return self:getBottomBoundary() 77 | end 78 | ccui.Widget.getBottomInParent = UIWidgetDeprecated.getBottomInParent 79 | 80 | function UIWidgetDeprecated.getRightInParent(self) 81 | deprecatedTip("ccui.Widget:getRightInParent","ccui.Widget:getRightBoundary") 82 | return self:getRightBoundary() 83 | end 84 | ccui.Widget.getRightInParent = UIWidgetDeprecated.getRightInParent 85 | 86 | function UIWidgetDeprecated.getTopInParent(self) 87 | deprecatedTip("ccui.Widget:getTopInParent","ccui.Widget:getTopBoundary") 88 | return self:getTopBoundary() 89 | end 90 | ccui.Widget.getTopInParent = UIWidgetDeprecated.getTopInParent 91 | 92 | function UIWidgetDeprecated.getSize(self) 93 | deprecatedTip("ccui.Widget:getSize","ccui.Widget:getContentSize") 94 | return self:getContentSize() 95 | end 96 | ccui.Widget.getSize = UIWidgetDeprecated.getSize 97 | 98 | function UIWidgetDeprecated.setSize(self, ...) 99 | deprecatedTip("ccui.Widget:setSize","ccui.Widget:setContentSize") 100 | return self:setContentSize(...) 101 | end 102 | ccui.Widget.setSize = UIWidgetDeprecated.setSize 103 | 104 | --functions of ccui.Widget will be deprecated end 105 | 106 | --functions of ccui.CheckBox will be deprecated begin 107 | local UICheckBoxDeprecated = { } 108 | function UICheckBoxDeprecated.addEventListenerCheckBox(self,handler) 109 | deprecatedTip("ccui.CheckBox:addEventListenerCheckBox","ccui.CheckBox:addEventListener") 110 | return self:addEventListener(handler) 111 | end 112 | ccui.CheckBox.addEventListenerCheckBox = UICheckBoxDeprecated.addEventListenerCheckBox 113 | 114 | function UICheckBoxDeprecated.setSelectedState(self,flag) 115 | deprecatedTip("ccui.CheckBox:setSelectedState", "ccui.CheckBox:setSelected") 116 | return self:setSelected(flag) 117 | end 118 | ccui.CheckBox.setSelectedState = UICheckBoxDeprecated.setSelectedState 119 | 120 | function UICheckBoxDeprecated.getSelectedState(self) 121 | deprecatedTip("ccui.CheckBox:getSelectedState", "ccui.CheckBox:getSelected") 122 | return self:getSelected() 123 | end 124 | ccui.CheckBox.getSelectedState = UICheckBoxDeprecated.setSelectedState 125 | 126 | --functions of ccui.CheckBox will be deprecated end 127 | 128 | --functions of ccui.Slider will be deprecated begin 129 | local UISliderDeprecated = { } 130 | function UISliderDeprecated.addEventListenerSlider(self,handler) 131 | deprecatedTip("ccui.Slider:addEventListenerSlider","ccui.Slider:addEventListener") 132 | return self:addEventListener(handler) 133 | end 134 | ccui.Slider.addEventListenerSlider = UISliderDeprecated.addEventListenerSlider 135 | --functions of ccui.Slider will be deprecated end 136 | 137 | --functions of ccui.TextField will be deprecated begin 138 | local UITextFieldDeprecated = { } 139 | function UITextFieldDeprecated.addEventListenerTextField(self,handler) 140 | deprecatedTip("ccui.TextField:addEventListenerTextField","ccui.TextField:addEventListener") 141 | return self:addEventListener(handler) 142 | end 143 | ccui.TextField.addEventListenerTextField = UITextFieldDeprecated.addEventListenerTextField 144 | 145 | function UITextFieldDeprecated.setText(self, str) 146 | deprecatedTip("ccui.TextField:setText","ccui.TextField:setString") 147 | return self:setString(str) 148 | end 149 | ccui.TextField.setText = UITextFieldDeprecated.setText 150 | 151 | function UITextFieldDeprecated.getStringValue(self) 152 | deprecatedTip("ccui.TextField:getStringValue","ccui.TextField:getString") 153 | return self:getString() 154 | end 155 | ccui.TextField.getStringValue = UITextFieldDeprecated.getStringValue 156 | --functions of ccui.TextField will be deprecated end 157 | 158 | --functions of ccui.PageView will be deprecated begin 159 | local UIPageViewDeprecated = { } 160 | function UIPageViewDeprecated.addEventListenerPageView(self,handler) 161 | deprecatedTip("ccui.PageView:addEventListenerPageView","ccui.PageView:addEventListener") 162 | return self:addEventListener(handler) 163 | end 164 | ccui.PageView.addEventListenerPageView = UIPageViewDeprecated.addEventListenerPageView 165 | 166 | function UIPageViewDeprecated.addWidgetToPage(self, widget, pageIdx) 167 | deprecatedTip("ccui.PageView:addWidgetToPage","ccui.PageView:insertPage") 168 | return self:insertPage(widget, pageIdx) 169 | end 170 | ccui.PageView.addWidgetToPage = UIPageViewDeprecated.addWidgetToPage 171 | 172 | function UIPageViewDeprecated.getCurPageIndex(self) 173 | deprecatedTip("ccui.PageView:getCurPageIndex","ccui.PageView:getCurrentPageIndex") 174 | return self:getCurrentPageIndex() 175 | end 176 | ccui.PageView.getCurPageIndex = UIPageViewDeprecated.getCurPageIndex 177 | 178 | function UIPageViewDeprecated.setCurPageIndex(self, index) 179 | deprecatedTip("ccui.PageView:setCurPageIndex","ccui.PageView:setCurrentPageIndex") 180 | return self:setCurrentPageIndex(index) 181 | end 182 | ccui.PageView.setCurPageIndex = UIPageViewDeprecated.setCurPageIndex 183 | 184 | function UIPageViewDeprecated.getPages(self) 185 | deprecatedTip("ccui.PageView:getPages","ccui.PageView:getItems") 186 | return self:getItems() 187 | end 188 | ccui.PageView.getPages = UIPageViewDeprecated.getPages 189 | 190 | function UIPageViewDeprecated.getPage(self, index) 191 | deprecatedTip("ccui.PageView:getPage","ccui.PageView:getItem") 192 | return self:getItem(index) 193 | end 194 | ccui.PageView.getPage = UIPageViewDeprecated.getPage 195 | 196 | function UIPageViewDeprecated.setCustomScrollThreshold(self) 197 | print("Since v3.9, this method has no effect.") 198 | end 199 | ccui.PageView.setCustomScrollThreshold = UIPageViewDeprecated.setCustomScrollThreshold 200 | 201 | function UIPageViewDeprecated.getCustomScrollThreshold(self) 202 | print("Since v3.9, this method has no effect.") 203 | end 204 | ccui.PageView.getCustomScrollThreshold = UIPageViewDeprecated.getCustomScrollThreshold 205 | 206 | function UIPageViewDeprecated.isUsingCustomScrollThreshold(self) 207 | print("Since v3.9, this method has no effect.") 208 | end 209 | ccui.PageView.isUsingCustomScrollThreshold = UIPageViewDeprecated.isUsingCustomScrollThreshold 210 | 211 | function UIPageViewDeprecated.setUsingCustomScrollThreshold(self) 212 | print("Since v3.9, this method has no effect.") 213 | end 214 | ccui.PageView.setUsingCustomScrollThreshold = UIPageViewDeprecated.setUsingCustomScrollThreshold 215 | --functions of ccui.PageView will be deprecated end 216 | 217 | --functions of ccui.ScrollView will be deprecated begin 218 | local UIScrollViewDeprecated = { } 219 | function UIScrollViewDeprecated.addEventListenerScrollView(self,handler) 220 | deprecatedTip("ccui.ScrollView:addEventListenerScrollView","ccui.ScrollView:addEventListener") 221 | return self:addEventListener(handler) 222 | end 223 | ccui.ScrollView.addEventListenerScrollView = UIScrollViewDeprecated.addEventListenerScrollView 224 | --functions of ccui.ScrollView will be deprecated end 225 | 226 | --functions of ccui.ListView will be deprecated begin 227 | local UIListViewDeprecated = { } 228 | function UIListViewDeprecated.addEventListenerListView(self,handler) 229 | deprecatedTip("ccui.ListView:addEventListenerListView","ccui.ListView:addEventListener") 230 | return self:addEventListener(handler) 231 | end 232 | ccui.ListView.addEventListenerListView = UIListViewDeprecated.addEventListenerListView 233 | 234 | function UIListViewDeprecated.requestRefreshView(self) 235 | deprecatedTip("ccui.ListView:requestRefreshView","ccui.ListView:forceDoLayout") 236 | return self:forceDoLayout() 237 | end 238 | ccui.ListView.requestRefreshView = UIListViewDeprecated.requestRefreshView 239 | 240 | function UIListViewDeprecated.refreshView(self) 241 | deprecatedTip("ccui.ListView:refreshView","ccui.ListView:refreshView") 242 | return self:forceDoLayout() 243 | end 244 | ccui.ListView.refreshView = UIListViewDeprecated.refreshView 245 | --functions of ccui.ListView will be deprecated end 246 | -------------------------------------------------------------------------------- /src/cocos/ui/GuiConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == ccui then 2 | return 3 | end 4 | 5 | ccui.BrightStyle = 6 | { 7 | none = -1, 8 | normal = 0, 9 | highlight = 1, 10 | } 11 | 12 | ccui.TextureResType = 13 | { 14 | localType = 0, 15 | plistType = 1, 16 | } 17 | 18 | ccui.TouchEventType = 19 | { 20 | began = 0, 21 | moved = 1, 22 | ended = 2, 23 | canceled = 3, 24 | } 25 | 26 | ccui.SizeType = 27 | { 28 | absolute = 0, 29 | percent = 1, 30 | } 31 | 32 | ccui.PositionType = { 33 | absolute = 0, 34 | percent = 1, 35 | } 36 | 37 | ccui.CheckBoxEventType = 38 | { 39 | selected = 0, 40 | unselected = 1, 41 | } 42 | 43 | ccui.RadioButtonEventType= 44 | { 45 | selected = 0, 46 | unselected = 1 47 | } 48 | 49 | ccui.RadioButtonGroupEventType= 50 | { 51 | select_changed = 0 52 | } 53 | 54 | ccui.TextFiledEventType = 55 | { 56 | attach_with_ime = 0, 57 | detach_with_ime = 1, 58 | insert_text = 2, 59 | delete_backward = 3, 60 | } 61 | 62 | ccui.LayoutBackGroundColorType = 63 | { 64 | none = 0, 65 | solid = 1, 66 | gradient = 2, 67 | } 68 | 69 | ccui.LayoutType = 70 | { 71 | ABSOLUTE = 0, 72 | VERTICAL = 1, 73 | HORIZONTAL = 2, 74 | RELATIVE = 3, 75 | } 76 | 77 | ccui.LayoutParameterType = 78 | { 79 | none = 0, 80 | linear = 1, 81 | relative = 2, 82 | } 83 | 84 | ccui.LinearGravity = 85 | { 86 | none = 0, 87 | left = 1, 88 | top = 2, 89 | right = 3, 90 | bottom = 4, 91 | centerVertical = 5, 92 | centerHorizontal = 6, 93 | } 94 | 95 | ccui.RelativeAlign = 96 | { 97 | alignNone = 0, 98 | alignParentTopLeft = 1, 99 | alignParentTopCenterHorizontal = 2, 100 | alignParentTopRight = 3, 101 | alignParentLeftCenterVertical = 4, 102 | centerInParent = 5, 103 | alignParentRightCenterVertical = 6, 104 | alignParentLeftBottom = 7, 105 | alignParentBottomCenterHorizontal = 8, 106 | alignParentRightBottom = 9, 107 | locationAboveLeftAlign = 10, 108 | locationAboveCenter = 11, 109 | locationAboveRightAlign = 12, 110 | locationLeftOfTopAlign = 13, 111 | locationLeftOfCenter = 14, 112 | locationLeftOfBottomAlign = 15, 113 | locationRightOfTopAlign = 16, 114 | locationRightOfCenter = 17, 115 | locationRightOfBottomAlign = 18, 116 | locationBelowLeftAlign = 19, 117 | locationBelowCenter = 20, 118 | locationBelowRightAlign = 21, 119 | } 120 | 121 | ccui.SliderEventType = { 122 | percentChanged = 0, 123 | slideBallDown = 1, 124 | slideBallUp = 2, 125 | slideBallCancel = 3 126 | } 127 | 128 | ccui.LoadingBarDirection = { LEFT = 0, RIGHT = 1} 129 | 130 | ccui.ScrollViewDir = { 131 | none = 0, 132 | vertical = 1, 133 | horizontal = 2, 134 | both = 3, 135 | } 136 | 137 | ccui.ScrollViewMoveDir = { 138 | none = 0, 139 | up = 1, 140 | down = 2, 141 | left = 3, 142 | right = 4, 143 | } 144 | 145 | ccui.ScrollviewEventType = { 146 | scrollToTop = 0, 147 | scrollToBottom = 1, 148 | scrollToLeft = 2, 149 | scrollToRight = 3, 150 | scrolling = 4, 151 | bounceTop = 5, 152 | bounceBottom = 6, 153 | bounceLeft = 7, 154 | bounceRight = 8, 155 | containerMoved = 9, 156 | autoscrollEnded = 10, 157 | } 158 | 159 | ccui.ListViewDirection = { 160 | none = 0, 161 | vertical = 1, 162 | horizontal = 2, 163 | } 164 | 165 | ccui.ListViewMoveDirection = { 166 | none = 0, 167 | up = 1, 168 | down = 2, 169 | left = 3, 170 | right = 4, 171 | } 172 | 173 | ccui.ListViewEventType = { 174 | ONSELECTEDITEM_START = 0, 175 | ONSELECTEDITEM_END = 1, 176 | } 177 | 178 | ccui.PageViewEventType = { 179 | turning = 0, 180 | } 181 | 182 | ccui.PageViewDirection = { 183 | NONE = 0, 184 | VERTICAL = 1, 185 | HORIZONTAL = 2, 186 | BOTH = 3 187 | } 188 | 189 | ccui.PVTouchDir = { 190 | touchLeft = 0, 191 | touchRight = 1, 192 | touchUp = 2, 193 | touchDown = 3 194 | } 195 | 196 | ccui.ListViewGravity = { 197 | left = 0, 198 | right = 1, 199 | centerHorizontal = 2, 200 | top = 3, 201 | bottom = 4 , 202 | centerVertical = 5, 203 | } 204 | 205 | ccui.TextType = { 206 | SYSTEM = 0, 207 | TTF = 1, 208 | } 209 | 210 | ccui.LayoutComponent.HorizontalEdge = { 211 | None = 0, 212 | Left = 1, 213 | Right = 2, 214 | Center = 3, 215 | } 216 | 217 | ccui.LayoutComponent.VerticalEdge = { 218 | None = 0, 219 | Bottom = 1, 220 | Top = 2, 221 | Center = 3, 222 | } 223 | -------------------------------------------------------------------------------- /src/cocos/ui/experimentalUIConstants.lua: -------------------------------------------------------------------------------- 1 | if nil == ccexp then 2 | return 3 | end 4 | 5 | ccexp.VideoPlayerEvent = { 6 | PLAYING = 0, 7 | PAUSED = 1, 8 | STOPPED= 2, 9 | COMPLETED =3, 10 | } 11 | -------------------------------------------------------------------------------- /src/config.lua: -------------------------------------------------------------------------------- 1 | 2 | -- 0 - disable debug info, 1 - less debug info, 2 - verbose debug info 3 | DEBUG = 2 4 | 5 | -- use framework, will disable all deprecated API, false - use legacy API 6 | CC_USE_FRAMEWORK = true 7 | 8 | -- show FPS on screen 9 | CC_SHOW_FPS = true 10 | 11 | -- disable create unexpected global variable 12 | CC_DISABLE_GLOBAL = true 13 | 14 | -- for module display 15 | CC_DESIGN_RESOLUTION = { 16 | width = 960, 17 | height = 640, 18 | autoscale = "FIXED_HEIGHT", 19 | callback = function(framesize) 20 | local ratio = framesize.width / framesize.height 21 | if ratio <= 1.34 then 22 | -- iPad 768*1024(1536*2048) is 4:3 screen 23 | return {autoscale = "FIXED_WIDTH"} 24 | end 25 | end 26 | } 27 | -------------------------------------------------------------------------------- /src/luasocket/ltn12.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- LTN12 - Filters, sources, sinks and pumps. 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module 9 | ----------------------------------------------------------------------------- 10 | local string = require("string") 11 | local table = require("table") 12 | local base = _G 13 | local _M = {} 14 | if module then -- heuristic for exporting a global package table 15 | ltn12 = _M 16 | end 17 | local filter,source,sink,pump = {},{},{},{} 18 | 19 | _M.filter = filter 20 | _M.source = source 21 | _M.sink = sink 22 | _M.pump = pump 23 | 24 | -- 2048 seems to be better in windows... 25 | _M.BLOCKSIZE = 2048 26 | _M._VERSION = "LTN12 1.0.3" 27 | 28 | ----------------------------------------------------------------------------- 29 | -- Filter stuff 30 | ----------------------------------------------------------------------------- 31 | -- returns a high level filter that cycles a low-level filter 32 | function filter.cycle(low, ctx, extra) 33 | base.assert(low) 34 | return function(chunk) 35 | local ret 36 | ret, ctx = low(ctx, chunk, extra) 37 | return ret 38 | end 39 | end 40 | 41 | -- chains a bunch of filters together 42 | -- (thanks to Wim Couwenberg) 43 | function filter.chain(...) 44 | local arg = {...} 45 | local n = select('#',...) 46 | local top, index = 1, 1 47 | local retry = "" 48 | return function(chunk) 49 | retry = chunk and retry 50 | while true do 51 | if index == top then 52 | chunk = arg[index](chunk) 53 | if chunk == "" or top == n then return chunk 54 | elseif chunk then index = index + 1 55 | else 56 | top = top+1 57 | index = top 58 | end 59 | else 60 | chunk = arg[index](chunk or "") 61 | if chunk == "" then 62 | index = index - 1 63 | chunk = retry 64 | elseif chunk then 65 | if index == n then return chunk 66 | else index = index + 1 end 67 | else base.error("filter returned inappropriate nil") end 68 | end 69 | end 70 | end 71 | end 72 | 73 | ----------------------------------------------------------------------------- 74 | -- Source stuff 75 | ----------------------------------------------------------------------------- 76 | -- create an empty source 77 | local function empty() 78 | return nil 79 | end 80 | 81 | function source.empty() 82 | return empty 83 | end 84 | 85 | -- returns a source that just outputs an error 86 | function source.error(err) 87 | return function() 88 | return nil, err 89 | end 90 | end 91 | 92 | -- creates a file source 93 | function source.file(handle, io_err) 94 | if handle then 95 | return function() 96 | local chunk = handle:read(_M.BLOCKSIZE) 97 | if not chunk then handle:close() end 98 | return chunk 99 | end 100 | else return source.error(io_err or "unable to open file") end 101 | end 102 | 103 | -- turns a fancy source into a simple source 104 | function source.simplify(src) 105 | base.assert(src) 106 | return function() 107 | local chunk, err_or_new = src() 108 | src = err_or_new or src 109 | if not chunk then return nil, err_or_new 110 | else return chunk end 111 | end 112 | end 113 | 114 | -- creates string source 115 | function source.string(s) 116 | if s then 117 | local i = 1 118 | return function() 119 | local chunk = string.sub(s, i, i+_M.BLOCKSIZE-1) 120 | i = i + _M.BLOCKSIZE 121 | if chunk ~= "" then return chunk 122 | else return nil end 123 | end 124 | else return source.empty() end 125 | end 126 | 127 | -- creates rewindable source 128 | function source.rewind(src) 129 | base.assert(src) 130 | local t = {} 131 | return function(chunk) 132 | if not chunk then 133 | chunk = table.remove(t) 134 | if not chunk then return src() 135 | else return chunk end 136 | else 137 | table.insert(t, chunk) 138 | end 139 | end 140 | end 141 | 142 | function source.chain(src, f) 143 | base.assert(src and f) 144 | local last_in, last_out = "", "" 145 | local state = "feeding" 146 | local err 147 | return function() 148 | if not last_out then 149 | base.error('source is empty!', 2) 150 | end 151 | while true do 152 | if state == "feeding" then 153 | last_in, err = src() 154 | if err then return nil, err end 155 | last_out = f(last_in) 156 | if not last_out then 157 | if last_in then 158 | base.error('filter returned inappropriate nil') 159 | else 160 | return nil 161 | end 162 | elseif last_out ~= "" then 163 | state = "eating" 164 | if last_in then last_in = "" end 165 | return last_out 166 | end 167 | else 168 | last_out = f(last_in) 169 | if last_out == "" then 170 | if last_in == "" then 171 | state = "feeding" 172 | else 173 | base.error('filter returned ""') 174 | end 175 | elseif not last_out then 176 | if last_in then 177 | base.error('filter returned inappropriate nil') 178 | else 179 | return nil 180 | end 181 | else 182 | return last_out 183 | end 184 | end 185 | end 186 | end 187 | end 188 | 189 | -- creates a source that produces contents of several sources, one after the 190 | -- other, as if they were concatenated 191 | -- (thanks to Wim Couwenberg) 192 | function source.cat(...) 193 | local arg = {...} 194 | local src = table.remove(arg, 1) 195 | return function() 196 | while src do 197 | local chunk, err = src() 198 | if chunk then return chunk end 199 | if err then return nil, err end 200 | src = table.remove(arg, 1) 201 | end 202 | end 203 | end 204 | 205 | ----------------------------------------------------------------------------- 206 | -- Sink stuff 207 | ----------------------------------------------------------------------------- 208 | -- creates a sink that stores into a table 209 | function sink.table(t) 210 | t = t or {} 211 | local f = function(chunk, err) 212 | if chunk then table.insert(t, chunk) end 213 | return 1 214 | end 215 | return f, t 216 | end 217 | 218 | -- turns a fancy sink into a simple sink 219 | function sink.simplify(snk) 220 | base.assert(snk) 221 | return function(chunk, err) 222 | local ret, err_or_new = snk(chunk, err) 223 | if not ret then return nil, err_or_new end 224 | snk = err_or_new or snk 225 | return 1 226 | end 227 | end 228 | 229 | -- creates a file sink 230 | function sink.file(handle, io_err) 231 | if handle then 232 | return function(chunk, err) 233 | if not chunk then 234 | handle:close() 235 | return 1 236 | else return handle:write(chunk) end 237 | end 238 | else return sink.error(io_err or "unable to open file") end 239 | end 240 | 241 | -- creates a sink that discards data 242 | local function null() 243 | return 1 244 | end 245 | 246 | function sink.null() 247 | return null 248 | end 249 | 250 | -- creates a sink that just returns an error 251 | function sink.error(err) 252 | return function() 253 | return nil, err 254 | end 255 | end 256 | 257 | -- chains a sink with a filter 258 | function sink.chain(f, snk) 259 | base.assert(f and snk) 260 | return function(chunk, err) 261 | if chunk ~= "" then 262 | local filtered = f(chunk) 263 | local done = chunk and "" 264 | while true do 265 | local ret, snkerr = snk(filtered, err) 266 | if not ret then return nil, snkerr end 267 | if filtered == done then return 1 end 268 | filtered = f(done) 269 | end 270 | else return 1 end 271 | end 272 | end 273 | 274 | ----------------------------------------------------------------------------- 275 | -- Pump stuff 276 | ----------------------------------------------------------------------------- 277 | -- pumps one chunk from the source to the sink 278 | function pump.step(src, snk) 279 | local chunk, src_err = src() 280 | local ret, snk_err = snk(chunk, src_err) 281 | if chunk and ret then return 1 282 | else return nil, src_err or snk_err end 283 | end 284 | 285 | -- pumps all data from a source to a sink, using a step function 286 | function pump.all(src, snk, step) 287 | base.assert(src and snk) 288 | step = step or pump.step 289 | while true do 290 | local ret, err = step(src, snk) 291 | if not ret then 292 | if err then return nil, err 293 | else return 1 end 294 | end 295 | end 296 | end 297 | 298 | return _M 299 | -------------------------------------------------------------------------------- /src/luasocket/mime.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- MIME support for the Lua language. 3 | -- Author: Diego Nehab 4 | -- Conforming to RFCs 2045-2049 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local ltn12 = require("ltn12") 12 | local mime = require("mime.core") 13 | local io = require("io") 14 | local string = require("string") 15 | local _M = mime 16 | 17 | -- encode, decode and wrap algorithm tables 18 | local encodet, decodet, wrapt = {},{},{} 19 | 20 | _M.encodet = encodet 21 | _M.decodet = decodet 22 | _M.wrapt = wrapt 23 | 24 | -- creates a function that chooses a filter by name from a given table 25 | local function choose(table) 26 | return function(name, opt1, opt2) 27 | if base.type(name) ~= "string" then 28 | name, opt1, opt2 = "default", name, opt1 29 | end 30 | local f = table[name or "nil"] 31 | if not f then 32 | base.error("unknown key (" .. base.tostring(name) .. ")", 3) 33 | else return f(opt1, opt2) end 34 | end 35 | end 36 | 37 | -- define the encoding filters 38 | encodet['base64'] = function() 39 | return ltn12.filter.cycle(_M.b64, "") 40 | end 41 | 42 | encodet['quoted-printable'] = function(mode) 43 | return ltn12.filter.cycle(_M.qp, "", 44 | (mode == "binary") and "=0D=0A" or "\r\n") 45 | end 46 | 47 | -- define the decoding filters 48 | decodet['base64'] = function() 49 | return ltn12.filter.cycle(_M.unb64, "") 50 | end 51 | 52 | decodet['quoted-printable'] = function() 53 | return ltn12.filter.cycle(_M.unqp, "") 54 | end 55 | 56 | local function format(chunk) 57 | if chunk then 58 | if chunk == "" then return "''" 59 | else return string.len(chunk) end 60 | else return "nil" end 61 | end 62 | 63 | -- define the line-wrap filters 64 | wrapt['text'] = function(length) 65 | length = length or 76 66 | return ltn12.filter.cycle(_M.wrp, length, length) 67 | end 68 | wrapt['base64'] = wrapt['text'] 69 | wrapt['default'] = wrapt['text'] 70 | 71 | wrapt['quoted-printable'] = function() 72 | return ltn12.filter.cycle(_M.qpwrp, 76, 76) 73 | end 74 | 75 | -- function that choose the encoding, decoding or wrap algorithm 76 | _M.encode = choose(encodet) 77 | _M.decode = choose(decodet) 78 | _M.wrap = choose(wrapt) 79 | 80 | -- define the end-of-line normalization filter 81 | function _M.normalize(marker) 82 | return ltn12.filter.cycle(_M.eol, 0, marker) 83 | end 84 | 85 | -- high level stuffing filter 86 | function _M.stuff() 87 | return ltn12.filter.cycle(_M.dot, 2) 88 | end 89 | 90 | return _M -------------------------------------------------------------------------------- /src/luasocket/socket.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- LuaSocket helper module 3 | -- Author: Diego Nehab 4 | ----------------------------------------------------------------------------- 5 | 6 | ----------------------------------------------------------------------------- 7 | -- Declare module and import dependencies 8 | ----------------------------------------------------------------------------- 9 | local base = _G 10 | local string = require("string") 11 | local math = require("math") 12 | local socket = require("socket.core") 13 | 14 | local _M = socket 15 | 16 | ----------------------------------------------------------------------------- 17 | -- Exported auxiliar functions 18 | ----------------------------------------------------------------------------- 19 | function _M.connect4(address, port, laddress, lport) 20 | return socket.connect(address, port, laddress, lport, "inet") 21 | end 22 | 23 | function _M.connect6(address, port, laddress, lport) 24 | return socket.connect(address, port, laddress, lport, "inet6") 25 | end 26 | 27 | function _M.bind(host, port, backlog) 28 | if host == "*" then host = "0.0.0.0" end 29 | local addrinfo, err = socket.dns.getaddrinfo(host); 30 | if not addrinfo then return nil, err end 31 | local sock, res 32 | err = "no info on address" 33 | for i, alt in base.ipairs(addrinfo) do 34 | if alt.family == "inet" then 35 | sock, err = socket.tcp() 36 | else 37 | sock, err = socket.tcp6() 38 | end 39 | if not sock then return nil, err end 40 | sock:setoption("reuseaddr", true) 41 | res, err = sock:bind(alt.addr, port) 42 | if not res then 43 | sock:close() 44 | else 45 | res, err = sock:listen(backlog) 46 | if not res then 47 | sock:close() 48 | else 49 | return sock 50 | end 51 | end 52 | end 53 | return nil, err 54 | end 55 | 56 | _M.try = _M.newtry() 57 | 58 | function _M.choose(table) 59 | return function(name, opt1, opt2) 60 | if base.type(name) ~= "string" then 61 | name, opt1, opt2 = "default", name, opt1 62 | end 63 | local f = table[name or "nil"] 64 | if not f then base.error("unknown key (".. base.tostring(name) ..")", 3) 65 | else return f(opt1, opt2) end 66 | end 67 | end 68 | 69 | ----------------------------------------------------------------------------- 70 | -- Socket sources and sinks, conforming to LTN12 71 | ----------------------------------------------------------------------------- 72 | -- create namespaces inside LuaSocket namespace 73 | local sourcet, sinkt = {}, {} 74 | _M.sourcet = sourcet 75 | _M.sinkt = sinkt 76 | 77 | _M.BLOCKSIZE = 2048 78 | 79 | sinkt["close-when-done"] = function(sock) 80 | return base.setmetatable({ 81 | getfd = function() return sock:getfd() end, 82 | dirty = function() return sock:dirty() end 83 | }, { 84 | __call = function(self, chunk, err) 85 | if not chunk then 86 | sock:close() 87 | return 1 88 | else return sock:send(chunk) end 89 | end 90 | }) 91 | end 92 | 93 | sinkt["keep-open"] = function(sock) 94 | return base.setmetatable({ 95 | getfd = function() return sock:getfd() end, 96 | dirty = function() return sock:dirty() end 97 | }, { 98 | __call = function(self, chunk, err) 99 | if chunk then return sock:send(chunk) 100 | else return 1 end 101 | end 102 | }) 103 | end 104 | 105 | sinkt["default"] = sinkt["keep-open"] 106 | 107 | _M.sink = _M.choose(sinkt) 108 | 109 | sourcet["by-length"] = function(sock, length) 110 | return base.setmetatable({ 111 | getfd = function() return sock:getfd() end, 112 | dirty = function() return sock:dirty() end 113 | }, { 114 | __call = function() 115 | if length <= 0 then return nil end 116 | local size = math.min(socket.BLOCKSIZE, length) 117 | local chunk, err = sock:receive(size) 118 | if err then return nil, err end 119 | length = length - string.len(chunk) 120 | return chunk 121 | end 122 | }) 123 | end 124 | 125 | sourcet["until-closed"] = function(sock) 126 | local done 127 | return base.setmetatable({ 128 | getfd = function() return sock:getfd() end, 129 | dirty = function() return sock:dirty() end 130 | }, { 131 | __call = function() 132 | if done then return nil end 133 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) 134 | if not err then return chunk 135 | elseif err == "closed" then 136 | sock:close() 137 | done = 1 138 | return partial 139 | else return nil, err end 140 | end 141 | }) 142 | end 143 | 144 | 145 | sourcet["default"] = sourcet["until-closed"] 146 | 147 | _M.source = _M.choose(sourcet) 148 | 149 | return _M 150 | -------------------------------------------------------------------------------- /src/luasocket/socket/ftp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- FTP support for the Lua language 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local table = require("table") 12 | local string = require("string") 13 | local math = require("math") 14 | local socket = require("socket.socket") 15 | local url = require("socket.url") 16 | local tp = require("socket.tp") 17 | local ltn12 = require("ltn12") 18 | socket.ftp = {} 19 | local _M = socket.ftp 20 | ----------------------------------------------------------------------------- 21 | -- Program constants 22 | ----------------------------------------------------------------------------- 23 | -- timeout in seconds before the program gives up on a connection 24 | _M.TIMEOUT = 60 25 | -- default port for ftp service 26 | _M.PORT = 21 27 | -- this is the default anonymous password. used when no password is 28 | -- provided in url. should be changed to your e-mail. 29 | _M.USER = "ftp" 30 | _M.PASSWORD = "anonymous@anonymous.org" 31 | 32 | ----------------------------------------------------------------------------- 33 | -- Low level FTP API 34 | ----------------------------------------------------------------------------- 35 | local metat = { __index = {} } 36 | 37 | function _M.open(server, port, create) 38 | local tp = socket.try(tp.connect(server, port or _M.PORT, _M.TIMEOUT, create)) 39 | local f = base.setmetatable({ tp = tp }, metat) 40 | -- make sure everything gets closed in an exception 41 | f.try = socket.newtry(function() f:close() end) 42 | return f 43 | end 44 | 45 | function metat.__index:portconnect() 46 | self.try(self.server:settimeout(_M.TIMEOUT)) 47 | self.data = self.try(self.server:accept()) 48 | self.try(self.data:settimeout(_M.TIMEOUT)) 49 | end 50 | 51 | function metat.__index:pasvconnect() 52 | self.data = self.try(socket.tcp()) 53 | self.try(self.data:settimeout(_M.TIMEOUT)) 54 | self.try(self.data:connect(self.pasvt.ip, self.pasvt.port)) 55 | end 56 | 57 | function metat.__index:login(user, password) 58 | self.try(self.tp:command("user", user or _M.USER)) 59 | local code, reply = self.try(self.tp:check{"2..", 331}) 60 | if code == 331 then 61 | self.try(self.tp:command("pass", password or _M.PASSWORD)) 62 | self.try(self.tp:check("2..")) 63 | end 64 | return 1 65 | end 66 | 67 | function metat.__index:pasv() 68 | self.try(self.tp:command("pasv")) 69 | local code, reply = self.try(self.tp:check("2..")) 70 | local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" 71 | local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) 72 | self.try(a and b and c and d and p1 and p2, reply) 73 | self.pasvt = { 74 | ip = string.format("%d.%d.%d.%d", a, b, c, d), 75 | port = p1*256 + p2 76 | } 77 | if self.server then 78 | self.server:close() 79 | self.server = nil 80 | end 81 | return self.pasvt.ip, self.pasvt.port 82 | end 83 | 84 | function metat.__index:port(ip, port) 85 | self.pasvt = nil 86 | if not ip then 87 | ip, port = self.try(self.tp:getcontrol():getsockname()) 88 | self.server = self.try(socket.bind(ip, 0)) 89 | ip, port = self.try(self.server:getsockname()) 90 | self.try(self.server:settimeout(_M.TIMEOUT)) 91 | end 92 | local pl = math.mod(port, 256) 93 | local ph = (port - pl)/256 94 | local arg = string.gsub(string.format("%s,%d,%d", ip, ph, pl), "%.", ",") 95 | self.try(self.tp:command("port", arg)) 96 | self.try(self.tp:check("2..")) 97 | return 1 98 | end 99 | 100 | function metat.__index:send(sendt) 101 | self.try(self.pasvt or self.server, "need port or pasv first") 102 | -- if there is a pasvt table, we already sent a PASV command 103 | -- we just get the data connection into self.data 104 | if self.pasvt then self:pasvconnect() end 105 | -- get the transfer argument and command 106 | local argument = sendt.argument or 107 | url.unescape(string.gsub(sendt.path or "", "^[/\\]", "")) 108 | if argument == "" then argument = nil end 109 | local command = sendt.command or "stor" 110 | -- send the transfer command and check the reply 111 | self.try(self.tp:command(command, argument)) 112 | local code, reply = self.try(self.tp:check{"2..", "1.."}) 113 | -- if there is not a a pasvt table, then there is a server 114 | -- and we already sent a PORT command 115 | if not self.pasvt then self:portconnect() end 116 | -- get the sink, source and step for the transfer 117 | local step = sendt.step or ltn12.pump.step 118 | local readt = {self.tp.c} 119 | local checkstep = function(src, snk) 120 | -- check status in control connection while downloading 121 | local readyt = socket.select(readt, nil, 0) 122 | if readyt[tp] then code = self.try(self.tp:check("2..")) end 123 | return step(src, snk) 124 | end 125 | local sink = socket.sink("close-when-done", self.data) 126 | -- transfer all data and check error 127 | self.try(ltn12.pump.all(sendt.source, sink, checkstep)) 128 | if string.find(code, "1..") then self.try(self.tp:check("2..")) end 129 | -- done with data connection 130 | self.data:close() 131 | -- find out how many bytes were sent 132 | local sent = socket.skip(1, self.data:getstats()) 133 | self.data = nil 134 | return sent 135 | end 136 | 137 | function metat.__index:receive(recvt) 138 | self.try(self.pasvt or self.server, "need port or pasv first") 139 | if self.pasvt then self:pasvconnect() end 140 | local argument = recvt.argument or 141 | url.unescape(string.gsub(recvt.path or "", "^[/\\]", "")) 142 | if argument == "" then argument = nil end 143 | local command = recvt.command or "retr" 144 | self.try(self.tp:command(command, argument)) 145 | local code,reply = self.try(self.tp:check{"1..", "2.."}) 146 | if (code >= 200) and (code <= 299) then 147 | recvt.sink(reply) 148 | return 1 149 | end 150 | if not self.pasvt then self:portconnect() end 151 | local source = socket.source("until-closed", self.data) 152 | local step = recvt.step or ltn12.pump.step 153 | self.try(ltn12.pump.all(source, recvt.sink, step)) 154 | if string.find(code, "1..") then self.try(self.tp:check("2..")) end 155 | self.data:close() 156 | self.data = nil 157 | return 1 158 | end 159 | 160 | function metat.__index:cwd(dir) 161 | self.try(self.tp:command("cwd", dir)) 162 | self.try(self.tp:check(250)) 163 | return 1 164 | end 165 | 166 | function metat.__index:type(type) 167 | self.try(self.tp:command("type", type)) 168 | self.try(self.tp:check(200)) 169 | return 1 170 | end 171 | 172 | function metat.__index:greet() 173 | local code = self.try(self.tp:check{"1..", "2.."}) 174 | if string.find(code, "1..") then self.try(self.tp:check("2..")) end 175 | return 1 176 | end 177 | 178 | function metat.__index:quit() 179 | self.try(self.tp:command("quit")) 180 | self.try(self.tp:check("2..")) 181 | return 1 182 | end 183 | 184 | function metat.__index:close() 185 | if self.data then self.data:close() end 186 | if self.server then self.server:close() end 187 | return self.tp:close() 188 | end 189 | 190 | ----------------------------------------------------------------------------- 191 | -- High level FTP API 192 | ----------------------------------------------------------------------------- 193 | local function override(t) 194 | if t.url then 195 | local u = url.parse(t.url) 196 | for i,v in base.pairs(t) do 197 | u[i] = v 198 | end 199 | return u 200 | else return t end 201 | end 202 | 203 | local function tput(putt) 204 | putt = override(putt) 205 | socket.try(putt.host, "missing hostname") 206 | local f = _M.open(putt.host, putt.port, putt.create) 207 | f:greet() 208 | f:login(putt.user, putt.password) 209 | if putt.type then f:type(putt.type) end 210 | f:pasv() 211 | local sent = f:send(putt) 212 | f:quit() 213 | f:close() 214 | return sent 215 | end 216 | 217 | local default = { 218 | path = "/", 219 | scheme = "ftp" 220 | } 221 | 222 | local function parse(u) 223 | local t = socket.try(url.parse(u, default)) 224 | socket.try(t.scheme == "ftp", "wrong scheme '" .. t.scheme .. "'") 225 | socket.try(t.host, "missing hostname") 226 | local pat = "^type=(.)$" 227 | if t.params then 228 | t.type = socket.skip(2, string.find(t.params, pat)) 229 | socket.try(t.type == "a" or t.type == "i", 230 | "invalid type '" .. t.type .. "'") 231 | end 232 | return t 233 | end 234 | 235 | local function sput(u, body) 236 | local putt = parse(u) 237 | putt.source = ltn12.source.string(body) 238 | return tput(putt) 239 | end 240 | 241 | _M.put = socket.protect(function(putt, body) 242 | if base.type(putt) == "string" then return sput(putt, body) 243 | else return tput(putt) end 244 | end) 245 | 246 | local function tget(gett) 247 | gett = override(gett) 248 | socket.try(gett.host, "missing hostname") 249 | local f = _M.open(gett.host, gett.port, gett.create) 250 | f:greet() 251 | f:login(gett.user, gett.password) 252 | if gett.type then f:type(gett.type) end 253 | f:pasv() 254 | f:receive(gett) 255 | f:quit() 256 | return f:close() 257 | end 258 | 259 | local function sget(u) 260 | local gett = parse(u) 261 | local t = {} 262 | gett.sink = ltn12.sink.table(t) 263 | tget(gett) 264 | return table.concat(t) 265 | end 266 | 267 | _M.command = socket.protect(function(cmdt) 268 | cmdt = override(cmdt) 269 | socket.try(cmdt.host, "missing hostname") 270 | socket.try(cmdt.command, "missing command") 271 | local f = open(cmdt.host, cmdt.port, cmdt.create) 272 | f:greet() 273 | f:login(cmdt.user, cmdt.password) 274 | f.try(f.tp:command(cmdt.command, cmdt.argument)) 275 | if cmdt.check then f.try(f.tp:check(cmdt.check)) end 276 | f:quit() 277 | return f:close() 278 | end) 279 | 280 | _M.get = socket.protect(function(gett) 281 | if base.type(gett) == "string" then return sget(gett) 282 | else return tget(gett) end 283 | end) 284 | 285 | return _M 286 | -------------------------------------------------------------------------------- /src/luasocket/socket/headers.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Canonic header field capitalization 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require("socket.socket") 7 | socket.headers = {} 8 | local _M = socket.headers 9 | 10 | _M.canonic = { 11 | ["accept"] = "Accept", 12 | ["accept-charset"] = "Accept-Charset", 13 | ["accept-encoding"] = "Accept-Encoding", 14 | ["accept-language"] = "Accept-Language", 15 | ["accept-ranges"] = "Accept-Ranges", 16 | ["action"] = "Action", 17 | ["alternate-recipient"] = "Alternate-Recipient", 18 | ["age"] = "Age", 19 | ["allow"] = "Allow", 20 | ["arrival-date"] = "Arrival-Date", 21 | ["authorization"] = "Authorization", 22 | ["bcc"] = "Bcc", 23 | ["cache-control"] = "Cache-Control", 24 | ["cc"] = "Cc", 25 | ["comments"] = "Comments", 26 | ["connection"] = "Connection", 27 | ["content-description"] = "Content-Description", 28 | ["content-disposition"] = "Content-Disposition", 29 | ["content-encoding"] = "Content-Encoding", 30 | ["content-id"] = "Content-ID", 31 | ["content-language"] = "Content-Language", 32 | ["content-length"] = "Content-Length", 33 | ["content-location"] = "Content-Location", 34 | ["content-md5"] = "Content-MD5", 35 | ["content-range"] = "Content-Range", 36 | ["content-transfer-encoding"] = "Content-Transfer-Encoding", 37 | ["content-type"] = "Content-Type", 38 | ["cookie"] = "Cookie", 39 | ["date"] = "Date", 40 | ["diagnostic-code"] = "Diagnostic-Code", 41 | ["dsn-gateway"] = "DSN-Gateway", 42 | ["etag"] = "ETag", 43 | ["expect"] = "Expect", 44 | ["expires"] = "Expires", 45 | ["final-log-id"] = "Final-Log-ID", 46 | ["final-recipient"] = "Final-Recipient", 47 | ["from"] = "From", 48 | ["host"] = "Host", 49 | ["if-match"] = "If-Match", 50 | ["if-modified-since"] = "If-Modified-Since", 51 | ["if-none-match"] = "If-None-Match", 52 | ["if-range"] = "If-Range", 53 | ["if-unmodified-since"] = "If-Unmodified-Since", 54 | ["in-reply-to"] = "In-Reply-To", 55 | ["keywords"] = "Keywords", 56 | ["last-attempt-date"] = "Last-Attempt-Date", 57 | ["last-modified"] = "Last-Modified", 58 | ["location"] = "Location", 59 | ["max-forwards"] = "Max-Forwards", 60 | ["message-id"] = "Message-ID", 61 | ["mime-version"] = "MIME-Version", 62 | ["original-envelope-id"] = "Original-Envelope-ID", 63 | ["original-recipient"] = "Original-Recipient", 64 | ["pragma"] = "Pragma", 65 | ["proxy-authenticate"] = "Proxy-Authenticate", 66 | ["proxy-authorization"] = "Proxy-Authorization", 67 | ["range"] = "Range", 68 | ["received"] = "Received", 69 | ["received-from-mta"] = "Received-From-MTA", 70 | ["references"] = "References", 71 | ["referer"] = "Referer", 72 | ["remote-mta"] = "Remote-MTA", 73 | ["reply-to"] = "Reply-To", 74 | ["reporting-mta"] = "Reporting-MTA", 75 | ["resent-bcc"] = "Resent-Bcc", 76 | ["resent-cc"] = "Resent-Cc", 77 | ["resent-date"] = "Resent-Date", 78 | ["resent-from"] = "Resent-From", 79 | ["resent-message-id"] = "Resent-Message-ID", 80 | ["resent-reply-to"] = "Resent-Reply-To", 81 | ["resent-sender"] = "Resent-Sender", 82 | ["resent-to"] = "Resent-To", 83 | ["retry-after"] = "Retry-After", 84 | ["return-path"] = "Return-Path", 85 | ["sender"] = "Sender", 86 | ["server"] = "Server", 87 | ["smtp-remote-recipient"] = "SMTP-Remote-Recipient", 88 | ["status"] = "Status", 89 | ["subject"] = "Subject", 90 | ["te"] = "TE", 91 | ["to"] = "To", 92 | ["trailer"] = "Trailer", 93 | ["transfer-encoding"] = "Transfer-Encoding", 94 | ["upgrade"] = "Upgrade", 95 | ["user-agent"] = "User-Agent", 96 | ["vary"] = "Vary", 97 | ["via"] = "Via", 98 | ["warning"] = "Warning", 99 | ["will-retry-until"] = "Will-Retry-Until", 100 | ["www-authenticate"] = "WWW-Authenticate", 101 | ["x-mailer"] = "X-Mailer", 102 | } 103 | 104 | return _M 105 | -------------------------------------------------------------------------------- /src/luasocket/socket/mbox.lua: -------------------------------------------------------------------------------- 1 | local _M = {} 2 | 3 | if module then 4 | mbox = _M 5 | end 6 | 7 | function _M.split_message(message_s) 8 | local message = {} 9 | message_s = string.gsub(message_s, "\r\n", "\n") 10 | string.gsub(message_s, "^(.-\n)\n", function (h) message.headers = h end) 11 | string.gsub(message_s, "^.-\n\n(.*)", function (b) message.body = b end) 12 | if not message.body then 13 | string.gsub(message_s, "^\n(.*)", function (b) message.body = b end) 14 | end 15 | if not message.headers and not message.body then 16 | message.headers = message_s 17 | end 18 | return message.headers or "", message.body or "" 19 | end 20 | 21 | function _M.split_headers(headers_s) 22 | local headers = {} 23 | headers_s = string.gsub(headers_s, "\r\n", "\n") 24 | headers_s = string.gsub(headers_s, "\n[ ]+", " ") 25 | string.gsub("\n" .. headers_s, "\n([^\n]+)", function (h) table.insert(headers, h) end) 26 | return headers 27 | end 28 | 29 | function _M.parse_header(header_s) 30 | header_s = string.gsub(header_s, "\n[ ]+", " ") 31 | header_s = string.gsub(header_s, "\n+", "") 32 | local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") 33 | return name, value 34 | end 35 | 36 | function _M.parse_headers(headers_s) 37 | local headers_t = _M.split_headers(headers_s) 38 | local headers = {} 39 | for i = 1, #headers_t do 40 | local name, value = _M.parse_header(headers_t[i]) 41 | if name then 42 | name = string.lower(name) 43 | if headers[name] then 44 | headers[name] = headers[name] .. ", " .. value 45 | else headers[name] = value end 46 | end 47 | end 48 | return headers 49 | end 50 | 51 | function _M.parse_from(from) 52 | local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") 53 | if not address then 54 | _, __, address = string.find(from, "%s*(.+)%s*") 55 | end 56 | name = name or "" 57 | address = address or "" 58 | if name == "" then name = address end 59 | name = string.gsub(name, '"', "") 60 | return name, address 61 | end 62 | 63 | function _M.split_mbox(mbox_s) 64 | mbox = {} 65 | mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" 66 | local nj, i, j = 1, 1, 1 67 | while 1 do 68 | i, nj = string.find(mbox_s, "\n\nFrom .-\n", j) 69 | if not i then break end 70 | local message = string.sub(mbox_s, j, i-1) 71 | table.insert(mbox, message) 72 | j = nj+1 73 | end 74 | return mbox 75 | end 76 | 77 | function _M.parse(mbox_s) 78 | local mbox = _M.split_mbox(mbox_s) 79 | for i = 1, #mbox do 80 | mbox[i] = _M.parse_message(mbox[i]) 81 | end 82 | return mbox 83 | end 84 | 85 | function _M.parse_message(message_s) 86 | local message = {} 87 | message.headers, message.body = _M.split_message(message_s) 88 | message.headers = _M.parse_headers(message.headers) 89 | return message 90 | end 91 | 92 | return _M 93 | -------------------------------------------------------------------------------- /src/luasocket/socket/smtp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- SMTP client support for the Lua language. 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local coroutine = require("coroutine") 12 | local string = require("string") 13 | local math = require("math") 14 | local os = require("os") 15 | local socket = require("socket.socket") 16 | local tp = require("socket.tp") 17 | local ltn12 = require("socket.ltn12") 18 | local headers = require("socket.headers") 19 | local mime = require("socket.mime") 20 | 21 | socket.smtp = {} 22 | local _M = socket.smtp 23 | 24 | ----------------------------------------------------------------------------- 25 | -- Program constants 26 | ----------------------------------------------------------------------------- 27 | -- timeout for connection 28 | _M.TIMEOUT = 60 29 | -- default server used to send e-mails 30 | _M.SERVER = "localhost" 31 | -- default port 32 | _M.PORT = 25 33 | -- domain used in HELO command and default sendmail 34 | -- If we are under a CGI, try to get from environment 35 | _M.DOMAIN = os.getenv("SERVER_NAME") or "localhost" 36 | -- default time zone (means we don't know) 37 | _M.ZONE = "-0000" 38 | 39 | --------------------------------------------------------------------------- 40 | -- Low level SMTP API 41 | ----------------------------------------------------------------------------- 42 | local metat = { __index = {} } 43 | 44 | function metat.__index:greet(domain) 45 | self.try(self.tp:check("2..")) 46 | self.try(self.tp:command("EHLO", domain or _M.DOMAIN)) 47 | return socket.skip(1, self.try(self.tp:check("2.."))) 48 | end 49 | 50 | function metat.__index:mail(from) 51 | self.try(self.tp:command("MAIL", "FROM:" .. from)) 52 | return self.try(self.tp:check("2..")) 53 | end 54 | 55 | function metat.__index:rcpt(to) 56 | self.try(self.tp:command("RCPT", "TO:" .. to)) 57 | return self.try(self.tp:check("2..")) 58 | end 59 | 60 | function metat.__index:data(src, step) 61 | self.try(self.tp:command("DATA")) 62 | self.try(self.tp:check("3..")) 63 | self.try(self.tp:source(src, step)) 64 | self.try(self.tp:send("\r\n.\r\n")) 65 | return self.try(self.tp:check("2..")) 66 | end 67 | 68 | function metat.__index:quit() 69 | self.try(self.tp:command("QUIT")) 70 | return self.try(self.tp:check("2..")) 71 | end 72 | 73 | function metat.__index:close() 74 | return self.tp:close() 75 | end 76 | 77 | function metat.__index:login(user, password) 78 | self.try(self.tp:command("AUTH", "LOGIN")) 79 | self.try(self.tp:check("3..")) 80 | self.try(self.tp:send(mime.b64(user) .. "\r\n")) 81 | self.try(self.tp:check("3..")) 82 | self.try(self.tp:send(mime.b64(password) .. "\r\n")) 83 | return self.try(self.tp:check("2..")) 84 | end 85 | 86 | function metat.__index:plain(user, password) 87 | local auth = "PLAIN " .. mime.b64("\0" .. user .. "\0" .. password) 88 | self.try(self.tp:command("AUTH", auth)) 89 | return self.try(self.tp:check("2..")) 90 | end 91 | 92 | function metat.__index:auth(user, password, ext) 93 | if not user or not password then return 1 end 94 | if string.find(ext, "AUTH[^\n]+LOGIN") then 95 | return self:login(user, password) 96 | elseif string.find(ext, "AUTH[^\n]+PLAIN") then 97 | return self:plain(user, password) 98 | else 99 | self.try(nil, "authentication not supported") 100 | end 101 | end 102 | 103 | -- send message or throw an exception 104 | function metat.__index:send(mailt) 105 | self:mail(mailt.from) 106 | if base.type(mailt.rcpt) == "table" then 107 | for i,v in base.ipairs(mailt.rcpt) do 108 | self:rcpt(v) 109 | end 110 | else 111 | self:rcpt(mailt.rcpt) 112 | end 113 | self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step) 114 | end 115 | 116 | function _M.open(server, port, create) 117 | local tp = socket.try(tp.connect(server or _M.SERVER, port or _M.PORT, 118 | _M.TIMEOUT, create)) 119 | local s = base.setmetatable({tp = tp}, metat) 120 | -- make sure tp is closed if we get an exception 121 | s.try = socket.newtry(function() 122 | s:close() 123 | end) 124 | return s 125 | end 126 | 127 | -- convert headers to lowercase 128 | local function lower_headers(headers) 129 | local lower = {} 130 | for i,v in base.pairs(headers or lower) do 131 | lower[string.lower(i)] = v 132 | end 133 | return lower 134 | end 135 | 136 | --------------------------------------------------------------------------- 137 | -- Multipart message source 138 | ----------------------------------------------------------------------------- 139 | -- returns a hopefully unique mime boundary 140 | local seqno = 0 141 | local function newboundary() 142 | seqno = seqno + 1 143 | return string.format('%s%05d==%05u', os.date('%d%m%Y%H%M%S'), 144 | math.random(0, 99999), seqno) 145 | end 146 | 147 | -- send_message forward declaration 148 | local send_message 149 | 150 | -- yield the headers all at once, it's faster 151 | local function send_headers(tosend) 152 | local canonic = headers.canonic 153 | local h = "\r\n" 154 | for f,v in base.pairs(tosend) do 155 | h = (canonic[f] or f) .. ': ' .. v .. "\r\n" .. h 156 | end 157 | coroutine.yield(h) 158 | end 159 | 160 | -- yield multipart message body from a multipart message table 161 | local function send_multipart(mesgt) 162 | -- make sure we have our boundary and send headers 163 | local bd = newboundary() 164 | local headers = lower_headers(mesgt.headers or {}) 165 | headers['content-type'] = headers['content-type'] or 'multipart/mixed' 166 | headers['content-type'] = headers['content-type'] .. 167 | '; boundary="' .. bd .. '"' 168 | send_headers(headers) 169 | -- send preamble 170 | if mesgt.body.preamble then 171 | coroutine.yield(mesgt.body.preamble) 172 | coroutine.yield("\r\n") 173 | end 174 | -- send each part separated by a boundary 175 | for i, m in base.ipairs(mesgt.body) do 176 | coroutine.yield("\r\n--" .. bd .. "\r\n") 177 | send_message(m) 178 | end 179 | -- send last boundary 180 | coroutine.yield("\r\n--" .. bd .. "--\r\n\r\n") 181 | -- send epilogue 182 | if mesgt.body.epilogue then 183 | coroutine.yield(mesgt.body.epilogue) 184 | coroutine.yield("\r\n") 185 | end 186 | end 187 | 188 | -- yield message body from a source 189 | local function send_source(mesgt) 190 | -- make sure we have a content-type 191 | local headers = lower_headers(mesgt.headers or {}) 192 | headers['content-type'] = headers['content-type'] or 193 | 'text/plain; charset="iso-8859-1"' 194 | send_headers(headers) 195 | -- send body from source 196 | while true do 197 | local chunk, err = mesgt.body() 198 | if err then coroutine.yield(nil, err) 199 | elseif chunk then coroutine.yield(chunk) 200 | else break end 201 | end 202 | end 203 | 204 | -- yield message body from a string 205 | local function send_string(mesgt) 206 | -- make sure we have a content-type 207 | local headers = lower_headers(mesgt.headers or {}) 208 | headers['content-type'] = headers['content-type'] or 209 | 'text/plain; charset="iso-8859-1"' 210 | send_headers(headers) 211 | -- send body from string 212 | coroutine.yield(mesgt.body) 213 | end 214 | 215 | -- message source 216 | function send_message(mesgt) 217 | if base.type(mesgt.body) == "table" then send_multipart(mesgt) 218 | elseif base.type(mesgt.body) == "function" then send_source(mesgt) 219 | else send_string(mesgt) end 220 | end 221 | 222 | -- set defaul headers 223 | local function adjust_headers(mesgt) 224 | local lower = lower_headers(mesgt.headers) 225 | lower["date"] = lower["date"] or 226 | os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE) 227 | lower["x-mailer"] = lower["x-mailer"] or socket._VERSION 228 | -- this can't be overriden 229 | lower["mime-version"] = "1.0" 230 | return lower 231 | end 232 | 233 | function _M.message(mesgt) 234 | mesgt.headers = adjust_headers(mesgt) 235 | -- create and return message source 236 | local co = coroutine.create(function() send_message(mesgt) end) 237 | return function() 238 | local ret, a, b = coroutine.resume(co) 239 | if ret then return a, b 240 | else return nil, a end 241 | end 242 | end 243 | 244 | --------------------------------------------------------------------------- 245 | -- High level SMTP API 246 | ----------------------------------------------------------------------------- 247 | _M.send = socket.protect(function(mailt) 248 | local s = _M.open(mailt.server, mailt.port, mailt.create) 249 | local ext = s:greet(mailt.domain) 250 | s:auth(mailt.user, mailt.password, ext) 251 | s:send(mailt) 252 | s:quit() 253 | return s:close() 254 | end) 255 | 256 | return _M 257 | -------------------------------------------------------------------------------- /src/luasocket/socket/tp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Unified SMTP/FTP subsystem 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local string = require("string") 12 | local socket = require("socket.socket") 13 | local ltn12 = require("socket.ltn12") 14 | 15 | socket.tp = {} 16 | local _M = socket.tp 17 | 18 | ----------------------------------------------------------------------------- 19 | -- Program constants 20 | ----------------------------------------------------------------------------- 21 | _M.TIMEOUT = 60 22 | 23 | ----------------------------------------------------------------------------- 24 | -- Implementation 25 | ----------------------------------------------------------------------------- 26 | -- gets server reply (works for SMTP and FTP) 27 | local function get_reply(c) 28 | local code, current, sep 29 | local line, err = c:receive() 30 | local reply = line 31 | if err then return nil, err end 32 | code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) 33 | if not code then return nil, "invalid server reply" end 34 | if sep == "-" then -- reply is multiline 35 | repeat 36 | line, err = c:receive() 37 | if err then return nil, err end 38 | current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) 39 | reply = reply .. "\n" .. line 40 | -- reply ends with same code 41 | until code == current and sep == " " 42 | end 43 | return code, reply 44 | end 45 | 46 | -- metatable for sock object 47 | local metat = { __index = {} } 48 | 49 | function metat.__index:check(ok) 50 | local code, reply = get_reply(self.c) 51 | if not code then return nil, reply end 52 | if base.type(ok) ~= "function" then 53 | if base.type(ok) == "table" then 54 | for i, v in base.ipairs(ok) do 55 | if string.find(code, v) then 56 | return base.tonumber(code), reply 57 | end 58 | end 59 | return nil, reply 60 | else 61 | if string.find(code, ok) then return base.tonumber(code), reply 62 | else return nil, reply end 63 | end 64 | else return ok(base.tonumber(code), reply) end 65 | end 66 | 67 | function metat.__index:command(cmd, arg) 68 | cmd = string.upper(cmd) 69 | if arg then 70 | return self.c:send(cmd .. " " .. arg.. "\r\n") 71 | else 72 | return self.c:send(cmd .. "\r\n") 73 | end 74 | end 75 | 76 | function metat.__index:sink(snk, pat) 77 | local chunk, err = c:receive(pat) 78 | return snk(chunk, err) 79 | end 80 | 81 | function metat.__index:send(data) 82 | return self.c:send(data) 83 | end 84 | 85 | function metat.__index:receive(pat) 86 | return self.c:receive(pat) 87 | end 88 | 89 | function metat.__index:getfd() 90 | return self.c:getfd() 91 | end 92 | 93 | function metat.__index:dirty() 94 | return self.c:dirty() 95 | end 96 | 97 | function metat.__index:getcontrol() 98 | return self.c 99 | end 100 | 101 | function metat.__index:source(source, step) 102 | local sink = socket.sink("keep-open", self.c) 103 | local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step) 104 | return ret, err 105 | end 106 | 107 | -- closes the underlying c 108 | function metat.__index:close() 109 | self.c:close() 110 | return 1 111 | end 112 | 113 | -- connect with server and return c object 114 | function _M.connect(host, port, timeout, create) 115 | local c, e = (create or socket.tcp)() 116 | if not c then return nil, e end 117 | c:settimeout(timeout or _M.TIMEOUT) 118 | local r, e = c:connect(host, port) 119 | if not r then 120 | c:close() 121 | return nil, e 122 | end 123 | return base.setmetatable({c = c}, metat) 124 | end 125 | 126 | return _M 127 | -------------------------------------------------------------------------------- /src/main.lua: -------------------------------------------------------------------------------- 1 | 2 | cc.FileUtils:getInstance():setPopupNotify(false) 3 | 4 | require "config" 5 | require "cocos.init" 6 | 7 | local isImportlpack = true 8 | xpcall(function() 9 | require("pack") 10 | end, function() 11 | local msg = "请在cocos引擎中导入lpack模块 !!" 12 | isImportlpack = false 13 | __G__TRACKBACK__(msg) 14 | end) 15 | 16 | if not isImportlpack then 17 | return 18 | end 19 | 20 | require "network.NetMgr" 21 | 22 | local function main() 23 | require("app.MyApp"):create():run() 24 | end 25 | 26 | local status, msg = xpcall(main, __G__TRACKBACK__) 27 | if not status then 28 | print(msg) 29 | end 30 | -------------------------------------------------------------------------------- /src/network/NetMgr.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 应用层的心跳检测请自行实现 3 | 如果有多个长连接的,单利模式去掉,new新的就行了 4 | 具体的封装自行实现,这里都只是给出一个简单的例子 5 | Author: EricDDK 6 | ]] 7 | 8 | -- 'z' /* zero-terminated string */ 空字符串 9 | -- 'p' /* string preceded by length byte */ 长度小于2^8的字符串 10 | -- 'P' /* string preceded by length word */ 长度小于2^16的字符串 11 | -- 'a' /* string preceded by length size_t */ 长度小于2^32/64的字符串 12 | -- 'A' /* string */ 指定长度字符串 13 | -- 'f' /* float */ float 4字节 14 | -- 'd' /* double */ double 8字节 15 | -- 'n' /* Lua number */ lua的number,是double 16 | -- 'c' /* char */ 1字节 17 | -- 'b' /* byte = unsigned char */ 1字节 18 | -- 'h' /* short */ 2字节 19 | -- 'H' /* unsigned short */ 2字节 20 | -- 'i' /* int */ 4字节 21 | -- 'I' /* unsigned int */ 4字节 22 | -- 'l' /* long */ 这里是long,4字节,但是我修改为了long long 在C中,这样就可以处理8字节的内容了 23 | -- 'L' /* unsigned long*/ 同上 24 | -- '<' /* little endian */ 小端字节序 25 | -- '>' /* big endian */ 大端字节序 26 | -- '=' /* native endian */ 27 | 28 | local NetMgr = class("NetMgr") 29 | 30 | local socket = require("luasocket.socket") 31 | local scheduler = cc.Director:getInstance():getScheduler() 32 | 33 | local CHECK_SELECT_INTERVAL = 0.05 -- 定时器检测间隔时间 34 | 35 | --[[ 36 | 构造函数 37 | ]] 38 | function NetMgr:ctor() 39 | self._isConnected = false -- 标识符是否已经连接 40 | self._sendTaskQueue = {} -- 发送消息队列 41 | end 42 | 43 | --[[ 44 | 单利模式 45 | @return: NetMgr实例 46 | ]] 47 | function NetMgr:getInstance() 48 | if not self.instance_ then 49 | self.instance_ = NetMgr:new() 50 | end 51 | return self.instance_ 52 | end 53 | 54 | --[[ 55 | 外部调用入口,发起长连接请求 56 | @param: ip ip地址 57 | @param: port 端口号 58 | ]] 59 | function NetMgr:connect(ip, port) 60 | print("[NetMgr:connect] ip, port = ", ip, port) 61 | self._ip = ip 62 | self._port = port 63 | self._socket = socket.tcp() -- socket 对象 64 | self._socket:settimeout(0) -- 非阻塞 65 | self._socket:setoption("tcp-nodelay", true) -- 去掉优化 66 | self._socket:connect(self._ip, self._port) -- 链接 67 | 68 | -- 定时器回调函数,每CHECK_SELECT_INTERVAL秒执行一次,直到连接发现断开 69 | local function checkConnect(dt) 70 | print("[NetMgr:connect] => checkConnect") 71 | if self:isConnected() then 72 | self._isConnected = true 73 | scheduler:unscheduleScriptEntry(self._schedulerID) 74 | self._processID = scheduler:scheduleScriptFunc( 75 | function(...) 76 | -- 这里是尝试读取socket 77 | self:disposeTCPIO() 78 | end, 79 | CHECK_SELECT_INTERVAL, 80 | false 81 | ) 82 | end 83 | end 84 | self._schedulerID = scheduler:scheduleScriptFunc(checkConnect, CHECK_SELECT_INTERVAL, false) 85 | end 86 | 87 | --[[ 88 | 停止发送接受socket 89 | @param: 90 | @return: 91 | ]] 92 | function NetMgr:stop() 93 | scheduler:unscheduleScriptEntry(self._processID) 94 | end 95 | 96 | --[[ 97 | 判断是否连接着 98 | @param: 99 | @return: 100 | ]] 101 | function NetMgr:isConnected() 102 | local forWrite = {} 103 | table.insert(forWrite, self._socket) 104 | local readyForWrite 105 | _, readyForWrite, _ = socket.select(nil, forWrite, 0) 106 | if #readyForWrite > 0 then 107 | return true 108 | end 109 | return false 110 | end 111 | 112 | --[[ 113 | 处理socket 114 | @param: 115 | @return: 116 | ]] 117 | function NetMgr:disposeTCPIO() 118 | if not self._isConnected then 119 | return 120 | end 121 | self:disposeReceiveTask() 122 | self:disposeSendTask() 123 | end 124 | 125 | --[[ 126 | 处理接受任务 127 | @param: 128 | @return: 129 | ]] 130 | function NetMgr:disposeReceiveTask() 131 | --检测是否有可读的socket 132 | local recvt, sendt, status = socket.select({self._socket}, nil, 0) 133 | print("[NetMgr:disposeReceiveTask] = ", #recvt, sendt, status) 134 | if #recvt <= 0 then 135 | return 136 | end 137 | -- 根据我们的服务器定义,包头2字节,是包的长度,为了处理粘包拆包等问题 138 | local buffer = self._socket:receive(2) 139 | -- 如果有2个字节的包头,那么说明有socket需要读取 140 | if buffer then 141 | -- 分别读取第一个,和第二个字节,从左往右的读取 142 | local first, sencond = string.byte(buffer, 1, 2) 143 | -- 这里因为服务端是是小端字节序,所以是first + second * 256 144 | -- 如果服务端是大端字节序,就是first * 256 + second 145 | -- 如果是4字节就往下写就行了 146 | local len = first + sencond * 256 147 | -- 获取到整个包的内容,与头部拼接 148 | buffer = buffer .. self._socket:receive(len + 2) 149 | -- 获取 protocolID ,第三个字节开始到第六个字节我们定义的是协议号,这些都可以随意修改 150 | -- 解释下为什么是 153 | if true then 154 | -- event是要接受的结构体构造 155 | local event = { 156 | name = "test_111", 157 | password = "csd131edfs", 158 | version = 25, 159 | key = "12dsacdss", 160 | } 161 | local len, head, protocolID, name, password, key, version = string.unpack(buffer, " 1 then 23 | dump(self.configs_, "AppBase configs") 24 | end 25 | 26 | if CC_SHOW_FPS then 27 | cc.Director:getInstance():setDisplayStats(true) 28 | end 29 | 30 | -- event 31 | self:onCreate() 32 | end 33 | 34 | function AppBase:run(initSceneName) 35 | initSceneName = initSceneName or self.configs_.defaultSceneName 36 | self:enterScene(initSceneName) 37 | end 38 | 39 | function AppBase:enterScene(sceneName, transition, time, more) 40 | local view = self:createView(sceneName) 41 | view:showWithScene(transition, time, more) 42 | return view 43 | end 44 | 45 | function AppBase:createView(name) 46 | for _, root in ipairs(self.configs_.viewsRoot) do 47 | local packageName = string.format("%s.%s", root, name) 48 | local status, view = xpcall(function() 49 | return require(packageName) 50 | end, function(msg) 51 | if not string.find(msg, string.format("'%s' not found:", packageName)) then 52 | print("load view error: ", msg) 53 | end 54 | end) 55 | local t = type(view) 56 | if status and (t == "table" or t == "userdata") then 57 | return view:create(self, name) 58 | end 59 | end 60 | error(string.format("AppBase:createView() - not found view \"%s\" in search paths \"%s\"", 61 | name, table.concat(self.configs_.viewsRoot, ",")), 0) 62 | end 63 | 64 | function AppBase:onCreate() 65 | end 66 | 67 | return AppBase 68 | -------------------------------------------------------------------------------- /src/packages/mvc/ViewBase.lua: -------------------------------------------------------------------------------- 1 | 2 | local ViewBase = class("ViewBase", cc.Node) 3 | 4 | function ViewBase:ctor(app, name) 5 | self:enableNodeEvents() 6 | self.app_ = app 7 | self.name_ = name 8 | 9 | -- check CSB resource file 10 | local res = rawget(self.class, "RESOURCE_FILENAME") 11 | if res then 12 | self:createResourceNode(res) 13 | end 14 | 15 | local binding = rawget(self.class, "RESOURCE_BINDING") 16 | if res and binding then 17 | self:createResourceBinding(binding) 18 | end 19 | 20 | if self.onCreate then self:onCreate() end 21 | end 22 | 23 | function ViewBase:getApp() 24 | return self.app_ 25 | end 26 | 27 | function ViewBase:getName() 28 | return self.name_ 29 | end 30 | 31 | function ViewBase:getResourceNode() 32 | return self.resourceNode_ 33 | end 34 | 35 | function ViewBase:createResourceNode(resourceFilename) 36 | if self.resourceNode_ then 37 | self.resourceNode_:removeSelf() 38 | self.resourceNode_ = nil 39 | end 40 | self.resourceNode_ = cc.CSLoader:createNode(resourceFilename) 41 | assert(self.resourceNode_, string.format("ViewBase:createResourceNode() - load resouce node from file \"%s\" failed", resourceFilename)) 42 | self:addChild(self.resourceNode_) 43 | end 44 | 45 | function ViewBase:createResourceBinding(binding) 46 | assert(self.resourceNode_, "ViewBase:createResourceBinding() - not load resource node") 47 | for nodeName, nodeBinding in pairs(binding) do 48 | local node = self.resourceNode_:getChildByName(nodeName) 49 | if nodeBinding.varname then 50 | self[nodeBinding.varname] = node 51 | end 52 | for _, event in ipairs(nodeBinding.events or {}) do 53 | if event.event == "touch" then 54 | node:onTouch(handler(self, self[event.method])) 55 | end 56 | end 57 | end 58 | end 59 | 60 | function ViewBase:showWithScene(transition, time, more) 61 | self:setVisible(true) 62 | local scene = display.newScene(self.name_) 63 | scene:addChild(self) 64 | display.runScene(scene, transition, time, more) 65 | return self 66 | end 67 | 68 | return ViewBase 69 | -------------------------------------------------------------------------------- /src/packages/mvc/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local _M = {} 3 | 4 | _M.AppBase = import(".AppBase") 5 | _M.ViewBase = import(".ViewBase") 6 | 7 | return _M 8 | --------------------------------------------------------------------------------