您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

108 行
2.8 KiB

  1. local M = {};
  2. M.KeyEventMap = {
  3. [44] = {func = "changeFrameSize", params = {width = 1280 * 0.6, height = 720 * 0.6}}, -- F1 切换至正常分辨率
  4. [45] = {func = "changeFrameSize", params = {width = 2436 * 0.4, height = 1125 * 0.4}}, -- F2 切换至iPhoneX
  5. [46] = {func = "changeFrameSize", params = {width = 2732 * 0.3, height = 2048 * 0.3}}, -- F3 切换至iPad
  6. [48] = {func = "restartGame", params = {}}, -- F5 重启游戏
  7. [49] = {func = "openLogFile", params = {}}, -- F6 打开日志文件
  8. [50] = {func = "showLogLocation", params = {}}, -- F7 定位到日志文件
  9. [52] = {func = "clearGameCache", params = {}}, -- F9 清除游戏缓存
  10. }
  11. M.init = function ()
  12. local listener = cc.EventListenerKeyboard:create(M.onKeyPressed , M.onKeyReleased);
  13. cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(listener, 1)
  14. end
  15. M.changeFrameSize = function (params)
  16. local director = cc.Director:getInstance();
  17. local glview = director:getOpenGLView();
  18. if glview then
  19. glview:setFrameSize(params.width, params.height)
  20. cc.Application:getInstance():restart();
  21. end
  22. end
  23. M.openLogFile = function ()
  24. local logPath = cc.Logger:getLogFile() -- 文件打印路径
  25. local isExist = cc.FileSystem:fileExists(logPath)
  26. if not isExist then
  27. showTooltip('log文件不存在')
  28. return
  29. end
  30. os.execute('start explorer file:\\\\\\' .. logPath)
  31. end
  32. M.showLogLocation = function ()
  33. local logPath = cc.Logger:getLogFile() -- 文件打印路径
  34. local isExist = cc.FileSystem:fileExists(logPath)
  35. if not isExist then
  36. showTooltip('log文件不存在')
  37. return
  38. end
  39. os.execute('start explorer /select,file:\\\\\\' .. logPath)
  40. end
  41. M.restartGame = function ()
  42. cc.SpriteFrameCache:getInstance():removeSpriteFrames()
  43. cc.TextureCache:getInstance():removeUnusedTextures()
  44. package.loaded = {}
  45. cc.Application:getInstance():restart();
  46. end
  47. M.onKeyPressed = function (keyCode, event)
  48. if keyCode < 44 or keyCode > 54 then
  49. return
  50. end
  51. local cfg = M.KeyEventMap[keyCode]
  52. if not cfg then
  53. showTooltip("快捷键未配置")
  54. return
  55. end
  56. if type(M[cfg.func]) == "function" then
  57. M[cfg.func](cfg.params)
  58. end
  59. end
  60. M.onKeyReleased = function ()
  61. end
  62. M.clearGameCache = function ()
  63. M.clearCache({
  64. "mj",
  65. "pk",
  66. "zp",
  67. "luaScript.Config.SubGame",
  68. "luaScript.SubGameDefine",
  69. "luaScript.SubGameFunctions",
  70. "luaScript.Views.Club",
  71. "luaScriptPengHu",
  72. "luaScriptSanRenXing",
  73. "hongzhong",
  74. "luaScript.startup",
  75. })
  76. end
  77. M.clearCache = function (paths)
  78. if not paths then return end
  79. local clearList = type(paths) == "string" and {paths} or paths
  80. for _, path in pairs(clearList or {}) do
  81. for k, __ in pairs(package.loaded or {}) do
  82. local res = string.find( k, path) or 0
  83. if res > 0 then
  84. package.loaded[k] = nil
  85. end
  86. end
  87. end
  88. end
  89. M.init()
  90. return M;