|
| 1 | + |
| 2 | +local simpleList = { |
| 3 | + {id="demo1_id", text="<b>One Demo</b> <br/> <img src=:/QuickIcon.png</img>", args=""}, |
| 4 | + {id="demo2_id", text="<b>Two Demo</b> <br/> <img src=:/QuickIcon.png</img>", args=""}, |
| 5 | +} |
| 6 | + |
| 7 | +-- string.split() |
| 8 | + |
| 9 | +function lua_string_split(s, p) |
| 10 | + local rt= {} |
| 11 | + string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end ) |
| 12 | + return rt |
| 13 | +end |
| 14 | + |
| 15 | +-- helper |
| 16 | + |
| 17 | +-- @return -p @packageName -f -r portrait -o @projectPath |
| 18 | +function GET_CREATE_PROJECT_COMMAND_ARGS( projectPath, packageName, isPortrait ) |
| 19 | + local screen = (isPortrait and " -r portrait") or " -r landscape" |
| 20 | + |
| 21 | + local cmd = "-f -p "..packageName..screen.." -o "..projectPath |
| 22 | + return cmd, " " |
| 23 | +end |
| 24 | + |
| 25 | +function GET_QUICK_SIMPLES() |
| 26 | + return json.encode(simpleList) |
| 27 | +end |
| 28 | + |
| 29 | +-- core |
| 30 | + |
| 31 | +local core = {} |
| 32 | +function core.openDemo( demoId ) |
| 33 | + QT_INTERFACE("core.openProject") |
| 34 | +end |
| 35 | + |
| 36 | +function core.login( data ) |
| 37 | + user = json.decode(data) |
| 38 | + print(user.user..user.pwd) |
| 39 | +end |
| 40 | + |
| 41 | +function core.positionNofity(name) |
| 42 | + local notificationCenter = CCNotificationCenter:sharedNotificationCenter() |
| 43 | + notificationCenter:postNotification(name) |
| 44 | +end |
| 45 | + |
| 46 | + |
| 47 | +-- player : register submodule |
| 48 | + |
| 49 | +local PLAYER = {core=core} |
| 50 | + |
| 51 | +-- interface for player |
| 52 | + |
| 53 | +function LUA_Interface(messageId, messageData) |
| 54 | + local messageList = lua_string_split(messageId, ".") |
| 55 | + local messageSize = #messageList; |
| 56 | + |
| 57 | + if messageSize == 1 then |
| 58 | + PLAYER[messageId](messageData) |
| 59 | + else |
| 60 | + local object = PLAYER[messageList[1]] |
| 61 | + for i=2, messageSize-1 do |
| 62 | + object = object[messageList[i]] |
| 63 | + i=i+1 |
| 64 | + end |
| 65 | + local functionName = messageList[messageSize] |
| 66 | + |
| 67 | + object[functionName](messageData) |
| 68 | + end |
| 69 | + |
| 70 | +end |
| 71 | + |
| 72 | +-- init |
| 73 | +function __QT_INIT() |
| 74 | + local notificationCenter = CCNotificationCenter:sharedNotificationCenter() |
| 75 | + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.newProject") end, "WELCOME_NEW_PROJECT") |
| 76 | + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openProject") end, "WELCOME_OPEN_PROJECT") |
| 77 | + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openDemo") end, "WELCOME_LIST_SAMPLES") |
| 78 | + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openURL", "http://quick.cocoachina.com/wiki/doku.php?id=zh_cn") end,"WELCOME_OPEN_COMMUNITY") |
| 79 | + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openURL", "http://quick.cocoachina.com/wiki/doku.php?id=zh_cn") end,"WELCOME_OPEN_DOCUMENTS") |
| 80 | +end |
| 81 | + |
| 82 | +__QT_INIT() |
0 commit comments