diff --git a/player/mac/quick-x-player.app/Contents/MacOS/bridge.lua b/player/mac/quick-x-player.app/Contents/MacOS/bridge.lua new file mode 100644 index 000000000..c4fafb41d --- /dev/null +++ b/player/mac/quick-x-player.app/Contents/MacOS/bridge.lua @@ -0,0 +1,82 @@ + +local simpleList = { + {id="demo1_id", text="One Demo
", args=""}, + {id="demo2_id", text="Two Demo
", args=""}, +} + +-- string.split() + +function lua_string_split(s, p) + local rt= {} + string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end ) + return rt +end + +-- helper + +-- @return -p @packageName -f -r portrait -o @projectPath +function GET_CREATE_PROJECT_COMMAND_ARGS( projectPath, packageName, isPortrait ) + local screen = (isPortrait and " -r portrait") or " -r landscape" + + local cmd = "-f -p "..packageName..screen.." -o "..projectPath + return cmd, " " +end + +function GET_QUICK_SIMPLES() + return json.encode(simpleList) +end + +-- core + +local core = {} +function core.openDemo( demoId ) + QT_INTERFACE("core.openProject") +end + +function core.login( data ) + user = json.decode(data) + print(user.user..user.pwd) +end + +function core.positionNofity(name) + local notificationCenter = CCNotificationCenter:sharedNotificationCenter() + notificationCenter:postNotification(name) +end + + +-- player : register submodule + +local PLAYER = {core=core} + +-- interface for player + +function LUA_Interface(messageId, messageData) + local messageList = lua_string_split(messageId, ".") + local messageSize = #messageList; + + if messageSize == 1 then + PLAYER[messageId](messageData) + else + local object = PLAYER[messageList[1]] + for i=2, messageSize-1 do + object = object[messageList[i]] + i=i+1 + end + local functionName = messageList[messageSize] + + object[functionName](messageData) + end + +end + +-- init +function __QT_INIT() + local notificationCenter = CCNotificationCenter:sharedNotificationCenter() + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.newProject") end, "WELCOME_NEW_PROJECT") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openProject") end, "WELCOME_OPEN_PROJECT") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openDemo") end, "WELCOME_LIST_SAMPLES") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openURL", "http://quick.cocoachina.com/wiki/doku.php?id=zh_cn") end,"WELCOME_OPEN_COMMUNITY") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openURL", "http://quick.cocoachina.com/wiki/doku.php?id=zh_cn") end,"WELCOME_OPEN_DOCUMENTS") +end + +__QT_INIT() diff --git a/player/mac/quick-x-player.app/Contents/MacOS/quick-x-player b/player/mac/quick-x-player.app/Contents/MacOS/quick-x-player index 94e7ae447..f729e67f5 100755 Binary files a/player/mac/quick-x-player.app/Contents/MacOS/quick-x-player and b/player/mac/quick-x-player.app/Contents/MacOS/quick-x-player differ diff --git a/player/win/bridge.lua b/player/win/bridge.lua new file mode 100644 index 000000000..a6a1e03f4 --- /dev/null +++ b/player/win/bridge.lua @@ -0,0 +1,82 @@ + +local simpleList = { + {id="demo1_id", text="One Demo
", args=""}, + {id="demo2_id", text="Two Demo
", args=""}, +} + +-- string.split() + +function lua_string_split(s, p) + local rt= {} + string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end ) + return rt +end + +-- helper + +-- @return -p @packageName -f -r portrait -o @projectPath +function GET_CREATE_PROJECT_COMMAND_ARGS( projectPath, packageName, isPortrait ) + local screen = (isPortrait and " -r portrait") or " -r landscape" + + local cmd = "-f -p "..packageName..screen.." -o "..projectPath + return cmd, " " +end + +function GET_QUICK_SIMPLES() + return json.encode(simpleList) +end + +-- core + +local core = {} +function core.openDemo( demoId ) + QT_INTERFACE("core.openProject") +end + +function core.login( data ) + user = json.decode(data) + print(user.user..user.pwd) +end + +function core.positionNofity(name) + local notificationCenter = CCNotificationCenter:sharedNotificationCenter() + notificationCenter:postNotification(name) +end + + +-- player : register submodule + +local PLAYER = {core=core} + +-- interface for player + +function LUA_Interface(messageId, messageData) + local messageList = lua_string_split(messageId, ".") + local messageSize = #messageList; + + if messageSize == 1 then + PLAYER[messageId](messageData) + else + local object = PLAYER[messageList[1]] + for i=2, messageSize-1 do + object = object[messageList[i]] + i=i+1 + end + local functionName = messageList[messageSize] + + object[functionName](messageData) + end + +end + +-- init +function __QT_INIT() + local notificationCenter = CCNotificationCenter:sharedNotificationCenter() + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.newProject") end, "WELCOME_NEW_PROJECT") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openProject") end, "WELCOME_OPEN_PROJECT") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openDemo") end, "WELCOME_LIST_SAMPLES") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openURL", "http://quick.cocoachina.com/wiki/doku.php?id=zh_cn") end,"WELCOME_OPEN_COMMUNITY") + notificationCenter:registerScriptObserver(nil, function() QT_INTERFACE("core.openURL", "http://quick.cocoachina.com/wiki/doku.php?id=zh_cn") end,"WELCOME_OPEN_DOCUMENTS") +end + +__QT_INIT() diff --git a/player/win/quick-x-player.exe b/player/win/quick-x-player.exe index 6f0ef4449..8157e0b33 100644 Binary files a/player/win/quick-x-player.exe and b/player/win/quick-x-player.exe differ