├── .gitignore ├── .laya ├── compile.js ├── launch.json └── publish.js ├── README.md ├── YKFrame.laya ├── bin ├── fileconfig.json ├── game.js ├── game.json ├── index.html ├── index.js ├── js │ ├── bundle.js │ └── ykLib.js ├── libs │ ├── bytebuffer.js │ ├── domparserinone.js │ ├── fairygui │ │ ├── fairygui.js │ │ └── fairygui.min.js │ ├── laya.ani.js │ ├── laya.bdmini.js │ ├── laya.core.js │ ├── laya.d3.js │ ├── laya.d3Plugin.js │ ├── laya.debugtool.js │ ├── laya.device.js │ ├── laya.effect.js │ ├── laya.filter.js │ ├── laya.html.js │ ├── laya.particle.js │ ├── laya.pathfinding.js │ ├── laya.physics.js │ ├── laya.physics3D.js │ ├── laya.physics3D.runtime.js │ ├── laya.physics3D.wasm.js │ ├── laya.physics3D.wasm.wasm │ ├── laya.tiledmap.js │ ├── laya.ui.js │ ├── laya.webgl.js │ ├── laya.wxmini.js │ ├── rawinflate │ │ └── rawinflate.min.js │ └── worker.js ├── project.config.json ├── project.swan.json ├── res │ ├── external │ │ ├── BasePack.bin │ │ ├── BasePack_atlas0.png │ │ ├── GamePack.bin │ │ ├── GamePack_atlas0.png │ │ ├── LoginPack.bin │ │ ├── MainPack.bin │ │ └── MainPack_atlas0.png │ ├── pb │ │ └── NetPack.proto │ └── source │ │ ├── Loading.bin │ │ ├── Loading_atlas0.png │ │ └── Loading_atlas_vckm32.jpg ├── swan-game-adapter.js ├── version.json └── weapp-adapter.js ├── laya ├── .laya ├── assets │ └── comp │ │ ├── blank.png │ │ ├── btn_close.png │ │ ├── button.png │ │ ├── checkbox.png │ │ ├── clip_num.png │ │ ├── clip_selectBox.png │ │ ├── clip_tree_arrow.png │ │ ├── clip_tree_folder.png │ │ ├── combobox.png │ │ ├── hscroll$bar.png │ │ ├── hscroll$down.png │ │ ├── hscroll$up.png │ │ ├── hscroll.png │ │ ├── hslider$bar.png │ │ ├── hslider.png │ │ ├── html.png │ │ ├── image.png │ │ ├── img_bg.png │ │ ├── label.png │ │ ├── linkbutton.png │ │ ├── progress$bar.png │ │ ├── progress.png │ │ ├── radio.png │ │ ├── radiogroup.png │ │ ├── tab.png │ │ ├── textarea.png │ │ ├── textinput.png │ │ ├── vscroll$bar.png │ │ ├── vscroll$down.png │ │ ├── vscroll$up.png │ │ ├── vscroll.png │ │ ├── vslider$bar.png │ │ └── vslider.png └── ignore.cfg ├── libs ├── LayaAir.d.ts ├── fairygui.d.ts └── wx.d.ts ├── protobuf ├── bundles │ ├── protobuf-bundles.d.ts │ ├── protobuf-bundles.js │ └── protobuf-bundles.min.js ├── library │ ├── protobuf-library.d.ts │ ├── protobuf-library.js │ └── protobuf-library.min.js ├── pbconfig.json └── protofile │ └── awesome.proto ├── src ├── Game │ ├── Defs │ │ ├── EventDef.ts │ │ └── ProtocolDef.ts │ ├── Modes │ │ ├── DDZLogic.ts │ │ └── RoleMode.ts │ ├── Scenes │ │ ├── LoadingScene.ts │ │ ├── LoginScene.ts │ │ └── MainScene.ts │ └── Winds │ │ ├── GamePlay │ │ ├── CardItem.ts │ │ └── CardMgr.ts │ │ ├── LoadingWind.ts │ │ ├── LoginWind.ts │ │ ├── MainWind.ts │ │ ├── MessageBox.ts │ │ └── WaitWind.ts ├── GameConfig.ts ├── Main.ts └── YKFarmework │ ├── EventMgr │ ├── DispatchEventNode.ts │ └── EventListenerMgr.ts │ ├── ModeMgr │ └── ModeMgr.ts │ ├── Net │ ├── NetMgr.ts │ ├── PackBase.ts │ ├── ProtoMap.ts │ └── ResponseMessageEvent.ts │ ├── ResMgr │ └── ResMgr.ts │ ├── SceneMgr │ ├── SceneBase.ts │ └── SceneMgr.ts │ ├── Task │ └── TaskBase.ts │ ├── UIMgr │ └── UIMgr.ts │ └── Util │ ├── GameFlag.ts │ ├── Log.ts │ └── TimeDelay.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | \.laya/chrome/ 3 | -------------------------------------------------------------------------------- /.laya/compile.js: -------------------------------------------------------------------------------- 1 | // v1.0.0 2 | //是否使用IDE自带的node环境和插件,设置false后,则使用自己环境(使用命令行方式执行) 3 | let useIDENode = process.argv[0].indexOf("LayaAir") > -1 ? true : false; 4 | //获取Node插件和工作路径 5 | let ideModuleDir = useIDENode ? process.argv[1].replace("gulp\\bin\\gulp.js", "").replace("gulp/bin/gulp.js", "") : ""; 6 | let workSpaceDir = useIDENode ? process.argv[2].replace("--gulpfile=", "").replace("\\.laya\\compile.js", "").replace("/.laya/compile.js", "") : "./../"; 7 | 8 | //引用插件模块 9 | let gulp = require(ideModuleDir + "gulp"); 10 | let browserify = require(ideModuleDir + "browserify"); 11 | let source = require(ideModuleDir + "vinyl-source-stream"); 12 | let tsify = require(ideModuleDir + "tsify"); 13 | 14 | 15 | // 如果是发布时调用编译功能,增加prevTasks 16 | let prevTasks = ""; 17 | if (global.publish) { 18 | prevTasks = ["loadConfig"]; 19 | } 20 | 21 | //===== zys 22 | //自己全局安装的插件 23 | // let gutil = require(ideModuleDir + "gulp-util"); 24 | // // let babel = require("C:\\Users\\zys\\AppData\\Roaming\\npm\\node_modules\\"+ "gulp-babel"); 25 | // let ts = require("C:\\Users\\zys\\AppData\\Roaming\\npm\\node_modules\\"+ "gulp-typescript"); 26 | // let uglify = require( ideModuleDir + "gulp-uglify"); 27 | 28 | // // gutil.log(gutil.colors.red('[log]'), "ideModuleDir is " + ideModuleDir); 29 | 30 | // // gutil.log(gutil.colors.red('[log]'), "start yk " + workSpaceDir); 31 | // console.log("start yk complie"); 32 | // gulp.task("yk", prevTasks, function () { 33 | // // gutil.log(gutil.colors.red('[log]'), "start yk compile"); 34 | // return gulp.src([ 35 | // workSpaceDir + "/libs/*.d.ts", 36 | // workSpaceDir + "/protobuf/**/*.d.ts", 37 | // //如果需要加入 配置库 文件 38 | // workSpaceDir + "/src/YKFarmework/**/*.ts"]) 39 | // .pipe(ts({ 40 | // noImplicitAny: false, 41 | // outFile: "ykLib.js", 42 | // target: "es6", 43 | // lib: ["es6", "dom"], 44 | // removeComments: true, 45 | // })) 46 | // // .pipe(babel({ 47 | // // presets: ['es2015'] 48 | // // })) 49 | // // .pipe(uglify()) 50 | // .on('error', function (err) { 51 | // console.log(err.toString()); 52 | // // gutil.log(gutil.colors.red('[Error]'), err.toString()); 53 | // }) 54 | // .pipe(gulp.dest(workSpaceDir + "/bin/js")) 55 | // }); 56 | 57 | // let yktask = ["yk"]; 58 | //==== 59 | //使用browserify,转换ts到js,并输出到bin/js目录 60 | gulp.task("compile", prevTasks, function () { 61 | // 发布时调用编译功能,判断是否点击了编译选项 62 | if (global.publish && !global.config.compile) { 63 | return; 64 | } else if (global.publish && global.config.compile) { 65 | // 发布时调用编译,workSpaceDir使用publish.js里的变量 66 | workSpaceDir = global.workSpaceDir; 67 | } 68 | return browserify({ 69 | basedir: workSpaceDir, 70 | //是否开启调试,开启后会生成jsmap,方便调试ts源码,但会影响编译速度 71 | debug: true, 72 | entries: ['src/Main.ts'], 73 | cache: {}, 74 | packageCache: {} 75 | }) 76 | //使用tsify插件编译ts 77 | .plugin(tsify) 78 | .bundle() 79 | //使用source把输出文件命名为bundle.js 80 | .pipe(source('bundle.js')) 81 | //把bundle.js复制到bin/js目录 82 | .pipe(gulp.dest(workSpaceDir + "/bin/js")); 83 | }); -------------------------------------------------------------------------------- /.laya/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "layaAir", 6 | "type": "chrome", 7 | "request": "launch", 8 | "file": "${workspaceRoot}/bin/index.html", 9 | "runtimeExecutable": "${execPath}", 10 | "useBuildInServer": true, 11 | "sourceMaps": true, 12 | "webRoot": "${workspaceRoot}", 13 | "port": 9222, 14 | "fixedPort":false, 15 | "sourceMapPathOverrides": { 16 | "src/*": "${workspaceRoot}/src/*" 17 | } 18 | }, 19 | { 20 | "name": "chrome调试", 21 | "type": "chrome", 22 | "request": "launch", 23 | "file": "${workspaceRoot}/bin/index.html", 24 | // "换成自己的谷歌安装路径,": 比如 25 | //window 默认安装路径为: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" 26 | //mac 系统上的默认安装路径为 "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; 27 | // "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", 28 | "runtimeArgs": [ 29 | "--allow-file-access-from-files", 30 | "--allow-file-access-frome-files", 31 | " --disable-web-security" 32 | ], 33 | "sourceMaps": true, 34 | "webRoot": "${workspaceRoot}", 35 | //假如谷歌调试报userDataDir不可用,请把谷歌安装路径取得管理员权限,或者更换${tmpdir}为其他可以读写的文件夹,也可以删除。 36 | "userDataDir": "${workspaceRoot}/.laya/chrome", 37 | "fixedPort":false, 38 | "sourceMapPathOverrides": { 39 | "src/*": "${workspaceRoot}/src/*" 40 | } 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /.laya/publish.js: -------------------------------------------------------------------------------- 1 | // v1.0.1 2 | //是否使用IDE自带的node环境和插件,设置false后,则使用自己环境(使用命令行方式执行) 3 | const useIDENode = process.argv[0].indexOf("LayaAir") > -1 ? true : false; 4 | //获取Node插件和工作路径 5 | let ideModuleDir = useIDENode ? process.argv[1].replace("gulp\\bin\\gulp.js", "").replace("gulp/bin/gulp.js", "") : ""; 6 | let workSpaceDir = useIDENode ? process.argv[2].replace("--gulpfile=", "").replace("\\.laya\\publish.js", "").replace("/.laya/publish.js", "") + "/" : "./../"; 7 | 8 | //引用插件模块 9 | const gulp = require(ideModuleDir + "gulp"); 10 | const fs = require("fs"); 11 | const path = require("path"); 12 | const uglify = require(ideModuleDir + "gulp-uglify"); 13 | const jsonminify = require(ideModuleDir + "gulp-jsonminify"); 14 | const image = require(ideModuleDir + "gulp-image"); 15 | const rev = require(ideModuleDir + "gulp-rev"); 16 | const revdel = require(ideModuleDir + "gulp-rev-delete-original"); 17 | const revCollector = require(ideModuleDir + 'gulp-rev-collector'); 18 | const del = require(ideModuleDir + "del"); 19 | const requireDir = require(ideModuleDir + 'require-dir'); 20 | 21 | // 结合compile.js使用 22 | global.publish = true; 23 | requireDir('./', { 24 | filter: function (fullPath) { 25 | // 只用到了compile.js和publish.js 26 | if (path.basename(fullPath) === "compile.js") { 27 | return true; 28 | } else { 29 | return false; 30 | } 31 | } 32 | }); 33 | 34 | 35 | //清理临时文件夹,加载配置 36 | let config, 37 | releaseDir, 38 | platform; 39 | gulp.task("loadConfig", function () { 40 | platform = "web" 41 | if (!useIDENode && process.argv.length > 5 && process.argv[4] == "--config") { 42 | platform = process.argv[5].replace(".json", ""); 43 | } 44 | if (useIDENode && process.argv.length >= 4 && process.argv[3].startsWith("--config") && process.argv[3].endsWith(".json")) { 45 | platform = process.argv[3].match(/(\w+).json/)[1]; 46 | } 47 | let _path; 48 | if (!useIDENode) { 49 | _path = platform + ".json"; 50 | releaseDir = "../release/" + platform; 51 | } 52 | if (useIDENode) { 53 | _path = path.join(workSpaceDir, ".laya", `${platform}.json`); 54 | releaseDir = path.join(workSpaceDir, "release", platform).replace(/\\/g, "/"); 55 | } 56 | let file = fs.readFileSync(_path, "utf-8"); 57 | if (file) { 58 | file = file.replace(/\$basePath/g, releaseDir); 59 | config = JSON.parse(file); 60 | global.config = config; 61 | global.workSpaceDir = workSpaceDir; 62 | } 63 | }); 64 | 65 | //重新编译项目 66 | // gulp.task("compile", ["loadConfig"], function () { 67 | // if (config.compile) { 68 | // console.log("compile"); 69 | // } 70 | // }); 71 | 72 | //清理release文件夹 73 | gulp.task("clearReleaseDir", ["compile"], function (cb) { 74 | if (config.clearReleaseDir) { 75 | del([releaseDir, releaseDir + "_pack", config.packfileTargetValue], { force: true }).then(paths => { 76 | cb(); 77 | }); 78 | } else cb(); 79 | }); 80 | 81 | //copy bin文件到release文件夹 82 | gulp.task("copyFile", ["clearReleaseDir"], function () { 83 | let baseCopyFilter = `${workSpaceDir}/bin/**/*.*`; 84 | if (platform === "wxgame") { // 微信项目,不拷贝index.html,不拷贝百度bin目录中的文件 85 | config.copyFilesFilter = [baseCopyFilter, `!${workSpaceDir}/bin/index.html`, `!${workSpaceDir}/bin/{project.swan.json,swan-game-adapter.js}`]; 86 | } else if (platform === "bdgame") { // 百度项目,不拷贝index.html,不拷贝微信bin目录中的文件 87 | config.copyFilesFilter = [baseCopyFilter, `!${workSpaceDir}/bin/index.html`, `!${workSpaceDir}/bin/{project.config.json,weapp-adapter.js}`]; 88 | } else { // web|QQ项目,不拷贝微信、百度在bin目录中的文件 89 | config.copyFilesFilter = [baseCopyFilter, `!${workSpaceDir}/bin/{game.js,game.json,project.config.json,weapp-adapter.js,project.swan.json,swan-game-adapter.js}`]; 90 | } 91 | var stream = gulp.src(config.copyFilesFilter); 92 | return stream.pipe(gulp.dest(releaseDir)); 93 | }); 94 | 95 | // 根据不同的项目类型拷贝平台文件 96 | gulp.task("copyPlatformFile", ["copyFile"], function () { 97 | let fileLibsPath; 98 | if (useIDENode) { 99 | fileLibsPath = path.join(ideModuleDir, "../", "out", "layarepublic", "LayaAirProjectPack", "lib", "data"); 100 | } else if (process.argv.length >= 8 && process.argv[6] === "--libspath") { 101 | fileLibsPath = process.argv[7]; 102 | console.log("平台文件包是否存在: " + fs.existsSync(fileLibsPath)); 103 | } else { 104 | console.log("没有接收到可用文件包位置,不拷贝对应平台文件"); 105 | return; 106 | } 107 | // 微信项目 108 | if (platform === "wxgame") { 109 | // 如果新建项目时已经点击了"微信/百度小游戏bin目录快速调试",不再拷贝 110 | let isHadWXFiles = 111 | fs.existsSync(path.join(workSpaceDir, "bin", "game.js")) && 112 | fs.existsSync(path.join(workSpaceDir, "bin", "game.json")) && 113 | fs.existsSync(path.join(workSpaceDir, "bin", "project.config.json")) && 114 | fs.existsSync(path.join(workSpaceDir, "bin", "weapp-adapter.js")); 115 | if (isHadWXFiles) { 116 | return; 117 | } 118 | let platformDir = path.join(fileLibsPath, "wxfiles"); 119 | let stream = gulp.src(platformDir + "/*.*"); 120 | return stream.pipe(gulp.dest(releaseDir)); 121 | } 122 | // qq玩一玩项目,区分语言 123 | if (platform === "qqwanyiwan") { 124 | let projectLangDir = config.projectType; 125 | let platformDir = path.join(fileLibsPath, "qqfiles", projectLangDir); 126 | let stream = gulp.src(platformDir + "/**/*.*"); 127 | return stream.pipe(gulp.dest(releaseDir)); 128 | } 129 | // 百度项目 130 | if (platform === "bdgame") { 131 | // 如果新建项目时已经点击了"微信/百度小游戏bin目录快速调试",不再拷贝 132 | let isHadBdFiles = 133 | fs.existsSync(path.join(workSpaceDir, "bin", "game.js")) && 134 | fs.existsSync(path.join(workSpaceDir, "bin", "game.json")) && 135 | fs.existsSync(path.join(workSpaceDir, "bin", "project.swan.json")) && 136 | fs.existsSync(path.join(workSpaceDir, "bin", "swan-game-adapter.js")); 137 | if (isHadBdFiles) { 138 | return; 139 | } 140 | let platformDir = path.join(fileLibsPath, "bdfiles"); 141 | let stream = gulp.src(platformDir + "/*.*"); 142 | return stream.pipe(gulp.dest(releaseDir)); 143 | } 144 | }); 145 | 146 | // 拷贝文件后,针对特定平台修改文件内容 147 | gulp.task("modifyFile", ["copyPlatformFile"], function () { 148 | // QQ玩一玩 149 | if (platform === "qqwanyiwan") { 150 | // 修改bundle.js 151 | let bundleFilePath = path.join(releaseDir, "js", "bundle.js"); 152 | if (fs.existsSync(bundleFilePath)) { 153 | let fileContent = fs.readFileSync(bundleFilePath, "utf8"); 154 | var appendCode = 'if(window["BK"]&&window["BK"]["Sprite"]){BK.Script.loadlib("GameRes://layaforqq/laya.bkadpter.js");}'; 155 | if (fileContent.includes("/**LayaGameStart**/") && !fileContent.includes(appendCode)) { 156 | fileContent = fileContent.split("/**LayaGameStart**/").join(`/**LayaGameStart**/\n${appendCode}`); 157 | fs.writeFileSync(bundleFilePath, fileContent, "utf8"); 158 | } 159 | } 160 | 161 | // 修改index.js 162 | let indexFilePath = path.join(releaseDir, "index.js"); 163 | if (fs.existsSync(indexFilePath)) { 164 | let fileContent = fs.readFileSync(indexFilePath, "utf8"); 165 | fileContent = fileContent.replace(/loadLib\("/g, "BK.Script.loadlib(\"GameRes://"); 166 | // 非as语言,要添加类库 167 | if ("as" !== config.projectType) { 168 | if (fileContent.includes("//-----libs-end-------")) { 169 | fileContent = fileContent.split("//-----libs-end-------").join(`//-----libs-end-------\nBK.Script.loadlib("GameRes://layaforqq/laya.bkadpter.js");`); 170 | } 171 | } 172 | fs.writeFileSync(indexFilePath, fileContent, "utf8"); 173 | } 174 | 175 | // 修改main.js 176 | let mainFilePath = path.join(releaseDir, "main.js"); 177 | if (fs.existsSync(mainFilePath)) { 178 | let fileContent = fs.readFileSync(mainFilePath, "utf8"); 179 | fileContent = `BK.Script.loadlib("GameRes://layaforqq/qqPlayCore.js"); 180 | BK.Script.loadlib("GameRes://layaforqq/bkadptpre.js"); 181 | BK.Script.loadlib("GameRes://layaforqq/domparserinone.js"); 182 | BK.Script.loadlib("GameRes://index.js");`; 183 | fs.writeFileSync(mainFilePath, fileContent, "utf8"); 184 | } 185 | 186 | return; 187 | } 188 | 189 | // 百度项目,修改index.js 190 | if (platform === "bdgame") { 191 | let filePath = path.join(releaseDir, "index.js"); 192 | if (!fs.existsSync(filePath)) { 193 | return; 194 | } 195 | let fileContent = fs.readFileSync(filePath, "utf8"); 196 | fileContent = fileContent.replace(/loadLib\(/g, "require("); 197 | fs.writeFileSync(filePath, fileContent, "utf8"); 198 | return; 199 | } 200 | }); 201 | 202 | //压缩json 203 | gulp.task("compressJson", ["modifyFile"], function () { 204 | if (config.compressJson) { 205 | return gulp.src(config.compressJsonFilter) 206 | .pipe(jsonminify()) 207 | .pipe(gulp.dest(releaseDir)); 208 | } 209 | }); 210 | 211 | //压缩js 212 | gulp.task("compressJs", ["compressJson"], function () { 213 | if (config.compressJs) { 214 | return gulp.src(config.compressJsFilter) 215 | .pipe(uglify()) 216 | .on('error', function (err) { 217 | console.warn(err.toString()); 218 | }) 219 | .pipe(gulp.dest(releaseDir)); 220 | } 221 | }); 222 | 223 | //压缩png,jpg 224 | gulp.task("compressImage", ["compressJs"], function () { 225 | if (config.compressImage) { 226 | return gulp.src(config.compressImageFilter) 227 | .pipe(image({ 228 | pngquant: true, //PNG优化工具 229 | optipng: false, //PNG优化工具 230 | zopflipng: true, //PNG优化工具 231 | jpegRecompress: false, //jpg优化工具 232 | mozjpeg: true, //jpg优化工具 233 | guetzli: false, //jpg优化工具 234 | gifsicle: false, //gif优化工具 235 | svgo: false, //SVG优化工具 236 | concurrent: 10, //并发线程数 237 | quiet: true //是否是静默方式 238 | // optipng: ['-i 1', '-strip all', '-fix', '-o7', '-force'], 239 | // pngquant: ['--speed=1', '--force', 256], 240 | // zopflipng: ['-y', '--lossy_8bit', '--lossy_transparent'], 241 | // jpegRecompress: ['--strip', '--quality', 'medium', '--min', 40, '--max', 80], 242 | // mozjpeg: ['-optimize', '-progressive'], 243 | // guetzli: ['--quality', 85] 244 | })) 245 | .pipe(gulp.dest(releaseDir)); 246 | } 247 | }); 248 | 249 | 250 | //开放域的情况下,合并game.js和index.js 251 | gulp.task("openData", ["compressImage"], function () { 252 | if (config.openDataZone) { 253 | let indexPath = releaseDir + "/index.js"; 254 | let indexjs = readFile(indexPath); 255 | let gamejs = readFile(releaseDir + "/game.js"); 256 | if (gamejs && indexjs) { 257 | gamejs = gamejs.replace('require("index.js")', indexjs); 258 | fs.writeFileSync(indexPath, gamejs, 'utf-8'); 259 | } 260 | } 261 | }); 262 | 263 | function readFile(path) { 264 | if (fs.existsSync(path)) { 265 | return fs.readFileSync(path, "utf-8"); 266 | } 267 | return null; 268 | } 269 | 270 | //生成版本管理信息 271 | gulp.task("version1", ["openData"], function () { 272 | if (config.version) { 273 | return gulp.src(config.versionFilter) 274 | .pipe(rev()) 275 | .pipe(gulp.dest(releaseDir)) 276 | .pipe(revdel()) 277 | .pipe(rev.manifest("version.json")) 278 | .pipe(gulp.dest(releaseDir)); 279 | } 280 | }); 281 | 282 | //替换index.js里面的变化的文件名 283 | gulp.task("version2", ["version1"], function () { 284 | if (config.version) { 285 | //替换index.html和index.js里面的文件名称 286 | 287 | let htmlPath = releaseDir + "/index.html"; 288 | let versionPath = releaseDir + "/version.json"; 289 | let gameJSPath = releaseDir + "/game.js"; 290 | let mainJSPath = releaseDir + "/main.js"; 291 | let indexJSPath; 292 | let versionCon = fs.readFileSync(versionPath, "utf8"); 293 | versionCon = JSON.parse(versionCon); 294 | indexJSPath = releaseDir + "/" + versionCon["index.js"]; 295 | // 替换config.packfileFullValue中的路径 296 | let packfileStr = JSON.stringify(config.packfileFullValue).replace(/\\\\/g, "/"); 297 | let tempPackfile = `${workSpaceDir}/.laya/configTemp.json`; 298 | fs.writeFileSync(tempPackfile, packfileStr, "utf8"); 299 | 300 | let srcList = [versionPath, indexJSPath, tempPackfile]; 301 | if (fs.existsSync(htmlPath)) { 302 | srcList.push(htmlPath); 303 | } 304 | if (fs.existsSync(gameJSPath)) { 305 | srcList.push(gameJSPath); 306 | } 307 | if (fs.existsSync(mainJSPath)) { 308 | srcList.push(mainJSPath); 309 | } 310 | return gulp.src(srcList) 311 | .pipe(revCollector()) 312 | .pipe(gulp.dest(releaseDir)); 313 | } 314 | }); 315 | 316 | //起始任务,筛选4M包 317 | gulp.task("publish", ["version2"], function () { 318 | if (config.version) { 319 | // 从release目录取得带有版本号的目录 320 | let tempPackfile = `${workSpaceDir}/.laya/configTemp.json`; 321 | let releasePackfile = `${releaseDir}/configTemp.json`; 322 | let packfileStr = fs.readFileSync(releasePackfile, "utf8"); 323 | config.packfileFullValue = JSON.parse(packfileStr); 324 | // 删掉临时目录 325 | fs.unlinkSync(tempPackfile); 326 | fs.unlinkSync(releasePackfile); 327 | } 328 | if (config.packfile) { // 提取本地包(文件列表形式) 329 | return gulp.src(config.packfileFullValue, { base: releaseDir }) 330 | .pipe(gulp.dest(config.packfileTargetValue || releaseDir + "_pack")); 331 | } 332 | }); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | laya1.0 的版本 https://github.com/YKPublicGame/LayaYKFamework.git 这是原作者 2 | 3 | laya2.0 的编译改了。把framework打成lib 文件加载 4 | -------------------------------------------------------------------------------- /YKFrame.laya: -------------------------------------------------------------------------------- 1 | {"proName":"YKFrame","engineType":0,"proType":1,"layaProType":0,"version":"2.0.0"} -------------------------------------------------------------------------------- /bin/fileconfig.json: -------------------------------------------------------------------------------- 1 | {"res/atlas/comp.atlas":["comp/",["blank.png","btn_close.png","button.png","checkbox.png","clip_num.png","clip_selectBox.png","clip_tree_arrow.png","clip_tree_folder.png","combobox.png","hscroll$bar.png","hscroll$down.png","hscroll$up.png","hscroll.png","hslider$bar.png","hslider.png","html.png","image.png","img_bg.png","label.png","linkbutton.png","progress$bar.png","progress.png","radio.png","radiogroup.png","tab.png","textarea.png","textinput.png","vscroll$bar.png","vscroll$down.png","vscroll$up.png","vscroll.png","vslider$bar.png","vslider.png"]]} -------------------------------------------------------------------------------- /bin/game.js: -------------------------------------------------------------------------------- 1 | if ((typeof swan !== 'undefined') && (typeof swanGlobal !== 'undefined')) { 2 | require("swan-game-adapter.js"); 3 | require("libs/laya.bdmini.js"); 4 | } else if (typeof wx!=="undefined") { 5 | require("weapp-adapter.js"); 6 | require("libs/laya.wxmini.js"); 7 | } 8 | window.loadLib = require; 9 | require("index.js"); -------------------------------------------------------------------------------- /bin/game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait", 3 | "showStatusBar": false, 4 | "networkTimeout": { 5 | "request": 10000, 6 | "connectSocket": 10000, 7 | "uploadFile": 10000, 8 | "downloadFile": 10000 9 | } 10 | } -------------------------------------------------------------------------------- /bin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | www.layabox.com 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 设置LayaNative屏幕方向,可设置以下值 3 | * landscape 横屏 4 | * portrait 竖屏 5 | * sensor_landscape 横屏(双方向) 6 | * sensor_portrait 竖屏(双方向) 7 | */ 8 | window.screenOrientation = "sensor_landscape"; 9 | 10 | //-----libs-begin----- 11 | loadLib("libs/laya.core.js"); 12 | loadLib("libs/laya.webgl.js"); 13 | loadLib("libs/laya.ui.js"); 14 | loadLib("libs/laya.physics.js"); 15 | 16 | loadLib("libs/laya.html.js"); 17 | 18 | loadLib("libs/rawinflate/rawinflate.min.js"); 19 | loadLib("libs/fairygui/fairygui.js"); 20 | loadLib("../protobuf/library/protobuf-library.js"); 21 | loadLib("../protobuf/bundles/protobuf-bundles.js"); 22 | //-----libs-end------- 23 | loadLib("js/ykLib.js"); 24 | loadLib("js/bundle.js"); 25 | -------------------------------------------------------------------------------- /bin/libs/laya.d3Plugin.js: -------------------------------------------------------------------------------- 1 | 2 | (function(window,document,Laya){ 3 | var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec; 4 | 5 | var Component=laya.components.Component,MeshTerrainSprite3D=laya.d3.core.MeshTerrainSprite3D,Sprite3D=laya.d3.core.Sprite3D; 6 | /** 7 | *PathFinding 类用于创建寻路。 8 | */ 9 | //class laya.d3.component.PathFind extends laya.components.Component 10 | var PathFind=(function(_super){ 11 | function PathFind(){ 12 | /**@private */ 13 | this._meshTerrainSprite3D=null; 14 | /**@private */ 15 | this._finder=null; 16 | /**@private */ 17 | this._setting=null; 18 | /**寻路网格。*/ 19 | this.grid=null; 20 | PathFind.__super.call(this); 21 | } 22 | 23 | __class(PathFind,'laya.d3.component.PathFind',_super); 24 | var __proto=PathFind.prototype; 25 | /** 26 | *@private 27 | *初始化载入蒙皮动画组件。 28 | *@param owner 所属精灵对象。 29 | */ 30 | __proto._onAdded=function(){ 31 | if (! (this.owner instanceof laya.d3.core.MeshTerrainSprite3D )) 32 | throw new Error("PathFinding: The owner must MeshTerrainSprite3D!"); 33 | this._meshTerrainSprite3D=this.owner; 34 | } 35 | 36 | /** 37 | *寻找路径。 38 | *@param startX 开始X。 39 | *@param startZ 开始Z。 40 | *@param endX 结束X。 41 | *@param endZ 结束Z。 42 | *@return 路径。 43 | */ 44 | __proto.findPath=function(startX,startZ,endX,endZ){ 45 | var minX=this._meshTerrainSprite3D.minX; 46 | var minZ=this._meshTerrainSprite3D.minZ; 47 | var cellX=this._meshTerrainSprite3D.width / this.grid.width; 48 | var cellZ=this._meshTerrainSprite3D.depth / this.grid.height; 49 | var halfCellX=cellX / 2; 50 | var halfCellZ=cellZ / 2; 51 | var gridStartX=Math.floor((startX-minX)/ cellX); 52 | var gridStartZ=Math.floor((startZ-minZ)/ cellZ); 53 | var gridEndX=Math.floor((endX-minX)/ cellX); 54 | var gridEndZ=Math.floor((endZ-minZ)/ cellZ); 55 | var boundWidth=this.grid.width-1; 56 | var boundHeight=this.grid.height-1; 57 | (gridStartX > boundWidth)&& (gridStartX=boundWidth); 58 | (gridStartZ > boundHeight)&& (gridStartZ=boundHeight); 59 | (gridStartX < 0)&& (gridStartX=0); 60 | (gridStartZ < 0)&& (gridStartZ=0); 61 | (gridEndX > boundWidth)&& (gridEndX=boundWidth); 62 | (gridEndZ > boundHeight)&& (gridEndZ=boundHeight); 63 | (gridEndX < 0)&& (gridEndX=0); 64 | (gridEndZ < 0)&& (gridEndZ=0); 65 | var path=this._finder.findPath(gridStartX,gridStartZ,gridEndX,gridEndZ,this.grid); 66 | this.grid.reset(); 67 | for (var i=1;i < path.length-1;i++){ 68 | var gridPos=path[i]; 69 | gridPos[0]=gridPos[0] *cellX+halfCellX+minX; 70 | gridPos[1]=gridPos[1] *cellZ+halfCellZ+minZ; 71 | } 72 | if (path.length==1){ 73 | path[0][0]=endX; 74 | path[0][1]=endX; 75 | }else if (path.length > 1){ 76 | path[0][0]=startX; 77 | path[0][1]=startZ; 78 | path[path.length-1][0]=endX; 79 | path[path.length-1][1]=endZ; 80 | } 81 | return path; 82 | } 83 | 84 | /** 85 | *设置寻路设置。 86 | *@param value 寻路设置。 87 | */ 88 | /** 89 | *获取寻路设置。 90 | *@return 寻路设置。 91 | */ 92 | __getset(0,__proto,'setting',function(){ 93 | return this._setting; 94 | },function(value){ 95 | (value)&& (this._finder=new PathFinding.finders.AStarFinder(value)); 96 | this._setting=value; 97 | }); 98 | 99 | return PathFind; 100 | })(Component) 101 | 102 | 103 | 104 | })(window,document,Laya); 105 | -------------------------------------------------------------------------------- /bin/libs/laya.filter.js: -------------------------------------------------------------------------------- 1 | 2 | (function(window,document,Laya){ 3 | var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec; 4 | 5 | var ColorUtils=laya.utils.ColorUtils,Filter=laya.filters.Filter,Matrix=laya.maths.Matrix,Render=laya.renders.Render; 6 | var RunDriver=laya.utils.RunDriver,ShaderDefines2D=laya.webgl.shader.d2.ShaderDefines2D,Sprite=laya.display.Sprite; 7 | var Value2D=laya.webgl.shader.d2.value.Value2D; 8 | /** 9 | *@private 10 | */ 11 | //class laya.filters.GlowFilterGLRender 12 | var GlowFilterGLRender=(function(){ 13 | function GlowFilterGLRender(){} 14 | __class(GlowFilterGLRender,'laya.filters.GlowFilterGLRender'); 15 | var __proto=GlowFilterGLRender.prototype; 16 | __proto.setShaderInfo=function(shader,w,h,data){ 17 | shader.defines.add(data.type); 18 | var sv=shader; 19 | sv.u_blurInfo1=data._sv_blurInfo1; 20 | var info2=data._sv_blurInfo2; 21 | info2[0]=w;info2[1]=h; 22 | sv.u_blurInfo2=info2; 23 | sv.u_color=data.getColor(); 24 | } 25 | 26 | __proto.render=function(rt,ctx,width,height,filter){ 27 | var w=width,h=height; 28 | var svBlur=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 29 | this.setShaderInfo(svBlur,w,h,filter); 30 | var svCP=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 31 | var matI=Matrix.TEMP.identity(); 32 | ctx.drawTarget(rt,0,0,w,h,matI,svBlur); 33 | ctx.drawTarget(rt,0,0,w,h,matI,svCP); 34 | } 35 | 36 | return GlowFilterGLRender; 37 | })() 38 | 39 | 40 | /** 41 | *@private 42 | */ 43 | //class laya.filters.BlurFilterGLRender 44 | var BlurFilterGLRender=(function(){ 45 | function BlurFilterGLRender(){} 46 | __class(BlurFilterGLRender,'laya.filters.BlurFilterGLRender'); 47 | var __proto=BlurFilterGLRender.prototype; 48 | __proto.render=function(rt,ctx,width,height,filter){ 49 | var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 50 | this.setShaderInfo(shaderValue,filter,rt.width,rt.height); 51 | ctx.drawTarget(rt,0,0,width,height,Matrix.EMPTY.identity(),shaderValue); 52 | } 53 | 54 | __proto.setShaderInfo=function(shader,filter,w,h){ 55 | shader.defines.add(/*laya.filters.Filter.BLUR*/0x10); 56 | var sv=shader; 57 | BlurFilterGLRender.blurinfo[0]=w;BlurFilterGLRender.blurinfo[1]=h; 58 | sv.blurInfo=BlurFilterGLRender.blurinfo; 59 | var sigma=filter.strength/3.0; 60 | var sigma2=sigma*sigma; 61 | filter.strength_sig2_2sig2_gauss1[0]=filter.strength; 62 | filter.strength_sig2_2sig2_gauss1[1]=sigma2; 63 | filter.strength_sig2_2sig2_gauss1[2]=2.0*sigma2; 64 | filter.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2); 65 | sv.strength_sig2_2sig2_gauss1=filter.strength_sig2_2sig2_gauss1; 66 | } 67 | 68 | __static(BlurFilterGLRender, 69 | ['blurinfo',function(){return this.blurinfo=new Array(2);} 70 | ]); 71 | return BlurFilterGLRender; 72 | })() 73 | 74 | 75 | /** 76 | *模糊滤镜 77 | */ 78 | //class laya.filters.BlurFilter extends laya.filters.Filter 79 | var BlurFilter=(function(_super){ 80 | function BlurFilter(strength){ 81 | /**模糊滤镜的强度(值越大,越不清晰 */ 82 | this.strength=NaN; 83 | this.strength_sig2_2sig2_gauss1=[]; 84 | //给shader用的。避免创建对象 85 | this.strength_sig2_native=null; 86 | //给native用的 87 | this.renderFunc=null; 88 | BlurFilter.__super.call(this); 89 | (strength===void 0)&& (strength=4); 90 | this.strength=strength; 91 | this._action=null; 92 | this._glRender=new BlurFilterGLRender(); 93 | } 94 | 95 | __class(BlurFilter,'laya.filters.BlurFilter',_super); 96 | var __proto=BlurFilter.prototype; 97 | __proto.getStrenth_sig2_2sig2_native=function(){ 98 | if (!this.strength_sig2_native){ 99 | this.strength_sig2_native=new Float32Array(4); 100 | }; 101 | var sigma=this.strength/3.0; 102 | var sigma2=sigma *sigma; 103 | this.strength_sig2_native[0]=this.strength; 104 | this.strength_sig2_native[1]=sigma2; 105 | this.strength_sig2_native[2]=2.0*sigma2; 106 | this.strength_sig2_native[3]=1.0 / (2.0 *Math.PI *sigma2); 107 | return this.strength_sig2_native; 108 | } 109 | 110 | /** 111 | *@private 112 | *当前滤镜的类型 113 | */ 114 | __getset(0,__proto,'type',function(){ 115 | return 0x10; 116 | }); 117 | 118 | return BlurFilter; 119 | })(Filter) 120 | 121 | 122 | /** 123 | *发光滤镜(也可以当成阴影滤使用) 124 | */ 125 | //class laya.filters.GlowFilter extends laya.filters.Filter 126 | var GlowFilter=(function(_super){ 127 | function GlowFilter(color,blur,offX,offY){ 128 | //给shader用 129 | this._sv_blurInfo2=[0,0,1,0]; 130 | /**滤镜的颜色*/ 131 | this._color=null; 132 | this._color_native=null; 133 | this._blurInof1_native=null; 134 | this._blurInof2_native=null; 135 | GlowFilter.__super.call(this); 136 | this._elements=new Float32Array(9); 137 | this._sv_blurInfo1=new Array(4); 138 | (blur===void 0)&& (blur=4); 139 | (offX===void 0)&& (offX=6); 140 | (offY===void 0)&& (offY=6); 141 | this._color=new ColorUtils(color); 142 | this.blur=Math.min(blur,20); 143 | this.offX=offX; 144 | this.offY=offY; 145 | this._sv_blurInfo1[0]=this._sv_blurInfo1[1]=this.blur;this._sv_blurInfo1[2]=offX;this._sv_blurInfo1[3]=-offY; 146 | this._glRender=new GlowFilterGLRender(); 147 | } 148 | 149 | __class(GlowFilter,'laya.filters.GlowFilter',_super); 150 | var __proto=GlowFilter.prototype; 151 | /**@private */ 152 | __proto.getColor=function(){ 153 | return this._color.arrColor; 154 | } 155 | 156 | __proto.getColorNative=function(){ 157 | if (!this._color_native){ 158 | this._color_native=new Float32Array(4); 159 | }; 160 | var color=this.getColor(); 161 | this._color_native[0]=color[0]; 162 | this._color_native[1]=color[1]; 163 | this._color_native[2]=color[2]; 164 | this._color_native[3]=color[3]; 165 | return this._color_native; 166 | } 167 | 168 | __proto.getBlurInfo1Native=function(){ 169 | if (!this._blurInof1_native){ 170 | this._blurInof1_native=new Float32Array(4); 171 | } 172 | this._blurInof1_native[0]=this._blurInof1_native[1]=this.blur; 173 | this._blurInof1_native[2]=this.offX; 174 | this._blurInof1_native[3]=this.offY; 175 | return this._blurInof1_native; 176 | } 177 | 178 | __proto.getBlurInfo2Native=function(){ 179 | if (!this._blurInof2_native){ 180 | this._blurInof2_native=new Float32Array(4); 181 | } 182 | this._blurInof2_native[2]=1; 183 | return this._blurInof2_native; 184 | } 185 | 186 | /** 187 | *@private 188 | *滤镜类型 189 | */ 190 | __getset(0,__proto,'type',function(){ 191 | return 0x08; 192 | }); 193 | 194 | /**@private */ 195 | /**@private */ 196 | __getset(0,__proto,'offY',function(){ 197 | return this._elements[6]; 198 | },function(value){ 199 | this._elements[6]=value; 200 | this._sv_blurInfo1[3]=-value; 201 | }); 202 | 203 | /**@private */ 204 | /**@private */ 205 | __getset(0,__proto,'offX',function(){ 206 | return this._elements[5]; 207 | },function(value){ 208 | this._elements[5]=value; 209 | this._sv_blurInfo1[2]=value; 210 | }); 211 | 212 | /**@private */ 213 | /**@private */ 214 | __getset(0,__proto,'blur',function(){ 215 | return this._elements[4]; 216 | },function(value){ 217 | this._elements[4]=value; 218 | this._sv_blurInfo1[0]=this._sv_blurInfo1[1]=value; 219 | }); 220 | 221 | return GlowFilter; 222 | })(Filter) 223 | 224 | 225 | 226 | })(window,document,Laya); 227 | -------------------------------------------------------------------------------- /bin/libs/laya.physics3D.wasm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/libs/laya.physics3D.wasm.wasm -------------------------------------------------------------------------------- /bin/libs/rawinflate/rawinflate.min.js: -------------------------------------------------------------------------------- 1 | /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var l=this;function p(b,e){var a=b.split("."),c=l;!(a[0]in c)&&c.execScript&&c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&void 0!==e?c[d]=e:c=c[d]?c[d]:c[d]={}};var q="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function t(b){var e=b.length,a=0,c=Number.POSITIVE_INFINITY,d,f,g,h,k,m,r,n,s,J;for(n=0;na&&(a=b[n]),b[n]>=1;J=g<<16|n;for(s=m;s>>=1;switch(b){case 0:var e=this.input,a=this.d,c=this.b,d=this.a,f=e.length,g=void 0,h=void 0,k=c.length,m=void 0;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=e[a++]|e[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=e[a++]|e[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>e.length)throw Error("input buffer is broken");switch(this.i){case w:for(;d+ 4 | g>c.length;){m=k-d;g-=m;if(q)c.set(e.subarray(a,a+m),d),d+=m,a+=m;else for(;m--;)c[d++]=e[a++];this.a=d;c=this.e();d=this.a}break;case v:for(;d+g>c.length;)c=this.e({o:2});break;default:throw Error("invalid inflate mode");}if(q)c.set(e.subarray(a,a+g),d),d+=g,a+=g;else for(;g--;)c[d++]=e[a++];this.d=a;this.a=d;this.b=c;break;case 1:this.j(y,z);break;case 2:A(this);break;default:throw Error("unknown BTYPE: "+b);}}return this.m()}; 5 | var B=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],C=q?new Uint16Array(B):B,D=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],E=q?new Uint16Array(D):D,F=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],G=q?new Uint8Array(F):F,H=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],I=q?new Uint16Array(H):H,K=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13, 6 | 13],L=q?new Uint8Array(K):K,M=new (q?Uint8Array:Array)(288),N,O;N=0;for(O=M.length;N=N?8:255>=N?9:279>=N?7:8;var y=t(M),P=new (q?Uint8Array:Array)(30),Q,R;Q=0;for(R=P.length;Q=g)throw Error("input buffer is broken");a|=d[f++]<>>e;b.c=c-e;b.d=f;return h} 7 | function S(b,e){for(var a=b.f,c=b.c,d=b.input,f=b.d,g=d.length,h=e[0],k=e[1],m,r;c=g);)a|=d[f++]<>>16;b.f=a>>r;b.c=c-r;b.d=f;return m&65535} 8 | function A(b){function e(a,b,c){var e,d=this.p,f,g;for(g=0;gf)c>=d&&(this.a=c,a=this.e(),c=this.a),a[c++]=f;else{g=f-257;k=E[g];0=d&&(this.a=c,a=this.e(),c=this.a);for(;k--;)a[c]=a[c++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=c}; 10 | u.prototype.t=function(b,e){var a=this.b,c=this.a;this.n=b;for(var d=a.length,f,g,h,k;256!==(f=S(this,b));)if(256>f)c>=d&&(a=this.e(),d=a.length),a[c++]=f;else{g=f-257;k=E[g];0d&&(a=this.e(),d=a.length);for(;k--;)a[c]=a[c++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=c}; 11 | u.prototype.e=function(){var b=new (q?Uint8Array:Array)(this.a-32768),e=this.a-32768,a,c,d=this.b;if(q)b.set(d.subarray(32768,b.length));else{a=0;for(c=b.length;aa;++a)d[a]=d[e+a];this.a=32768;return d}; 12 | u.prototype.v=function(b){var e,a=this.input.length/this.d+1|0,c,d,f,g=this.input,h=this.b;b&&("number"===typeof b.o&&(a=b.o),"number"===typeof b.r&&(a+=b.r));2>a?(c=(g.length-this.d)/this.n[2],f=258*(c/2)|0,d=fe&&(this.b.length=e),b=this.b);return this.buffer=b};p("Zlib.RawInflate",u);p("Zlib.RawInflate.prototype.decompress",u.prototype.u);var T={ADAPTIVE:v,BLOCK:w},U,V,W,X;if(Object.keys)U=Object.keys(T);else for(V in U=[],W=0,T)U[W++]=V;W=0;for(X=U.length;Wt)return e;for(var i=512;t>i;)i<<=1;for(var r=new Uint8Array(i),s=0;a>s;++s)r[s]=e[s];return this.buffer=r},getByte:function(){for(var t=this.pos;this.bufferLength<=t;){if(this.eof)return null;this.readBlock()}return this.buffer[this.pos++]},getBytes:function(t){var e=this.pos;if(t){this.ensureBuffer(e+t);for(var a=e+t;!this.eof&&this.bufferLengthi&&(a=i)}else{for(;!this.eof;)this.readBlock();var a=this.bufferLength}return this.pos=a,this.buffer.subarray(e,a)},lookChar:function(){for(var t=this.pos;this.bufferLength<=t;){if(this.eof)return null;this.readBlock()}return String.fromCharCode(this.buffer[this.pos])},getChar:function(){for(var t=this.pos;this.bufferLength<=t;){if(this.eof)return null;this.readBlock()}return String.fromCharCode(this.buffer[this.pos++])},makeSubStream:function(t,e,a){for(var i=t+e;this.bufferLength<=i&&!this.eof;)this.readBlock();return new Stream(this.buffer,t,e,a)},skip:function(t){t||(t=1),this.pos+=t},reset:function(){this.pos=0}},t}(),FlateStream=function(){function t(t){throw new Error(t)}function e(e){var a=0,i=e[a++],r=e[a++];-1!=i&&-1!=r||t("Invalid header in flate stream"),8!=(15&i)&&t("Unknown compression method in flate stream"),((i<<8)+r)%31!=0&&t("Bad FCHECK in flate stream"),32&r&&t("FDICT bit set in flate stream"),this.bytes=e,this.bytesPos=a,this.codeSize=0,this.codeBuf=0,DecodeStream.call(this)}var a=new Uint32Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),i=new Uint32Array([3,4,5,6,7,8,9,10,65547,65549,65551,65553,131091,131095,131099,131103,196643,196651,196659,196667,262211,262227,262243,262259,327811,327843,327875,327907,258,258,258]),r=new Uint32Array([1,2,3,4,65541,65543,131081,131085,196625,196633,262177,262193,327745,327777,393345,393409,459009,459137,524801,525057,590849,591361,657409,658433,724993,727041,794625,798721,868353,876545]),s=[new Uint32Array([459008,524368,524304,524568,459024,524400,524336,590016,459016,524384,524320,589984,524288,524416,524352,590048,459012,524376,524312,589968,459028,524408,524344,590032,459020,524392,524328,59e4,524296,524424,524360,590064,459010,524372,524308,524572,459026,524404,524340,590024,459018,524388,524324,589992,524292,524420,524356,590056,459014,524380,524316,589976,459030,524412,524348,590040,459022,524396,524332,590008,524300,524428,524364,590072,459009,524370,524306,524570,459025,524402,524338,590020,459017,524386,524322,589988,524290,524418,524354,590052,459013,524378,524314,589972,459029,524410,524346,590036,459021,524394,524330,590004,524298,524426,524362,590068,459011,524374,524310,524574,459027,524406,524342,590028,459019,524390,524326,589996,524294,524422,524358,590060,459015,524382,524318,589980,459031,524414,524350,590044,459023,524398,524334,590012,524302,524430,524366,590076,459008,524369,524305,524569,459024,524401,524337,590018,459016,524385,524321,589986,524289,524417,524353,590050,459012,524377,524313,589970,459028,524409,524345,590034,459020,524393,524329,590002,524297,524425,524361,590066,459010,524373,524309,524573,459026,524405,524341,590026,459018,524389,524325,589994,524293,524421,524357,590058,459014,524381,524317,589978,459030,524413,524349,590042,459022,524397,524333,590010,524301,524429,524365,590074,459009,524371,524307,524571,459025,524403,524339,590022,459017,524387,524323,589990,524291,524419,524355,590054,459013,524379,524315,589974,459029,524411,524347,590038,459021,524395,524331,590006,524299,524427,524363,590070,459011,524375,524311,524575,459027,524407,524343,590030,459019,524391,524327,589998,524295,524423,524359,590062,459015,524383,524319,589982,459031,524415,524351,590046,459023,524399,524335,590014,524303,524431,524367,590078,459008,524368,524304,524568,459024,524400,524336,590017,459016,524384,524320,589985,524288,524416,524352,590049,459012,524376,524312,589969,459028,524408,524344,590033,459020,524392,524328,590001,524296,524424,524360,590065,459010,524372,524308,524572,459026,524404,524340,590025,459018,524388,524324,589993,524292,524420,524356,590057,459014,524380,524316,589977,459030,524412,524348,590041,459022,524396,524332,590009,524300,524428,524364,590073,459009,524370,524306,524570,459025,524402,524338,590021,459017,524386,524322,589989,524290,524418,524354,590053,459013,524378,524314,589973,459029,524410,524346,590037,459021,524394,524330,590005,524298,524426,524362,590069,459011,524374,524310,524574,459027,524406,524342,590029,459019,524390,524326,589997,524294,524422,524358,590061,459015,524382,524318,589981,459031,524414,524350,590045,459023,524398,524334,590013,524302,524430,524366,590077,459008,524369,524305,524569,459024,524401,524337,590019,459016,524385,524321,589987,524289,524417,524353,590051,459012,524377,524313,589971,459028,524409,524345,590035,459020,524393,524329,590003,524297,524425,524361,590067,459010,524373,524309,524573,459026,524405,524341,590027,459018,524389,524325,589995,524293,524421,524357,590059,459014,524381,524317,589979,459030,524413,524349,590043,459022,524397,524333,590011,524301,524429,524365,590075,459009,524371,524307,524571,459025,524403,524339,590023,459017,524387,524323,589991,524291,524419,524355,590055,459013,524379,524315,589975,459029,524411,524347,590039,459021,524395,524331,590007,524299,524427,524363,590071,459011,524375,524311,524575,459027,524407,524343,590031,459019,524391,524327,589999,524295,524423,524359,590063,459015,524383,524319,589983,459031,524415,524351,590047,459023,524399,524335,590015,524303,524431,524367,590079]),9],n=[new Uint32Array([327680,327696,327688,327704,327684,327700,327692,327708,327682,327698,327690,327706,327686,327702,327694,0,327681,327697,327689,327705,327685,327701,327693,327709,327683,327699,327691,327707,327687,327703,327695,0]),5];return e.prototype=Object.create(DecodeStream.prototype),e.prototype.getBits=function(e){for(var a,i=this.codeSize,r=this.codeBuf,s=this.bytes,n=this.bytesPos;e>i;)"undefined"==typeof(a=s[n++])&&t("Bad encoding in flate stream"),r|=a<>e,this.codeSize=i-=e,this.bytesPos=n,a},e.prototype.getCode=function(e){for(var a=e[0],i=e[1],r=this.codeSize,s=this.codeBuf,n=this.bytes,o=this.bytesPos;i>r;){var h;"undefined"==typeof(h=n[o++])&&t("Bad encoding in flate stream"),s|=h<>16,c=65535&f;return(0==r||d>r||0==d)&&t("Bad encoding in flate stream"),this.codeBuf=s>>d,this.codeSize=r-d,this.bytesPos=o,c},e.prototype.generateHuffmanTable=function(t){for(var e=t.length,a=0,i=0;e>i;++i)t[i]>a&&(a=t[i]);for(var r=1<=n;++n,o<<=1,h<<=1)for(var f=0;e>f;++f)if(t[f]==n){for(var d=0,c=o,i=0;n>i;++i)d=d<<1|1&c,c>>=1;for(var i=d;r>i;i+=h)s[i]=n<<16|f;++o}return[s,a]},e.prototype.readBlock=function(){function e(t,e,a,i,r){for(var s=t.getBits(a)+i;s-- >0;)e[I++]=r}var o=this.getBits(3);if(1&o&&(this.eof=!0),o>>=1,0==o){var h,f=this.bytes,d=this.bytesPos;"undefined"==typeof(h=f[d++])&&t("Bad block header in flate stream");var c=h;"undefined"==typeof(h=f[d++])&&t("Bad block header in flate stream"),c|=h<<8,"undefined"==typeof(h=f[d++])&&t("Bad block header in flate stream");var l=h;"undefined"==typeof(h=f[d++])&&t("Bad block header in flate stream"),l|=h<<8,l!=(65535&~c)&&t("Bad uncompressed block length in flate stream"),this.codeBuf=0,this.codeSize=0;var u=this.bufferLength,p=this.ensureBuffer(u+c),g=u+c;this.bufferLength=g;for(var m=u;g>m;++m){if("undefined"==typeof(h=f[d++])){this.eof=!0;break}p[m]=h}return void(this.bytesPos=d)}var y,v;if(1==o)y=s,v=n;else if(2==o){for(var b=this.getBits(5)+257,w=this.getBits(5)+1,B=this.getBits(4)+4,T=Array(a.length),I=0;B>I;)T[a[I++]]=this.getBits(3);for(var U=this.generateHuffmanTable(T),D=0,I=0,k=b+w,A=new Array(k);k>I;){var C=this.getCode(U);16==C?e(this,A,2,3,D):17==C?e(this,A,3,3,D=0):18==C?e(this,A,7,11,D=0):A[I++]=D=C}y=this.generateHuffmanTable(A.slice(0,b)),v=this.generateHuffmanTable(A.slice(b,k))}else t("Unknown block type in flate stream");for(var p=this.buffer,S=p?p.length:0,P=this.bufferLength;;){var M=this.getCode(y);if(256>M)P+1>=S&&(p=this.ensureBuffer(P+1),S=p.length),p[P++]=M;else{if(256==M)return void(this.bufferLength=P);M-=257,M=i[M];var L=M>>16;L>0&&(L=this.getBits(L));var D=(65535&M)+L;M=this.getCode(v),M=r[M],L=M>>16,L>0&&(L=this.getBits(L));var x=(65535&M)+L;P+D>=S&&(p=this.ensureBuffer(P+D),S=p.length);for(var N=0;D>N;++N,++P)p[P]=p[P-x]}}},e}();(function(){var t;t=function(){function t(t){var e,a,i,r,s,n,o,h,f,d,c,l,u,p;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},s=null;;){switch(e=this.readUInt32(),f=function(){var t,e;for(e=[],n=t=0;4>t;n=++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join("")){case"IHDR":if(this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++],0!=this.interlaceMethod)throw new Error("Invalid interlaceMethod: "+this.interlaceMethod);break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":s&&this.animation.frames.push(s),this.pos+=4,s={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},r=this.readUInt16(),i=this.readUInt16()||100,s.delay=1e3*r/i,s.disposeOp=this.data[this.pos++],s.blendOp=this.data[this.pos++],s.data=[];break;case"IDAT":case"fdAT":for("fdAT"===f&&(this.pos+=4,e-=4),t=(null!=s?s.data:void 0)||this.imgData,n=l=0;e>=0?e>l:l>e;n=e>=0?++l:--l)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),d=255-this.transparency.indexed.length,d>0)for(n=u=0;d>=0?d>u:u>d;n=d>=0?++u:--u)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":c=this.read(e),o=c.indexOf(0),h=String.fromCharCode.apply(String,c.slice(0,o)),this.text[h]=String.fromCharCode.apply(String,c.slice(o+1));break;case"IEND":return s&&this.animation.frames.push(s),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(p=this.colorType)||6===p,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}var e,a,i,r,s,n;return t.load=function(e,a){var i;return"function"==typeof canvas&&(a=canvas),i=new XMLHttpRequest,i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(){var r,s;return r=new Uint8Array(i.response||i.mozResponseArrayBuffer),s=new t(r),s.url=e,"function"==typeof a?a(s):void 0},i.send(null)},r=0,i=1,s=2,a=0,e=1,t.prototype.read=function(t){var e,a,i;for(i=[],e=a=0;t>=0?t>a:a>t;e=t>=0?++a:--a)i.push(this.data[this.pos++]);return i},t.prototype.readUInt32=function(){var t,e,a,i;return t=this.data[this.pos++]<<24,e=this.data[this.pos++]<<16,a=this.data[this.pos++]<<8,i=this.data[this.pos++],t|e|a|i},t.prototype.readUInt16=function(){var t,e;return t=this.data[this.pos++]<<8,e=this.data[this.pos++],t|e},t.prototype.decodePixels=function(t){var e,a,i,r,s,n,o,h,f,d,c,l,u,p,g,m,y,v,b,w,B,T,I;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=new FlateStream(t),t=t.getBytes(),l=this.pixelBitlength/8,m=l*this.width,u=new Uint8Array(m*this.height),n=t.length,g=0,p=0,a=0;n>p;){switch(t[p++]){case 0:for(r=b=0;m>b;r=b+=1)u[a++]=t[p++];break;case 1:for(r=w=0;m>w;r=w+=1)e=t[p++],s=l>r?0:u[a-l],u[a++]=(e+s)%256;break;case 2:for(r=B=0;m>B;r=B+=1)e=t[p++],i=(r-r%l)/l,y=g&&u[(g-1)*m+i*l+r%l],u[a++]=(y+e)%256;break;case 3:for(r=T=0;m>T;r=T+=1)e=t[p++],i=(r-r%l)/l,s=l>r?0:u[a-l],y=g&&u[(g-1)*m+i*l+r%l],u[a++]=(e+Math.floor((s+y)/2))%256;break;case 4:for(r=I=0;m>I;r=I+=1)e=t[p++],i=(r-r%l)/l,s=l>r?0:u[a-l],0===g?y=v=0:(y=u[(g-1)*m+i*l+r%l],v=i&&u[(g-1)*m+(i-1)*l+r%l]),o=s+y-v,h=Math.abs(o-s),d=Math.abs(o-y),c=Math.abs(o-v),f=d>=h&&c>=h?s:c>=d?y:v,u[a++]=(e+f)%256;break;default:throw new Error("Invalid filter algorithm: "+t[p-1])}g++}return u},t.prototype.decodePalette=function(){var t,e,a,i,r,s,n,o,h,f;i=this.palette,n=this.transparency.indexed||[];var d;for(d=4*i.length/3,s=new Uint8Array(d),r=0,a=i.length,t=0,e=o=0,h=i.length;h>o;e=o+=3)s[r++]=i[e],s[r++]=i[e+1],s[r++]=i[e+2],s[r++]=null!=(f=n[t++])?f:255;return s},t.prototype.getImageData=function(){var t=new self.ImageData(this.width,this.height);return this.copyToImageData(t,this.decodePixels()),t},t.prototype.getImageDataBuffer=function(){var t;return t=self.Uint8ClampedArray?new self.Uint8ClampedArray(this.width*this.height*4):new self.Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},t.prototype.copyToImageData=function(t,e){var a,i,r,s,n,o,h,f,d,c,l;if(i=this.colors,d=null,a=this.hasAlphaChannel,this.palette.length&&(d=null!=(l=this._decodedPalette)?l:this._decodedPalette=this.decodePalette(),i=4,a=!0),r=t.data||t,f=r.length,n=d||e,s=o=0,1===i)for(;f>s;)h=d?4*e[s/4]:o,c=n[h++],r[s++]=c,r[s++]=c,r[s++]=c,r[s++]=a?n[h++]:255,o=h;else for(;f>s;)h=d?4*e[s/4]:o,r[s++]=n[h++],r[s++]=n[h++],r[s++]=n[h++],r[s++]=a?n[h++]:255,o=h},t.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},t.prototype.decodeFrames=function(t){var e,a,i,r,s,o,h,f;if(this.animation){for(h=this.animation.frames,f=[],a=s=0,o=h.length;o>s;a=++s)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,f.push(e.image=n(i));return f}},t}(),this.PNG=t}).call(this),onmessage=function(t){var e=t.data;switch(e.type){case"load":loadImage2(e)}};var canUseImageData=!1;testCanImageData(); -------------------------------------------------------------------------------- /bin/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": false, 5 | "es6": false, 6 | "postcss": true, 7 | "minified": false, 8 | "newFeature": true 9 | }, 10 | "compileType": "game", 11 | "libVersion": "game", 12 | "appid": "wx9170ca1ff6f31088", 13 | "projectname": "layaWXTest", 14 | "condition": { 15 | "search": { 16 | "current": -1, 17 | "list": [] 18 | }, 19 | "conversation": { 20 | "current": -1, 21 | "list": [] 22 | }, 23 | "game": { 24 | "currentL": -1, 25 | "list": [] 26 | }, 27 | "miniprogram": { 28 | "current": -1, 29 | "list": [] 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /bin/project.swan.json: -------------------------------------------------------------------------------- 1 | {"appid":"无智能小程序AppId部分功能受限","libversion":"game","compileType":"game","setting":{"urlCheck":true},"libVersion":"1.13.29","condition":{"swan":{"current":-2,"list":[]}}} -------------------------------------------------------------------------------- /bin/res/external/BasePack.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/BasePack.bin -------------------------------------------------------------------------------- /bin/res/external/BasePack_atlas0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/BasePack_atlas0.png -------------------------------------------------------------------------------- /bin/res/external/GamePack.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/GamePack.bin -------------------------------------------------------------------------------- /bin/res/external/GamePack_atlas0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/GamePack_atlas0.png -------------------------------------------------------------------------------- /bin/res/external/LoginPack.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/LoginPack.bin -------------------------------------------------------------------------------- /bin/res/external/MainPack.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/MainPack.bin -------------------------------------------------------------------------------- /bin/res/external/MainPack_atlas0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/external/MainPack_atlas0.png -------------------------------------------------------------------------------- /bin/res/pb/NetPack.proto: -------------------------------------------------------------------------------- 1 | 2 | message test { 3 | optional string str = 1; 4 | 5 | } 6 | message packbase { 7 | optional int32 cmd = 1; 8 | optional int32 msgid = 2; 9 | optional int32 errorcode = 3; 10 | optional bytes contentBuff = 4; 11 | 12 | } 13 | message UserData { 14 | optional int32 roleId = 1; 15 | optional string nickName = 2; 16 | optional string headUrl = 3; 17 | optional int32 sex = 4; 18 | optional string signature = 5; 19 | optional int32 constellation = 6; 20 | optional string county = 7; 21 | optional string city = 8; 22 | optional string weChat = 9; 23 | optional int32 gold = 10; 24 | optional int32 diamond = 11; 25 | optional int32 playerNum = 12; 26 | optional int32 winNum = 13; 27 | optional string awardNum = 14; 28 | 29 | } 30 | message loginReq { 31 | optional string token = 1; 32 | optional int32 roleid = 2; 33 | 34 | } 35 | message loginResp { 36 | optional UserData roleinfo = 1; 37 | 38 | } 39 | message tickOutEvent { 40 | optional int32 tickType = 1; 41 | 42 | } 43 | message ParamConfig { 44 | optional string name = 1; 45 | optional int32 value = 2; 46 | 47 | } 48 | message PrivateRoomInfo { 49 | repeated ParamConfig param = 1; 50 | optional int32 roomid = 2; 51 | optional int32 ownerid = 3; 52 | optional int32 dealNum = 4; 53 | optional int32 roleNum = 5; 54 | optional int32 gameid = 6; 55 | 56 | } 57 | message roomIdData { 58 | optional int32 roomId = 1; 59 | 60 | } 61 | message PrivateDeskInfoReply { 62 | optional int32 dealId = 1; 63 | optional int32 state = 2; 64 | optional int32 banker = 3; 65 | repeated MatchPlayer matchPlayers = 4; 66 | optional int32 curSeat = 5; 67 | repeated int32 lowCards = 6; 68 | optional int32 nowMultiple = 7; 69 | repeated OpEvent opInfos = 8; 70 | optional int32 dzState = 9; 71 | optional PrivateRoomInfo roomInfo = 10; 72 | 73 | } 74 | message MatchPlayer { 75 | optional int32 seat = 1; 76 | optional int32 score = 2; 77 | repeated int32 cards = 3; 78 | optional int32 cardsNum = 4; 79 | optional bool isDZ = 5; 80 | optional int32 boomNums = 6; 81 | repeated int32 outCards = 7; 82 | optional UserData userData = 8; 83 | optional int32 state = 9; 84 | 85 | } 86 | message CallOpInfo { 87 | optional int32 seat = 1; 88 | optional int32 value = 2; 89 | 90 | } 91 | message OpReq { 92 | optional int32 weaveKind = 1; 93 | optional int32 value = 2; 94 | repeated int32 cards = 3; 95 | 96 | } 97 | message OpEvent { 98 | optional int32 weaveKind = 1; 99 | optional int32 value = 2; 100 | optional int32 seat = 3; 101 | repeated int32 cards = 4; 102 | 103 | } 104 | message GameStartEvent { 105 | repeated MatchPlayer matchPlayers = 1; 106 | optional int32 curSeat = 2; 107 | optional int32 dzState = 3; 108 | repeated int32 lowCards = 4; 109 | optional int32 laizIndex = 5; 110 | 111 | } 112 | message opData { 113 | optional int32 state = 1; 114 | 115 | } 116 | message DissRoleRep { 117 | optional int32 id = 1; 118 | optional string nickname = 2; 119 | optional int32 agree = 3; 120 | optional bool suggest = 4; 121 | 122 | } 123 | message DissRoomData { 124 | repeated DissRoleRep roles = 1; 125 | optional int32 state = 2; 126 | optional int32 endtime = 3; 127 | optional int32 type = 4; 128 | 129 | } 130 | message GameOverPlayerData { 131 | optional int32 seat = 1; 132 | repeated int32 cards = 2; 133 | optional int32 curScore = 3; 134 | optional int32 score = 4; 135 | optional int32 boom = 5; 136 | optional int32 overState = 6; 137 | 138 | } 139 | message ParamConfigList { 140 | repeated ParamConfig datas = 1; 141 | 142 | } -------------------------------------------------------------------------------- /bin/res/source/Loading.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/source/Loading.bin -------------------------------------------------------------------------------- /bin/res/source/Loading_atlas0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/source/Loading_atlas0.png -------------------------------------------------------------------------------- /bin/res/source/Loading_atlas_vckm32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/bin/res/source/Loading_atlas_vckm32.jpg -------------------------------------------------------------------------------- /bin/version.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /laya/.laya: -------------------------------------------------------------------------------- 1 | 2 | img,temp,sound 3 | embed 4 | png,jpg 5 | bin/res/atlas 6 | bin 7 | src/ui 8 | 9 | 11 | 3 12 | bin/ui.json 13 | Sprite,Box,List,Tab,RadioGroup,ViewStack,Panel,HBox,VBox,Tree 14 | Scene,View,Dialog 15 | 16 | 1 17 | 18 | 80 19 | 20 | 21 | 24 | 2048 25 | 2048 26 | 512 27 | 512 28 | false 29 | false 30 | 31 | 2D 32 | fixedwidth 33 | none 34 | top 35 | left 36 | 640 37 | 1136 38 | src/view 39 | 0 40 | 1 41 | 42 | false 43 | true 44 | true 45 | false 46 | 47 | 2.0 48 | false 49 | false 50 | true 51 | -------------------------------------------------------------------------------- /laya/assets/comp/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/blank.png -------------------------------------------------------------------------------- /laya/assets/comp/btn_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/btn_close.png -------------------------------------------------------------------------------- /laya/assets/comp/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/button.png -------------------------------------------------------------------------------- /laya/assets/comp/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/checkbox.png -------------------------------------------------------------------------------- /laya/assets/comp/clip_num.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/clip_num.png -------------------------------------------------------------------------------- /laya/assets/comp/clip_selectBox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/clip_selectBox.png -------------------------------------------------------------------------------- /laya/assets/comp/clip_tree_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/clip_tree_arrow.png -------------------------------------------------------------------------------- /laya/assets/comp/clip_tree_folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/clip_tree_folder.png -------------------------------------------------------------------------------- /laya/assets/comp/combobox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/combobox.png -------------------------------------------------------------------------------- /laya/assets/comp/hscroll$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/hscroll$bar.png -------------------------------------------------------------------------------- /laya/assets/comp/hscroll$down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/hscroll$down.png -------------------------------------------------------------------------------- /laya/assets/comp/hscroll$up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/hscroll$up.png -------------------------------------------------------------------------------- /laya/assets/comp/hscroll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/hscroll.png -------------------------------------------------------------------------------- /laya/assets/comp/hslider$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/hslider$bar.png -------------------------------------------------------------------------------- /laya/assets/comp/hslider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/hslider.png -------------------------------------------------------------------------------- /laya/assets/comp/html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/html.png -------------------------------------------------------------------------------- /laya/assets/comp/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/image.png -------------------------------------------------------------------------------- /laya/assets/comp/img_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/img_bg.png -------------------------------------------------------------------------------- /laya/assets/comp/label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/label.png -------------------------------------------------------------------------------- /laya/assets/comp/linkbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/linkbutton.png -------------------------------------------------------------------------------- /laya/assets/comp/progress$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/progress$bar.png -------------------------------------------------------------------------------- /laya/assets/comp/progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/progress.png -------------------------------------------------------------------------------- /laya/assets/comp/radio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/radio.png -------------------------------------------------------------------------------- /laya/assets/comp/radiogroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/radiogroup.png -------------------------------------------------------------------------------- /laya/assets/comp/tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/tab.png -------------------------------------------------------------------------------- /laya/assets/comp/textarea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/textarea.png -------------------------------------------------------------------------------- /laya/assets/comp/textinput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/textinput.png -------------------------------------------------------------------------------- /laya/assets/comp/vscroll$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/vscroll$bar.png -------------------------------------------------------------------------------- /laya/assets/comp/vscroll$down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/vscroll$down.png -------------------------------------------------------------------------------- /laya/assets/comp/vscroll$up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/vscroll$up.png -------------------------------------------------------------------------------- /laya/assets/comp/vscroll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/vscroll.png -------------------------------------------------------------------------------- /laya/assets/comp/vslider$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/vslider$bar.png -------------------------------------------------------------------------------- /laya/assets/comp/vslider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/superzys/YKFrame/5e53d6a95349ab9367197de22ae06206b0ac19c4/laya/assets/comp/vslider.png -------------------------------------------------------------------------------- /laya/ignore.cfg: -------------------------------------------------------------------------------- 1 | {"src/Main.ts":true,"src/GameConfig.ts":true,"src/ui":true} -------------------------------------------------------------------------------- /protobuf/pbconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "options": { 3 | "no-create": false, 4 | "no-verify": false, 5 | "no-convert": true 6 | }, 7 | "sourceRoot": "protofile", 8 | "outputFile": "bundles/protobuf-bundles.js" 9 | } -------------------------------------------------------------------------------- /protobuf/protofile/awesome.proto: -------------------------------------------------------------------------------- 1 | // awesome.proto 2 | package netpack; 3 | syntax = "proto2"; 4 | 5 | 6 | message test { 7 | optional string str = 1; 8 | 9 | } 10 | message packbase { 11 | optional int32 cmd = 1; 12 | optional int32 msgid = 2; 13 | optional int32 errorcode = 3; 14 | optional bytes contentBuff = 4; 15 | 16 | } 17 | message UserData { 18 | optional int32 roleId = 1; 19 | optional string nickName = 2; 20 | optional string headUrl = 3; 21 | optional int32 sex = 4; 22 | optional string signature = 5; 23 | optional int32 constellation = 6; 24 | optional string county = 7; 25 | optional string city = 8; 26 | optional string weChat = 9; 27 | optional int32 gold = 10; 28 | optional int32 diamond = 11; 29 | optional int32 playerNum = 12; 30 | optional int32 winNum = 13; 31 | optional string awardNum = 14; 32 | 33 | } 34 | message loginReq { 35 | optional string token = 1; 36 | optional int32 roleid = 2; 37 | 38 | } 39 | message loginResp { 40 | optional UserData roleinfo = 1; 41 | 42 | } 43 | message tickOutEvent { 44 | optional int32 tickType = 1; 45 | 46 | } 47 | message ParamConfig { 48 | optional string name = 1; 49 | optional int32 value = 2; 50 | 51 | } 52 | message PrivateRoomInfo { 53 | repeated ParamConfig param = 1; 54 | optional int32 roomid = 2; 55 | optional int32 ownerid = 3; 56 | optional int32 dealNum = 4; 57 | optional int32 roleNum = 5; 58 | optional int32 gameid = 6; 59 | 60 | } 61 | message roomIdData { 62 | optional int32 roomId = 1; 63 | 64 | } 65 | message PrivateDeskInfoReply { 66 | optional int32 dealId = 1; 67 | optional int32 state = 2; 68 | optional int32 banker = 3; 69 | repeated MatchPlayer matchPlayers = 4; 70 | optional int32 curSeat = 5; 71 | repeated int32 lowCards = 6; 72 | optional int32 nowMultiple = 7; 73 | repeated OpEvent opInfos = 8; 74 | optional int32 dzState = 9; 75 | optional PrivateRoomInfo roomInfo = 10; 76 | 77 | } 78 | message MatchPlayer { 79 | optional int32 seat = 1; 80 | optional int32 score = 2; 81 | repeated int32 cards = 3; 82 | optional int32 cardsNum = 4; 83 | optional bool isDZ = 5; 84 | optional int32 boomNums = 6; 85 | repeated int32 outCards = 7; 86 | optional UserData userData = 8; 87 | optional int32 state = 9; 88 | 89 | } 90 | message CallOpInfo { 91 | optional int32 seat = 1; 92 | optional int32 value = 2; 93 | 94 | } 95 | message OpReq { 96 | optional int32 weaveKind = 1; 97 | optional int32 value = 2; 98 | repeated int32 cards = 3; 99 | 100 | } 101 | message OpEvent { 102 | optional int32 weaveKind = 1; 103 | optional int32 value = 2; 104 | optional int32 seat = 3; 105 | repeated int32 cards = 4; 106 | 107 | } 108 | message GameStartEvent { 109 | repeated MatchPlayer matchPlayers = 1; 110 | optional int32 curSeat = 2; 111 | optional int32 dzState = 3; 112 | repeated int32 lowCards = 4; 113 | optional int32 laizIndex = 5; 114 | 115 | } 116 | message opData { 117 | optional int32 state = 1; 118 | 119 | } 120 | message DissRoleRep { 121 | optional int32 id = 1; 122 | optional string nickname = 2; 123 | optional int32 agree = 3; 124 | optional bool suggest = 4; 125 | 126 | } 127 | message DissRoomData { 128 | repeated DissRoleRep roles = 1; 129 | optional int32 state = 2; 130 | optional int32 endtime = 3; 131 | optional int32 type = 4; 132 | 133 | } 134 | message GameOverPlayerData { 135 | optional int32 seat = 1; 136 | repeated int32 cards = 2; 137 | optional int32 curScore = 3; 138 | optional int32 score = 4; 139 | optional int32 boom = 5; 140 | optional int32 overState = 6; 141 | 142 | } 143 | message ParamConfigList { 144 | repeated ParamConfig datas = 1; 145 | 146 | } -------------------------------------------------------------------------------- /src/Game/Defs/EventDef.ts: -------------------------------------------------------------------------------- 1 | 2 | // Learn TypeScript: 3 | // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html 4 | // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html 5 | // Learn Attribute: 6 | // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html 7 | // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html 8 | // Learn life-cycle callbacks: 9 | // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html 10 | // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html 11 | 12 | export default class LoadingProgressEvenet extends YK.EventData 13 | { 14 | public data: LoadingProgressData 15 | public static EventID = "LoadingProgressEvenet" 16 | public constructor() 17 | { 18 | super(LoadingProgressEvenet.EventID, { Progress: 0, showInfoString: "正在加载..." }) 19 | } 20 | 21 | public set Progress(progress: number) 22 | { 23 | this.data.progress = progress 24 | 25 | } 26 | 27 | public set ShowInfoString(ShowInfoString: string) 28 | { 29 | this.data.showInfoString = ShowInfoString 30 | } 31 | 32 | } 33 | 34 | type LoadingProgressData = 35 | { 36 | progress: number, 37 | showInfoString: string 38 | } -------------------------------------------------------------------------------- /src/Game/Defs/ProtocolDef.ts: -------------------------------------------------------------------------------- 1 | // module netpack 2 | // { 3 | export default class ProtocolDef 4 | { 5 | public static ProtocolNames = 6 | [ 7 | "test", 8 | "packbase", 9 | "UserData", 10 | "loginReq", 11 | "loginResp", 12 | "tickOutEvent", 13 | "ParamConfig", 14 | "PrivateRoomInfo", 15 | "roomIdData", 16 | "PrivateDeskInfoReply", 17 | "MatchPlayer", 18 | "CallOpInfo", 19 | "OpReq", 20 | "OpEvent", 21 | "GameStartEvent", 22 | "opData", 23 | "DissRoleRep", 24 | "DissRoomData", 25 | "GameOverPlayerData", 26 | "ParamConfigList", 27 | 28 | ] 29 | public static Protocols: Array = [ 30 | { 31 | id: 100, 32 | request: "test", 33 | response: "test", 34 | }, 35 | { 36 | id: 101, 37 | request: "test", 38 | response: "", 39 | }, 40 | { 41 | id: 200, 42 | request: "loginReq", 43 | response: "loginResp", 44 | }, 45 | { 46 | id: 201, 47 | request: null, 48 | response: "tickOutEvent", 49 | }, 50 | { 51 | id: 401, 52 | request: "ParamConfigList", 53 | response: "PrivateDeskInfoReply", 54 | }, 55 | { 56 | id: 402, 57 | request: "roomIdData", 58 | response: "PrivateDeskInfoReply", 59 | }, 60 | { 61 | id: 403, 62 | request: null, 63 | response: null, 64 | }, 65 | { 66 | id: 404, 67 | request: null, 68 | response: "CallOpInfo", 69 | }, 70 | { 71 | id: 405, 72 | request: null, 73 | response: "GameStartEvent", 74 | }, 75 | { 76 | id: 406, 77 | request: "OpReq", 78 | response: null, 79 | }, 80 | { 81 | id: 407, 82 | request: null, 83 | response: "OpEvent", 84 | }, 85 | { 86 | id: 408, 87 | request: "roomIdData", 88 | response: "opData", 89 | }, 90 | { 91 | id: 409, 92 | request: null, 93 | response: "DissRoomData", 94 | }, 95 | { 96 | id: 410, 97 | request: null, 98 | response: "CallOpInfo", 99 | }, 100 | { 101 | id: 411, 102 | request: null, 103 | response: null, 104 | }, 105 | { 106 | id: 412, 107 | request: null, 108 | response: null, 109 | }, 110 | { 111 | id: 413, 112 | request: null, 113 | response: "MatchPlayer", 114 | }, 115 | 116 | ] 117 | 118 | } 119 | export class ActionType 120 | { 121 | public static test = 100; 122 | public static TestUserData = 101; 123 | public static login = 200; 124 | public static tickOutPlayer = 201; 125 | public static CreatePrivRoomReq = 401; 126 | public static LoginPirvRoom = 402; 127 | public static userReady = 403; 128 | public static userReadyEvent = 404; 129 | public static PrivGameStart = 405; 130 | public static PrivOp = 406; 131 | public static PrivOpEvent = 407; 132 | public static userReturn = 408; 133 | public static userDissEvent = 409; 134 | public static userReturnEvent = 410; 135 | public static privGameOverEvent = 411; 136 | public static privGameEndEvent = 412; 137 | public static loginPirvRoomEvent = 413; 138 | 139 | } 140 | export class ErrorCode 141 | { 142 | public static errorDic: Map = new Map() 143 | 144 | private static Add(id: number, msg: string): number 145 | { 146 | ErrorCode.errorDic.set(id, msg) 147 | return id 148 | } 149 | 150 | public static Get(id) 151 | { 152 | if (ErrorCode.errorDic.has(id)) 153 | return ErrorCode.Get(id) 154 | return "未知错误:id=" + id 155 | } 156 | public static SystemError = 157 | { 158 | success: ErrorCode.Add(0, "请求成功"), 159 | unknow: ErrorCode.Add(1, "未知错误"), 160 | argument: ErrorCode.Add(2, "参数错误"), 161 | protoNotExists: ErrorCode.Add(3, "不存在此协议"), 162 | serviceIsStoped: ErrorCode.Add(4, "服务故障"), 163 | sessionNotExists: ErrorCode.Add(5, "不存在此Session"), 164 | moduleNotImpl: ErrorCode.Add(6, "此模块未实现"), 165 | protoNotImpl: ErrorCode.Add(7, "此协议未实现"), 166 | noLogin: ErrorCode.Add(8, "尚未登录"), 167 | packHeaderNil: ErrorCode.Add(9, "包头是空的"), 168 | forward: ErrorCode.Add(10, "重定向"), 169 | serverMaintenance: ErrorCode.Add(11, "服务器维护"), 170 | busy: ErrorCode.Add(12, "服务忙"), 171 | logined: ErrorCode.Add(13, "已登录"), 172 | dbServerStoped: ErrorCode.Add(14, "数据服务故障"), 173 | noLoginGame: ErrorCode.Add(15, "未进入游戏"), 174 | notOnline: ErrorCode.Add(16, "玩家不在线"), 175 | saveCacheFailed: ErrorCode.Add(17, "写入缓存失败"), 176 | logoutingGame: ErrorCode.Add(18, "正在退出游戏中"), 177 | noUseableService: ErrorCode.Add(19, "没有可用的服务"), 178 | sessionInvalid: ErrorCode.Add(20, "此session是非法的"), 179 | sessionTimeout: ErrorCode.Add(21, "此session已过期"), 180 | sessionNoMatch: ErrorCode.Add(22, "会话不匹配"), 181 | serviceNotImpl: ErrorCode.Add(23, "此服务未实现"), 182 | functionNotOpen: ErrorCode.Add(24, "此功能尚未开放"), 183 | serviceIsOpened: ErrorCode.Add(25, "服务已开放"), 184 | serviceIsClosed: ErrorCode.Add(26, "服务已关闭"), 185 | serviceIsOffline: ErrorCode.Add(27, "服务已下线"), 186 | msgTimeOut: ErrorCode.Add(-1, "超时"), 187 | } 188 | public static authError = 189 | { 190 | loginAccountFill: ErrorCode.Add(1001, "账号或者密码错误"), 191 | accountExist: ErrorCode.Add(1002, "账号重复"), 192 | accountAndPwdIsNull: ErrorCode.Add(1003, "账号或者密码不能为空"), 193 | roleIdNoExist: ErrorCode.Add(1004, "无效的用户id或者token无效"), 194 | } 195 | 196 | } 197 | // } -------------------------------------------------------------------------------- /src/Game/Modes/DDZLogic.ts: -------------------------------------------------------------------------------- 1 | class DDZLogic 2 | { 3 | public CFG = 4 | { 5 | MAX_SHUN: 14, 6 | MAX_ZHA: 16 7 | } 8 | 9 | public static CardPools = 10 | [ 11 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 12 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 13 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 14 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 15 | 0x0E, 0x0F 16 | ] 17 | 18 | public static GetColorTypeAndValue(cardid: number) 19 | { 20 | let color = cardid >> 4 21 | let value = cardid & 0x0F 22 | return { color: color, value: value } 23 | } 24 | 25 | public GetCardIndex(card) 26 | { 27 | let c = card & 0x0f 28 | if (c == 0x01) c = 14 29 | else if (c == 0x02) c = 16 30 | else if (c == 0x0E) c = 17 31 | else if (c == 0x0F) c = 18 32 | return c 33 | } 34 | 35 | /** 36 | * 获取牌的类型 37 | * @param outCards 外部 38 | */ 39 | public GetCardType(outCards: Array) 40 | { 41 | let tmpCards = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] 42 | outCards.forEach(element => 43 | { 44 | let index = this.GetCardIndex(element) 45 | tmpCards[index] = tmpCards[index] + 1 46 | }); 47 | 48 | let counts = [0, 0, 0, 0] 49 | let cards = [[], [], [], []] 50 | 51 | for (var index = 0; index < tmpCards.length; index++) 52 | { 53 | var c = tmpCards[index]; 54 | if (c > 0) 55 | { 56 | counts[c] = counts[c] + 1 57 | cards[c].push(cards[c], index + 1) 58 | } 59 | } 60 | 61 | if (counts[3] != 0) 62 | return this.GetType4(counts, cards) 63 | else if (counts[2] != 0) 64 | return this.GetType3(counts, cards) 65 | else if (counts[1] != 0) 66 | return this.GetType2(counts, cards) 67 | else if (counts[0] != 0) 68 | return this.GetType1(counts, cards) 69 | } 70 | 71 | /** 72 | * 判断四张相同的牌的组合 73 | * @param counts 1,2,3,4组合的数目 74 | * @param cards 数目分别为1,2,3,4的牌 75 | */ 76 | public GetType4(counts: Array, cards: Array>): CardTypeInfo 77 | { 78 | let ret = null 79 | 80 | let sp = this.SplitCards(counts, cards) 81 | 82 | let lastCard = sp.cs_4[sp.cs_4.length - 1] 83 | 84 | let otherSum = sp.count3Num * 3 + sp.count2Num * 2 + sp.count1Num //剩余的牌张数 除了炸弹 85 | 86 | if (sp.count4Num == 1) 87 | { 88 | if (otherSum == 0) 89 | { 90 | ret = new CardTypeInfo(CardType.t_4, lastCard) 91 | } 92 | else if (otherSum == 2) //此处要注意能不能出现四代二是一个对子的两个 93 | { 94 | ret = new CardTypeInfo(CardType.t_42, lastCard) 95 | } 96 | else if (otherSum == 4 && sp.count2Num == 2) 97 | { 98 | ret = new CardTypeInfo(CardType.t_422, lastCard) 99 | } 100 | } 101 | if (ret == null) 102 | { 103 | if (sp.count3Num > 1 && this.IsContinue(sp.cs_3)) //三张的个数大于三才有可能是飞机 那么可能就是飞机做了翅膀 104 | { 105 | 106 | //炸弹当单牌 107 | if (sp.count3Num == 4) 108 | { 109 | if (sp.count2Num + sp.count1Num == 0) //如果有三个三张的那么就不能有多余的牌了 110 | { 111 | ret = new CardTypeInfo(CardType.t_31n, sp.cs_3[sp.cs_3.length - 1], sp.count3Num) 112 | } 113 | } 114 | else if (sp.count3Num == (2 + sp.count2Num) && sp.count1Num == 0) 115 | { 116 | ret = new CardTypeInfo(CardType.t_32n, sp.cs_3[sp.cs_3.length - 1], sp.count3Num) 117 | } 118 | } 119 | if (ret == null) 120 | { 121 | if (sp.count4Num == 2 && otherSum == 0) 122 | { 123 | ret = new CardTypeInfo(CardType.t_422, sp.cs_4[sp.cs_4.length - 1], sp.count3Num) 124 | } 125 | } 126 | 127 | if (ret == null) 128 | { 129 | if ((otherSum + sp.count4Num * 4) % 4 == 0) 130 | { 131 | for (var index = 0; index < sp.count4Num; index++) 132 | { 133 | let c = sp.cs_4.splice(0, 1) 134 | sp.cs_3.push(c[0]) 135 | sp.cs_1.push(c[0]) 136 | counts[3]-- 137 | counts[2]++ 138 | counts[0]++ 139 | } 140 | sp.cs_3.sort((a: number, b: number) => 141 | { 142 | if (a < b) return -1 143 | else if (a == b) return 0 144 | else return 1 145 | }) 146 | return this.GetType3(counts, cards) 147 | } 148 | } 149 | } 150 | return ret 151 | } 152 | 153 | 154 | public GetType3(counts: Array, cards: Array>): CardTypeInfo 155 | { 156 | let ret: CardTypeInfo = null 157 | 158 | let sp = this.SplitCards(counts, cards) 159 | 160 | let lastCard = sp.cs_3[sp.cs_3.length - 1] 161 | let otherSum = sp.count2Num * 2 + sp.count1Num 162 | 163 | if (sp.count3Num == 1) 164 | { 165 | if (sp.count2Num == 1 && sp.count1Num == 0) 166 | { 167 | ret = new CardTypeInfo(CardType.t_32, lastCard) 168 | } 169 | else if (sp.count2Num == 0 && sp.count1Num == 1) 170 | { 171 | ret = new CardTypeInfo(CardType.t_31, lastCard) 172 | } 173 | else if (sp.count2Num == 0 && sp.count1Num == 0) 174 | { 175 | ret = new CardTypeInfo(CardType.t_3, lastCard) 176 | } 177 | } 178 | if (ret == null) 179 | { 180 | let sum: number = sp.count1Num + sp.count2Num * 2 + sp.count3Num * 3 181 | let max = this.GetMaxContinue(sp.cs_3) 182 | if (max.length >= 2) 183 | { 184 | if (sum / 3 == max.length && sp.count3Num == max.length) 185 | { 186 | ret = new CardTypeInfo(CardType.t_3n, max[max.length - 1]) 187 | } 188 | else if (sum / 4 == max.length) 189 | { 190 | ret = new CardTypeInfo(CardType.t_31n, max[max.length - 1]) 191 | } 192 | } 193 | if (ret == null) 194 | { 195 | //特殊型3334445556667778 196 | if (max.length == 5 && sum == 16) 197 | ret = new CardTypeInfo(CardType.t_31n, max[max.length - 1]) 198 | else if (max.length == 6 && sum == 20) 199 | ret = new CardTypeInfo(CardType.t_31n, max[max.length - 1]) 200 | } 201 | } 202 | 203 | 204 | return ret 205 | } 206 | 207 | public GetType2(counts: Array, cards: Array>) 208 | { 209 | let ret: CardTypeInfo = null 210 | if (counts[0] == 0) 211 | { 212 | if (counts[1] == 1) 213 | { 214 | ret = new CardTypeInfo(CardType.t_2, cards[1][cards[1].length - 1]) 215 | } 216 | 217 | if (this.IsContinue(cards[1]) && counts[1] > 2) 218 | { 219 | ret = new CardTypeInfo(CardType.t_2n, cards[1][cards[1].length - 1], counts[2]) 220 | } 221 | } 222 | } 223 | 224 | public GetType1(counts: Array, cards: Array>) 225 | { 226 | let ret: CardTypeInfo = null 227 | let count = counts[0] 228 | if (count == 1) 229 | { 230 | ret = new CardTypeInfo(CardType.t_1, cards[0][cards[0].length - 1]) 231 | } 232 | else 233 | { 234 | if (count == 2 && cards[0][0] == 17 && cards[0][1] == 18) 235 | { 236 | ret = new CardTypeInfo(CardType.t_king, cards[0][1]) 237 | } 238 | if (ret == null) 239 | { 240 | if (cards[0].length >= 5 && this.IsContinue(cards[0])) 241 | { 242 | ret = new CardTypeInfo(CardType.t_king, cards[0][cards[0].length - 1], cards[0].length) 243 | } 244 | } 245 | } 246 | return ret 247 | } 248 | 249 | private SplitCards(counts: Array, cards: Array>) 250 | { 251 | /** 252 | * 所有单牌 253 | */ 254 | let cs_1 = cards[0] 255 | /** 256 | * 对子 257 | */ 258 | let cs_2 = cards[1] 259 | 260 | /** 261 | * 三张的 262 | */ 263 | let cs_3 = cards[2] 264 | 265 | /** 266 | * 四张相同的 267 | */ 268 | let cs_4 = cards[3] 269 | 270 | let count4Num = counts[3] 271 | let count3Num = counts[2] 272 | let count2Num = counts[1] 273 | let count1Num = counts[0] 274 | return { 275 | cs_1: cs_1, cs_2: cs_2, cs_3: cs_3, cs_4: cs_4, 276 | count4Num: count4Num, count3Num: count3Num, count2Num: count2Num, count1Num: count1Num 277 | } 278 | } 279 | 280 | /** 281 | * 是否连续的牌 282 | * @param cards 牌列表 283 | */ 284 | public IsContinue(cards: Array) 285 | { 286 | let last = -1 287 | for (var index = 0; index < cards.length; index++) 288 | { 289 | var element = cards[index]; 290 | if (last != -1 && last + 1 != element) 291 | { 292 | return false 293 | } 294 | last = element 295 | } 296 | return true 297 | } 298 | 299 | /** 300 | * 301 | * @param cards 获取最大能连的牌 302 | */ 303 | public GetMaxContinue(cards: Array) 304 | { 305 | let all: Array> = new Array>() 306 | let temp: Array = new Array() 307 | for (let index = 0; index < cards.length; index++) 308 | { 309 | let element = cards[index]; 310 | if (temp.length > 0 && temp[temp.length - 1] == element - 1) 311 | { 312 | temp.push(element) 313 | } 314 | else 315 | { 316 | if (temp.length > 0) 317 | { 318 | all.push(temp) 319 | } 320 | temp = new Array() 321 | temp.push(element) 322 | } 323 | } 324 | let m: Array = null 325 | all.forEach(element => 326 | { 327 | if (m == null) m = element 328 | else if (element.length >= m.length) 329 | { 330 | m = element 331 | } 332 | }); 333 | return m 334 | } 335 | 336 | /** 337 | * 是不是能压得过 338 | * @param info1 牌的类型 339 | * @param info2 牌的类型 340 | */ 341 | public IsBig(info1: CardTypeInfo, info2: CardTypeInfo) 342 | { 343 | 344 | } 345 | } 346 | 347 | 348 | /** 349 | * 牌的类型 350 | */ 351 | enum CardType 352 | { 353 | /** 354 | * 单张 355 | */ 356 | t_1 = 0, 357 | 358 | /** 359 | * 顺子 360 | */ 361 | t_1n, 362 | 363 | /** 364 | * 对子 365 | */ 366 | t_2, 367 | 368 | /** 369 | * 连对 370 | */ 371 | t_2n, 372 | 373 | /** 374 | * 三不带 375 | */ 376 | t_3, 377 | 378 | /** 379 | * 飞机不带 380 | */ 381 | t_3n, 382 | 383 | /** 384 | * 三带一 385 | */ 386 | t_31, 387 | 388 | /** 389 | * 飞机带单牌 390 | */ 391 | t_31n, 392 | 393 | /** 394 | * 三带二 395 | */ 396 | t_32, 397 | 398 | /** 399 | * 飞机带对 400 | */ 401 | t_32n, 402 | 403 | /** 404 | * 炸弹 405 | */ 406 | t_4, 407 | 408 | /** 409 | * 四带二 410 | */ 411 | t_42, 412 | /** 413 | * 四带两对 414 | */ 415 | t_422, 416 | /** 417 | * 王炸 418 | */ 419 | t_king, 420 | } 421 | 422 | /** 423 | * 牌的花色 424 | */ 425 | enum CardColor 426 | { 427 | /** 428 | * 黑 429 | */ 430 | Hei = 0, 431 | 432 | /** 433 | * 红 434 | */ 435 | Hong, 436 | 437 | /** 438 | * 梅 439 | */ 440 | Mei, 441 | 442 | /** 443 | * 方片 444 | */ 445 | Fang 446 | } 447 | 448 | /** 449 | * 牌的类型信息 450 | */ 451 | class CardTypeInfo 452 | { 453 | constructor(type: CardType, card: number, n: number = 0) 454 | { 455 | this.type = type 456 | this.card = card 457 | this.n = n 458 | } 459 | /** 460 | * 牌型 461 | */ 462 | public type: CardType = null; 463 | /** 464 | * 最大的牌 465 | */ 466 | public card: number = null; 467 | 468 | /** 469 | * 连着的长度 470 | */ 471 | n: number = 0 472 | } 473 | -------------------------------------------------------------------------------- /src/Game/Modes/RoleMode.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class RoleMode extends YK.IMode 3 | { 4 | public accountInfo = { userid: 0, token: "" } 5 | public roleInfo: netpack.UserData 6 | public OnInitData(param: any): void 7 | { 8 | this.eventMgr.setNetCallback(this.OnNetEvenet, 99) 9 | this.eventMgr.addNetEvent(200); 10 | } 11 | public OnClear(): void 12 | { 13 | } 14 | 15 | public OnDestroy(): void 16 | { 17 | super.OnDestroy() 18 | } 19 | 20 | public OnNetEvenet(ev: YK.ResponseMessageEvent) 21 | { 22 | if (ev.Data.head.errorcode == 0) 23 | { 24 | if (ev.Data.head.cmd == 200) 25 | { 26 | this.OnLoginResp(ev.Data.msg) 27 | } 28 | } 29 | 30 | } 31 | 32 | public SendHttpLogin(account: string, pwd: string, callBack: YK.Func) 33 | { 34 | YK.NetMgr.Instance.SendGet("modeName=account&api=login&account=" + account + "&pwd=" + pwd, new YK.Func(this, (res: YK.HttpRespData) => 35 | { 36 | if (res != null && res.errorcode == 0) 37 | { 38 | this.accountInfo.token = res.data.token 39 | this.accountInfo.userid = res.data.userid 40 | } 41 | if (callBack != null) 42 | { 43 | callBack.Invoke(res) 44 | } 45 | })); 46 | } 47 | 48 | /** 49 | * 发送登陆 50 | * @param userid 用户id 51 | * @param token 账号token 52 | */ 53 | public SendLogin(): void 54 | { 55 | let sendData: netpack.loginReq = { token: this.accountInfo.token, roleid: this.accountInfo.userid } 56 | YK.NetMgr.Instance.Send(200, sendData) 57 | } 58 | 59 | /** 60 | * 登陆返回 61 | * @param loginResp 登陆的返回信息 62 | */ 63 | public OnLoginResp(loginResp: netpack.loginResp) 64 | { 65 | this.roleInfo = loginResp.roleinfo as netpack.UserData 66 | } 67 | } -------------------------------------------------------------------------------- /src/Game/Scenes/LoadingScene.ts: -------------------------------------------------------------------------------- 1 | import ProtocolDef from "../Defs/ProtocolDef"; 2 | import SceneBase = YK.SceneBase 3 | import EventData = YK.EventData 4 | import LoginScene from "./LoginScene"; 5 | import WaitWind from "../Winds/WaitWind"; 6 | import LoadingWind from "../Winds/LoadingWind"; 7 | import LoadingProgressEvenet from "../Defs/EventDef"; 8 | export default class LoadingScene extends SceneBase 9 | { 10 | private initNeedLoadTask: YK.LoadGruopInfo 11 | protected OnInit(param: any) 12 | { 13 | super.OnInit(param) 14 | this.needLoadRes.add("res/source/Loading_atlas_vckm32.jpg", Laya.Loader.IMAGE, true) 15 | .add("res/source/Loading_atlas0.png", Laya.Loader.IMAGE, true) 16 | .add("res/source/Loading.bin", Laya.Loader.BUFFER, true, true) 17 | 18 | this.initNeedLoadTask = new YK.LoadGruopInfo() 19 | 20 | this.initNeedLoadTask.add("res/external/BasePack_atlas0.png", Laya.Loader.IMAGE, true) 21 | .add("res/external/BasePack.bin", Laya.Loader.BUFFER, true, true) 22 | .onItemCompletion(this.loadItemCompletion, this) 23 | .onCompletion(this.loadGameResFinish, this) 24 | } 25 | 26 | 27 | private loadItemCompletion() 28 | { 29 | console.log(this.initNeedLoadTask.Progress) 30 | let ev = new LoadingProgressEvenet(); 31 | ev.Progress = this.initNeedLoadTask.Progress 32 | YK.UIMgr.Instance.DispatchEvent(ev) 33 | } 34 | 35 | /** 36 | * 资源加载完成 37 | */ 38 | private loadGameResFinish() 39 | { 40 | fairygui.UIObjectFactory.setPackageItemExtension(fairygui.UIConfig.globalModalWaiting,WaitWind) 41 | this.AddProto() 42 | 43 | ProtocolDef.Protocols.forEach(element => 44 | { 45 | YK.ProtoMap.AddProto(element) 46 | }); 47 | } 48 | 49 | private AddProto() 50 | { 51 | YK.NetMgr.Instance.AddProto("netpack", ProtocolDef.ProtocolNames) 52 | this.StartGame() 53 | } 54 | 55 | 56 | public StartGame() 57 | { 58 | let ev = new LoadingProgressEvenet(); 59 | ev.Progress = 100 60 | YK.UIMgr.Instance.DispatchEvent(ev) 61 | YK. SceneMgr.Instance.GoToScene(LoginScene) 62 | } 63 | 64 | protected OnEnter(param: any) 65 | { 66 | super.OnEnter(param) 67 | YK.UIMgr.Instance.ShowWind(LoadingWind) 68 | this.initNeedLoadTask.start() 69 | } 70 | 71 | protected OnHandler(ev: YK.EventData) 72 | { 73 | super.OnHandler(ev) 74 | } 75 | 76 | protected OnLeave() 77 | { 78 | super.OnLeave() 79 | } 80 | 81 | protected OnDestroy() 82 | { 83 | super.OnDestroy() 84 | } 85 | 86 | protected OnLoaded() 87 | { 88 | super.OnLoaded() 89 | } 90 | 91 | protected OnTaskFinished() 92 | { 93 | super.OnTaskFinished() 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Game/Scenes/LoginScene.ts: -------------------------------------------------------------------------------- 1 | import SceneBase = YK.SceneBase 2 | import EventData = YK.EventData 3 | import LoginWind from "../Winds/LoginWind"; 4 | 5 | export default class LoginScene extends SceneBase 6 | { 7 | protected firstWind: any = LoginWind 8 | protected OnInit(param: any) 9 | { 10 | super.OnInit(param) 11 | this.needLoadRes 12 | .add("res/external/LoginPack.bin", Laya.Loader.BUFFER, true, true) 13 | .add("res/external/BasePack.bin", Laya.Loader.BUFFER, true, true) 14 | .add("res/external/BasePack_atlas0.png", Laya.Loader.IMAGE, true) 15 | } 16 | 17 | protected OnEnter(param: any) 18 | { 19 | super.OnEnter(param) 20 | } 21 | 22 | protected OnHandler(ev: EventData) 23 | { 24 | super.OnHandler(ev) 25 | } 26 | 27 | protected OnLeave() 28 | { 29 | super.OnLeave() 30 | } 31 | 32 | protected OnDestroy() 33 | { 34 | super.OnDestroy() 35 | } 36 | 37 | protected OnLoaded() 38 | { 39 | super.OnLoaded() 40 | } 41 | 42 | protected OnTaskFinished() 43 | { 44 | super.OnTaskFinished() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Game/Scenes/MainScene.ts: -------------------------------------------------------------------------------- 1 | import MainWind from "../Winds/MainWind"; 2 | 3 | export default class MainScene extends YK.SceneBase 4 | { 5 | protected firstWind: any = MainWind 6 | protected OnInit(param: any) 7 | { 8 | super.OnInit(param) 9 | this.needLoadRes.add("res/external/MainPack_atlas0.png" 10 | , Laya.Loader.IMAGE, true) 11 | 12 | this.needLoadRes.add("res/external/MainPack.bin" 13 | , Laya.Loader.BUFFER, true, true) 14 | } 15 | 16 | protected OnEnter(param: any) 17 | { 18 | super.OnEnter(param) 19 | } 20 | 21 | protected OnHandler(ev: YK.EventData) 22 | { 23 | super.OnHandler(ev) 24 | } 25 | 26 | protected OnLeave() 27 | { 28 | super.OnLeave() 29 | } 30 | 31 | protected OnDestroy() 32 | { 33 | super.OnDestroy() 34 | } 35 | 36 | protected OnLoaded() 37 | { 38 | super.OnLoaded() 39 | } 40 | 41 | protected OnTaskFinished() 42 | { 43 | super.OnTaskFinished() 44 | } 45 | } -------------------------------------------------------------------------------- /src/Game/Winds/GamePlay/CardItem.ts: -------------------------------------------------------------------------------- 1 | class CardItem extends fairygui.GComponent 2 | { 3 | private back: fairygui.Controller 4 | private hua: fairygui.Controller 5 | private blackNum: fairygui.GTextField 6 | private redNum: fairygui.GTextField 7 | protected constructFromXML(xml: any): void 8 | { 9 | super.constructFromXML(xml); 10 | this.back = this.getController("back") 11 | this.hua = this.getController("hua") 12 | this.blackNum = this.getChild("blackNum").asTextField 13 | this.redNum = this.getChild("redNum").asTextField 14 | } 15 | public Use(data: ShowCardItemData) 16 | { 17 | if (data.isShow) 18 | { 19 | this.back.selectedIndex = 1 20 | let info = DDZLogic.GetColorTypeAndValue(data.id) 21 | if (info.value == 0x0E || info.value == 0x0F) 22 | { 23 | if (info.value == 0xE) 24 | { 25 | info.color = 4 26 | } 27 | else 28 | { 29 | info.color = 5 30 | } 31 | info.value = 0x0E 32 | } 33 | this.hua.selectedIndex = info.color 34 | this.redNum.text = info.value.toString(16) 35 | this.blackNum.text = this.redNum.text 36 | } 37 | else 38 | { 39 | this.back.selectedIndex = 0 40 | } 41 | this.parent = data.parent 42 | this.setScale(data.scal,data.scal) 43 | this.setXY(data.x, data.y) 44 | } 45 | 46 | public UnUse() 47 | { 48 | this.parent = null 49 | } 50 | 51 | public dispose() 52 | { 53 | super.dispose() 54 | } 55 | } -------------------------------------------------------------------------------- /src/Game/Winds/GamePlay/CardMgr.ts: -------------------------------------------------------------------------------- 1 | class CardMgr 2 | { 3 | private url = "ui://GamePack/CardMode" 4 | private mPools: fairygui.GObjectPool 5 | private static mInstance: CardMgr 6 | public constructor() 7 | { 8 | if (CardMgr.mInstance == null) CardMgr.mInstance = this 9 | this.mPools = new fairygui.GObjectPool() 10 | fairygui.UIObjectFactory.setPackageItemExtension(this.url, CardItem) 11 | } 12 | public static get Instance() 13 | { 14 | if (this.mInstance == null) new CardMgr() 15 | return this.mInstance 16 | } 17 | 18 | public Get(data: ShowCardItemData) 19 | { 20 | let obj: CardItem = this.mPools.getObject(this.url) as CardItem 21 | if (obj != null) 22 | { 23 | obj.Use(data) 24 | } 25 | } 26 | 27 | public Return(obj: CardItem) 28 | { 29 | if (obj != null) 30 | { 31 | obj.UnUse() 32 | } 33 | this.mPools.returnObject(obj) 34 | } 35 | 36 | public Clear() 37 | { 38 | this.mPools.clear() 39 | } 40 | } 41 | 42 | class ShowCardItemData 43 | { 44 | public isShow: boolean = true 45 | public id: number = 0x00 46 | public parent: fairygui.GRoot = null 47 | public x: number = 0 48 | public y: number = 0 49 | public scal = 1 50 | } -------------------------------------------------------------------------------- /src/Game/Winds/LoadingWind.ts: -------------------------------------------------------------------------------- 1 | import BaseUI = YK.BaseUI 2 | import LoadingProgressEvenet from "../Defs/EventDef"; 3 | export default class LoadingWind extends YK.BaseUI 4 | { 5 | protected packName = "Loading" 6 | protected resName = "loadingWind" 7 | public modal: boolean = false 8 | public dontDel: boolean = true 9 | protected btnNameStartsWith: string = "Btn" 10 | protected isNeedShowAnimation: boolean = false 11 | protected isNeedHideAnimation: boolean = false 12 | 13 | protected mlabelProgress: fairygui.GTextField 14 | protected mlablMsg: fairygui.GTextField 15 | private mProgress: number = 0 16 | private mShowInfoString: string = "正在加载..." 17 | 18 | protected OninitWind() 19 | { 20 | this.mlabelProgress = this.UIObj.get("labelProgress") 21 | this.mlablMsg = this.UIObj.get("lablMsg") 22 | this.mlabelProgress.text = "0%" 23 | 24 | } 25 | 26 | protected OnShowWind() 27 | { 28 | this.eventMgr.addUIEvent(LoadingProgressEvenet.EventID) 29 | 30 | this.mProgress = 0 31 | this.mShowInfoString = "正在加载..." 32 | this.mlabelProgress.text = this.mProgress.toFixed() + "%" 33 | } 34 | 35 | protected OnHideWind() 36 | { 37 | 38 | } 39 | protected OnHandler(ev: YK.EventData) 40 | { 41 | switch (ev.cmd) 42 | { 43 | case LoadingProgressEvenet.EventID: 44 | this.RefreshInfo(ev as LoadingProgressEvenet) 45 | break; 46 | } 47 | } 48 | 49 | public RefreshInfo(ev: LoadingProgressEvenet) 50 | { 51 | this.mProgress = ev.data.progress 52 | this.mlabelProgress.text = this.mProgress.toFixed() + "%" 53 | } 54 | } -------------------------------------------------------------------------------- /src/Game/Winds/LoginWind.ts: -------------------------------------------------------------------------------- 1 | import RoleMode from "../Modes/RoleMode"; 2 | import LoadingWind from "./LoadingWind"; 3 | import MessageBox from "./MessageBox"; 4 | import MainScene from "../Scenes/MainScene"; 5 | 6 | export default class LoginWind extends YK.BaseUI 7 | { 8 | protected packName = "LoginPack" 9 | protected resName = "LoginWindow" 10 | public modal: boolean = false 11 | public dontDel: boolean = true 12 | protected btnNameStartsWith: string = "Btn" 13 | protected isNeedShowAnimation: boolean = false 14 | protected isNeedHideAnimation: boolean = false 15 | 16 | private mLabelAcc: fairygui.GTextField 17 | private mLabelPass: fairygui.GTextField 18 | 19 | protected OninitWind() 20 | { 21 | this.eventMgr.setNetCallback(this.OnNetMsg) 22 | this.mLabelAcc = this.UIObj.get("LabelAcc") 23 | this.mLabelPass = this.UIObj.get("LabelPass") 24 | } 25 | 26 | protected OnShowWind() 27 | { 28 | YK.UIMgr.Instance.HideWind(LoadingWind) 29 | this.eventMgr.addNetEvent(200); 30 | this.eventMgr.addNetEvent(YK.NetMgrEventDef.onopen) 31 | this.eventMgr.addNetEvent(YK.NetMgrEventDef.onerror) 32 | this.eventMgr.addModeEvent(YK.ModeMgr.EventType.SENDINITMSGOK) 33 | } 34 | 35 | protected OnHideWind() 36 | { 37 | 38 | } 39 | 40 | protected OnBtnClick(ev: fairygui.GButton) 41 | { 42 | super.OnBtnClick(ev) 43 | if (ev.name == "BtnLogin") 44 | { 45 | this.HttpLogin() 46 | } 47 | } 48 | 49 | 50 | public HttpLogin() 51 | { 52 | if (this.mLabelAcc.text == "" || this.mLabelPass.text == "") 53 | { 54 | MessageBox.Create("请输入账号密码").Show() 55 | } 56 | else 57 | { 58 | YK.UIMgr.Instance.ShowModalWait() 59 | YK. ModeMgr.Instance.GetMode(RoleMode).SendHttpLogin(this.mLabelAcc.text, 60 | this.mLabelPass.text, 61 | new YK.Func(this, (res: YK.HttpRespData) => 62 | { 63 | 64 | if (res != null) 65 | { 66 | if (res.errorcode == 0) 67 | { 68 | this.ConnectServer() 69 | } 70 | else 71 | { 72 | YK.UIMgr.Instance.CloseModalWait() 73 | MessageBox.Create(res.msg).Show() 74 | } 75 | } 76 | else 77 | { 78 | YK.UIMgr.Instance.CloseModalWait() 79 | MessageBox.Create("登陆失败尝试重新登陆").Show() 80 | } 81 | })) 82 | } 83 | } 84 | 85 | public ConnectServer() 86 | { 87 | YK.NetMgr.Instance.connect() 88 | } 89 | 90 | public OnConnetServer() 91 | { 92 | YK. ModeMgr.Instance.GetMode(RoleMode).SendLogin() 93 | } 94 | 95 | public OnLogin(ev: YK.ResponseDataInfo) 96 | { 97 | YK.UIMgr.Instance.CloseModalWait() 98 | if (ev.head.errorcode == 0) 99 | { 100 | YK.UIMgr.Instance.ShowModalWait() 101 | YK.ModeMgr.Instance.SendInitMsg() 102 | } 103 | else 104 | { 105 | MessageBox.Create(ev.msg).Show() 106 | } 107 | } 108 | 109 | 110 | public OnInitMsged() 111 | { 112 | console.error("开始游戏") 113 | YK.UIMgr.Instance.CloseModalWait() 114 | 115 | YK.SceneMgr.Instance.GoToScene(MainScene) 116 | } 117 | 118 | public OnConnetServerError(error: string) 119 | { 120 | MessageBox.Create("链接服务器失败,尝试重连") 121 | .SetBtnConfirmCallBack(new YK.Func(this, () => 122 | { 123 | this.ConnectServer() 124 | }), "重试") 125 | .Show() 126 | } 127 | 128 | protected OnNetMsg(ev: YK.ResponseMessageEvent) 129 | { 130 | if (ev.cmd == YK.NetMgrEventDef.onopen) 131 | { 132 | this.OnConnetServer() 133 | } 134 | else if (ev.cmd == YK.NetMgrEventDef.onerror 135 | || ev.cmd == YK.NetMgrEventDef.onclose) 136 | { 137 | this.OnConnetServerError(ev.data) 138 | } 139 | else 140 | { 141 | if (ev.Data.head.cmd == 200) 142 | { 143 | this.OnLogin(ev.Data) 144 | } 145 | } 146 | } 147 | 148 | protected OnHandler(ev: YK.EventData) 149 | { 150 | if (ev.cmd ==YK. ModeMgr.EventType.SENDINITMSGOK) 151 | { 152 | this.OnInitMsged() 153 | } 154 | } 155 | } -------------------------------------------------------------------------------- /src/Game/Winds/MainWind.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class MainWind extends YK.BaseUI 3 | { 4 | protected packName = "MainPack" 5 | protected resName = "MainWindow" 6 | public modal: boolean = false 7 | protected btnNameStartsWith: string = "Btn" 8 | protected isNeedShowAnimation: boolean = false 9 | protected isNeedHideAnimation: boolean = false 10 | protected OninitWind() 11 | { 12 | 13 | } 14 | 15 | protected OnShowWind() 16 | { 17 | } 18 | 19 | protected OnHideWind() 20 | { 21 | 22 | } 23 | protected OnHandler(ev: YK.EventData) 24 | { 25 | } 26 | } -------------------------------------------------------------------------------- /src/Game/Winds/MessageBox.ts: -------------------------------------------------------------------------------- 1 | export default class MessageBox extends YK.BaseUI 2 | { 3 | public modal: boolean = true 4 | public dontDel: boolean = true 5 | protected packName = "BasePack" 6 | protected resName = "MessageBox" 7 | protected clickBbackgroundClose = false 8 | 9 | protected labelMsg: fairygui.GTextField 10 | 11 | private BtnOK: fairygui.GButton 12 | 13 | private BtnCancel: fairygui.GButton 14 | 15 | private BtnConfirm: fairygui.GButton 16 | 17 | private static mMessageBoxDataPools: Array = new Array() 18 | 19 | public static Create(content: string): MessageBoxData 20 | { 21 | if (this.mMessageBoxDataPools.length > 0) 22 | { 23 | let da = this.mMessageBoxDataPools.pop() 24 | da.SetContent(content) 25 | return da 26 | } 27 | return new MessageBoxData(content) 28 | } 29 | 30 | 31 | public dispose() 32 | { 33 | super.dispose() 34 | MessageBox.mMessageBoxDataPools.splice(0, MessageBox.mMessageBoxDataPools.length) 35 | } 36 | 37 | protected OnBtnClick(ev: fairygui.GButton) 38 | { 39 | super.OnBtnClick(ev) 40 | if (ev == this.BtnOK) 41 | { 42 | if (this.mData.BtnOkCallBack != null) 43 | this.mData.BtnOkCallBack.Invoke() 44 | this.OnBtnClose() 45 | } 46 | else if (ev == this.BtnCancel) 47 | { 48 | if (this.mData.BtnCancelCallBack != null) 49 | this.mData.BtnCancelCallBack.Invoke() 50 | this.OnBtnClose() 51 | } 52 | else if (ev == this.BtnConfirm) 53 | { 54 | if (this.mData.BtnBtnConfirmCallBack != null) 55 | this.mData.BtnBtnConfirmCallBack.Invoke() 56 | this.OnBtnClose() 57 | } 58 | } 59 | 60 | protected OninitWind() 61 | { 62 | this.BtnOK = this.UIObj.get("BtnOK") 63 | this.BtnCancel = this.UIObj.get("BtnCancel") 64 | this.BtnConfirm = this.UIObj.get("BtnConfirm") 65 | this.labelMsg = this.UIObj.get("labelMsg") 66 | } 67 | 68 | protected OnShowWind() 69 | { 70 | this.mData = this.data as MessageBoxData 71 | if (this.mData.type == MessageBoxType.None) 72 | { 73 | } 74 | else if (this.mData.type == MessageBoxType.ShowConfirm) 75 | { 76 | this.BtnConfirm.text = this.mData.labBtnConfirmStr 77 | } 78 | else 79 | { 80 | this.BtnOK.text = this.mData.labBtnOkStr 81 | this.BtnCancel.text = this.mData.labBtnCancelStr 82 | } 83 | 84 | this.UICtrls.get("stateCtrl").selectedIndex = this.mData.type 85 | this.labelMsg.text = this.mData.content 86 | } 87 | 88 | private mData: MessageBoxData = null 89 | protected OnHideWind() 90 | { 91 | 92 | if (this.mData != null) 93 | { 94 | this.mData.reset() 95 | MessageBox.mMessageBoxDataPools.push(this.mData) 96 | this.mData = null 97 | } 98 | } 99 | } 100 | 101 | enum MessageBoxType 102 | { 103 | None, 104 | ShowConfirm, 105 | ShowOkAndCancel, 106 | } 107 | class MessageBoxData 108 | { 109 | public constructor(content) 110 | { 111 | this.content = content 112 | } 113 | 114 | public get type(): MessageBoxType 115 | { 116 | let t = MessageBoxType.None; 117 | if (this.BtnBtnConfirmCallBack != null) 118 | { 119 | t = MessageBoxType.ShowConfirm 120 | } 121 | else if (this.BtnOkCallBack != null || this.BtnCancelCallBack != null) 122 | { 123 | t = MessageBoxType.ShowOkAndCancel 124 | } 125 | return t 126 | } 127 | 128 | public content: string = null 129 | 130 | public BtnOkCallBack: YK.Func = null 131 | public labBtnOkStr: string = null 132 | 133 | public BtnCancelCallBack: YK.Func = null 134 | public labBtnCancelStr: string = null 135 | 136 | public BtnBtnConfirmCallBack: YK.Func = null 137 | public labBtnConfirmStr: string = null 138 | 139 | public SetBtnOkAndCancelCallBack(okCallBack: YK.Func, okStr: string = "好的", 140 | cancelCallBack: YK.Func = null, cancelStr: string = "好的") 141 | { 142 | this.BtnOkCallBack = okCallBack 143 | this.labBtnOkStr = okStr 144 | this.BtnCancelCallBack = cancelCallBack 145 | this.labBtnCancelStr = cancelStr 146 | return this 147 | } 148 | 149 | public SetBtnConfirmCallBack(callBack: YK.Func, labStr: string = "确定") 150 | { 151 | this.BtnBtnConfirmCallBack = callBack 152 | this.labBtnConfirmStr = labStr 153 | 154 | this.BtnOkCallBack = null 155 | this.labBtnOkStr = null 156 | this.BtnCancelCallBack = null 157 | this.labBtnCancelStr = null 158 | return this 159 | } 160 | 161 | public SetContent(content: string) 162 | { 163 | this.content = content 164 | } 165 | 166 | public reset() 167 | { 168 | this.BtnOkCallBack = null 169 | this.labBtnOkStr = null 170 | this.BtnCancelCallBack = null 171 | this.labBtnCancelStr = null 172 | this.BtnBtnConfirmCallBack = null 173 | this.labBtnConfirmStr = null 174 | this.content = null 175 | } 176 | 177 | public Show() 178 | { 179 | YK.UIMgr.Instance.ShowWind(MessageBox, this) 180 | } 181 | } -------------------------------------------------------------------------------- /src/Game/Winds/WaitWind.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class WaitWind extends fairygui.GComponent 3 | { 4 | private lablMsg: fairygui.GTextField 5 | private state: fairygui.Controller 6 | constructor() 7 | { 8 | super() 9 | 10 | 11 | } 12 | 13 | protected constructFromXML(xml: any): void 14 | { 15 | super.constructFromXML(xml); 16 | this.displayObject.on(Laya.Event.DISPLAY, this, this.__onShown); 17 | this.displayObject.on(Laya.Event.UNDISPLAY, this, this.__onHidden); 18 | this.lablMsg = this.getChild("lablMsg").asTextField 19 | this.lablMsg = this.getChild("lablMsg").asTextField 20 | 21 | this.state = this.getController("c1") 22 | 23 | 24 | } 25 | 26 | public set text(value: string) 27 | { 28 | if (value != null) 29 | { 30 | this.lablMsg.text = value 31 | } 32 | else 33 | { 34 | this.lablMsg.text = "" 35 | } 36 | } 37 | 38 | protected __onShown() 39 | { 40 | 41 | YK.TimeDelay.Instance.Remove(this.ShownLoadingRing, this) 42 | YK.TimeDelay.Instance.Remove(this.TimeOut, this) 43 | 44 | YK.TimeDelay.Instance.Add(1, 1, this.ShownLoadingRing, this) 45 | YK.TimeDelay.Instance.Add(10, 1, this.TimeOut, this) 46 | this.state.selectedIndex = 1 47 | } 48 | 49 | protected __onHidden() 50 | { 51 | YK.TimeDelay.Instance.Remove(this.ShownLoadingRing, this) 52 | YK.TimeDelay.Instance.Remove(this.TimeOut, this) 53 | } 54 | 55 | 56 | public ShownLoadingRing() 57 | { 58 | this.state.selectedIndex = 0 59 | } 60 | 61 | /** 62 | * 十秒自动关闭 63 | */ 64 | public TimeOut() 65 | { 66 | fairygui.GRoot.inst.closeModalWait() 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/GameConfig.ts: -------------------------------------------------------------------------------- 1 | /**This class is automatically generated by LayaAirIDE, please do not make any modifications. */ 2 | 3 | /* 4 | * 游戏初始化配置; 5 | */ 6 | export default class GameConfig{ 7 | static width:number=640; 8 | static height:number=1136; 9 | static scaleMode:string="fixedwidth"; 10 | static screenMode:string="none"; 11 | static alignV:string="top"; 12 | static alignH:string="left"; 13 | static startScene:any=""; 14 | static sceneRoot:string=""; 15 | static debug:boolean=false; 16 | static stat:boolean=false; 17 | static physicsDebug:boolean=false; 18 | static exportSceneToJson:boolean=true; 19 | constructor(){} 20 | static init(){ 21 | var reg: Function = Laya.ClassUtils.regClass; 22 | 23 | } 24 | } 25 | GameConfig.init(); -------------------------------------------------------------------------------- /src/Main.ts: -------------------------------------------------------------------------------- 1 | import GameConfig from "./GameConfig"; 2 | import ProtocolDef from "./Game/Defs/ProtocolDef" 3 | import RoleMode from "./Game/Modes/RoleMode"; 4 | import LoadingScene from "./Game/Scenes/LoadingScene"; 5 | 6 | class Main { 7 | constructor() { 8 | //根据IDE设置初始化引擎 9 | if (window["Laya3D"]) Laya3D.init(GameConfig.width, GameConfig.height); 10 | else Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]); 11 | Laya["Physics"] && Laya["Physics"].enable(); 12 | Laya["DebugPanel"] && Laya["DebugPanel"].enable(); 13 | Laya.stage.scaleMode = GameConfig.scaleMode; 14 | Laya.stage.screenMode = GameConfig.screenMode; 15 | //兼容微信不支持加载scene后缀场景 16 | Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson; 17 | 18 | //打开调试面板(通过IDE设置调试模式,或者url地址增加debug=true参数,均可打开调试面板) 19 | if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true") Laya.enableDebugPanel(); 20 | if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"]) Laya["PhysicsDebugDraw"].enable(); 21 | if (GameConfig.stat) Laya.Stat.show(); 22 | Laya.alertGlobalError = true; 23 | 24 | //激活资源版本控制,version.json由IDE发布功能自动生成,如果没有也不影响后续流程 25 | Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION); 26 | } 27 | 28 | onVersionLoaded(): void { 29 | //激活大小图映射,加载小图的时候,如果发现小图在大图合集里面,则优先加载大图合集,而不是小图 30 | Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded)); 31 | } 32 | 33 | onConfigLoaded(): void { 34 | Laya.stage.addChild(fairygui.GRoot.inst.displayObject); 35 | fairygui.UIConfig.packageFileExtension = "bin" 36 | fairygui.UIConfig.bringWindowToFrontOnClick = false 37 | //加载IDE指定的场景 38 | // GameConfig.startScene && Laya.Scene.open(GameConfig.startScene); 39 | // this.initGame() 40 | 41 | Laya.loader.load([ 42 | { url: "res/external/BasePack_atlas0.png", type: Laya.Loader.IMAGE }, 43 | { url: "res/external/BasePack.bin", type:Laya. Loader.BUFFER }, 44 | { url: "res/source/Loading_atlas_vckm32.jpg", type: Laya.Loader.IMAGE }, 45 | { url: "res/source/Loading_atlas0.png", type: Laya.Loader.IMAGE }, 46 | { url: "res/source/Loading.bin", type:Laya. Loader.BUFFER }, 47 | { url: "res/external/GamePack_atlas0.png", type: Laya.Loader.IMAGE }, 48 | { url: "res/external/GamePack.bin", type:Laya. Loader.BUFFER }, 49 | { url: "res/external/LoginPack.bin", type:Laya. Loader.BUFFER } 50 | ], Laya.Handler.create(this, this.onLoaded)); 51 | } 52 | //直接fgui测试 是没问题的 53 | onLoaded(){ 54 | Laya.stage.addChild(fairygui.GRoot.inst.displayObject); 55 | fairygui.UIPackage.addPackage("res/external/BasePack"); 56 | fairygui.UIPackage.addPackage("res/source/Loading"); 57 | fairygui.UIPackage.addPackage("res/external/GamePack"); 58 | fairygui.UIPackage.addPackage("res/external/LoginPack"); 59 | 60 | let _view = fairygui.UIPackage.createObject("LoginPack", "LoginWindow"); 61 | _view.setSize(fairygui.GRoot.inst.width, fairygui.GRoot.inst.height); 62 | fairygui.GRoot.inst.addChild(_view); 63 | 64 | } 65 | initGame() { 66 | 67 | fairygui.UIConfig.globalModalWaiting = "ui://Loading/waitWind" 68 | YK.NetMgr.Instance.AddProto("netpack", ProtocolDef.ProtocolNames) 69 | YK.ModeMgr.Instance.AddMode(RoleMode) 70 | YK.ModeMgr.Instance.InitData() 71 | YK.SceneMgr.Instance.GoToScene(LoadingScene) 72 | 73 | } 74 | } 75 | //激活启动类 76 | new Main(); 77 | -------------------------------------------------------------------------------- /src/YKFarmework/EventMgr/DispatchEventNode.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class DispatchEventNode 4 | { 5 | private eventDataPools: Array = new Array(); 6 | 7 | private createEventData(cmd, data) 8 | { 9 | let ev: EventData 10 | if (this.eventDataPools.length > 0) 11 | { 12 | ev = this.eventDataPools.pop() 13 | ev.cmd = cmd 14 | ev.data = data 15 | ev.isSotp = false 16 | } 17 | else 18 | { 19 | ev = new EventData(cmd, data) 20 | } 21 | return ev 22 | } 23 | 24 | private returnEventData(ev: EventData) 25 | { 26 | ev.data = null 27 | ev.cmd = null 28 | ev.isSotp = false 29 | this.eventDataPools.push(ev) 30 | } 31 | private eventDic: EventListenerClassDic = 32 | { 33 | 34 | } 35 | 36 | /** 37 | * 添加一个消息监听器 38 | * @param type 消息类型 39 | * @param callBack 回调函数 40 | * @param target 作用对象 41 | * @param priority 消息的优先级 42 | * @param once 是否只监听一次 43 | */ 44 | public addEventListener(type: string | number, callBack: EventCallbackListener, target: any, priority: number = 0, once: boolean = false) 45 | { 46 | type = type.toString() 47 | let info: EventListenerInfoData = { 48 | callBack: callBack, 49 | target: target, 50 | priority: priority, 51 | once: once 52 | } 53 | 54 | let array = this.eventDic[type] 55 | let has = false 56 | let pos = 0 57 | if (array != null) 58 | { 59 | array.forEach(element => 60 | { 61 | if (element.target == target && element.callBack == callBack) 62 | { 63 | has = true 64 | } 65 | if (element.priority > info.priority) 66 | { 67 | pos++ 68 | } 69 | }); 70 | } 71 | else 72 | { 73 | array = new Array() 74 | this.eventDic[type] = array 75 | } 76 | if (has) 77 | { 78 | console.error("重复注册消息:type=" + type) 79 | } 80 | else 81 | { 82 | array.splice(pos, 0, info) 83 | } 84 | } 85 | 86 | /** 87 | * 移除一个消息监听器 88 | * @param type 消息id 89 | * @param callBack 回调函数 90 | * @param target 作用的对象 91 | */ 92 | public removeEventListener(type: string | number, callBack: EventCallbackListener, target: any) 93 | { 94 | type = type.toString() 95 | let info: EventListenerInfoData = null 96 | let array = this.eventDic[type] 97 | if (array != null) 98 | { 99 | let infoIndex = -1 100 | array.every((value: EventListenerInfoData, index: number, array: EventListenerInfoData[]) => 101 | { 102 | if (value.target == target && value.callBack == callBack) 103 | { 104 | infoIndex = index 105 | info = value 106 | return false 107 | } 108 | return true 109 | }) 110 | 111 | if (infoIndex != -1) 112 | { 113 | array.splice(infoIndex, 1) 114 | } 115 | } 116 | } 117 | 118 | /** 119 | * 是否存在这个监听消息 120 | * @param type 消息类型 121 | * @param callBack 回调类型 122 | * @param target 回调对象 123 | */ 124 | public hasEventListener(type: string | number, callBack: EventCallbackListener, target: any) 125 | { 126 | let flag = false 127 | let array = this.eventDic[type] 128 | if (array) 129 | { 130 | let index = array.findIndex((obj, index, any) => 131 | { 132 | return obj.target == target && obj.callBack == callBack 133 | }) 134 | flag = index != -1 135 | } 136 | return flag 137 | } 138 | 139 | /** 140 | * 派发消息 141 | * @param ev 派发的消息内容 142 | */ 143 | public DispatchEvent(ev: EventData) 144 | { 145 | this._DispatchEvent(ev) 146 | } 147 | 148 | /** 149 | * 派发消息 150 | * @param type 消息id 151 | * @param data 消息内容 152 | */ 153 | public DispatchEventByType(type: string | number, data: any = null) 154 | { 155 | let ev = this.createEventData(type, data) 156 | this._DispatchEvent(ev) 157 | if (ev != null) 158 | { 159 | this.returnEventData(ev) 160 | } 161 | } 162 | 163 | private _DispatchEvent(ev: EventData) 164 | { 165 | let array = this.eventDic[ev.cmd] 166 | if (array != null) 167 | { 168 | 169 | for (let i = 0; i < array.length; i++) 170 | { 171 | let info = array[i] 172 | if (info.callBack != null) 173 | { 174 | info.callBack.call(info.target, ev) 175 | } 176 | if (info.once) 177 | { 178 | array.splice(i--, 1) 179 | } 180 | if (ev.isSotp) 181 | { 182 | break; 183 | } 184 | } 185 | } 186 | } 187 | } 188 | 189 | export type EventListenerInfoData = 190 | { 191 | callBack: EventCallbackListener, 192 | target: any, 193 | priority: number, 194 | once: boolean 195 | } 196 | 197 | export type EventListenerClassDic = { 198 | [key: string]: Array 199 | } 200 | 201 | 202 | export type EventCallbackListener = ((ev: EventData) => void); 203 | 204 | export class EventData 205 | { 206 | constructor(cmd: string, obj: any) 207 | { 208 | this.cmd = cmd 209 | this.data = obj 210 | this.isSotp = false 211 | } 212 | public cmd: string 213 | public data: any 214 | public isSotp = false 215 | /** 216 | * Stop 217 | */ 218 | public Stop() 219 | { 220 | this.isSotp = true 221 | } 222 | } 223 | 224 | export class Func 225 | { 226 | private mThisObj: any 227 | private mCallBack: Function 228 | 229 | public constructor(thisObj: any, callBack: Function) 230 | { 231 | this.mThisObj = thisObj 232 | this.mCallBack = callBack 233 | } 234 | 235 | public Invoke(...args: any[]) 236 | { 237 | this.mCallBack.call(this.mThisObj, ...args) 238 | } 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /src/YKFarmework/EventMgr/EventListenerMgr.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class EventListenerMgr 4 | { 5 | private mOwner = null 6 | public constructor(dis: DispatchEventNode = null) 7 | { 8 | this.mOwner = dis 9 | } 10 | 11 | private mListener: Array = new Array(); 12 | /** 13 | * 14 | * @param callback 回调 15 | * @param thisObj 作用对象 16 | * @param type 消息类型 17 | * @param _priority 优先级 18 | * @param _dispatchOnce 是否只派发一次 19 | */ 20 | public addListener(type: string | number, callback: EventCallbackListener, thisObj: any, _priority: number = 0, _dispatchOnce: boolean = false) 21 | { 22 | if (this.mOwner.hasEventListener(type, callback, thisObj)) 23 | { 24 | console.warn("重复注册消息 消息id" + type) 25 | } 26 | else 27 | { 28 | let listener = EventListenerData.CreateEventListenerData(this.mOwner, callback, thisObj, type.toString(), _priority, _dispatchOnce) 29 | listener.AttachListener() 30 | this.mListener.push(listener) 31 | } 32 | } 33 | 34 | /** 35 | * 36 | * @param callback 回调 37 | * @param thisObj 作用对象 38 | * @param type 消息类型 39 | */ 40 | public removeListener(callback: EventCallbackListener, thisObj: any, type: string | number) 41 | { 42 | if (this.mOwner.hasEventListener(type, callback, thisObj)) 43 | { 44 | let listener: EventListenerData = null 45 | let index = this.mListener.findIndex((value, index, array) => 46 | { 47 | if (value.thisObj == thisObj && value.callback == callback) 48 | { 49 | listener = value 50 | return true 51 | } 52 | return false 53 | }) 54 | 55 | if (index != -1) 56 | { 57 | listener.DetachListener() 58 | this.mListener.splice(index, 1) 59 | } 60 | 61 | } 62 | } 63 | 64 | public removeAllListener() 65 | { 66 | this.mListener.forEach(listener => 67 | { 68 | listener.DetachListener() 69 | }); 70 | this.mListener.splice(0, this.mListener.length) 71 | } 72 | } 73 | 74 | 75 | export class InterchangeableEventListenerMgr 76 | { 77 | private networkEvnets: EventListenerMgr 78 | private sceneEvents: EventListenerMgr 79 | private uiEvents: EventListenerMgr 80 | private modeEvents: EventListenerMgr 81 | private otherEvents: Array = new Array() 82 | private mDefCallback: EventListenerData 83 | private mDefObj: any 84 | 85 | private mNetCallback: EventListenerData 86 | private mModeCallback: EventListenerData 87 | private mSceneCallback: EventListenerData 88 | private mUICallback: EventListenerData 89 | 90 | constructor(thisObj: any, defCallback: EventCallbackListener = null) 91 | { 92 | this.networkEvnets = new EventListenerMgr(NetMgr.Instance) 93 | this.sceneEvents = new EventListenerMgr(SceneMgr.Instance) 94 | this.uiEvents = new EventListenerMgr(UIMgr.Instance) 95 | this.modeEvents = new EventListenerMgr(ModeMgr.Instance) 96 | this.mDefObj = thisObj 97 | 98 | this.otherEvents = new Array() 99 | this.mDefCallback = new EventListenerData(NetMgr.Instance, defCallback, thisObj, null) 100 | 101 | 102 | this.mNetCallback = new EventListenerData(NetMgr.Instance, defCallback, thisObj, null) 103 | this.mModeCallback = new EventListenerData(NetMgr.Instance, defCallback, thisObj, null) 104 | this.mSceneCallback = new EventListenerData(NetMgr.Instance, defCallback, thisObj, null) 105 | this.mUICallback = new EventListenerData(NetMgr.Instance, defCallback, thisObj, null) 106 | } 107 | 108 | public setDegCallback(callback: EventCallbackListener, priority = 0) 109 | { 110 | this.mDefCallback.callback = callback 111 | this.mDefCallback.priority = priority 112 | return this 113 | } 114 | 115 | public setNetCallback(callback: EventCallbackListener, priority = 0) 116 | { 117 | this.mNetCallback.callback = callback 118 | this.mNetCallback.priority = priority 119 | return this 120 | } 121 | 122 | public setModeCallback(callback: EventCallbackListener, priority = 0) 123 | { 124 | this.mModeCallback.callback = callback 125 | this.mModeCallback.priority = priority 126 | return this 127 | } 128 | 129 | public setSceneCallback(callback: EventCallbackListener, priority = 0) 130 | { 131 | this.mSceneCallback.callback = callback 132 | this.mSceneCallback.priority = priority 133 | return this 134 | } 135 | 136 | public setUICallback(callback: EventCallbackListener, priority = 0) 137 | { 138 | this.mUICallback.callback = callback 139 | this.mSceneCallback.priority = priority 140 | return this 141 | } 142 | 143 | 144 | public addListener(dis: DispatchEventNode, type: string | number 145 | , callback: EventCallbackListener = null, thisObj: any = null, _priority: number = 0, _dispatchOnce: boolean = false) 146 | { 147 | if (dis == NetMgr.Instance) this.addNetEvent(type, callback, thisObj) 148 | else if (dis == SceneMgr.Instance) this.addSceneEvent(type, callback, thisObj) 149 | else if (dis == UIMgr.Instance) this.addUIEvent(type, callback, thisObj) 150 | else if (dis == ModeMgr.Instance) this.addModeEvent(type, callback, thisObj) 151 | else 152 | { 153 | 154 | if (callback == null) callback = this.mDefCallback.callback 155 | if (thisObj == null) thisObj = this.mDefCallback.thisObj 156 | if (_priority == 0) _priority = this.mDefCallback.priority 157 | 158 | let x = this.otherEvents.findIndex((value: EventListenerData, index: number, obj: Array) => 159 | { 160 | if (value.dis == dis && type == value.type 161 | && callback != value.callback 162 | && thisObj == value.thisObj) 163 | { 164 | x = index 165 | return true 166 | } 167 | else 168 | { 169 | return false 170 | } 171 | }) 172 | 173 | if (x != -1) 174 | { 175 | let data = EventListenerData.CreateEventListenerData(dis, callback, this, type.toString(), _priority, _dispatchOnce) 176 | data.AttachListener() 177 | this.otherEvents.push(data) 178 | } 179 | } 180 | } 181 | 182 | public removeListener(dis: DispatchEventNode, type: string | number 183 | , callback: EventCallbackListener = null, thisObj: any = null) 184 | { 185 | if (dis == NetMgr.Instance) this.removeNetEvent(type, callback, thisObj) 186 | else if (dis == SceneMgr.Instance) this.removeSceneEvent(type, callback, thisObj) 187 | else if (dis == UIMgr.Instance) this.removeUIEvent(type, callback, thisObj) 188 | else if (dis == ModeMgr.Instance) this.removeModeEvent(type, callback, thisObj) 189 | else 190 | { 191 | if (callback == null) callback = this.mDefCallback.callback 192 | if (thisObj == null) thisObj = this.mDefCallback.callback 193 | let x = this.otherEvents.findIndex((value: EventListenerData, index: number, obj: Array) => 194 | { 195 | if (value.dis == dis && type == value.type 196 | && callback != value.callback 197 | && thisObj == value.thisObj) 198 | { 199 | x = index 200 | return true 201 | } 202 | else 203 | { 204 | return false 205 | } 206 | }) 207 | 208 | if (x != -1) 209 | { 210 | this.otherEvents[x].DetachListener() 211 | this.otherEvents.splice(x, 1) 212 | } 213 | } 214 | } 215 | 216 | public addNetEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null, 217 | _priority: number = 0, _dispatchOnce: boolean = false) 218 | { 219 | if (callback == null) 220 | { 221 | callback = this.mNetCallback.callback 222 | thisObj = this.mNetCallback.thisObj 223 | } 224 | if (_priority == 0) 225 | { 226 | _priority = this.mNetCallback.priority 227 | } 228 | this.networkEvnets.addListener(type, callback, thisObj, _priority, _dispatchOnce) 229 | } 230 | 231 | public removeNetEvent(type: string | number 232 | , callback: EventCallbackListener = null, thisObj: any = null) 233 | { 234 | if (callback == null) 235 | { 236 | callback = this.mNetCallback.callback 237 | thisObj = this.mDefCallback.thisObj 238 | } 239 | this.networkEvnets.removeListener(callback, thisObj, type) 240 | } 241 | 242 | public addUIEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null, _priority: number = 0, _dispatchOnce: boolean = false) 243 | { 244 | if (callback == null) 245 | { 246 | callback = this.mUICallback.callback 247 | thisObj = this.mUICallback.thisObj 248 | } 249 | if (_priority == 0) 250 | { 251 | _priority = this.mUICallback.priority 252 | } 253 | this.uiEvents.addListener(type, callback, thisObj, _priority, _dispatchOnce) 254 | } 255 | 256 | public removeUIEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null) 257 | { 258 | if (callback == null) 259 | { 260 | callback = this.mUICallback.callback 261 | thisObj = this.mUICallback.thisObj 262 | } 263 | this.uiEvents.removeListener(callback, thisObj, type) 264 | } 265 | 266 | public addSceneEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null, _priority: number = 0, _dispatchOnce: boolean = false) 267 | { 268 | if (callback == null) 269 | { 270 | callback = this.mSceneCallback.callback 271 | thisObj = this.mSceneCallback.thisObj 272 | } 273 | if (_priority == 0) 274 | { 275 | _priority = this.mUICallback.priority 276 | } 277 | this.sceneEvents.addListener(type, callback, thisObj, _priority, _dispatchOnce) 278 | } 279 | 280 | public removeSceneEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null) 281 | { 282 | if (callback == null) 283 | { 284 | callback = this.mSceneCallback.callback 285 | thisObj = this.mSceneCallback.thisObj 286 | } 287 | this.sceneEvents.removeListener(callback, thisObj, type) 288 | } 289 | 290 | public addModeEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null, _priority: number = 0, _dispatchOnce: boolean = false) 291 | { 292 | if (callback == null) 293 | { 294 | callback = this.mModeCallback.callback 295 | thisObj = this.mModeCallback.thisObj 296 | } 297 | this.modeEvents.addListener(type, callback, thisObj) 298 | } 299 | 300 | public removeModeEvent(type: string | number, callback: EventCallbackListener = null, thisObj: any = null) 301 | { 302 | if (callback == null) 303 | { 304 | callback = this.mModeCallback.callback 305 | thisObj = this.mModeCallback.thisObj 306 | } 307 | this.modeEvents.removeListener(callback, thisObj, type) 308 | } 309 | 310 | public RemoveAll() 311 | { 312 | if (this.networkEvnets != null) 313 | this.networkEvnets.removeAllListener() 314 | if (this.sceneEvents != null) 315 | this.sceneEvents.removeAllListener() 316 | if (this.uiEvents != null) 317 | this.uiEvents.removeAllListener() 318 | if (this.modeEvents != null) 319 | this.modeEvents.removeAllListener() 320 | this.otherEvents.forEach(element => 321 | { 322 | element.DetachListener() 323 | }); 324 | this.otherEvents.splice(0, this.otherEvents.length) 325 | } 326 | } 327 | 328 | export class EventListenerData 329 | { 330 | private static mEventListenerData: Array = new Array() 331 | public static CreateEventListenerData(dis: DispatchEventNode, callback: EventCallbackListener, thisObj: any, type: string, 332 | _priority: number = 0, _dispatchOnce: boolean = false) 333 | { 334 | let listener: EventListenerData = null 335 | if (this.mEventListenerData.length > 0) 336 | { 337 | listener = this.mEventListenerData.pop() 338 | listener.dis = dis 339 | listener.callback = callback 340 | listener.thisObj = thisObj 341 | listener.type = type 342 | listener 343 | } 344 | else 345 | { 346 | listener = new EventListenerData(dis, callback, thisObj, type, _priority, _dispatchOnce) 347 | } 348 | return listener 349 | } 350 | 351 | public static ReturnEventListenerData(listener: EventListenerData) 352 | { 353 | if (listener) 354 | { 355 | listener.dis.removeEventListener(listener.type, listener.callback, listener.thisObj) 356 | listener.dis = null 357 | listener.callback = null 358 | listener.thisObj = null 359 | listener.type = null 360 | this.mEventListenerData.push(listener) 361 | } 362 | } 363 | 364 | public dis: DispatchEventNode 365 | public callback: EventCallbackListener 366 | public thisObj: any 367 | public type: string 368 | public priority: number 369 | public dispatchOnce: boolean = false 370 | 371 | public constructor(dis: DispatchEventNode, callback: EventCallbackListener, thisObj: any, type: string 372 | , _priority: number = 0, _dispatchOnce: boolean = false) 373 | { 374 | this.dis = dis 375 | this.thisObj = thisObj 376 | this.type = type 377 | this.callback = callback 378 | this.priority = _priority 379 | this.dispatchOnce = _dispatchOnce 380 | // this.AttachListener() 381 | } 382 | 383 | public AttachListener(): boolean 384 | { 385 | if (this.dis.hasEventListener(this.type, this.callback, this.thisObj)) 386 | { 387 | this.DetachListener() 388 | return false 389 | } 390 | this.dis.addEventListener(this.type, this.callback, this.thisObj, this.priority, this.dispatchOnce) 391 | return true 392 | } 393 | 394 | public DetachListener() 395 | { 396 | EventListenerData.ReturnEventListenerData(this) 397 | } 398 | } 399 | } -------------------------------------------------------------------------------- /src/YKFarmework/ModeMgr/ModeMgr.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class ModeMgr extends DispatchEventNode 4 | { 5 | constructor() 6 | { 7 | super() 8 | if(ModeMgr.mInstance == null) ModeMgr.mInstance = this 9 | TimeDelay.Instance.AddUpdate(this.update,this) 10 | } 11 | public static EventType = { 12 | SENDINITMSGOK: "SENDINITMSGOK" 13 | } 14 | public mModes: Map = new Map() 15 | private static mInstance: ModeMgr 16 | private mIsLoginSendingFlag = false 17 | 18 | public static get Instance() 19 | { 20 | if (this.mInstance == null) new ModeMgr() 21 | return this.mInstance 22 | } 23 | 24 | public AddMode(type: { new (): T }): T 25 | { 26 | if (!this.mModes.has(type)) 27 | { 28 | this.mModes.set(type, new type()) 29 | } 30 | return this.mModes.get(type) as T 31 | } 32 | 33 | public GetMode(type: { new (): T }): T 34 | { 35 | if (this.mModes.has(type)) 36 | return this.mModes.get(type) as T 37 | else 38 | return null 39 | } 40 | 41 | public InitData(param: any = null) 42 | { 43 | this.mIsLoginSendingFlag = false 44 | this.mModes.forEach((value: IMode, key: any, map: Map) => 45 | { 46 | value.initMsgRespOk = false 47 | value.OnInitData(param) 48 | }); 49 | } 50 | 51 | public SendInitMsg() 52 | { 53 | this.mIsLoginSendingFlag = true 54 | this.mModes.forEach((value: IMode, key: any, map: Map) => 55 | { 56 | value.OnSendInitMsg() 57 | }); 58 | } 59 | 60 | public ClearData() 61 | { 62 | this.mModes.forEach((value: IMode, key: any, map: Map) => 63 | { 64 | value.OnClear() 65 | }); 66 | } 67 | 68 | public onDestroy() 69 | { 70 | this.mModes.forEach((value: IMode, key: any, map: Map) => 71 | { 72 | value.OnDestroy() 73 | }); 74 | this.ClearData(); 75 | } 76 | 77 | 78 | public update(dt) 79 | { 80 | if (this.mIsLoginSendingFlag) 81 | { 82 | let isOk = true 83 | 84 | this.mModes.forEach((value: IMode, key: any, map: Map) => 85 | { 86 | if (!value.initMsgRespOk) 87 | { 88 | isOk = false 89 | } 90 | }); 91 | 92 | if (isOk) 93 | { 94 | this.DispatchEventByType(ModeMgr.EventType.SENDINITMSGOK) 95 | this.mIsLoginSendingFlag = false 96 | } 97 | } 98 | } 99 | } 100 | 101 | export abstract class IMode 102 | { 103 | public eventMgr: InterchangeableEventListenerMgr 104 | constructor() 105 | { 106 | this.eventMgr = new InterchangeableEventListenerMgr(this, this.OnHandler) 107 | this.eventMgr.setNetCallback(this.OnHandler, 99) 108 | this.eventMgr.setModeCallback(this.OnHandler, 99) 109 | } 110 | 111 | public abstract OnInitData(param: any): void 112 | public OnSendInitMsg(): void 113 | { 114 | this.initMsgRespOk = true 115 | } 116 | 117 | /** 118 | * 处理消息 119 | * @param ev 参数 120 | */ 121 | protected OnHandler(ev: EventData) 122 | { 123 | 124 | } 125 | public abstract OnClear(): void 126 | public OnDestroy(): void 127 | { 128 | this.eventMgr.RemoveAll() 129 | } 130 | public initMsgRespOk = false 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/YKFarmework/Net/NetMgr.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class NetMgr extends DispatchEventNode 4 | { 5 | public httpUrl: string = "http://39.107.84.87:9100/?" 6 | private static mInstance: NetMgr; 7 | private mTimeout = 10//默认十秒 8 | private mHeartTimeout = 10 9 | public static get Instance() 10 | { 11 | if (this.mInstance == null)new NetMgr() 12 | return this.mInstance 13 | } 14 | ip: string = 'ws://39.107.84.87:9023'; 15 | /** 16 | * 17 | */ 18 | constructor() 19 | { 20 | super(); 21 | if(NetMgr.mInstance == null) NetMgr.mInstance = this 22 | TimeDelay.Instance.Add(1, 0, this.CheckSendTimeOut, this) 23 | this.socket = new Laya.Socket(null, null, Laya.Byte) 24 | this.socket.on(Laya.Event.OPEN, this, this.onopen); 25 | this.socket.on(Laya.Event.CLOSE, this, this.onclose); 26 | this.socket.on(Laya.Event.MESSAGE, this, this.onmessage); 27 | this.socket.on(Laya.Event.ERROR, this, this.onerror); 28 | } 29 | 30 | onDestroy() 31 | { 32 | TimeDelay.Instance.Remove(this.CheckSendTimeOut, this) 33 | } 34 | private CheckSendTimeOut() 35 | { 36 | if (this.mSendQueue.length > 0) 37 | { 38 | let array: Array = new Array() 39 | this.mSendQueue.forEach(element => 40 | { 41 | if (Date.now() - element.sendTime > this.mTimeout * 1000) 42 | { 43 | array.push(element) 44 | } 45 | }); 46 | 47 | array.forEach(element => 48 | { 49 | let index = this.mSendQueue.indexOf(element) 50 | if (index != -1) 51 | { 52 | this.mSendQueue.splice(index, 1) 53 | } 54 | this.msgTimeOut(element.head) 55 | }); 56 | } 57 | } 58 | 59 | public AddProto(pbName: string, protoNames: Array): void 60 | { 61 | let roots = protobuf.roots["default"][pbName] 62 | for (let key in protoNames) 63 | { 64 | let protoName = protoNames[key] 65 | let _class = roots[protoName] 66 | ProtoMap.Add(protoName, _class) 67 | } 68 | } 69 | 70 | private socket: Laya.Socket = null 71 | public connect(wsurl = null) 72 | { 73 | wsurl = wsurl == null ? this.ip : wsurl 74 | if (this.socket.connected) 75 | { 76 | this.onopen(null) 77 | } 78 | else 79 | { 80 | this.socket.connectByUrl(wsurl) 81 | } 82 | } 83 | 84 | private lastActivityTime 85 | private heartbeatIntervalTimeId 86 | private checkHeartbeatTimeOutIntervalTimeId 87 | private onopen(ev: Event) 88 | { 89 | console.log("链接服务器成功") 90 | TimeDelay.Instance.Remove(this.sendHeartbeat, this) 91 | TimeDelay.Instance.Remove(this.checkHeartbeat, this) 92 | TimeDelay.Instance.Add(3, 0, this.sendHeartbeat, this) 93 | TimeDelay.Instance.Add(3, 0, this.checkHeartbeat, this) 94 | this.lastActivityTime = Date.now() 95 | this.DispatchEventByType(NetMgrEventDef.onopen); 96 | } 97 | 98 | public isConnect(): boolean 99 | { 100 | return this.socket != null && this.socket.connected 101 | } 102 | private disConnect(msgType, msg) 103 | { 104 | if (this.mSendQueue) 105 | { 106 | this.mSendQueue.splice(0, this.mSendQueue.length) 107 | } 108 | if (this.isConnect()) 109 | { 110 | this.socket.close() 111 | this.socket.cleanSocket() 112 | } 113 | TimeDelay.Instance.Remove(this.sendHeartbeat, this) 114 | TimeDelay.Instance.Remove(this.checkHeartbeat, this) 115 | let data = { type: msgType, msg: msg } 116 | this.DispatchEventByType(NetMgrEventDef.disConnect, data) 117 | } 118 | 119 | private onerror(ev: Event) 120 | { 121 | console.log("与服务器连接失败") 122 | this.disConnect(NetMgrEventDef.onerror, "与服务器连接失败") 123 | } 124 | 125 | private onclose(ev: Event) 126 | { 127 | console.log("与服务器连接断开") 128 | this.disConnect(NetMgrEventDef.onclose, "与服务器连接断开") 129 | } 130 | 131 | private onmessage(data) 132 | { 133 | let head: PackBase 134 | //try 135 | { 136 | head = ProtoMap.UnPackHead(data) 137 | if (head != null) 138 | { 139 | this.lastActivityTime = Date.now() 140 | 141 | if (head.cmd != 1) 142 | { 143 | this.distributeMsg(head) 144 | } 145 | else 146 | { 147 | //console.log("收到心跳包") 148 | } 149 | } 150 | else 151 | { 152 | console.error("协议解析失败") 153 | } 154 | } //catch (error) 155 | // { 156 | // console.error("协议解析失败") 157 | // this.disConnect("onerror","解析消息失败") 158 | // } 159 | } 160 | 161 | private mMsgId = 0 162 | private get Msgid() 163 | { 164 | return this.mMsgId++; 165 | } 166 | 167 | private mSendQueue: Array = new Array() 168 | private sendHeartbeat() 169 | { 170 | if (this.isConnect()) 171 | { 172 | //console.log("发送一次心跳" + Date.now()) 173 | this.Send(1) 174 | } 175 | } 176 | 177 | private checkHeartbeat() 178 | { 179 | if (Date.now() - this.lastActivityTime > 10 * 1000) 180 | { 181 | this.disConnect(NetMgrEventDef.HeartbeatTimeOut, "与服务器连接超时") 182 | } 183 | } 184 | 185 | private msgTimeOut(head: PackBase) 186 | { 187 | if (head.cmd == 1) 188 | { 189 | this.disConnect(NetMgrEventDef.HeartbeatTimeOut, "与服务器连接超时") 190 | } 191 | else 192 | { 193 | let ev = new ResponseMessageEvent(head.cmd.toString()) 194 | head.errorcode = -1 195 | ev.SetData(head, null) 196 | 197 | console.error("消息返回超时id=" + head.cmd) 198 | this.DispatchEvent(ev) 199 | } 200 | } 201 | 202 | public SendGet(url, callback: Func) 203 | { 204 | url = this.httpUrl + url 205 | console.log(url) 206 | let flag = false; 207 | let request = new laya.net.HttpRequest() 208 | request.once(laya.events.Event.COMPLETE, this, (e: laya.events.Event) => 209 | { 210 | let respone = request.data 211 | let data = null 212 | if (respone != null) 213 | { 214 | data = JSON.parse(respone) 215 | } 216 | callback.Invoke(data); 217 | }) 218 | request.once(laya.events.Event.ERROR, this, (e) => 219 | { 220 | callback.Invoke(null); 221 | }) 222 | request.send(url, null, "get"); 223 | } 224 | 225 | public Send(id: number, data: any = null) 226 | { 227 | let head = new PackBase() 228 | head.cmd = id 229 | head.errorcode = 0 230 | head.msgid = this.Msgid 231 | let sendData = 232 | { 233 | head: head, 234 | sendTime: Date.now() 235 | } 236 | 237 | if (this.isConnect()) 238 | { 239 | let buffer: ArrayBuffer = ProtoMap.Pack(head, data) 240 | if (id != 1) 241 | { 242 | console.log("发送消息给服务器》") 243 | console.log(head) 244 | console.log(data) 245 | this.mSendQueue.push(sendData) 246 | } 247 | this.socket.send(buffer) 248 | } 249 | else 250 | { 251 | console.error("网络断开无法发送消息"); 252 | } 253 | } 254 | 255 | private distributeMsg(head: PackBase) 256 | { 257 | let msg = ProtoMap.UnPack(head) 258 | console.log("收到服务返回的消息信息头:") 259 | console.log(head) 260 | if (head.errorcode != null && head.errorcode != 0) 261 | { 262 | console.warn("服务器返回错误码 消息id:" + head.cmd + "/errorcode=" + head.errorcode) 263 | } 264 | if (head == null || head.cmd == null) 265 | { 266 | console.warn("服务器返回无效的cmdid") 267 | } 268 | else 269 | { 270 | let index = this.mSendQueue.findIndex((obj, index, any) => 271 | { 272 | return obj.head.msgid == head.msgid && obj.head.cmd == head.cmd 273 | }) 274 | if (index != -1) 275 | { 276 | this.mSendQueue.splice(index, 1) 277 | } 278 | let ev = new ResponseMessageEvent(head.cmd.toString()) 279 | ev.SetData(head, msg) 280 | this.DispatchEvent(ev) 281 | } 282 | } 283 | 284 | } 285 | export class NetMgrEventDef 286 | { 287 | public static disConnect: string = "disConnect"; 288 | public static onerror: string = "onerror" 289 | public static onclose: string = "onclose" 290 | public static onopen: string = "onopen" 291 | public static HeartbeatTimeOut: string = "HeartbeatTimeOut" 292 | } 293 | 294 | export type HttpRespData = 295 | { 296 | msg: string, 297 | errorcode: number, 298 | data: any, 299 | } 300 | 301 | } -------------------------------------------------------------------------------- /src/YKFarmework/Net/PackBase.ts: -------------------------------------------------------------------------------- 1 | // Learn TypeScript: 2 | // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html 3 | // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html 4 | // Learn Attribute: 5 | // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html 6 | // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html 7 | // Learn life-cycle callbacks: 8 | // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html 9 | // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html 10 | module YK 11 | { 12 | export class PackBase 13 | { 14 | public cmd: number = 0; 15 | public msgid: number = 0; 16 | public errorcode: number = 0; 17 | public contentBuff: ArrayBuffer = null; 18 | } 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/YKFarmework/Net/ProtoMap.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class ProtoMap 4 | { 5 | public static protos = 6 | { 7 | 1: { 8 | id: 1, 9 | request: null, 10 | response: null, 11 | }, 12 | } 13 | 14 | 15 | public static classMap = {} 16 | public static Add(key, type): void 17 | { 18 | this.classMap[key] = type 19 | } 20 | 21 | public static Pack(head: PackBase, data: any = null): any 22 | { 23 | let proto = this.protos[head.cmd] 24 | if (proto == null) 25 | { 26 | console.error("尝试封包一个没有注册的消息 id=" + head.cmd); 27 | return null 28 | } 29 | let _c = proto.request 30 | if (_c != null && data != null) 31 | { 32 | head.contentBuff = this.PackByClasName(_c, data) 33 | } 34 | return this.PackByClasName("packbase", head) 35 | } 36 | 37 | public static UnPack(head: PackBase, buff: ArrayBuffer = null): any 38 | { 39 | let proto = this.protos[head.cmd] 40 | if (proto == null) 41 | { 42 | console.error("尝试解包一个没有注册的消息 id=" + head.cmd); 43 | return null 44 | } 45 | let _c = proto.response 46 | if (_c != null) 47 | { 48 | buff = buff == null ? head.contentBuff : buff 49 | return this.UnPackByClasName(_c, buff) 50 | } 51 | else 52 | { 53 | return null 54 | } 55 | } 56 | 57 | public static UnPackHead(buffer: ArrayBuffer): PackBase 58 | { 59 | if (buffer == null || buffer.byteLength == 0) return null 60 | return this.UnPackByClasName("packbase", buffer) 61 | } 62 | 63 | public static PackByClasName(cname: string, data: any) 64 | { 65 | let c = this.classMap[cname] 66 | if (c != null) 67 | { 68 | let obj = new c(data) 69 | return c.encode(obj).finish() 70 | } 71 | else 72 | { 73 | console.error("反序列化一条没有实现的消息id:" + cname) 74 | } 75 | return null 76 | } 77 | public static UnPackByClasName(cname: string, buff: ArrayBuffer) 78 | { 79 | let c = this.classMap[cname] 80 | if (c != null && buff != null) 81 | { 82 | let bf = new Uint8Array(buff) 83 | return c.decode(bf) 84 | } 85 | if (c == null) 86 | { 87 | console.error("反序列化一条没有实现的消息id:" + cname) 88 | } 89 | return null 90 | } 91 | 92 | public static AddProto(proto: ProtoInfo) 93 | { 94 | if (this.protos[proto.id] != null) 95 | { 96 | console.log(this.protos) 97 | console.error("不能重复注册消息 id=" + proto.id); 98 | } 99 | this.protos[proto.id] = proto 100 | } 101 | } 102 | export type ProtoInfo = 103 | { 104 | id: number, 105 | request: string, 106 | response: string, 107 | } 108 | } -------------------------------------------------------------------------------- /src/YKFarmework/Net/ResponseMessageEvent.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class ResponseMessageEvent extends EventData 4 | { 5 | public data : ResponseDataInfo | any = null 6 | constructor(type: string) 7 | { 8 | super(type, null); 9 | } 10 | 11 | public SetData(head: PackBase, msg: any) 12 | { 13 | this.cmd = head.cmd.toString() 14 | this.data = { head: head, msg: msg } 15 | } 16 | public get Data(): ResponseDataInfo 17 | { 18 | return this.data 19 | } 20 | } 21 | 22 | export type ResponseDataInfo = 23 | { 24 | head: PackBase, 25 | msg: any 26 | } 27 | } -------------------------------------------------------------------------------- /src/YKFarmework/ResMgr/ResMgr.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | import Handler = Laya.Handler; 4 | class ResInfo 5 | { 6 | public url: string; 7 | public type: string 8 | public isKeepMemory = false 9 | public isFGUIPack = false 10 | 11 | public get fullUrl() 12 | { 13 | if (this.isFGUIPack) 14 | { 15 | return this.url.replace("." + fairygui.UIConfig.packageFileExtension, "") 16 | } 17 | return this.url 18 | } 19 | } 20 | 21 | type resDicType = { [key: string]: ResInfo } 22 | export class LoadGruopInfo 23 | { 24 | public Progress: number = 0 25 | public needLoad: Array = new Array() 26 | public add(url: string, type: string, isKeepMemory = false, isFGUIPack = false) 27 | { 28 | let index = this.needLoad.findIndex((value: ResInfo, index: number, obj: Array) => 29 | { 30 | return value.url == url 31 | }) 32 | if (index == -1) 33 | { 34 | let info = new ResInfo() 35 | info.isKeepMemory = isKeepMemory 36 | info.url = url 37 | info.type = type 38 | info.isFGUIPack = isFGUIPack 39 | this.needLoad.push(info) 40 | } 41 | return this 42 | } 43 | 44 | public onCompletion(callback: Function, thisObjs: any) 45 | { 46 | this.finish = new Func(thisObjs, callback) 47 | return this 48 | } 49 | 50 | public onItemCompletion(callback: Function, thisObjs: any) 51 | { 52 | this.loadItem = new Func(thisObjs, callback) 53 | return this 54 | } 55 | 56 | 57 | public start() 58 | { 59 | ResMgr.Instance.LoadGroup(this) 60 | } 61 | public loadItem: Func 62 | public finish: Func 63 | } 64 | 65 | export class ResMgr extends DispatchEventNode 66 | { 67 | constructor() 68 | { 69 | super() 70 | if(ResMgr.mInstance == null) ResMgr.mInstance = this 71 | } 72 | private mOldRes: Array = new Array() 73 | private resDic: Map = new Map() 74 | private static mInstance: ResMgr = null 75 | public static get Instance(): ResMgr 76 | { 77 | if (this.mInstance == null)new ResMgr() 78 | return this.mInstance 79 | } 80 | 81 | public GetRes(url) 82 | { 83 | return Laya.loader.getRes(url) 84 | } 85 | 86 | public LoadGroup(loads: LoadGruopInfo) 87 | { 88 | 89 | let urls: Array = new Array() 90 | loads.needLoad.forEach(element => 91 | { 92 | urls.push({ url: element.url, type: element.type }) 93 | }); 94 | Laya.loader.load(urls, Handler.create(this, (success: boolean) => 95 | { 96 | if (success) 97 | { 98 | for (let index = 0; index < loads.needLoad.length; index++) 99 | { 100 | let info = loads.needLoad[index] 101 | if (info.isFGUIPack) 102 | { 103 | fairygui.UIPackage.addPackage(info.fullUrl) 104 | } 105 | if (!this.resDic.has(info.url)) 106 | { 107 | this.resDic.set(info.url, info) 108 | } 109 | } 110 | if (loads.finish != null) 111 | { 112 | loads.finish.Invoke() 113 | } 114 | } 115 | else 116 | { 117 | console.error("加载资源失败:") 118 | console.log(urls) 119 | } 120 | }), Handler.create(this, (progress: number) => 121 | { 122 | loads.Progress = progress * 100 123 | if (loads.loadItem != null) 124 | { 125 | loads.loadItem.Invoke() 126 | } 127 | })) 128 | } 129 | 130 | /** 131 | * 释放资源 132 | * @param forced 是否强制释放所有 133 | */ 134 | public pop(forced = false) 135 | { 136 | if (forced) 137 | { 138 | this.mOldRes.splice(0, this.mOldRes.length) 139 | 140 | this.resDic.forEach((v: ResInfo, key: string) => 141 | { 142 | this.mOldRes.push(key) 143 | }); 144 | } 145 | while (this.mOldRes.length > 0) 146 | { 147 | let url = this.mOldRes.pop() 148 | let info = this.resDic.get(url) 149 | if (info != null) 150 | { 151 | if (info.isFGUIPack) fairygui.UIPackage.removePackage(info.fullUrl) 152 | this.resDic.delete(info.url) 153 | } 154 | Laya.loader.clearRes(url) 155 | 156 | } 157 | 158 | if (forced) 159 | { 160 | this.resDic.clear() 161 | } 162 | else 163 | { 164 | 165 | } 166 | } 167 | 168 | /** 169 | * 压入要释放的资源 170 | */ 171 | public push() 172 | { 173 | this.resDic.forEach((v: ResInfo, key: string) => 174 | { 175 | if (!v.isKeepMemory) 176 | this.mOldRes.push(key) 177 | }); 178 | } 179 | } 180 | } -------------------------------------------------------------------------------- /src/YKFarmework/SceneMgr/SceneBase.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class SceneBase 4 | { 5 | protected firstWind: any = null 6 | 7 | public needLoadRes: LoadGruopInfo; 8 | 9 | public eventMgr: InterchangeableEventListenerMgr 10 | public tasks: TaskMgr 11 | 12 | public constructor() 13 | { 14 | this.needLoadRes = new LoadGruopInfo() 15 | this.needLoadRes.onCompletion(this.Loaded, this) 16 | this.tasks = new TaskMgr(true, new Func(this, this.TaskFinished)) 17 | this.eventMgr = new InterchangeableEventListenerMgr(this, this.OnHandler) 18 | } 19 | 20 | private mParam: any 21 | private mLoaded = false 22 | private mTaskFinished = false 23 | public Enter(param: any) 24 | { 25 | ResMgr.Instance.push() 26 | 27 | //UIMgr.Instance.HideAllWind() 28 | this.mLoaded = false 29 | this.mTaskFinished = false 30 | 31 | this.tasks.Stop() 32 | this.mParam = param 33 | this.OnInit(param) 34 | this.needLoadRes.start() 35 | this.tasks.Execute() 36 | } 37 | 38 | public Leave() 39 | { 40 | if (this.eventMgr != null) 41 | this.eventMgr.RemoveAll() 42 | 43 | if (this.tasks != null) 44 | this.tasks.Stop() 45 | this.OnLeave() 46 | } 47 | 48 | public Destroy(): void 49 | { 50 | this.OnDestroy() 51 | } 52 | 53 | 54 | 55 | /** 56 | * 任务完成 57 | * @param error 错误 58 | */ 59 | protected TaskFinished(error) 60 | { 61 | if (error != null) 62 | { 63 | console.error(error) 64 | } 65 | else 66 | { 67 | this.OnTaskFinished() 68 | this.mTaskFinished = true 69 | this.ChechEnter() 70 | } 71 | } 72 | 73 | /** 74 | * 加载完成 75 | * @param error 加载错误 76 | */ 77 | protected Loaded(error) 78 | { 79 | if (error != null) 80 | { 81 | console.error(error) 82 | } 83 | else 84 | { 85 | this.OnLoaded() 86 | this.mLoaded = true 87 | this.ChechEnter() 88 | } 89 | 90 | } 91 | 92 | private ChechEnter() 93 | { 94 | if (this.mLoaded && this.mTaskFinished) 95 | { 96 | UIMgr.Instance.HideAllWind(true) 97 | ResMgr.Instance.pop() 98 | if (this.firstWind != null) 99 | { 100 | UIMgr.Instance.ShowWind(this.firstWind) 101 | } 102 | this.OnEnter(this.mParam) 103 | } 104 | } 105 | 106 | 107 | /** 108 | * 加载完成 109 | */ 110 | protected OnLoaded() 111 | { 112 | 113 | } 114 | 115 | /** 116 | * 任务完成 117 | */ 118 | protected OnTaskFinished() 119 | { 120 | 121 | } 122 | 123 | /** 124 | * 处理消息 125 | * @param ev 参数 126 | */ 127 | protected OnHandler(ev: EventData) 128 | { 129 | 130 | } 131 | 132 | /** 133 | * 场景初始化 134 | * @param param 参数 135 | */ 136 | protected OnInit(param: any) 137 | { 138 | 139 | } 140 | 141 | /** 142 | * 进入场景 143 | */ 144 | protected OnEnter(param: any): void 145 | { 146 | 147 | } 148 | 149 | /** 150 | * 离开场景 151 | */ 152 | protected OnLeave(): void 153 | { 154 | 155 | } 156 | 157 | /** 158 | * 当场景被销毁的时候 159 | */ 160 | protected OnDestroy(): void 161 | { 162 | 163 | } 164 | } 165 | } -------------------------------------------------------------------------------- /src/YKFarmework/SceneMgr/SceneMgr.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class SceneMgr extends DispatchEventNode 4 | { 5 | constructor() 6 | { 7 | super(); 8 | if(SceneMgr.mInstance == null) SceneMgr.mInstance = this 9 | } 10 | private mScenes: Map = new Map() 11 | //private mBolckBg : cc.Node = null 12 | private static mInstance: SceneMgr = null 13 | public static get Instance(): SceneMgr 14 | { 15 | if (this.mInstance == null)new SceneMgr() 16 | return this.mInstance 17 | } 18 | 19 | private mCurScene: SceneBase = null 20 | 21 | /** 22 | * 跳转场景 23 | * @param type 场景脚本文件 24 | * @param param 参数 25 | */ 26 | public GoToScene(script: any, param: any = null) 27 | { 28 | if (!this.mScenes.has(script)) 29 | { 30 | if (this.mCurScene != null) 31 | { 32 | this.mCurScene.Leave() 33 | } 34 | let scene: SceneBase = new script() 35 | this.mScenes.set(script, scene) 36 | this.mCurScene = scene 37 | this.mCurScene.Enter(param) 38 | } 39 | else 40 | { 41 | let scene = this.mScenes.get(script) 42 | if (scene == this.mCurScene) 43 | { 44 | console.error("当前场景与目标场景一样无法重新进入这个场景") 45 | return 46 | } 47 | else 48 | { 49 | if (this.mCurScene != null) 50 | { 51 | this.mCurScene.Leave() 52 | this.mCurScene = this.mScenes.get(script) 53 | this.mCurScene.Enter(param) 54 | } 55 | } 56 | } 57 | 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/YKFarmework/Task/TaskBase.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | /** 4 | * 任务管理器 5 | */ 6 | export class TaskMgr 7 | { 8 | /** 9 | * 任务数 10 | */ 11 | protected mTaskNum: number = 0 12 | 13 | /** 14 | * 一个任务被完成 15 | */ 16 | protected mTaskItemFinished: Func 17 | 18 | /** 19 | * 遇到错误是否停止 20 | */ 21 | protected mFailureStop: boolean = true 22 | 23 | /** 24 | * 任务全部完成 25 | */ 26 | protected mFinished: Func 27 | 28 | /** 29 | * 并行任务 30 | */ 31 | protected mParallelTask: Array = new Array() 32 | 33 | /** 34 | * 顺序任务 35 | */ 36 | protected mSequence: Array = new Array() 37 | 38 | /** 39 | * 是否在执行任务 40 | */ 41 | protected mIsRuning = false 42 | 43 | /** 44 | * 任务进度 45 | */ 46 | public progress: number = 0; 47 | 48 | /** 49 | * 当前任务 50 | */ 51 | public currentTask: ITask = null 52 | 53 | /** 54 | * 当前任务是否完成 55 | */ 56 | public isFinished: boolean = false 57 | 58 | public constructor(failureStop: boolean 59 | , finished: Func) 60 | { 61 | this.mFinished = finished 62 | this.mParallelTask.splice(0, this.mParallelTask.length) 63 | this.mSequence.splice(0, this.mSequence.length) 64 | TimeDelay.Instance.Remove(this.Update, this) 65 | TimeDelay.Instance.AddUpdate(this.Update, this) 66 | } 67 | 68 | /** 69 | * 添加一个任务 70 | * @param task 任务对象 71 | * @param isSequence 是否是需要时序 72 | * @return 任务id -1则为添加失败 73 | */ 74 | public AddTask(task: ITask, isSequence: boolean = true): number 75 | { 76 | let array: Array 77 | let ret = -1 78 | if (isSequence) 79 | { 80 | array = this.mSequence 81 | } 82 | else 83 | { 84 | array = this.mParallelTask 85 | } 86 | 87 | let index = array.findIndex((value: ITask, index: number, obj: Array) => 88 | { 89 | return value == task 90 | }) 91 | if (index == -1) 92 | { 93 | task.Id = this.mTaskNum 94 | ret = task.Id 95 | array.push(task) 96 | this.mTaskNum = this.mSequence.length + this.mParallelTask.length 97 | } 98 | return ret 99 | } 100 | 101 | private Update() 102 | { 103 | 104 | if (!this.mIsRuning) 105 | { 106 | return 107 | } 108 | this.OnUpdate() 109 | } 110 | 111 | 112 | protected OnUpdate() 113 | { 114 | for (var index = 0; index < this.mParallelTask.length; index++) 115 | { 116 | var element = this.mParallelTask[index]; 117 | if (element.IsRuning && element.IsDone) 118 | { 119 | this.mParallelTask.splice(index, 1) 120 | index-- 121 | this.progress = (this.mTaskNum - (this.mSequence.length + this.mParallelTask.length)) / this.mTaskNum * 100 122 | let error = element.Error 123 | if (error != null && this.mFailureStop) 124 | { 125 | this.Finished(error) 126 | } 127 | else 128 | { 129 | if (this.mTaskItemFinished) 130 | { 131 | this.mTaskItemFinished.Invoke(element, this.progress) 132 | } 133 | } 134 | 135 | } 136 | else if (!element.IsRuning && !element.IsDone) 137 | { 138 | element.OnExecute() 139 | this.currentTask = element 140 | } 141 | } 142 | 143 | for (var index = 0; index < this.mSequence.length; index++) 144 | { 145 | var element = this.mSequence[index] 146 | 147 | if (element.IsRuning) 148 | { 149 | if (element.IsDone) 150 | { 151 | this.mSequence.splice(index, 1) 152 | index-- 153 | let error = element.Error 154 | if (error != null && this.mFailureStop) 155 | { 156 | this.Finished(error) 157 | } 158 | else 159 | { 160 | this.progress = (this.mTaskNum - (this.mSequence.length + this.mParallelTask.length)) / this.mTaskNum * 100 161 | if (this.mTaskItemFinished) 162 | { 163 | this.mTaskItemFinished.Invoke(element, this.progress) 164 | } 165 | } 166 | } 167 | break 168 | } 169 | else if (!element.IsDone) 170 | { 171 | this.currentTask = element 172 | element.OnExecute() 173 | } 174 | } 175 | if (this.mSequence.length + this.mParallelTask.length <= 0) 176 | { 177 | this.Finished() 178 | } 179 | } 180 | 181 | protected Finished(error = null) 182 | { 183 | this.isFinished = true 184 | this.mIsRuning = false 185 | this.progress = 100 186 | if (this.mFinished != null) 187 | { 188 | this.mFinished.Invoke(error) 189 | } 190 | 191 | if (error) 192 | { 193 | TimeDelay.Instance.Remove(this.Update, this) 194 | } 195 | } 196 | 197 | /** 198 | * 199 | * @param id 任务id 200 | */ 201 | public HasTask(id): boolean 202 | { 203 | let index = this.mSequence.findIndex((value: ITask, index: number, obj: Array) => 204 | { 205 | return value.Id == id 206 | }) 207 | 208 | index = this.mParallelTask.findIndex((value: ITask, index: number, obj: Array) => 209 | { 210 | return value.Id == id 211 | }) 212 | 213 | return index != -1 214 | } 215 | 216 | public Stop() 217 | { 218 | this.mIsRuning = false 219 | //TimeDelay.Instance.Remove(this.Update, this) 220 | } 221 | 222 | public Execute() 223 | { 224 | this.mIsRuning = true 225 | } 226 | } 227 | 228 | /** 229 | * 任务接口 230 | */ 231 | export interface ITask 232 | { 233 | IsRuning: boolean 234 | Id: number 235 | IsDone: boolean 236 | Error: string 237 | TaskName: () => string 238 | OnExecute: () => void 239 | Reset: () => void 240 | } 241 | 242 | /** 243 | * 任务基类 244 | */ 245 | export class TaskBase implements ITask 246 | { 247 | IsRuning: boolean = false; 248 | Id: number = 0; 249 | IsDone: boolean = false; 250 | Error: string = null; 251 | 252 | public TaskName(): string 253 | { 254 | return null 255 | } 256 | public OnExecute(): void 257 | { 258 | this.IsRuning = true 259 | } 260 | public Reset(): void 261 | { 262 | this.IsRuning = false 263 | } 264 | 265 | } 266 | } -------------------------------------------------------------------------------- /src/YKFarmework/UIMgr/UIMgr.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | import Groot = fairygui.GRoot 4 | import UIPackage = fairygui.UIPackage 5 | export class UIMgr extends DispatchEventNode 6 | { 7 | public constructor() 8 | { 9 | super() 10 | if (UIMgr.mInstance == null) UIMgr.mInstance = this 11 | } 12 | public static UIStartScale = 0.6 13 | private static mInstance: UIMgr = null 14 | public static get Instance(): UIMgr 15 | { 16 | if (this.mInstance == null) 17 | new UIMgr() 18 | return this.mInstance 19 | } 20 | 21 | /** 22 | * 获取所有窗口 23 | */ 24 | public GetAllWinds(): Array 25 | { 26 | let array: Array = new Array() 27 | 28 | for (var index = 0; index < Groot.inst.numChildren; index++) 29 | { 30 | var element: fairygui.GObject = Groot.inst.getChildAt(index) 31 | if (element instanceof fairygui.Window) 32 | { 33 | array.push(element) 34 | } 35 | } 36 | return array 37 | } 38 | 39 | /** 40 | * 寻找窗口 41 | * @param type 类型 42 | */ 43 | public FindWind(type: any) 44 | { 45 | let array = this.GetAllWinds() 46 | return array.find((value: fairygui.Window, index: number, 47 | obj: Array) => 48 | { 49 | return value instanceof type 50 | }) 51 | } 52 | 53 | /** 54 | * 显示界面 55 | * @param type 界面类型 56 | * @param param 界面数据 57 | */ 58 | public ShowWind(type: any, param = null) 59 | { 60 | let wind = this.FindWind(type) 61 | if (wind == null) 62 | { 63 | wind = new type() 64 | } 65 | wind.data = param 66 | 67 | fairygui.GRoot.inst.showWindow(wind) 68 | } 69 | 70 | /** 71 | * 隐藏窗口 72 | * @param type 界面类型 73 | */ 74 | public HideWind(type: any) 75 | { 76 | let wind = this.FindWind(type) 77 | if (wind != null) 78 | { 79 | fairygui.GRoot.inst.hideWindow(wind) 80 | } 81 | } 82 | 83 | /** 84 | * 获取窗口 85 | * @param isShow 是否只找显示 86 | * @param containDotDel 是否包含不需要被删除的界面 87 | */ 88 | public GetAllWind(isShow = false, containDotDel = true): Array 89 | { 90 | let keys = new Array() 91 | 92 | let array = this.GetAllWinds() 93 | 94 | array.forEach(((value: fairygui.Window, key: any, map: Array) => 95 | { 96 | if (!isShow || value.isShowing) 97 | { 98 | if (value instanceof BaseUI) 99 | { 100 | let wind: BaseUI = value as BaseUI 101 | if (!value.dontDel || containDotDel) 102 | { 103 | keys.push(value) 104 | } 105 | } 106 | else 107 | { 108 | keys.push(value) 109 | } 110 | } 111 | })); 112 | 113 | return keys 114 | } 115 | 116 | /** 117 | * 隐藏所有 118 | * @param dispose 销毁 119 | * @param containDotDel 是否包含不能删除的 120 | */ 121 | public HideAllWind(dispose = false, containDotDel = false) 122 | { 123 | let winds = this.GetAllWind(false, containDotDel) 124 | winds.forEach(element => 125 | { 126 | if (dispose) 127 | element.dispose() 128 | else 129 | fairygui.GRoot.inst.hideWindowImmediately(element) 130 | }); 131 | 132 | fairygui.GRoot.inst.hidePopup() 133 | } 134 | 135 | /** 136 | * 显示等待 137 | * @param msg 消息 138 | */ 139 | public ShowModalWait(msg: string = null) 140 | { 141 | fairygui.GRoot.inst.showModalWait(msg) 142 | console.log("msg =" + msg) 143 | } 144 | 145 | /** 146 | * 关闭等待界面 147 | */ 148 | public CloseModalWait(): void 149 | { 150 | fairygui.GRoot.inst.closeModalWait() 151 | } 152 | } 153 | 154 | export abstract class BaseUI extends fairygui.Window 155 | { 156 | protected packName = "" 157 | protected resName = "Main" 158 | public eventMgr: InterchangeableEventListenerMgr = null; 159 | 160 | protected btnCloseNodeName: string = "BtnClose" 161 | public modal: boolean = false 162 | public dontDel: boolean = false 163 | public UIObj: Map = new Map() 164 | public UICtrls: Map = new Map() 165 | protected btnNameStartsWith: string = "Btn" 166 | protected isNeedShowAnimation: boolean = false 167 | protected isNeedHideAnimation: boolean = false 168 | 169 | protected onInit() 170 | { 171 | super.onInit() 172 | this.eventMgr = new InterchangeableEventListenerMgr(this, this.OnHandler) 173 | if (this.contentPane == null) 174 | { 175 | let windObj = UIPackage.createObject(this.packName, this.resName); 176 | windObj.setSize(fairygui.GRoot.inst.width, fairygui.GRoot.inst.height); 177 | this.contentPane = windObj.asCom 178 | } 179 | 180 | this.center(); 181 | this.UIObj.clear() 182 | this.UICtrls.clear() 183 | for (var index = 0; index < this.contentPane.numChildren; index++) 184 | { 185 | var element = this.contentPane.getChildAt(index); 186 | if (element.name.startsWith(this.btnNameStartsWith)) 187 | { 188 | if (element.name == "BtnClose") 189 | { 190 | element.onClick(this, this.OnBtnClose) 191 | } 192 | else 193 | { 194 | let xx = element 195 | element.onClick(this, () => 196 | { 197 | this.OnBtnClick(xx as fairygui.GButton) 198 | }) 199 | } 200 | } 201 | this.UIObj.set(element.name, element) 202 | } 203 | 204 | this.contentPane.controllers.forEach(element => 205 | { 206 | this.UICtrls.set(element.name, element) 207 | }); 208 | 209 | this.setPivot(0.5, 0.5) 210 | this.OninitWind() 211 | 212 | } 213 | 214 | protected onHide() 215 | { 216 | this.data = null 217 | this.eventMgr.RemoveAll() 218 | this.OnHideWind() 219 | } 220 | 221 | protected OnHandler(ev: EventData) 222 | { 223 | } 224 | 225 | protected doHideAnimation() 226 | { 227 | if (this.isNeedHideAnimation) 228 | { 229 | this.setScale(UIMgr.UIStartScale, UIMgr.UIStartScale) 230 | fairygui.tween.GTween.to(this.scaleX, 0, 0.3) 231 | .onUpdate((v: fairygui.tween.GTweener) => 232 | { 233 | this.setScale(v.value.x, v.value.x) 234 | }, this) 235 | .onComplete(() => 236 | { 237 | super.doHideAnimation() 238 | }, this) 239 | } 240 | else 241 | { 242 | super.doHideAnimation() 243 | } 244 | } 245 | 246 | protected doShowAnimation() 247 | { 248 | if (this.isNeedHideAnimation) 249 | { 250 | this.scaleX = 0 251 | this.scaleY = 0 252 | fairygui.tween.GTween.to(this.scaleX, 1, 0.3) 253 | .setEase(fairygui.tween.EaseType.BounceOut) 254 | .onUpdate((v: fairygui.tween.GTweener) => 255 | { 256 | this.setScale(v.value.x, v.value.x) 257 | }, this) 258 | .onComplete(() => 259 | { 260 | super.doShowAnimation() 261 | }, this) 262 | } 263 | else 264 | { 265 | super.doShowAnimation() 266 | } 267 | } 268 | 269 | protected OnBtnClick(ev: fairygui.GButton) 270 | { 271 | 272 | } 273 | 274 | protected OnBtnClose() 275 | { 276 | this.hide() 277 | } 278 | 279 | protected onShown() 280 | { 281 | super.onShown() 282 | this.OnShowWind() 283 | } 284 | 285 | 286 | protected abstract OninitWind() 287 | 288 | protected abstract OnShowWind() 289 | 290 | protected abstract OnHideWind() 291 | } 292 | } -------------------------------------------------------------------------------- /src/YKFarmework/Util/GameFlag.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class GameFlag 4 | { 5 | /// 6 | /// 标志量 7 | /// 8 | private mValue: number = 0; 9 | 10 | public get Value(): number 11 | { 12 | return this.mValue 13 | } 14 | 15 | public set Value(v) 16 | { 17 | this.mValue = v 18 | } 19 | 20 | public constructor(flag = 0) 21 | { 22 | this.mValue = flag 23 | } 24 | 25 | public Add(flag) 26 | { 27 | this.mValue |= flag 28 | return this 29 | } 30 | 31 | public Remove(flag) 32 | { 33 | this.mValue &= ~flag 34 | return this 35 | } 36 | 37 | public Has(flag) 38 | { 39 | return (this.mValue & flag) != 0 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/YKFarmework/Util/Log.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class Log 4 | { 5 | public static Log = console.log 6 | public static Error = console.error 7 | public static Warn = console.warn() 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/YKFarmework/Util/TimeDelay.ts: -------------------------------------------------------------------------------- 1 | module YK 2 | { 3 | export class TimeDelay 4 | { 5 | constructor() 6 | { 7 | Laya.timer.frameLoop(0.01, this, this.update) 8 | } 9 | /** 10 | * 当前事件执行的次数 11 | */ 12 | public repeat: number = 0 13 | private items: Array = new Array() 14 | private toAdd: Array = new Array() 15 | private toRemove: Array = new Array() 16 | private pool: Array = new Array() 17 | 18 | private static mInstance: TimeDelay = null 19 | public static get Instance() 20 | { 21 | if (this.mInstance == null) 22 | { 23 | this.mInstance = new TimeDelay() 24 | } 25 | return this.mInstance 26 | } 27 | 28 | private GetFromPool(): TimeDelayData 29 | { 30 | let t: TimeDelayData; 31 | if (this.pool.length > 0) 32 | { 33 | t = this.pool.pop() 34 | } 35 | else 36 | t = new TimeDelayData(); 37 | return t; 38 | } 39 | 40 | private ReturnToPool(t: TimeDelayData) 41 | { 42 | t.set(0, 0, null, null, null) 43 | t.elapsed = 0 44 | t.deleted = false 45 | this.pool.push(t) 46 | } 47 | 48 | public Exists(callback: TimerCallback, thisObj: any) 49 | { 50 | let t = this.toAdd.find((value: TimeDelayData, index: number, obj: Array) => 51 | { 52 | return value.callback == callback && value.thisObj == thisObj 53 | }) 54 | 55 | if (t != null) 56 | { 57 | return true 58 | } 59 | t = this.items.find((value: TimeDelayData, index: number, obj: Array) => 60 | { 61 | return value.callback == callback && value.thisObj == thisObj 62 | }) 63 | if (t != null && !t.deleted) 64 | { 65 | return true 66 | } 67 | return false 68 | } 69 | 70 | public Add(interval: number, repeat: number, callback: TimerCallback, thisObj: any, callbackParam: any = null) 71 | { 72 | let t: TimeDelayData; 73 | t = this.items.find((value: TimeDelayData, index: number, obj: Array) => 74 | { 75 | return value.callback == callback && value.thisObj == thisObj 76 | }) 77 | 78 | if (t == null) 79 | { 80 | t = this.toAdd.find((value: TimeDelayData, index: number, obj: Array) => 81 | { 82 | return value.callback == callback && value.thisObj == thisObj 83 | }) 84 | } 85 | 86 | if (t == null) 87 | { 88 | t = this.GetFromPool() 89 | this.toAdd.push(t); 90 | } 91 | 92 | t.set(interval, repeat, callback, thisObj, callbackParam) 93 | t.deleted = false 94 | t.elapsed = 0 95 | } 96 | 97 | public AddUpdate(callback: TimerCallback, thisObj: any, callbackParam: any = null) 98 | { 99 | this.Add(0.001, 0, callback, thisObj, callbackParam); 100 | } 101 | 102 | public Remove(callback: TimerCallback, thisObj: any) 103 | { 104 | let findindex = -1 105 | let t = this.toAdd.find((value: TimeDelayData, index: number, obj: Array) => 106 | { 107 | if (value.callback == callback && value.thisObj == thisObj) 108 | { 109 | findindex = index 110 | return true 111 | } 112 | else 113 | { 114 | return false 115 | } 116 | }) 117 | if (t != null) 118 | { 119 | this.toAdd.splice(findindex, 1) 120 | this.ReturnToPool(t) 121 | } 122 | 123 | t = this.items.find((value: TimeDelayData, index: number, obj: Array) => { return value.callback == callback && value.thisObj == thisObj }) 124 | if (t != null) 125 | t.deleted = true 126 | } 127 | 128 | private lastTime: number = 0 129 | private deltaTime: number = 0 130 | start() 131 | { 132 | this.lastTime = Laya.timer.currTimer; 133 | } 134 | 135 | update() 136 | { 137 | this.deltaTime = (Laya.timer.currTimer - this.lastTime) / 1000 138 | this.lastTime = Laya.timer.currTimer 139 | 140 | for (let index = 0; index < this.items.length; index++) 141 | { 142 | let t = this.items[index]; 143 | if (t.deleted) 144 | { 145 | this.toRemove.push(t) 146 | continue; 147 | } 148 | 149 | t.elapsed += this.deltaTime 150 | if (t.elapsed < t.interval) 151 | { 152 | continue 153 | } 154 | 155 | t.elapsed = 0; 156 | 157 | if (t.repeat > 0) 158 | { 159 | t.repeat-- 160 | if (t.repeat == 0) 161 | { 162 | t.deleted = true 163 | this.toRemove.push(t) 164 | } 165 | } 166 | this.repeat = t.repeat 167 | if (t.callback != null) 168 | { 169 | try 170 | { 171 | t.callback.call(t.thisObj, t.param) 172 | } catch (error) 173 | { 174 | t.deleted = true 175 | } 176 | } 177 | } 178 | let len = this.toRemove.length 179 | while (len) 180 | { 181 | let t = this.toRemove.pop() 182 | let index = this.items.indexOf(t) 183 | if (t.deleted && index != -1) 184 | { 185 | this.items.splice(index, 1) 186 | this.ReturnToPool(t) 187 | } 188 | len-- 189 | } 190 | len = this.toAdd.length 191 | while (len) 192 | { 193 | let t = this.toAdd.pop() 194 | this.items.push(t) 195 | len-- 196 | } 197 | } 198 | } 199 | 200 | export class TimeDelayData 201 | { 202 | public repeat: number 203 | public interval: number 204 | public param: any 205 | public callback: TimerCallback 206 | public thisObj: any 207 | public deleted: boolean 208 | public elapsed: number 209 | 210 | public set(interval: number, repeat: number, callback: TimerCallback, thisObj: any, param: any): void 211 | { 212 | this.interval = interval 213 | this.repeat = repeat 214 | this.callback = callback 215 | this.param = param 216 | this.thisObj = thisObj 217 | } 218 | } 219 | 220 | export type TimerCallback = (param: any) => void 221 | } 222 | 223 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "noEmitHelpers": true, 6 | "sourceMap": false 7 | }, 8 | "exclude": [ 9 | "node_modules" 10 | ] 11 | } --------------------------------------------------------------------------------