|
-
- local M = {};
-
- M.KeyEventMap = {
- [44] = {func = "changeFrameSize", params = {width = 1280 * 0.6, height = 720 * 0.6}}, -- F1 切换至正常分辨率
- [45] = {func = "changeFrameSize", params = {width = 2436 * 0.4, height = 1125 * 0.4}}, -- F2 切换至iPhoneX
- [46] = {func = "changeFrameSize", params = {width = 2732 * 0.3, height = 2048 * 0.3}}, -- F3 切换至iPad
- [48] = {func = "restartGame", params = {}}, -- F5 重启游戏
- [49] = {func = "openLogFile", params = {}}, -- F6 打开日志文件
- [50] = {func = "showLogLocation", params = {}}, -- F7 定位到日志文件
- [52] = {func = "clearGameCache", params = {}}, -- F9 清除游戏缓存
- }
-
- M.init = function ()
- local listener = cc.EventListenerKeyboard:create(M.onKeyPressed , M.onKeyReleased);
- cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(listener, 1)
- end
-
- M.changeFrameSize = function (params)
- local director = cc.Director:getInstance();
- local glview = director:getOpenGLView();
- if glview then
- glview:setFrameSize(params.width, params.height)
- cc.Application:getInstance():restart();
- end
- end
-
- M.openLogFile = function ()
- local logPath = cc.Logger:getLogFile() -- 文件打印路径
- local isExist = cc.FileSystem:fileExists(logPath)
- if not isExist then
- showTooltip('log文件不存在')
- return
- end
-
- os.execute('start explorer file:\\\\\\' .. logPath)
- end
-
- M.showLogLocation = function ()
- local logPath = cc.Logger:getLogFile() -- 文件打印路径
- local isExist = cc.FileSystem:fileExists(logPath)
- if not isExist then
- showTooltip('log文件不存在')
- return
- end
-
- os.execute('start explorer /select,file:\\\\\\' .. logPath)
- end
-
- M.restartGame = function ()
- cc.SpriteFrameCache:getInstance():removeSpriteFrames()
- cc.TextureCache:getInstance():removeUnusedTextures()
- package.loaded = {}
- cc.Application:getInstance():restart();
- end
-
- M.onKeyPressed = function (keyCode, event)
- if keyCode < 44 or keyCode > 54 then
- return
- end
-
- local cfg = M.KeyEventMap[keyCode]
- if not cfg then
- showTooltip("快捷键未配置")
- return
- end
- if type(M[cfg.func]) == "function" then
- M[cfg.func](cfg.params)
- end
- end
-
- M.onKeyReleased = function ()
-
- end
-
- M.clearGameCache = function ()
- M.clearCache({
- "mj",
- "pk",
- "zp",
- "luaScript.Config.SubGame",
- "luaScript.SubGameDefine",
- "luaScript.SubGameFunctions",
- "luaScript.Views.Club",
- "luaScriptPengHu",
- "luaScriptSanRenXing",
- "hongzhong",
- "luaScript.startup",
- })
- end
-
- M.clearCache = function (paths)
- if not paths then return end
-
- local clearList = type(paths) == "string" and {paths} or paths
- for _, path in pairs(clearList or {}) do
- for k, __ in pairs(package.loaded or {}) do
- local res = string.find( k, path) or 0
- if res > 0 then
- package.loaded[k] = nil
- end
- end
- end
- end
-
- M.init()
-
- return M;
|