device.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --[[
  2. Copyright (c) 2011-2014 chukong-inc.com
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. ]]
  19. local device = {}
  20. device.platform = "unknown"
  21. device.model = "unknown"
  22. local app = cc.Application:getInstance()
  23. local target = app:getTargetPlatform()
  24. if target == cc.PLATFORM_OS_WINDOWS then
  25. device.platform = "windows"
  26. elseif target == cc.PLATFORM_OS_MAC then
  27. device.platform = "mac"
  28. elseif target == cc.PLATFORM_OS_ANDROID then
  29. device.platform = "android"
  30. elseif target == cc.PLATFORM_OS_IPHONE or target == cc.PLATFORM_OS_IPAD then
  31. device.platform = "ios"
  32. local director = cc.Director:getInstance()
  33. local view = director:getOpenGLView()
  34. local framesize = view:getFrameSize()
  35. local w, h = framesize.width, framesize.height
  36. if w == 640 and h == 960 then
  37. device.model = "iphone 4"
  38. elseif w == 640 and h == 1136 then
  39. device.model = "iphone 5"
  40. elseif w == 750 and h == 1334 then
  41. device.model = "iphone 6"
  42. elseif w == 1242 and h == 2208 then
  43. device.model = "iphone 6 plus"
  44. elseif w == 768 and h == 1024 then
  45. device.model = "ipad"
  46. elseif w == 1536 and h == 2048 then
  47. device.model = "ipad retina"
  48. end
  49. elseif target == cc.PLATFORM_OS_WINRT then
  50. device.platform = "winrt"
  51. elseif target == cc.PLATFORM_OS_WP8 then
  52. device.platform = "wp8"
  53. end
  54. local language_ = app:getCurrentLanguage()
  55. if language_ == cc.LANGUAGE_CHINESE then
  56. language_ = "cn"
  57. elseif language_ == cc.LANGUAGE_FRENCH then
  58. language_ = "fr"
  59. elseif language_ == cc.LANGUAGE_ITALIAN then
  60. language_ = "it"
  61. elseif language_ == cc.LANGUAGE_GERMAN then
  62. language_ = "gr"
  63. elseif language_ == cc.LANGUAGE_SPANISH then
  64. language_ = "sp"
  65. elseif language_ == cc.LANGUAGE_RUSSIAN then
  66. language_ = "ru"
  67. elseif language_ == cc.LANGUAGE_KOREAN then
  68. language_ = "kr"
  69. elseif language_ == cc.LANGUAGE_JAPANESE then
  70. language_ = "jp"
  71. elseif language_ == cc.LANGUAGE_HUNGARIAN then
  72. language_ = "hu"
  73. elseif language_ == cc.LANGUAGE_PORTUGUESE then
  74. language_ = "pt"
  75. elseif language_ == cc.LANGUAGE_ARABIC then
  76. language_ = "ar"
  77. else
  78. language_ = "en"
  79. end
  80. device.language = language_
  81. device.writablePath = cc.FileUtils:getInstance():getWritablePath()
  82. device.directorySeparator = "/"
  83. device.pathSeparator = ":"
  84. if device.platform == "windows" then
  85. device.directorySeparator = "\\"
  86. device.pathSeparator = ";"
  87. end
  88. printInfo("# device.platform = " .. device.platform)
  89. printInfo("# device.model = " .. device.model)
  90. printInfo("# device.language = " .. device.language)
  91. printInfo("# device.writablePath = " .. device.writablePath)
  92. printInfo("# device.directorySeparator = " .. device.directorySeparator)
  93. printInfo("# device.pathSeparator = " .. device.pathSeparator)
  94. printInfo("#")
  95. return device