├── README.md ├── main ├── .laya │ ├── launch.json │ ├── pubset.json │ └── tasks.json ├── bin │ ├── index.html │ ├── libs │ │ ├── LayaRender.js │ │ ├── bytebuffer.js │ │ ├── domparserinone.js │ │ ├── laya.ani.js │ │ ├── laya.core.js │ │ ├── laya.d3.js │ │ ├── laya.d3Plugin.js │ │ ├── laya.debugtool.js │ │ ├── laya.device.js │ │ ├── laya.filter.js │ │ ├── laya.html.js │ │ ├── laya.particle.js │ │ ├── laya.pathfinding.js │ │ ├── laya.tiledmap.js │ │ ├── laya.ui.js │ │ ├── laya.webgl.js │ │ ├── laya.wxmini.js │ │ ├── matter-RenderLaya.js │ │ ├── matter.js │ │ ├── min │ │ │ ├── laya.ani.min.js │ │ │ ├── laya.core.min.js │ │ │ ├── laya.d3.min.js │ │ │ ├── laya.d3Plugin.min.js │ │ │ ├── laya.debugtool.min.js │ │ │ ├── laya.device.min.js │ │ │ ├── laya.filter.min.js │ │ │ ├── laya.html.min.js │ │ │ ├── laya.particle.min.js │ │ │ ├── laya.pathfinding.min.js │ │ │ ├── laya.tiledmap.min.js │ │ │ ├── laya.ui.min.js │ │ │ ├── laya.webgl.min.js │ │ │ └── laya.wxmini.min.js │ │ ├── protobuf.js │ │ └── worker.js │ ├── unpack.json │ └── version.json ├── copy.bat ├── laya │ ├── .laya │ ├── assets │ │ ├── comp │ │ │ ├── bg.png │ │ │ ├── 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 │ │ │ ├── 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 │ │ └── rank │ │ │ ├── first.png │ │ │ ├── second.png │ │ │ └── third.png │ ├── pages │ │ └── index.ui │ └── styles.xml ├── libs │ └── LayaAir.d.ts ├── rank-main.laya ├── release.bat ├── release │ └── wxgame │ │ ├── game.json │ │ └── src │ │ └── openDataContext │ │ └── .gitkeep ├── src │ ├── Main.ts │ ├── ui │ │ └── layaUI.max.all.ts │ └── views │ │ └── Index.ts └── tsconfig.json ├── open-data ├── .laya │ ├── launch.json │ ├── pubset.json │ └── tasks.json ├── bin │ ├── index.html │ ├── libs │ │ ├── LayaRender.js │ │ ├── bytebuffer.js │ │ ├── domparserinone.js │ │ ├── laya.ani.js │ │ ├── laya.core.js │ │ ├── laya.d3.js │ │ ├── laya.d3Plugin.js │ │ ├── laya.debugtool.js │ │ ├── laya.device.js │ │ ├── laya.filter.js │ │ ├── laya.html.js │ │ ├── laya.particle.js │ │ ├── laya.pathfinding.js │ │ ├── laya.tiledmap.js │ │ ├── laya.ui.js │ │ ├── laya.webgl.js │ │ ├── laya.wxmini.js │ │ ├── matter-RenderLaya.js │ │ ├── matter.js │ │ ├── min │ │ │ ├── laya.ani.min.js │ │ │ ├── laya.core.min.js │ │ │ ├── laya.d3.min.js │ │ │ ├── laya.d3Plugin.min.js │ │ │ ├── laya.debugtool.min.js │ │ │ ├── laya.device.min.js │ │ │ ├── laya.filter.min.js │ │ │ ├── laya.html.min.js │ │ │ ├── laya.particle.min.js │ │ │ ├── laya.pathfinding.min.js │ │ │ ├── laya.tiledmap.min.js │ │ │ ├── laya.ui.min.js │ │ │ ├── laya.webgl.min.js │ │ │ └── laya.wxmini.min.js │ │ ├── protobuf.js │ │ └── worker.js │ ├── unpack.json │ └── version.json ├── laya │ ├── .laya │ ├── assets │ │ └── rank │ │ │ ├── first.png │ │ │ ├── second.png │ │ │ └── third.png │ └── pages │ │ └── rank.ui ├── libs │ └── LayaAir.d.ts ├── open-data.laya ├── release_opendata.bat ├── src │ ├── Main.ts │ ├── ui │ │ └── layaUI.max.all.ts │ └── views │ │ └── Rank.ts └── tsconfig.json ├── view.png └── wxgame └── .gitkeep /README.md: -------------------------------------------------------------------------------- 1 | # laya-wx-rank-ts 2 | Layabox(windows版本,因为没钱买苹果)开发的微信小游戏排行榜demo,使用开放数据域,开发用的Typescript语言,对应Laya类库版本 >= 1.7.19 3 | 4 | # 使用步骤(版本 <= 1.7.20) 5 | 为了同时使用版本管理和图集加载,做了一些特殊的处理,具体原理会在之后说明,这里请先照着用吧:)。 6 | 1. 下载本项目解压,可以看到三个文件夹,main为主代码,open-data为开放数据域代码,wxgame对应最后发布出来的小游戏代码(现在是空的,等这些步骤执行完,它就有东西了)。 7 | 2. 在两个Layabox窗口中分别打开main项目和open-data项目。 8 | 3. 在两个项目中都切换到编辑模式,按F12导出资源。 9 | 4. 执行main项目下的copy.bat脚本,将排行榜图集拷贝到单独的文件夹下。 10 | 5. main项目切换回代码模式,编译,然后发布项目。这里是重点,发布项目的选项,要勾选启用版本管理,后续执行脚本要选择main项目下的release.bat文件。然后就能看到与main平级的wxgame文件夹下有内容了。 11 | 6. 继续发布open-data项目,注意,发布选项,*不要*勾选版本管理,后续执行脚本选择open-data项目下的release_opendata文件。 12 | 7. 用微信web开发者工具打开wxgame文件夹,填入你自己的小游戏AppID,即可执行看到效果了。 13 | 14 | # 使用步骤(版本 >= 1.7.21) 15 | 由于laya库升级,增加了将图集直接传到子域的方法,这样就不再需要将排行榜图集独立出来了,子域也可以使用版本管理,但是官方库中还有点问题,需要改一行代码,请先照着用:)。 16 | 1. 下载本项目解压,可以看到三个文件夹,main为主代码,open-data为开放数据域代码,wxgame对应最后发布出来的小游戏代码(现在是空的,等这些步骤执行完,它就有东西了)。 17 | 2. 在两个Layabox窗口中分别打开main项目和open-data项目。 18 | 3. 在两个项目中都切换到编辑模式,按F12导出资源。 19 | 4. main项目中,打开`bin/libs/laya.wxmini.js`,找到`MiniAdpter.postInfoToContext`方法,将里面的 20 | ``` 21 | fileNativeUrl=textureUrl 22 | ``` 23 | 改为 24 | ``` 25 | fileNativeUrl=URL.formatURL(textureUrl) 26 | ``` 27 | 5. main项目切换回代码模式,编译,然后发布项目。这里是重点,发布项目的选项,要勾选启用版本管理,后续执行脚本要选择main项目下的release.bat文件。然后就能看到与main平级的wxgame文件夹下有内容了。 28 | 6. 继续发布open-data项目,注意,发布选项,*不要*勾选版本管理,后续执行脚本选择open-data项目下的release_opendata文件。 29 | 7. 用微信web开发者工具打开wxgame文件夹,填入你自己的小游戏AppID,即可执行看到效果了。 30 | 31 | 界面比较丑,请忽略 32 | ![view](./view.png?raw=true) 33 | 34 | # 代码说明 35 | ### 基础实现 36 | 这个其实在社区里有不少文章说过了,但是在这里我还是重复讲一遍吧。 37 | 首先,大家都知道肯定是需要两个项目的,一个对应小游戏的主域,另一个对应小游戏的开放数据域(子域)。 38 | main文件夹,对应主域,初始化的时候用 Laya.MiniAdpter.init(true, false);,表示是主域,并自动将加载的文本数据自动传递到子域。 39 | 而open-data对应子域,初始化时用 Laya.MiniAdpter.init(true, true);,其实我觉得第一个参数没啥用,关键是第二个参数表示它是子域。 40 | 41 | --- 42 | 在主域中,做了以下几件事: 43 | * 设置共享画布,根据小游戏的文档,它的宽高只能在主域设置,不能在开放数据域中设置,我这里使用了如下的代码: 44 | ``` 45 | let wx = Laya.Browser.window.wx; 46 | Laya.timer.once(1000, this, () => { 47 | //设置共享画布大小 48 | let sharedCanvas = wx.getOpenDataContext().canvas; 49 | sharedCanvas.width = Laya.stage.width; 50 | sharedCanvas.height = Laya.stage.height; 51 | //主域往子域透传消息 52 | wx.postMessage({type:"resizeShared",url:"",data:{width:Laya.stage.width,height:Laya.stage.height,matrix:Laya.stage._canvasTransform},isLoad:false}); 53 | Laya.ResourceVersion.type = Laya.ResourceVersion.FILENAME_VERSION; 54 | Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.loadOpenDataResource)); 55 | }); 56 | ``` 57 | * 绘制离屏画布,我在这里是把它放在了页面里,首先创建了一个Sprite组件,并设置它的var为openDataCanvas,然后,在View初始化时使用如下代码: 58 | ``` 59 | let texture:Laya.Texture = new Laya.Texture(Laya.Browser.window.sharedCanvas); 60 | texture.bitmap.alwaysChange = true;//小程序使用,非常费,这个参数可以根据自己的需求适当调整,如果内容不变可以不用设置成true 61 | this.openDataCanvas.graphics.drawTexture(texture, 0, 0, texture.width, texture.height); 62 | ``` 63 | * 控制离屏画布的显示和隐藏,有了上面的openDataCanvas,直接设置它的visible属性就好。然后在显示的同时,向子域发送刷新数据的命令(参考下方子域接收命令的说明),以下是部分代码: 64 | ``` 65 | protected postMessage(item:Object):void 66 | { 67 | if (Laya.Browser.onMiniGame) { 68 | let wx = Laya.Browser.window.wx; 69 | let openDataContext = wx.getOpenDataContext(); 70 | openDataContext.postMessage(item); 71 | } 72 | } 73 | 74 | public showRankList():void 75 | { 76 | this.rankBox.x = -480; 77 | this.openDataCanvas.x = -471; 78 | this.rankBox.visible = true; 79 | this.openDataCanvas.visible = true; 80 | 81 | Laya.Tween.to(this.rankBox, {"x": 0}, 200); 82 | Laya.Tween.to(this.openDataCanvas, {"x": 0}, 200); 83 | 84 | this.postMessage({ 85 | cmd: 'showRank', 86 | }); 87 | } 88 | ``` 89 | 90 | --- 91 | 在子域中,主要就是一件事,接收主域的命令并处理,在这里,我把它分为系统需要的部分和自定义部分。 92 | * 系统需要部分,主要就是缓存文件数据和重设渲染canvas。 93 | * 自定义部分,主要是处理关系链数据及绘制。 94 | 示例代码如下: 95 | ``` 96 | wx.onMessage(data => { 97 | let MiniFileMgr = laya.wx.mini.MiniFileMgr; 98 | //console.log(data); 99 | if (data.cmd != undefined) { 100 | if (data.cmd == 'addScore') { 101 | this.increaseWeekScore(); 102 | } else if (data.cmd == 'showRank') { 103 | (this.rankView as views.Rank).showRankList(); 104 | } else if (data.cmd == 'hideRank') { 105 | 106 | } else if (data.cmd == 'loadRes') { 107 | this.loadResource(); 108 | } 109 | } else { 110 | if (data['isLoad'] == "filedata") { 111 | MiniFileMgr.ziyuFileData[data.url] = data.data;//文本数据 112 | } else if(data['isLoad']=="opendatacontext"){ 113 | if(data.url){ 114 | MiniFileMgr.ziyuFileData[data.url]=data.atlasdata; 115 | (MiniFileMgr as any).ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl; 116 | } 117 | }else if(data['isLoad']=="openJsondatacontext"){ 118 | if(data.url){ 119 | MiniFileMgr.ziyuFileData[data.url]=data.atlasdata; 120 | } 121 | }else if(data['isLoad']=="openJsondatacontextPic"){ 122 | (MiniFileMgr as any).ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl; 123 | } else if (data['isLoad'] == "filenative") { 124 | if(data.isAdd) 125 | MiniFileMgr.filesListObj[data.url] = data.data; 126 | else 127 | delete MiniFileMgr.filesListObj[data.url]; 128 | } else if (data['type'] == "resizeShared") { 129 | let tempMatrix = data.data.matrix; 130 | let matrix:Laya.Matrix = new Laya.Matrix(); 131 | matrix.a = tempMatrix.a; 132 | matrix.b = tempMatrix.b; 133 | matrix.c = tempMatrix.c; 134 | matrix.d = tempMatrix.d; 135 | Laya.stage._canvasTransform = matrix;//重新设置矩阵 136 | } 137 | } 138 | }); 139 | ``` 140 | 141 | ### 版本管理&图集使用 142 | ##### 版本 <= 1.7.20 143 | 主域使用版本管理,子域不使用,当主域自动把atlas内容通过消息传给子域后,子域再去加载资源。 144 | 145 | 主域中,资源加载完成后,将atlas内容传给子域。因为使用了版本管理,因此系统自动的传递,子域接收到后对应的URL是不正确的,所以需要手动再传一次,如下: 146 | ``` 147 | protected loadOpenDataResource():void 148 | { 149 | Laya.loader.load("rankRes/rank.atlas", Laya.Handler.create(this, this.openDataHandle), null, Laya.Loader.ATLAS); 150 | } 151 | 152 | protected openDataHandle():void 153 | { 154 | if (Laya.Browser.onMiniGame) { 155 | let wx = Laya.Browser.window.wx; 156 | let urlArr = ["rankRes/rank.atlas"]; 157 | for (let i = 0; i < urlArr.length; i++) { 158 | wx.postMessage({url:urlArr[i], data:Laya.loader.getRes(urlArr[i]),isLoad:"filedata"}); 159 | } 160 | wx.postMessage({cmd:"loadRes"}); 161 | } 162 | this.loadResource(); 163 | } 164 | ``` 165 | 166 | 子域收到loadRes的消息后,才开始加载资源。 167 | 但是这里还有一个问题,在主域,加载atlas之后,再加载对应的png文件,也是带着版本号的,而在子域中,是直接加载不带版本号的png文件。 168 | 所以,我在这里多做了一个操作,将原始不带版本号的png文件拷贝了一份,放在同一个文件夹下。 169 | 我以rank.atlas和rank.png为例,将它们从res文件夹中拷贝出来,放在单独rankRes文件夹中,就是发布图集之后执行copy.bat做的事情,然后进行加载。 170 | 当然,直接将它们从bin/res/atlas文件夹拷贝到release/wxgame/res/atlas文件夹下也是可以的。 171 | 那么,我把它放在单独的文件夹中有什么好处呢?答案是,整个res文件夹,我是放在网上进行加载的,最后发布出来的微信小游戏项目中,res文件夹我是直接删除的,本地和网络加载的文件混在一起,处理起来会有些麻烦:) 172 | 173 | ##### 版本 >= 1.7.21 174 | 首先,版本管理暂时不太容易绕过,因为需要读取version.json文件的内容,而在子域里,非常不幸,没有办法使用文件系统相关的方法。 175 | 或许可以更改laya源码部分,将version.json内容传送到子域,但是这个改动可能有点大,不是一行代码的事,坐等官方更新。所以,还是先将就着不要用版本管理吧,而且实际跟使用版本管理也没有区别,因为最终加载的是带版本号的文件。 176 | 177 | 比起之前版本的进步在于,rank.atlas和rank.png,不需要放在单独的文件夹中了,从主域加载了可以直接将本地文件url传过去,需要时直接使用即可。 178 | 存在的一个问题就是,使用`MiniAdpter.sendAtlasToOpenDataContext`时,传的url还是原始的未经过版本管理解析的,这样子域会加载不到,因此需要改一行代码,变成真正存在的url。 179 | 180 | # ~~TODO~~ 181 | ~~研究一下有没有什么开挂的方法,让子域需要的图集也能从网络加载,或者说,主域从网络加载了,同步到子域中。~~ 182 | 从版本1.7.21开始,laya已经增加了将图集直接传到子域的方法`MiniAdpter.sendAtlasToOpenDataContext`,使用它即可,使用步骤里已经有补充,不再赘述。 183 | -------------------------------------------------------------------------------- /main/.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 | }, 16 | { 17 | "name": "chrome调试", 18 | "type": "chrome", 19 | "request": "launch", 20 | "file": "${workspaceRoot}/bin/index.html", 21 | // "换成自己的谷歌安装路径,": 比如 22 | //window 默认安装路径为: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" 23 | //mac 系统上的默认安装路径为 "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; 24 | // "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", 25 | "runtimeArgs": [ 26 | "--allow-file-access-from-files", 27 | "--allow-file-access-frome-files", 28 | " --disable-web-security" 29 | ], 30 | "sourceMaps": true, 31 | "webRoot": "${workspaceRoot}", 32 | //假如谷歌调试报userDataDir不可用,请把谷歌安装路径取得管理员权限,或者更换${tmpdir}为其他可以读写的文件夹,也可以删除。 33 | "userDataDir": "${workspaceRoot}/.laya/chrome", 34 | "fixedPort":false 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /main/.laya/pubset.json: -------------------------------------------------------------------------------- 1 | {"1":{"sourcePath":"E:\\laya_workspace\\laya-wx-rank-ts\\main\\bin","outPath":"E:\\laya_workspace\\laya-wx-rank-ts\\main\\release\\wxgame","pngQualityLow":"65","pngQualityHigh":"80","jpgQuality":"85","mergeJs":true,"compressPng":false,"compressJpg":false,"compressJson":false,"jsontypes":"json,atlas,ls,lh,lmat,lav","compressJs":false,"enableVersion":true,"excludeFiles":"","publishType":1,"projectType":"ts","copyOutFiles":"","copyOutPath":"","userCmd":"E:\\laya_workspace\\laya-wx-rank-ts\\main\\release.bat"},"pf":1} -------------------------------------------------------------------------------- /main/.laya/tasks.json: -------------------------------------------------------------------------------- 1 | {"version":"0.1.0","command":"tsc","isShellCommand":true,"args":["-p",".","--outDir","bin/js"],"showOutput":"silent","problemMatcher":"$tsc"} -------------------------------------------------------------------------------- /main/bin/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | www.layabox.com 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /main/bin/libs/LayaRender.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Matter.js 渲染器在 LayaAir 的实现。 3 | */ 4 | (function() 5 | { 6 | var LayaRender = {}; 7 | 8 | var Common = Matter.Common; 9 | var Composite = Matter.Composite; 10 | var Bounds = Matter.Bounds; 11 | var Events = Matter.Events; 12 | var Grid = Matter.Grid; 13 | var Vector = Matter.Vector; 14 | 15 | /** 16 | * 创建新的渲染器。 17 | * @param {object} options 所有属性都有默认值,options中的属性会覆盖默认属性。 18 | * @return {render} 返回创建的旋绕器 19 | */ 20 | LayaRender.create = function(options) 21 | { 22 | var defaults = { 23 | controller: LayaRender, 24 | engine: null, 25 | element: null, 26 | canvas: null, 27 | mouse: null, 28 | frameRequestId: null, 29 | options: 30 | { 31 | width: 800, 32 | height: 600, 33 | pixelRatio: 1, 34 | background: '#fafafa', 35 | wireframeBackground: '#222222', 36 | hasBounds: !!options.bounds, 37 | enabled: true, 38 | wireframes: true, 39 | showSleeping: true, 40 | showDebug: false, 41 | showBroadphase: false, 42 | showBounds: false, 43 | showVelocity: false, 44 | showCollisions: false, 45 | showSeparations: false, 46 | showAxes: false, 47 | showPositions: false, 48 | showAngleIndicator: false, 49 | showIds: false, 50 | showShadows: false, 51 | showVertexNumbers: false, 52 | showConvexHulls: false, 53 | showInternalEdges: false, 54 | showMousePosition: false 55 | } 56 | }; 57 | var render = Common.extend(defaults, options); 58 | render.mouse = options.mouse; 59 | render.engine = options.engine; 60 | // 如果用户没有指定contaienr,默认使用stage 61 | render.container = render.container || Laya.stage; 62 | render.bounds = render.bounds || 63 | { 64 | min: 65 | { 66 | x: 0, 67 | y: 0 68 | }, 69 | max: 70 | { 71 | x: render.width, 72 | y: render.height 73 | } 74 | }; 75 | 76 | return render; 77 | } 78 | 79 | /** 80 | * 运行渲染器。 81 | * @param {render} render 渲染的目标是LayaRender.create()返回的对象 82 | * @return {void} 83 | */ 84 | LayaRender.run = function(render) 85 | { 86 | Laya.timer.frameLoop(1, this, LayaRender.world, [render]); 87 | Events.on(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite); 88 | }; 89 | 90 | /** 91 | * 停止渲染器。 92 | * @param {render} LayaRender.create()返回的对象 93 | * @return {void} 94 | */ 95 | LayaRender.stop = function(render) 96 | { 97 | Laya.timer.clear(this, LayaRender.world); 98 | Events.off(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite); 99 | } 100 | 101 | LayaRender.onRemoveSprite = function(args) 102 | { 103 | var sprite = args.object.layaSprite; 104 | if (sprite && sprite.parent) 105 | sprite.parent.removeChild(sprite); 106 | } 107 | 108 | /** 109 | * 渲染给定的 engine 的 Matter.World 对象。 110 | * 这是渲染的入口,每次场景改变时都应该被调用。 111 | * @param {render} render 112 | * @return {void} 113 | */ 114 | LayaRender.world = function(render) 115 | { 116 | var engine = render.engine, 117 | world = engine.world, 118 | renderer = render.renderer, 119 | container = render.container, 120 | options = render.options, 121 | bodies = Composite.allBodies(world), 122 | allConstraints = Composite.allConstraints(world), 123 | constraints = [], 124 | i; 125 | 126 | if (options.wireframes) 127 | { 128 | LayaRender.setBackground(render, options.wireframeBackground); 129 | } 130 | else 131 | { 132 | LayaRender.setBackground(render, options.background); 133 | } 134 | 135 | // 处理 bounds 136 | var boundsWidth = render.bounds.max.x - render.bounds.min.x, 137 | boundsHeight = render.bounds.max.y - render.bounds.min.y, 138 | boundsScaleX = boundsWidth / render.options.width, 139 | boundsScaleY = boundsHeight / render.options.height; 140 | 141 | if (options.hasBounds) 142 | { 143 | // 隐藏不在视口内的bodies 144 | for (i = 0; i < bodies.length; i++) 145 | { 146 | var body = bodies[i]; 147 | body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds); 148 | } 149 | 150 | // 过滤掉不在视口内的 constraints 151 | for (i = 0; i < allConstraints.length; i++) 152 | { 153 | var constraint = allConstraints[i], 154 | bodyA = constraint.bodyA, 155 | bodyB = constraint.bodyB, 156 | pointAWorld = constraint.pointA, 157 | pointBWorld = constraint.pointB; 158 | 159 | if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA); 160 | if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB); 161 | 162 | if (!pointAWorld || !pointBWorld) 163 | continue; 164 | 165 | if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld)) 166 | constraints.push(constraint); 167 | } 168 | 169 | // 改变视口 170 | container.scale(1 / boundsScaleX, 1 / boundsScaleY); 171 | container.pos(-render.bounds.min.x * (1 / boundsScaleX), -render.bounds.min.y * (1 / boundsScaleY)); 172 | } 173 | else 174 | { 175 | constraints = allConstraints; 176 | } 177 | 178 | for (i = 0; i < bodies.length; i++) 179 | LayaRender.body(render, bodies[i]); 180 | 181 | for (i = 0; i < constraints.length; i++) 182 | LayaRender.constraint(render, constraints[i]); 183 | }; 184 | 185 | /** 186 | * 设置背景色或者背景图片。 187 | * @param {render} render 188 | * @param {string} background 16进制颜色字符串或者图片路径 189 | */ 190 | LayaRender.setBackground = function(render, background) 191 | { 192 | if (render.currentBackground !== background) 193 | { 194 | var isColor = background.indexOf && background.indexOf('#') !== -1; 195 | 196 | render.container.graphics.clear(); 197 | 198 | if (isColor) 199 | { 200 | // 使用纯色背景 201 | render.container.bgColor = background; 202 | } 203 | else 204 | { 205 | render.container.loadImage(background); 206 | // 使用背景图片时把背景色设置为白色 207 | render.container.bgColor = "#FFFFFF"; 208 | } 209 | 210 | render.currentBackground = background; 211 | } 212 | } 213 | 214 | /** 215 | * 渲染 body 216 | * @param {render} render 217 | * @param {body} body 218 | * @return {void} 219 | */ 220 | LayaRender.body = function(render, body) 221 | { 222 | var engine = render.engine, 223 | bodyRender = body.render; 224 | 225 | if (!bodyRender.visible) 226 | return; 227 | 228 | // 有纹理的body 229 | if (bodyRender.sprite && bodyRender.sprite.texture) 230 | { 231 | var spriteId = 'b-' + body.id, 232 | sprite = body.layaSprite, 233 | container = render.container; 234 | 235 | // 如果sprite不存在,则初始化一个 236 | if (!sprite) 237 | sprite = body.layaSprite = _createBodySprite(render, body); 238 | 239 | // 如果sprite未在显示列表,则添加至显示列表 240 | if (!container.contains(sprite)) 241 | container.addChild(sprite); 242 | 243 | // 更新sprite位置 244 | sprite.x = body.position.x; 245 | sprite.y = body.position.y; 246 | sprite.rotation = body.angle * 180 / Math.PI; 247 | sprite.scaleX = bodyRender.sprite.xScale || 1; 248 | sprite.scaleY = bodyRender.sprite.yScale || 1; 249 | } 250 | else // 没有纹理的body 251 | { 252 | var primitiveId = 'b-' + body.id, 253 | sprite = body.layaSprite, 254 | container = render.container; 255 | 256 | // 如果sprite不存在,则初始化一个 257 | if (!sprite) 258 | { 259 | sprite = body.layaSprite = _createBodyPrimitive(render, body); 260 | sprite.initialAngle = body.angle; 261 | } 262 | 263 | // 如果sprite未在显示列表,则添加至显示列表 264 | if (!container.contains(sprite)) 265 | container.addChild(sprite); 266 | // 更新sprite位置 267 | sprite.x = body.position.x; 268 | sprite.y = body.position.y; 269 | sprite.rotation = (body.angle - sprite.initialAngle) * 180 / Math.PI; 270 | } 271 | }; 272 | 273 | /** 274 | * 创建使用纹理的Sprite对象。 275 | * @param {render} render 276 | * @param {body} body 277 | * @return {void} 278 | */ 279 | var _createBodySprite = function(render, body) 280 | { 281 | var bodyRender = body.render, 282 | texturePath = bodyRender.sprite.texture, 283 | sprite = new Laya.Sprite(); 284 | 285 | sprite.loadImage(texturePath); 286 | sprite.pivotX = body.render.sprite.xOffset; 287 | sprite.pivotY = body.render.sprite.yOffset; 288 | 289 | return sprite; 290 | }; 291 | 292 | /** 293 | * 创建使用矢量绘图的Sprite对象。 294 | * @param {render} render 295 | * @param {body} body 296 | * @return {void} 297 | */ 298 | var _createBodyPrimitive = function(render, body) 299 | { 300 | var bodyRender = body.render, 301 | options = render.options, 302 | sprite = new Laya.Sprite(), 303 | fillStyle, strokeStyle, lineWidth, 304 | part, points = []; 305 | 306 | var primitive = sprite.graphics; 307 | primitive.clear(); 308 | 309 | // 处理 compound parts 310 | for (var k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++) 311 | { 312 | part = body.parts[k]; 313 | 314 | if (!options.wireframes) 315 | { 316 | fillStyle = bodyRender.fillStyle; 317 | strokeStyle = bodyRender.strokeStyle; 318 | lineWidth = bodyRender.lineWidth; 319 | } 320 | else 321 | { 322 | fillStyle = null; 323 | strokeStyle = '#bbbbbb'; 324 | lineWidth = 1; 325 | } 326 | 327 | points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y); 328 | 329 | for (var j = 1; j < part.vertices.length; j++) 330 | { 331 | points.push(part.vertices[j].x - body.position.x, part.vertices[j].y - body.position.y); 332 | } 333 | 334 | points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y); 335 | 336 | primitive.drawPoly(0, 0, points, fillStyle, strokeStyle, lineWidth); 337 | 338 | // 角度指示器 339 | if (options.showAngleIndicator || options.showAxes) 340 | { 341 | lineWidth = 1; 342 | if (options.wireframes) 343 | { 344 | strokeStyle = '#CD5C5C'; 345 | } 346 | else 347 | { 348 | strokeStyle = bodyRender.strokeStyle; 349 | } 350 | 351 | primitive.drawLine(part.position.x - body.position.x, part.position.y - body.position.y, 352 | ((part.vertices[0].x + part.vertices[part.vertices.length - 1].x) / 2 - body.position.x), 353 | ((part.vertices[0].y + part.vertices[part.vertices.length - 1].y) / 2 - body.position.y)); 354 | } 355 | } 356 | 357 | return sprite; 358 | }; 359 | 360 | /** 361 | * 绘制 constraint。 362 | * @param {render} render 363 | * @param {constraint} constraint 364 | * @return {void} 365 | */ 366 | LayaRender.constraint = function(render, constraint) 367 | { 368 | var engine = render.engine, 369 | bodyA = constraint.bodyA, 370 | bodyB = constraint.bodyB, 371 | pointA = constraint.pointA, 372 | pointB = constraint.pointB, 373 | container = render.container, 374 | constraintRender = constraint.render, 375 | primitiveId = 'c-' + constraint.id, 376 | sprite = constraint.layaSprite; 377 | 378 | // 如果sprite不存在,则初始化一个 379 | if (!sprite) 380 | sprite = constraint.layaSprite = new Laya.Sprite(); 381 | 382 | var primitive = sprite.graphics; 383 | 384 | // constraint 没有两个终点时不渲染 385 | if (!constraintRender.visible || !constraint.pointA || !constraint.pointB) 386 | { 387 | primitive.clear(); 388 | return; 389 | } 390 | 391 | // 如果sprite未在显示列表,则添加至显示列表 392 | if (!container.contains(sprite)) 393 | container.addChild(sprite); 394 | 395 | // 渲染 constraint 396 | primitive.clear(); 397 | 398 | var fromX, fromY, toX, toY; 399 | if (bodyA) 400 | { 401 | fromX = bodyA.position.x + pointA.x; 402 | fromY = bodyA.position.y + pointA.y; 403 | } 404 | else 405 | { 406 | fromX = pointA.x; 407 | fromY = pointA.y; 408 | } 409 | 410 | if (bodyB) 411 | { 412 | toX = bodyB.position.x + pointB.x; 413 | toY = bodyB.position.y + pointB.y; 414 | } 415 | else 416 | { 417 | toX = pointB.x; 418 | toY = pointB.y; 419 | } 420 | 421 | primitive.drawLine(fromX, fromY, toX, toY, constraintRender.strokeStyle, constraintRender.lineWidth); 422 | }; 423 | 424 | window.LayaRender = LayaRender; 425 | })(); -------------------------------------------------------------------------------- /main/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 Component3D=laya.d3.component.Component3D,ComponentNode=laya.d3.core.ComponentNode,MeshTerrainSprite3D=laya.d3.core.MeshTerrainSprite3D; 6 | var Sprite3D=laya.d3.core.Sprite3D; 7 | /** 8 | *PathFinding 类用于创建寻路。 9 | */ 10 | //class laya.d3.component.PathFind extends laya.d3.component.Component3D 11 | var PathFind=(function(_super){ 12 | function PathFind(){ 13 | /**@private */ 14 | this._meshTerrainSprite3D=null; 15 | /**@private */ 16 | this._finder=null; 17 | /**@private */ 18 | this._setting=null; 19 | /**寻路网格。*/ 20 | this.grid=null; 21 | PathFind.__super.call(this); 22 | } 23 | 24 | __class(PathFind,'laya.d3.component.PathFind',_super); 25 | var __proto=PathFind.prototype; 26 | /** 27 | *@private 28 | *初始化载入蒙皮动画组件。 29 | *@param owner 所属精灵对象。 30 | */ 31 | __proto._load=function(owner){ 32 | if (! (owner instanceof laya.d3.core.MeshTerrainSprite3D )) 33 | throw new Error("PathFinding: The owner must MeshTerrainSprite3D!"); 34 | _super.prototype._load.call(this,owner); 35 | this._meshTerrainSprite3D=owner; 36 | } 37 | 38 | /** 39 | *寻找路径。 40 | *@param startX 开始X。 41 | *@param startZ 开始Z。 42 | *@param endX 结束X。 43 | *@param endZ 结束Z。 44 | *@return 路径。 45 | */ 46 | __proto.findPath=function(startX,startZ,endX,endZ){ 47 | var minX=this._meshTerrainSprite3D.minX; 48 | var minZ=this._meshTerrainSprite3D.minZ; 49 | var cellX=this._meshTerrainSprite3D.width / this.grid.width; 50 | var cellZ=this._meshTerrainSprite3D.depth / this.grid.height; 51 | var halfCellX=cellX / 2; 52 | var halfCellZ=cellZ / 2; 53 | var gridStartX=Math.floor((startX-minX)/ cellX); 54 | var gridStartZ=Math.floor((startZ-minZ)/ cellZ); 55 | var gridEndX=Math.floor((endX-minX)/ cellX); 56 | var gridEndZ=Math.floor((endZ-minZ)/ cellZ); 57 | var boundWidth=this.grid.width-1; 58 | var boundHeight=this.grid.height-1; 59 | (gridStartX > boundWidth)&& (gridStartX=boundWidth); 60 | (gridStartZ > boundHeight)&& (gridStartZ=boundHeight); 61 | (gridStartX < 0)&& (gridStartX=0); 62 | (gridStartZ < 0)&& (gridStartZ=0); 63 | (gridEndX > boundWidth)&& (gridEndX=boundWidth); 64 | (gridEndZ > boundHeight)&& (gridEndZ=boundHeight); 65 | (gridEndX < 0)&& (gridEndX=0); 66 | (gridEndZ < 0)&& (gridEndZ=0); 67 | var path=this._finder.findPath(gridStartX,gridStartZ,gridEndX,gridEndZ,this.grid); 68 | this.grid.reset(); 69 | for (var i=1;i < path.length-1;i++){ 70 | var gridPos=path[i]; 71 | gridPos[0]=gridPos[0] *cellX+halfCellX+minX; 72 | gridPos[1]=gridPos[1] *cellZ+halfCellZ+minZ; 73 | } 74 | if (path.length==1){ 75 | path[0][0]=endX; 76 | path[0][1]=endX; 77 | }else if (path.length > 1){ 78 | path[0][0]=startX; 79 | path[0][1]=startZ; 80 | path[path.length-1][0]=endX; 81 | path[path.length-1][1]=endZ; 82 | } 83 | return path; 84 | } 85 | 86 | /** 87 | *设置寻路设置。 88 | *@param value 寻路设置。 89 | */ 90 | /** 91 | *获取寻路设置。 92 | *@return 寻路设置。 93 | */ 94 | __getset(0,__proto,'setting',function(){ 95 | return this._setting; 96 | },function(value){ 97 | (value)&& (this._finder=new PathFinding.finders.AStarFinder(value)); 98 | this._setting=value; 99 | }); 100 | 101 | return PathFind; 102 | })(Component3D) 103 | 104 | 105 | 106 | })(window,document,Laya); 107 | 108 | if (typeof define === 'function' && define.amd){ 109 | define('laya.core', ['require', "exports"], function(require, exports) { 110 | 'use strict'; 111 | Object.defineProperty(exports, '__esModule', { value: true }); 112 | for (var i in Laya) { 113 | var o = Laya[i]; 114 | o && o.__isclass && (exports[i] = o); 115 | } 116 | }); 117 | } -------------------------------------------------------------------------------- /main/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 Browser=laya.utils.Browser,Color=laya.utils.Color,ColorFilterAction=laya.filters.ColorFilterAction; 6 | var ColorFilterActionGL=laya.filters.webgl.ColorFilterActionGL,Filter=laya.filters.Filter,FilterActionGL=laya.filters.webgl.FilterActionGL; 7 | var Matrix=laya.maths.Matrix,Rectangle=laya.maths.Rectangle,Render=laya.renders.Render,RenderContext=laya.renders.RenderContext; 8 | var RenderTarget2D=laya.webgl.resource.RenderTarget2D,RunDriver=laya.utils.RunDriver,ShaderDefines2D=laya.webgl.shader.d2.ShaderDefines2D; 9 | var Sprite=laya.display.Sprite,Texture=laya.resource.Texture,Value2D=laya.webgl.shader.d2.value.Value2D; 10 | /** 11 | *默认的FILTER,什么都不做 12 | *@private 13 | */ 14 | //class laya.filters.FilterAction 15 | var FilterAction=(function(){ 16 | function FilterAction(){ 17 | this.data=null; 18 | } 19 | 20 | __class(FilterAction,'laya.filters.FilterAction'); 21 | var __proto=FilterAction.prototype; 22 | Laya.imps(__proto,{"laya.filters.IFilterAction":true}) 23 | __proto.apply=function(data){ 24 | return null; 25 | } 26 | 27 | return FilterAction; 28 | })() 29 | 30 | 31 | /** 32 | *@private 33 | */ 34 | //class laya.filters.WebGLFilter 35 | var WebGLFilter=(function(){ 36 | function WebGLFilter(){} 37 | __class(WebGLFilter,'laya.filters.WebGLFilter'); 38 | WebGLFilter.enable=function(){ 39 | if (WebGLFilter.isInit)return; 40 | WebGLFilter.isInit=true; 41 | if (!Render.isWebGL)return; 42 | RunDriver.createFilterAction=function (type){ 43 | var action; 44 | switch (type){ 45 | case /*laya.filters.Filter.COLOR*/0x20: 46 | action=new ColorFilterActionGL(); 47 | break ; 48 | case /*laya.filters.Filter.BLUR*/0x10: 49 | action=new BlurFilterActionGL(); 50 | break ; 51 | case /*laya.filters.Filter.GLOW*/0x08: 52 | action=new GlowFilterActionGL(); 53 | break ; 54 | } 55 | return action; 56 | } 57 | } 58 | 59 | WebGLFilter.isInit=false; 60 | WebGLFilter.__init$=function(){ 61 | BlurFilterActionGL; 62 | ColorFilterActionGL; 63 | GlowFilterActionGL; 64 | Render; 65 | RunDriver;{ 66 | RunDriver.createFilterAction=function (type){ 67 | var action; 68 | switch (type){ 69 | case /*laya.filters.Filter.BLUR*/0x10: 70 | action=new FilterAction(); 71 | break ; 72 | case /*laya.filters.Filter.GLOW*/0x08: 73 | action=new FilterAction(); 74 | break ; 75 | case /*laya.filters.Filter.COLOR*/0x20: 76 | action=new ColorFilterAction(); 77 | break ; 78 | } 79 | return action; 80 | } 81 | } 82 | } 83 | 84 | return WebGLFilter; 85 | })() 86 | 87 | 88 | /** 89 | *模糊滤镜 90 | */ 91 | //class laya.filters.BlurFilter extends laya.filters.Filter 92 | var BlurFilter=(function(_super){ 93 | function BlurFilter(strength){ 94 | /**模糊滤镜的强度(值越大,越不清晰 */ 95 | this.strength=NaN; 96 | this.strength_sig2_2sig2_gauss1=[]; 97 | BlurFilter.__super.call(this); 98 | (strength===void 0)&& (strength=4); 99 | if (Render.isWebGL)WebGLFilter.enable(); 100 | this.strength=strength; 101 | this._action=RunDriver.createFilterAction(0x10); 102 | this._action.data=this; 103 | } 104 | 105 | __class(BlurFilter,'laya.filters.BlurFilter',_super); 106 | var __proto=BlurFilter.prototype; 107 | /** 108 | *@private 通知微端 109 | */ 110 | __proto.callNative=function(sp){ 111 | sp.conchModel &&sp.conchModel.blurFilter&&sp.conchModel.blurFilter(this.strength); 112 | } 113 | 114 | /** 115 | *@private 116 | *当前滤镜对应的操作器 117 | */ 118 | __getset(0,__proto,'action',function(){ 119 | return this._action; 120 | }); 121 | 122 | /** 123 | *@private 124 | *当前滤镜的类型 125 | */ 126 | __getset(0,__proto,'type',function(){ 127 | return 0x10; 128 | }); 129 | 130 | return BlurFilter; 131 | })(Filter) 132 | 133 | 134 | /** 135 | *发光滤镜(也可以当成阴影滤使用) 136 | */ 137 | //class laya.filters.GlowFilter extends laya.filters.Filter 138 | var GlowFilter=(function(_super){ 139 | function GlowFilter(color,blur,offX,offY){ 140 | /**滤镜的颜色*/ 141 | this._color=null; 142 | GlowFilter.__super.call(this); 143 | this._elements=new Float32Array(9); 144 | (blur===void 0)&& (blur=4); 145 | (offX===void 0)&& (offX=6); 146 | (offY===void 0)&& (offY=6); 147 | if (Render.isWebGL){ 148 | WebGLFilter.enable(); 149 | } 150 | this._color=new Color(color); 151 | this.blur=Math.min(blur,20); 152 | this.offX=offX; 153 | this.offY=offY; 154 | this._action=RunDriver.createFilterAction(0x08); 155 | this._action.data=this; 156 | } 157 | 158 | __class(GlowFilter,'laya.filters.GlowFilter',_super); 159 | var __proto=GlowFilter.prototype; 160 | /**@private */ 161 | __proto.getColor=function(){ 162 | return this._color._color; 163 | } 164 | 165 | /** 166 | *@private 通知微端 167 | */ 168 | __proto.callNative=function(sp){ 169 | sp.conchModel &&sp.conchModel.glowFilter&&sp.conchModel.glowFilter(this._color.strColor,this._elements[4],this._elements[5],this._elements[6]); 170 | } 171 | 172 | /** 173 | *@private 174 | *滤镜类型 175 | */ 176 | __getset(0,__proto,'type',function(){ 177 | return 0x08; 178 | }); 179 | 180 | /**@private */ 181 | __getset(0,__proto,'action',function(){ 182 | return this._action; 183 | }); 184 | 185 | /**@private */ 186 | /**@private */ 187 | __getset(0,__proto,'offY',function(){ 188 | return this._elements[6]; 189 | },function(value){ 190 | this._elements[6]=value; 191 | }); 192 | 193 | /**@private */ 194 | /**@private */ 195 | __getset(0,__proto,'offX',function(){ 196 | return this._elements[5]; 197 | },function(value){ 198 | this._elements[5]=value; 199 | }); 200 | 201 | /**@private */ 202 | /**@private */ 203 | __getset(0,__proto,'blur',function(){ 204 | return this._elements[4]; 205 | },function(value){ 206 | this._elements[4]=value; 207 | }); 208 | 209 | return GlowFilter; 210 | })(Filter) 211 | 212 | 213 | /** 214 | *@private 215 | */ 216 | //class laya.filters.webgl.BlurFilterActionGL extends laya.filters.webgl.FilterActionGL 217 | var BlurFilterActionGL=(function(_super){ 218 | function BlurFilterActionGL(){ 219 | this.data=null; 220 | BlurFilterActionGL.__super.call(this); 221 | } 222 | 223 | __class(BlurFilterActionGL,'laya.filters.webgl.BlurFilterActionGL',_super); 224 | var __proto=BlurFilterActionGL.prototype; 225 | __proto.setValueMix=function(shader){ 226 | shader.defines.add(this.data.type); 227 | var o=shader; 228 | } 229 | 230 | __proto.apply3d=function(scope,sprite,context,x,y){ 231 | var b=scope.getValue("bounds"); 232 | var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 233 | shaderValue.setFilters([this.data]); 234 | var tMatrix=Matrix.EMPTY; 235 | tMatrix.identity(); 236 | context.ctx.drawTarget(scope,0,0,b.width,b.height,Matrix.EMPTY,"src",shaderValue); 237 | shaderValue.setFilters(null); 238 | } 239 | 240 | __proto.setValue=function(shader){ 241 | shader.strength=this.data.strength; 242 | var sigma=this.data.strength/3.0; 243 | var sigma2=sigma*sigma; 244 | this.data.strength_sig2_2sig2_gauss1[0]=this.data.strength; 245 | this.data.strength_sig2_2sig2_gauss1[1]=sigma2; 246 | this.data.strength_sig2_2sig2_gauss1[2]=2.0*sigma2; 247 | this.data.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2); 248 | shader.strength_sig2_2sig2_gauss1=this.data.strength_sig2_2sig2_gauss1; 249 | } 250 | 251 | __getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.BLUR*/0x10;}); 252 | return BlurFilterActionGL; 253 | })(FilterActionGL) 254 | 255 | 256 | /** 257 | *@private 258 | */ 259 | //class laya.filters.webgl.GlowFilterActionGL extends laya.filters.webgl.FilterActionGL 260 | var GlowFilterActionGL=(function(_super){ 261 | function GlowFilterActionGL(){ 262 | this.data=null; 263 | this._initKey=false; 264 | this._textureWidth=0; 265 | this._textureHeight=0; 266 | GlowFilterActionGL.__super.call(this); 267 | } 268 | 269 | __class(GlowFilterActionGL,'laya.filters.webgl.GlowFilterActionGL',_super); 270 | var __proto=GlowFilterActionGL.prototype; 271 | Laya.imps(__proto,{"laya.filters.IFilterActionGL":true}) 272 | __proto.setValueMix=function(shader){} 273 | __proto.apply3d=function(scope,sprite,context,x,y){ 274 | var b=scope.getValue("bounds"); 275 | scope.addValue("color",this.data.getColor()); 276 | var w=b.width,h=b.height; 277 | this._textureWidth=w; 278 | this._textureHeight=h; 279 | var shaderValue; 280 | var mat=Matrix.TEMP; 281 | mat.identity(); 282 | shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 283 | shaderValue.setFilters([this.data]); 284 | context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue,null); 285 | shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 286 | context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue); 287 | return null; 288 | } 289 | 290 | __proto.setSpriteWH=function(sprite){ 291 | this._textureWidth=sprite.width; 292 | this._textureHeight=sprite.height; 293 | } 294 | 295 | __proto.setValue=function(shader){ 296 | shader.u_offsetX=this.data.offX; 297 | shader.u_offsetY=-this.data.offY; 298 | shader.u_strength=1.0; 299 | shader.u_blurX=this.data.blur; 300 | shader.u_blurY=this.data.blur; 301 | shader.u_textW=this._textureWidth; 302 | shader.u_textH=this._textureHeight; 303 | shader.u_color=this.data.getColor(); 304 | } 305 | 306 | __getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.GLOW*/0x08;}); 307 | GlowFilterActionGL.tmpTarget=function(scope,sprite,context,x,y){ 308 | var b=scope.getValue("bounds"); 309 | var out=scope.getValue("out"); 310 | out.end(); 311 | var tmpTarget=RenderTarget2D.create(b.width,b.height); 312 | tmpTarget.start(); 313 | var color=scope.getValue("color"); 314 | if (color){ 315 | tmpTarget.clear(color[0],color[1],color[2],0); 316 | } 317 | scope.addValue("tmpTarget",tmpTarget); 318 | } 319 | 320 | GlowFilterActionGL.startOut=function(scope,sprite,context,x,y){ 321 | var tmpTarget=scope.getValue("tmpTarget"); 322 | tmpTarget.end(); 323 | var out=scope.getValue("out"); 324 | out.start(); 325 | var color=scope.getValue("color"); 326 | if (color){ 327 | out.clear(color[0],color[1],color[2],0); 328 | } 329 | } 330 | 331 | GlowFilterActionGL.recycleTarget=function(scope,sprite,context,x,y){ 332 | var src=scope.getValue("src"); 333 | var tmpTarget=scope.getValue("tmpTarget"); 334 | tmpTarget.recycle(); 335 | } 336 | 337 | return GlowFilterActionGL; 338 | })(FilterActionGL) 339 | 340 | 341 | Laya.__init([WebGLFilter]); 342 | })(window,document,Laya); 343 | 344 | if (typeof define === 'function' && define.amd){ 345 | define('laya.core', ['require', "exports"], function(require, exports) { 346 | 'use strict'; 347 | Object.defineProperty(exports, '__esModule', { value: true }); 348 | for (var i in Laya) { 349 | var o = Laya[i]; 350 | o && o.__isclass && (exports[i] = o); 351 | } 352 | }); 353 | } -------------------------------------------------------------------------------- /main/bin/libs/matter-RenderLaya.js: -------------------------------------------------------------------------------- 1 | var Browser = laya.utils.Browser; 2 | 3 | var Composite = Matter.Composite; 4 | var Events = Matter.Events; 5 | var Bounds = Matter.Bounds; 6 | var Common = Matter.Common; 7 | var Vertices = Matter.Vertices; 8 | var Vector = Matter.Vector; 9 | var Sleeping = Matter.Sleeping; 10 | var Axes = Matter.Axes; 11 | var Body = Matter.Body; 12 | var SAT = Matter.SAT; 13 | var Contact = Matter.Contact; 14 | var Pair = Matter.Pair; 15 | var Detector = Matter.Detector; 16 | var Grid = Matter.Grid; 17 | 18 | var LayaRender = {}; 19 | 20 | (function() 21 | { 22 | var graphics, 23 | spriteCon, 24 | graphicsCon; 25 | 26 | LayaRender.create = function(options) 27 | { 28 | var defaults = { 29 | controller: LayaRender, 30 | element: null, 31 | canvas: null, 32 | mouse: null, 33 | options: 34 | { 35 | width: 800, 36 | height: 600, 37 | pixelRatio: 1, 38 | background: '#fafafa', 39 | wireframeBackground: '#222', 40 | hasBounds: !!options.bounds, 41 | enabled: true, 42 | wireframes: true, 43 | showSleeping: true, 44 | showDebug: false, 45 | showBroadphase: false, 46 | showBounds: false, 47 | showVelocity: false, 48 | showCollisions: false, 49 | showSeparations: false, 50 | showAxes: false, 51 | showPositions: false, 52 | showAngleIndicator: false, 53 | showIds: false, 54 | showShadows: false, 55 | showVertexNumbers: false, 56 | showConvexHulls: false, 57 | showInternalEdges: false, 58 | showMousePosition: false 59 | } 60 | }; 61 | 62 | var render = Common.extend(defaults, options); 63 | 64 | render.canvas = laya.renders.Render.canvas; 65 | render.context = laya.renders.Render.context.ctx; 66 | 67 | render.textures = {}; 68 | 69 | render.bounds = render.bounds || 70 | { 71 | min: 72 | { 73 | x: 0, 74 | y: 0 75 | }, 76 | max: 77 | { 78 | x: Laya.stage.width, 79 | y: Laya.stage.height 80 | } 81 | }; 82 | 83 | createContainer(render); 84 | setBackground(render); 85 | setPixelRatio(); 86 | 87 | return render; 88 | }; 89 | 90 | function createContainer(render) 91 | { 92 | var con = render.container; 93 | 94 | spriteCon = new Laya.Sprite(); 95 | graphicsCon = new Laya.Sprite(); 96 | 97 | render.spriteContainer = spriteCon; 98 | render.graphicsContainer = graphicsCon; 99 | 100 | con.addChild(spriteCon); 101 | con.addChild(graphicsCon); 102 | 103 | graphics = graphicsCon.graphics; 104 | } 105 | 106 | // 设置背景 107 | function setBackground(render) 108 | { 109 | var bg = render.options.background; 110 | // 纯色背景 111 | if (bg.length == 7 && bg[0] == '#') 112 | { 113 | spriteCon.graphics.drawRect( 114 | 0, 0, 115 | render.options.width, render.options.height, 116 | bg); 117 | } 118 | // 图片背景 119 | else 120 | { 121 | spriteCon.loadImage(bg); 122 | } 123 | } 124 | 125 | function setPixelRatio() 126 | { 127 | var pixelRatio; 128 | pixelRatio = 1; 129 | Laya.Render.canvas.setAttribute('data-pixel-ratio', pixelRatio); 130 | } 131 | 132 | /** 133 | * Renders the given `engine`'s `Matter.World` object. 134 | * This is the entry point for all rendering and should be called every time the scene changes. 135 | * @method world 136 | * @param {engine} engine 137 | */ 138 | LayaRender.world = function(engine) 139 | { 140 | var render = engine.render, 141 | world = engine.world, 142 | options = render.options, 143 | allConstraints = Composite.allConstraints(world), 144 | bodies = Composite.allBodies(world), 145 | constraints = [], 146 | i; 147 | 148 | // handle bounds 149 | if (options.hasBounds) 150 | { 151 | var boundsWidth = render.bounds.max.x - render.bounds.min.x, 152 | boundsHeight = render.bounds.max.y - render.bounds.min.y, 153 | boundsScaleX = boundsWidth / options.width, 154 | boundsScaleY = boundsHeight / options.height; 155 | 156 | // filter out bodies that are not in view 157 | for (i = 0; i < bodies.length; i++) 158 | { 159 | var body = bodies[i]; 160 | body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds); 161 | } 162 | 163 | // filter out constraints that are not in view 164 | for (i = 0; i < allConstraints.length; i++) 165 | { 166 | var constraint = allConstraints[i], 167 | bodyA = constraint.bodyA, 168 | bodyB = constraint.bodyB, 169 | pointAWorld = constraint.pointA, 170 | pointBWorld = constraint.pointB; 171 | 172 | if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA); 173 | if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB); 174 | 175 | if (!pointAWorld || !pointBWorld) 176 | continue; 177 | 178 | if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld)) 179 | constraints.push(constraint); 180 | } 181 | 182 | // transform the view 183 | // context.scale(1 / boundsScaleX, 1 / boundsScaleY); 184 | // context.translate(-render.bounds.min.x, -render.bounds.min.y); 185 | } 186 | else 187 | { 188 | constraints = allConstraints; 189 | } 190 | 191 | graphics.clear(); 192 | for (i = 0; i < bodies.length; i++) 193 | LayaRender.body(engine, bodies[i]); 194 | 195 | for (i = 0; i < constraints.length; i++) 196 | LayaRender.constraint(engine, constraints[i]); 197 | }; 198 | LayaRender.body = function(engine, body) 199 | { 200 | var render = engine.render, 201 | bodyRender = body.render; 202 | 203 | if (!bodyRender.visible) 204 | { 205 | return; 206 | } 207 | 208 | var spInfo = bodyRender.sprite; 209 | var sp = body.sprite; 210 | if (bodyRender.sprite && bodyRender.sprite.texture) 211 | { 212 | // initialize body sprite if not existing 213 | if (!sp) 214 | { 215 | sp = body.sprite = createBodySprite(spInfo.xOffset, spInfo.yOffset); 216 | sp.loadImage(spInfo.texture); 217 | } 218 | 219 | sp.scale(spInfo.xScale, spInfo.yScale); 220 | sp.pos(body.position.x, body.position.y); 221 | sp.rotation = body.angle * 180 / Math.PI; 222 | } 223 | else 224 | { 225 | var options = render.options; 226 | // handle compound parts 227 | for (k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++) 228 | { 229 | part = body.parts[k]; 230 | 231 | if (!part.render.visible) 232 | continue; 233 | 234 | var fillStyle = options.wireframes ? null : part.render.fillStyle; 235 | var lineWidth = part.render.lineWidth; 236 | var strokeStyle = part.render.strokeStyle; 237 | // part polygon 238 | if (part.circleRadius) 239 | { 240 | graphics.drawCircle(part.position.x, part.position.y, part.circleRadius, fillStyle, strokeStyle, lineWidth); 241 | } 242 | else 243 | { 244 | var path = []; 245 | path.push(part.vertices[0].x, part.vertices[0].y); 246 | 247 | for (var j = 1; j < part.vertices.length; j++) 248 | { 249 | if (!part.vertices[j - 1].isInternal || showInternalEdges) 250 | { 251 | path.push(part.vertices[j].x, part.vertices[j].y); 252 | } 253 | else 254 | { 255 | path.push(part.vertices[j].x, part.vertices[j].y); 256 | } 257 | 258 | if (part.vertices[j].isInternal && !showInternalEdges) 259 | { 260 | path.push(part.vertices[(j + 1) % part.vertices.length].x, part.vertices[(j + 1) % part.vertices.length].y); 261 | } 262 | } 263 | 264 | graphics.drawPoly(0, 0, path, fillStyle, strokeStyle, lineWidth); 265 | } 266 | } 267 | } 268 | }; 269 | 270 | LayaRender.constraint = function(engine, constraint) 271 | { 272 | var sx, sy, ex, ey; 273 | if (!constraint.render.visible || !constraint.pointA || !constraint.pointB) 274 | { 275 | return; 276 | } 277 | 278 | var bodyA = constraint.bodyA, 279 | bodyB = constraint.bodyB; 280 | 281 | if (bodyA) 282 | { 283 | sx = bodyA.position.x + constraint.pointA.x; 284 | sy = bodyA.position.y + constraint.pointA.y; 285 | } 286 | else 287 | { 288 | sx = constraint.pointA.x; 289 | sy = constraint.pointA.y; 290 | } 291 | 292 | if (bodyB) 293 | { 294 | ex = bodyB.position.x + constraint.pointB.x; 295 | ey = bodyB.position.y + constraint.pointB.y; 296 | } 297 | else 298 | { 299 | ex = constraint.pointB.x; 300 | ey = constraint.pointB.y; 301 | } 302 | 303 | graphics.drawLine( 304 | sx, sy, ex, ey, 305 | constraint.render.strokeStyle, 306 | constraint.render.lineWidth); 307 | }; 308 | 309 | function createBodySprite(xOffset, yOffset) 310 | { 311 | var sp = new Laya.Sprite(); 312 | 313 | sp.pivot(xOffset, yOffset); 314 | sp.pos(-9999, -9999); 315 | spriteCon.addChild(sp); 316 | 317 | return sp; 318 | } 319 | })(); -------------------------------------------------------------------------------- /main/bin/libs/min/laya.d3Plugin.min.js: -------------------------------------------------------------------------------- 1 | !function(t,i,e){e.un,e.uns,e.static;var n=e.class,r=e.getset,a=(e.__newvec,laya.d3.component.Component3D);laya.d3.core.ComponentNode,laya.d3.core.MeshTerrainSprite3D,laya.d3.core.Sprite3D,function(i){function t(){this._meshTerrainSprite3D=null,this._finder=null,this._setting=null,this.grid=null,t.__super.call(this)}n(t,"laya.d3.component.PathFind",i);var e=t.prototype;e._load=function(t){if(!(t instanceof laya.d3.core.MeshTerrainSprite3D))throw new Error("PathFinding: The owner must MeshTerrainSprite3D!");i.prototype._load.call(this,t),this._meshTerrainSprite3D=t},e.findPath=function(t,i,e,n){var r=this._meshTerrainSprite3D.minX,a=this._meshTerrainSprite3D.minZ,h=this._meshTerrainSprite3D.width/this.grid.width,s=this._meshTerrainSprite3D.depth/this.grid.height,o=h/2,d=s/2,l=Math.floor((t-r)/h),f=Math.floor((i-a)/s),c=Math.floor((e-r)/h),u=Math.floor((n-a)/s),p=this.grid.width-1,_=this.grid.height-1;pthis.shakeInterval&&(this.event("change"),this.lastMillSecond=l.now()));this.lastX=t.x,this.lastY=t.y,this.lastZ=t.z},n.isShaked=function(e,t,n){return e>this.throushold&&t>this.throushold||e>this.throushold&&n>this.throushold||t>this.throushold&&n>this.throushold},c(1,t,"instance",function(){return t._instance=t._instance||new t},laya.events.EventDispatcher._$SET_instance),t._instance=null}(),function(n){function i(e,t){this.htmlVideo=null,this.videoElement=null,this.internalTexture=null,void 0===e&&(e=320),void 0===t&&(t=240),i.__super.call(this),d.isWebGL?this.htmlVideo=new x:this.htmlVideo=new w,this.videoElement=this.htmlVideo.getVideo(),(this.videoElement.layaTarget=this).internalTexture=new u(this.htmlVideo),this.videoElement.addEventListener("abort",i.onAbort),this.videoElement.addEventListener("canplay",i.onCanplay),this.videoElement.addEventListener("canplaythrough",i.onCanplaythrough),this.videoElement.addEventListener("durationchange",i.onDurationchange),this.videoElement.addEventListener("emptied",i.onEmptied),this.videoElement.addEventListener("error",i.onError),this.videoElement.addEventListener("loadeddata",i.onLoadeddata),this.videoElement.addEventListener("loadedmetadata",i.onLoadedmetadata),this.videoElement.addEventListener("loadstart",i.onLoadstart),this.videoElement.addEventListener("pause",i.onPause),this.videoElement.addEventListener("play",i.onPlay),this.videoElement.addEventListener("playing",i.onPlaying),this.videoElement.addEventListener("progress",i.onProgress),this.videoElement.addEventListener("ratechange",i.onRatechange),this.videoElement.addEventListener("seeked",i.onSeeked),this.videoElement.addEventListener("seeking",i.onSeeking),this.videoElement.addEventListener("stalled",i.onStalled),this.videoElement.addEventListener("suspend",i.onSuspend),this.videoElement.addEventListener("timeupdate",i.onTimeupdate),this.videoElement.addEventListener("volumechange",i.onVolumechange),this.videoElement.addEventListener("waiting",i.onWaiting),this.videoElement.addEventListener("ended",this.onPlayComplete.bind(this)),this.size(e,t),l.onMobile&&(this.onDocumentClick=this.onDocumentClick.bind(this),l.document.addEventListener("touchend",this.onDocumentClick))}s(i,"laya.device.media.Video",n);var e=i.prototype;return e.onPlayComplete=function(e){r.timer.clear(this,this.renderCanvas),this.event("ended")},e.load=function(e){0==e.indexOf("blob:")?this.videoElement.src=e:this.htmlVideo.setSource(e,laya.device.media.Video.MP4)},e.play=function(){this.videoElement.play(),r.timer.frameLoop(1,this,this.renderCanvas)},e.pause=function(){this.videoElement.pause(),r.timer.clear(this,this.renderCanvas)},e.reload=function(){this.videoElement.load()},e.canPlayType=function(e){var t;switch(e){case laya.device.media.Video.MP4:t="video/mp4";break;case laya.device.media.Video.OGG:t="video/ogg";break;case laya.device.media.Video.WEBM:t="video/webm"}return this.videoElement.canPlayType(t)},e.renderCanvas=function(){0!==this.readyState&&(d.isWebGL&&this.htmlVideo.updateTexture(),this.graphics.clear(),this.graphics.drawTexture(this.internalTexture,0,0,this.width,this.height))},e.onDocumentClick=function(){this.videoElement.play(),this.videoElement.pause(),l.document.removeEventListener("touchend",this.onDocumentClick)},e.size=function(e,t){return n.prototype.size.call(this,e,t),this.videoElement.width=e/l.pixelRatio,this.paused&&this.renderCanvas(),this},e.destroy=function(e){void 0===e&&(e=!0),n.prototype.destroy.call(this,e),this.videoElement.removeEventListener("abort",i.onAbort),this.videoElement.removeEventListener("canplay",i.onCanplay),this.videoElement.removeEventListener("canplaythrough",i.onCanplaythrough),this.videoElement.removeEventListener("durationchange",i.onDurationchange),this.videoElement.removeEventListener("emptied",i.onEmptied),this.videoElement.removeEventListener("error",i.onError),this.videoElement.removeEventListener("loadeddata",i.onLoadeddata),this.videoElement.removeEventListener("loadedmetadata",i.onLoadedmetadata),this.videoElement.removeEventListener("loadstart",i.onLoadstart),this.videoElement.removeEventListener("pause",i.onPause),this.videoElement.removeEventListener("play",i.onPlay),this.videoElement.removeEventListener("playing",i.onPlaying),this.videoElement.removeEventListener("progress",i.onProgress),this.videoElement.removeEventListener("ratechange",i.onRatechange),this.videoElement.removeEventListener("seeked",i.onSeeked),this.videoElement.removeEventListener("seeking",i.onSeeking),this.videoElement.removeEventListener("stalled",i.onStalled),this.videoElement.removeEventListener("suspend",i.onSuspend),this.videoElement.removeEventListener("timeupdate",i.onTimeupdate),this.videoElement.removeEventListener("volumechange",i.onVolumechange),this.videoElement.removeEventListener("waiting",i.onWaiting),this.videoElement.removeEventListener("ended",this.onPlayComplete),this.pause(),this.videoElement=null},e.syncVideoPosition=function(){var e,t=r.stage;e=v.getGlobalPosAndScale(this);var n=t._canvasTransform.a,i=t._canvasTransform.d,a=e.x*t.clientScaleX*n+t.offset.x,o=e.y*t.clientScaleY*i+t.offset.y;this.videoElement.style.left=a+"px",this.videoElement.style.top=o+"px",this.videoElement.width=this.width/l.pixelRatio,this.videoElement.height=this.height/l.pixelRatio},c(0,e,"buffered",function(){return this.videoElement.buffered}),c(0,e,"videoWidth",function(){return this.videoElement.videoWidth}),c(0,e,"currentSrc",function(){return this.videoElement.currentSrc}),c(0,e,"currentTime",function(){return this.videoElement.currentTime},function(e){this.videoElement.currentTime=e,this.renderCanvas()}),c(0,e,"ended",function(){return this.videoElement.ended}),c(0,e,"volume",function(){return this.videoElement.volume},function(e){this.videoElement.volume=e}),c(0,e,"videoHeight",function(){return this.videoElement.videoHeight}),c(0,e,"readyState",function(){return this.videoElement.readyState}),c(0,e,"duration",function(){return this.videoElement.duration}),c(0,e,"error",function(){return this.videoElement.error}),c(0,e,"loop",function(){return this.videoElement.loop},function(e){this.videoElement.loop=e}),c(0,e,"playbackRate",function(){return this.videoElement.playbackRate},function(e){this.videoElement.playbackRate=e}),c(0,e,"muted",function(){return this.videoElement.muted},function(e){this.videoElement.muted=e}),c(0,e,"paused",function(){return this.videoElement.paused}),c(0,e,"preload",function(){return this.videoElement.preload},function(e){this.videoElement.preload=e}),c(0,e,"seekable",function(){return this.videoElement.seekable}),c(0,e,"seeking",function(){return this.videoElement.seeking}),c(0,e,"height",n.prototype._$get_height,function(e){r.superSet(h,this,"height",e),this.paused&&this.renderCanvas()}),c(0,e,"width",n.prototype._$get_width,function(e){this.videoElement.width=this.width/l.pixelRatio,r.superSet(h,this,"width",e),this.paused&&this.renderCanvas()}),i.onAbort=function(e){e.target.layaTarget.event("abort")},i.onCanplay=function(e){e.target.layaTarget.event("canplay")},i.onCanplaythrough=function(e){e.target.layaTarget.event("canplaythrough")},i.onDurationchange=function(e){e.target.layaTarget.event("durationchange")},i.onEmptied=function(e){e.target.layaTarget.event("emptied")},i.onError=function(e){e.target.layaTarget.event("error")},i.onLoadeddata=function(e){e.target.layaTarget.event("loadeddata")},i.onLoadedmetadata=function(e){e.target.layaTarget.event("loadedmetadata")},i.onLoadstart=function(e){e.target.layaTarget.event("loadstart")},i.onPause=function(e){e.target.layaTarget.event("pause")},i.onPlay=function(e){e.target.layaTarget.event("play")},i.onPlaying=function(e){e.target.layaTarget.event("playing")},i.onProgress=function(e){e.target.layaTarget.event("progress")},i.onRatechange=function(e){e.target.layaTarget.event("ratechange")},i.onSeeked=function(e){e.target.layaTarget.event("seeked")},i.onSeeking=function(e){e.target.layaTarget.event("seeking")},i.onStalled=function(e){e.target.layaTarget.event("stalled")},i.onSuspend=function(e){e.target.layaTarget.event("suspend")},i.onTimeupdate=function(e){e.target.layaTarget.event("timeupdate")},i.onVolumechange=function(e){e.target.layaTarget.event("volumechange")},i.onWaiting=function(e){e.target.layaTarget.event("waiting")},i.MP4=1,i.OGG=2,i.CAMERA=4,i.WEBM=8,i.SUPPORT_PROBABLY="probably",i.SUPPORT_MAYBY="maybe",i.SUPPORT_NO="",i}(h)),w=function(e){function t(){this.video=null,t.__super.call(this),this._w=1,this._h=1,this.createDomElement()}s(t,"laya.device.media.HtmlVideo",i);var n=t.prototype;return n.createDomElement=function(){var e=this;this._source=this.video=l.createElement("video");var t=this.video.style;t.position="absolute",t.top="0px",t.left="0px",this.video.addEventListener("loadedmetadata",function(){this._w=e.video.videoWidth,this._h=e.video.videoHeight}.bind(this))},n.setSource=function(e,t){for(;this.video.childElementCount;)this.video.firstChild.remove();t&L.MP4&&this.appendSource(e,"video/mp4"),t&L.OGG&&this.appendSource(e+".ogg","video/ogg")},n.appendSource=function(e,t){var n=l.createElement("source");n.src=e,n.type=t,this.video.appendChild(n)},n.getVideo=function(){return this.video},t.create=function(){return new t},t}(),x=function(e){function t(){this.gl=null,this.preTarget=null,this.preTexture=null,t.__super.call(this),l.onIPhone||(this.gl=n.mainContext,this._source=this.gl.createTexture(),this.preTarget=m.curBindTexTarget,this.preTexture=m.curBindTexValue,m.bindTexture(this.gl,3553,this._source),this.gl.texParameteri(3553,10242,33071),this.gl.texParameteri(3553,10243,33071),this.gl.texParameteri(3553,10240,9729),this.gl.texParameteri(3553,10241,9729),this.preTarget&&this.preTexture&&m.bindTexture(this.gl,this.preTarget,this.preTexture))}return s(t,"laya.device.media.WebGLVideo",w),t.prototype.updateTexture=function(){l.onIPhone||(m.bindTexture(this.gl,3553,this._source),this.gl.texImage2D(3553,0,6407,6407,5121,this.video))},t}();r.__init([f])}(window,document,Laya),"function"==typeof define&&define.amd&&define("laya.core",["require","exports"],function(e,t){"use strict";for(var n in Object.defineProperty(t,"__esModule",{value:!0}),Laya){var i=Laya[n];i&&i.__isclass&&(t[n]=i)}}); -------------------------------------------------------------------------------- /main/bin/libs/min/laya.filter.min.js: -------------------------------------------------------------------------------- 1 | !function(t,e,a){a.un,a.uns,a.static;var n=a.class,s=a.getset,l=(a.__newvec,laya.utils.Browser,laya.utils.Color),i=laya.filters.ColorFilterAction,r=laya.filters.webgl.ColorFilterActionGL,o=laya.filters.Filter,u=laya.filters.webgl.FilterActionGL,c=laya.maths.Matrix,h=(laya.maths.Rectangle,laya.renders.Render),f=(laya.renders.RenderContext,laya.webgl.resource.RenderTarget2D),_=laya.utils.RunDriver,d=(laya.webgl.shader.d2.ShaderDefines2D,laya.display.Sprite,laya.resource.Texture,laya.webgl.shader.d2.value.Value2D),g=function(){function t(){this.data=null}n(t,"laya.filters.FilterAction");var e=t.prototype;return a.imps(e,{"laya.filters.IFilterAction":!0}),e.apply=function(t){return null},t}(),y=function(){function t(){}return n(t,"laya.filters.WebGLFilter"),t.enable=function(){t.isInit||(t.isInit=!0,h.isWebGL&&(_.createFilterAction=function(t){var e;switch(t){case 32:e=new r;break;case 16:e=new p;break;case 8:e=new w}return e}))},t.isInit=!1,t.__init$=function(){_.createFilterAction=function(t){var e;switch(t){case 16:case 8:e=new g;break;case 32:e=new i}return e}},t}(),p=(function(t){function e(t){this.strength=NaN,this.strength_sig2_2sig2_gauss1=[],e.__super.call(this),void 0===t&&(t=4),h.isWebGL&&y.enable(),this.strength=t,this._action=_.createFilterAction(16),this._action.data=this}n(e,"laya.filters.BlurFilter",o);var i=e.prototype;i.callNative=function(t){t.conchModel&&t.conchModel.blurFilter&&t.conchModel.blurFilter(this.strength)},s(0,i,"action",function(){return this._action}),s(0,i,"type",function(){return 16})}(),function(t){function r(t,e,i,a){this._color=null,r.__super.call(this),this._elements=new Float32Array(9),void 0===e&&(e=4),void 0===i&&(i=6),void 0===a&&(a=6),h.isWebGL&&y.enable(),this._color=new l(t),this.blur=Math.min(e,20),this.offX=i,this.offY=a,this._action=_.createFilterAction(8),this._action.data=this}n(r,"laya.filters.GlowFilter",o);var e=r.prototype;e.getColor=function(){return this._color._color},e.callNative=function(t){t.conchModel&&t.conchModel.glowFilter&&t.conchModel.glowFilter(this._color.strColor,this._elements[4],this._elements[5],this._elements[6])},s(0,e,"type",function(){return 8}),s(0,e,"action",function(){return this._action}),s(0,e,"offY",function(){return this._elements[6]},function(t){this._elements[6]=t}),s(0,e,"offX",function(){return this._elements[5]},function(t){this._elements[5]=t}),s(0,e,"blur",function(){return this._elements[4]},function(t){this._elements[4]=t})}(),function(t){function e(){this.data=null,e.__super.call(this)}n(e,"laya.filters.webgl.BlurFilterActionGL",u);var i=e.prototype;return i.setValueMix=function(t){t.defines.add(this.data.type)},i.apply3d=function(t,e,i,a,r){var n=t.getValue("bounds"),s=d.create(1,0);s.setFilters([this.data]),c.EMPTY.identity(),i.ctx.drawTarget(t,0,0,n.width,n.height,c.EMPTY,"src",s),s.setFilters(null)},i.setValue=function(t){t.strength=this.data.strength;var e=this.data.strength/3,i=e*e;this.data.strength_sig2_2sig2_gauss1[0]=this.data.strength,this.data.strength_sig2_2sig2_gauss1[1]=i,this.data.strength_sig2_2sig2_gauss1[2]=2*i,this.data.strength_sig2_2sig2_gauss1[3]=1/(2*Math.PI*i),t.strength_sig2_2sig2_gauss1=this.data.strength_sig2_2sig2_gauss1},s(0,i,"typeMix",function(){return 16}),e}()),w=function(t){function e(){this.data=null,this._initKey=!1,this._textureWidth=0,this._textureHeight=0,e.__super.call(this)}n(e,"laya.filters.webgl.GlowFilterActionGL",u);var i=e.prototype;return a.imps(i,{"laya.filters.IFilterActionGL":!0}),i.setValueMix=function(t){},i.apply3d=function(t,e,i,a,r){var n=t.getValue("bounds");t.addValue("color",this.data.getColor());var s,l=n.width,o=n.height;this._textureWidth=l,this._textureHeight=o;var u=c.TEMP;return u.identity(),(s=d.create(1,0)).setFilters([this.data]),i.ctx.drawTarget(t,0,0,this._textureWidth,this._textureHeight,u,"src",s,null),s=d.create(1,0),i.ctx.drawTarget(t,0,0,this._textureWidth,this._textureHeight,u,"src",s),null},i.setSpriteWH=function(t){this._textureWidth=t.width,this._textureHeight=t.height},i.setValue=function(t){t.u_offsetX=this.data.offX,t.u_offsetY=-this.data.offY,t.u_strength=1,t.u_blurX=this.data.blur,t.u_blurY=this.data.blur,t.u_textW=this._textureWidth,t.u_textH=this._textureHeight,t.u_color=this.data.getColor()},s(0,i,"typeMix",function(){return 8}),e.tmpTarget=function(t,e,i,a,r){var n=t.getValue("bounds");t.getValue("out").end();var s=f.create(n.width,n.height);s.start();var l=t.getValue("color");l&&s.clear(l[0],l[1],l[2],0),t.addValue("tmpTarget",s)},e.startOut=function(t,e,i,a,r){t.getValue("tmpTarget").end();var n=t.getValue("out");n.start();var s=t.getValue("color");s&&n.clear(s[0],s[1],s[2],0)},e.recycleTarget=function(t,e,i,a,r){t.getValue("src");t.getValue("tmpTarget").recycle()},e}();a.__init([y])}(window,document,Laya),"function"==typeof define&&define.amd&&define("laya.core",["require","exports"],function(t,e){"use strict";for(var i in Object.defineProperty(e,"__esModule",{value:!0}),Laya){var a=Laya[i];a&&a.__isclass&&(e[i]=a)}}); -------------------------------------------------------------------------------- /main/bin/libs/min/laya.html.min.js: -------------------------------------------------------------------------------- 1 | !function(t,e,n){n.un,n.uns;var h=n.static,l=n.class,s=n.getset,r=(n.__newvec,laya.utils.Browser,laya.display.css.CSSStyle),_=laya.utils.ClassUtils,u=(laya.events.Event,laya.utils.HTMLChar),a=laya.net.Loader,o=(laya.display.Node,laya.maths.Rectangle),d=laya.renders.Render,c=(laya.renders.RenderContext,laya.renders.RenderSprite,laya.display.Sprite),f=laya.utils.Stat,b=laya.display.Text,g=laya.resource.Texture,y=laya.net.URL,p=laya.utils.Utils,m=function(){function f(){}return l(f,"laya.html.utils.HTMLParse"),f.parse=function(t,e,i){e=(e=""+(e=e.replace(/
/g,"
"))+"
").replace(f.spacePattern,f.char255);var n=p.parseXMLFromString(e);f._parseXML(t,n.childNodes[0].childNodes,i)},f._parseXML=function(t,e,i,n){var h=0,l=0;if(e.join||e.item)for(h=0,l=e.length;ht.height&&(t.height=v),[g,v]},U._multiLineLayout2=function(t){var e=new Array;t._addChildsToLayout(e);var i,n,h,l,s,r=0,a=e.length,o=t._getCSSStyle(),d=o.letterSpacing,u=o.leading,c=o.lineHeight,f=o._widthAuto()||!o.wordWrap,_=f?999999:t.width,g=(t.height,0),y=o.italic?o.fontSize/3:0,p=2-o._getAlign(),m=o._getValign(),w=0!==m||0!==p||0!=c,x=0,v=0,S=0,L=0,T=new Array,C=T[0]=new P,E=!1,M=!1;C.h=0,o.italic&&(_-=o.fontSize/3);var H=0,I=!0;function A(){C.y=v,v+=C.h+u,0==C.h&&(v+=c),C.mWidth=H,H=0,C=new P,T.push(C),C.h=0,E=!(I=!(x=0))}for(r=0;rt.height&&(t.height=v),r=0,a=T.length;rt)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(); -------------------------------------------------------------------------------- /main/bin/unpack.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /main/bin/version.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /main/copy.bat: -------------------------------------------------------------------------------- 1 | cd /d %~dp0 2 | mkdir bin\rankRes 3 | copy bin\res\atlas\rank.atlas bin\rankRes\rank.atlas /Y 4 | copy bin\res\atlas\rank.png bin\rankRes\rank.png /Y -------------------------------------------------------------------------------- /main/laya/.laya: -------------------------------------------------------------------------------- 1 | 2 | img,temp,sound 3 | embed 4 | png,jpg 5 | bin/res/atlas 6 | bin 7 | src/ui 8 | 9 | 11 | 0 12 | bin/ui.json 13 | Box,List,Tab,RadioGroup,ViewStack,Panel,HBox,VBox,Tree,Sprite 14 | View,Dialog 15 | 16 | 1 17 | 18 | 80 19 | 20 | 21 | 23 | 2048 24 | 2048 25 | 512 26 | 512 27 | false 28 | false 29 | -------------------------------------------------------------------------------- /main/laya/assets/comp/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/bg.png -------------------------------------------------------------------------------- /main/laya/assets/comp/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/blank.png -------------------------------------------------------------------------------- /main/laya/assets/comp/btn_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/btn_close.png -------------------------------------------------------------------------------- /main/laya/assets/comp/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/button.png -------------------------------------------------------------------------------- /main/laya/assets/comp/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/checkbox.png -------------------------------------------------------------------------------- /main/laya/assets/comp/clip_num.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/clip_num.png -------------------------------------------------------------------------------- /main/laya/assets/comp/clip_selectBox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/clip_selectBox.png -------------------------------------------------------------------------------- /main/laya/assets/comp/clip_tree_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/clip_tree_arrow.png -------------------------------------------------------------------------------- /main/laya/assets/comp/clip_tree_folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/clip_tree_folder.png -------------------------------------------------------------------------------- /main/laya/assets/comp/combobox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/combobox.png -------------------------------------------------------------------------------- /main/laya/assets/comp/hscroll$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/hscroll$bar.png -------------------------------------------------------------------------------- /main/laya/assets/comp/hscroll$down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/hscroll$down.png -------------------------------------------------------------------------------- /main/laya/assets/comp/hscroll$up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/hscroll$up.png -------------------------------------------------------------------------------- /main/laya/assets/comp/hscroll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/hscroll.png -------------------------------------------------------------------------------- /main/laya/assets/comp/hslider$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/hslider$bar.png -------------------------------------------------------------------------------- /main/laya/assets/comp/hslider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/hslider.png -------------------------------------------------------------------------------- /main/laya/assets/comp/html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/html.png -------------------------------------------------------------------------------- /main/laya/assets/comp/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/image.png -------------------------------------------------------------------------------- /main/laya/assets/comp/label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/label.png -------------------------------------------------------------------------------- /main/laya/assets/comp/linkbutton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/linkbutton.png -------------------------------------------------------------------------------- /main/laya/assets/comp/progress$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/progress$bar.png -------------------------------------------------------------------------------- /main/laya/assets/comp/progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/progress.png -------------------------------------------------------------------------------- /main/laya/assets/comp/radio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/radio.png -------------------------------------------------------------------------------- /main/laya/assets/comp/radiogroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/radiogroup.png -------------------------------------------------------------------------------- /main/laya/assets/comp/tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/tab.png -------------------------------------------------------------------------------- /main/laya/assets/comp/textarea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/textarea.png -------------------------------------------------------------------------------- /main/laya/assets/comp/textinput.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/textinput.png -------------------------------------------------------------------------------- /main/laya/assets/comp/vscroll$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/vscroll$bar.png -------------------------------------------------------------------------------- /main/laya/assets/comp/vscroll$down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/vscroll$down.png -------------------------------------------------------------------------------- /main/laya/assets/comp/vscroll$up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/vscroll$up.png -------------------------------------------------------------------------------- /main/laya/assets/comp/vscroll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/vscroll.png -------------------------------------------------------------------------------- /main/laya/assets/comp/vslider$bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/vslider$bar.png -------------------------------------------------------------------------------- /main/laya/assets/comp/vslider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/comp/vslider.png -------------------------------------------------------------------------------- /main/laya/assets/rank/first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/rank/first.png -------------------------------------------------------------------------------- /main/laya/assets/rank/second.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/rank/second.png -------------------------------------------------------------------------------- /main/laya/assets/rank/third.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/laya/assets/rank/third.png -------------------------------------------------------------------------------- /main/laya/pages/index.ui: -------------------------------------------------------------------------------- 1 | { 2 | "x":0, 3 | "type":"View", 4 | "selectedBox":1, 5 | "selecteID":17, 6 | "props":{"width":1334,"sceneColor":"#000000","height":750,"centerY":0.5,"centerX":0.5}, 7 | "nodeParent":-1, 8 | "label":"View", 9 | "isOpen":true, 10 | "isDirectory":true, 11 | "isAniNode":true, 12 | "hasChild":true, 13 | "compId":1, 14 | "child":[ 15 | { 16 | "x":15, 17 | "type":"Box", 18 | "props":{"y":0,"x":0,"var":"back"}, 19 | "nodeParent":1, 20 | "label":"Box(back)", 21 | "isOpen":null, 22 | "isDirectory":true, 23 | "isAniNode":true, 24 | "hasChild":true, 25 | "compId":4, 26 | "child":[ 27 | { 28 | "type":"Rect", 29 | "props":{"y":0,"x":0,"width":1334,"lineWidth":0,"height":750,"fillColor":"#938a8a"}, 30 | "nodeParent":4, 31 | "label":"Rect", 32 | "isDirectory":false, 33 | "isAniNode":true, 34 | "hasChild":false, 35 | "compId":3, 36 | "child":[ 37 | ] 38 | }] 39 | }, 40 | { 41 | "x":15, 42 | "type":"Button", 43 | "props":{"y":89,"x":17,"width":193,"var":"add","skin":"comp/button.png","labelSize":26,"labelFont":"SimSun","label":"增加小游戏分数","height":63}, 44 | "nodeParent":1, 45 | "label":"Button(add)", 46 | "isDirectory":false, 47 | "isAniNode":true, 48 | "hasChild":false, 49 | "compId":5, 50 | "child":[ 51 | ] 52 | }, 53 | { 54 | "x":15, 55 | "type":"Button", 56 | "props":{"y":88,"x":230,"width":208,"var":"showButton","skin":"comp/button.png","labelSize":26,"labelFont":"SimSun","label":"显示/隐藏排行榜","height":68}, 57 | "nodeParent":1, 58 | "label":"Button(showButton)", 59 | "isDirectory":false, 60 | "isAniNode":true, 61 | "hasChild":false, 62 | "compId":8, 63 | "child":[ 64 | ] 65 | }, 66 | { 67 | "x":15, 68 | "type":"Box", 69 | "props":{"y":185,"x":0,"visible":false,"var":"rankBox"}, 70 | "nodeParent":1, 71 | "label":"Box(rankBox)", 72 | "isOpen":false, 73 | "isDirectory":true, 74 | "isAniNode":true, 75 | "hasChild":true, 76 | "compId":18, 77 | "child":[ 78 | { 79 | "type":"Image", 80 | "props":{"width":482,"skin":"comp/bg.png","sizeGrid":"33,26,20,24","height":442}, 81 | "nodeParent":18, 82 | "label":"Image", 83 | "isDirectory":false, 84 | "isAniNode":true, 85 | "hasChild":false, 86 | "compId":6, 87 | "child":[ 88 | ] 89 | }] 90 | }, 91 | { 92 | "x":15, 93 | "type":"Sprite", 94 | "props":{"y":0,"x":0,"width":1334,"visible":false,"var":"openDataCanvas","height":750}, 95 | "nodeParent":1, 96 | "label":"Sprite(openDataCanvas)", 97 | "isDirectory":false, 98 | "isAniNode":true, 99 | "hasChild":false, 100 | "compId":17, 101 | "child":[ 102 | ], 103 | "$HIDDEN":true 104 | }], 105 | "animations":[ 106 | { 107 | "nodes":[ 108 | ], 109 | "name":"ani1", 110 | "id":1, 111 | "frameRate":24, 112 | "action":0 113 | }] 114 | } -------------------------------------------------------------------------------- /main/laya/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /main/rank-main.laya: -------------------------------------------------------------------------------- 1 | {"proName":"rank-main","engineType":2,"proType":1,"layaProType":1} -------------------------------------------------------------------------------- /main/release.bat: -------------------------------------------------------------------------------- 1 | cd /d %~dp0 2 | set binDir=bin 3 | set srcDir=release\wxgame 4 | set dstDir=..\wxgame 5 | 6 | del /f /s /q %srcDir%\libs\*.* 7 | rd /s /q %srcDir%\libs 8 | del /f /s /q %srcDir%\js\*.* 9 | rd /s /q %srcDir%\js 10 | 11 | md %srcDir%\rankRes 12 | Xcopy %binDir%\rankRes %srcDir%\rankRes /s /e /y 13 | 14 | Xcopy %srcDir% %dstDir% /s /e /y -------------------------------------------------------------------------------- /main/release/wxgame/game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "landscape", 3 | "openDataContext": "src/openDataContext", 4 | "showStatusBar": "false", 5 | "networkTimeout": { 6 | "request": 1000, 7 | "connectSocket": 2000, 8 | "uploadFile": 6000, 9 | "downloadFile": 6000 10 | } 11 | } -------------------------------------------------------------------------------- /main/release/wxgame/src/openDataContext/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/main/release/wxgame/src/openDataContext/.gitkeep -------------------------------------------------------------------------------- /main/src/Main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * name; 3 | */ 4 | class Main{ 5 | protected wxSystemInfo:any = null; 6 | protected static instance:Main; 7 | protected openDataNeedReload:boolean = true; 8 | 9 | public static GetInstance():Main 10 | { 11 | if(null == Main.instance) 12 | { 13 | Main.instance = new Main(); 14 | } 15 | return Main.instance; 16 | } 17 | 18 | constructor() 19 | { 20 | this.openDataNeedReload = (this.versionCompare(Laya.version, '1.7.20') <= 0); 21 | } 22 | 23 | protected versionCompare(versionOne:string, versionTwo:string):number 24 | { 25 | let arrOne = versionOne.split('.'); 26 | let arrTwo = versionTwo.split('.'); 27 | for (let i = 0, len = arrOne.length; i < len; i++) { 28 | let numberOne = parseInt(arrOne[i]); 29 | let numberTwo = parseInt(arrTwo[i]); 30 | if (numberOne < numberTwo) { 31 | return -1; 32 | } else if (numberOne > numberTwo) { 33 | return 1; 34 | } 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | public getWxSystemInfo():any 41 | { 42 | if (Laya.Browser.onMiniGame) { 43 | if (this.wxSystemInfo == null) { 44 | this.wxSystemInfo = Laya.Browser.window.wx.getSystemInfoSync(); 45 | } 46 | } 47 | 48 | return this.wxSystemInfo; 49 | } 50 | 51 | public start() 52 | { 53 | Laya.MiniAdpter.init(true, false); 54 | Laya.init(1334, 750, Laya.WebGL); 55 | 56 | this.initStage(); 57 | } 58 | 59 | //初始化stage 60 | protected initStage(): void 61 | { 62 | if (Laya.Browser.onMiniGame) { 63 | let systemInfo = this.getWxSystemInfo(); 64 | if (systemInfo.windowWidth * 750 > systemInfo.windowHeight * 1334) { //宽屏,高度固定 65 | Laya.stage.scaleMode = Laya.Stage.SCALE_FIXED_HEIGHT; 66 | } else { 67 | Laya.stage.scaleMode = Laya.Stage.SCALE_FIXED_WIDTH; 68 | } 69 | } else { 70 | Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL; 71 | } 72 | 73 | //自动横屏 74 | Laya.stage.screenMode = Laya.Stage.SCREEN_HORIZONTAL; 75 | Laya.stage.alignV = Laya.Stage.ALIGN_CENTER; 76 | Laya.stage.alignH = Laya.Stage.ALIGN_CENTER; 77 | Laya.stage.bgColor = "#627069"; 78 | 79 | if (Laya.Browser.onMiniGame) { 80 | let wx = Laya.Browser.window.wx; 81 | Laya.timer.once(1000, this, () => { 82 | //设置共享画布大小 83 | let sharedCanvas = wx.getOpenDataContext().canvas; 84 | sharedCanvas.width = Laya.stage.width; 85 | sharedCanvas.height = Laya.stage.height; 86 | //主域往子域透传消息 87 | wx.postMessage({type:"resizeShared",url:"",data:{width:Laya.stage.width,height:Laya.stage.height,matrix:Laya.stage._canvasTransform},isLoad:false}); 88 | Laya.ResourceVersion.type = Laya.ResourceVersion.FILENAME_VERSION; 89 | Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.loadOpenDataResource)); 90 | }); 91 | } else { 92 | Laya.ResourceVersion.type = Laya.ResourceVersion.FILENAME_VERSION; 93 | Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.loadOpenDataResource)); 94 | } 95 | } 96 | 97 | protected loadOpenDataResource():void 98 | { 99 | //Laya.URL.basePath = "http://test.mine.cn/opendata/"; 100 | Laya.loader.load(this.openDataNeedReload ? "rankRes/rank.atlas" : "res/atlas/rank.atlas", Laya.Handler.create(this, this.openDataHandle), null, Laya.Loader.ATLAS); 101 | } 102 | 103 | protected openDataHandle():void 104 | { 105 | if (Laya.Browser.onMiniGame) { 106 | let wx = Laya.Browser.window.wx; 107 | if (this.openDataNeedReload) { 108 | let urlArr = ["rankRes/rank.atlas"]; 109 | for (let i = 0; i < urlArr.length; i++) { 110 | wx.postMessage({url:urlArr[i], data:Laya.loader.getRes(urlArr[i]),isLoad:"filedata"}); 111 | } 112 | } else { 113 | let urlArr = ["res/atlas/rank.atlas"]; 114 | for (let i = 0; i < urlArr.length; i++) { 115 | (Laya.MiniAdpter as any).sendAtlasToOpenDataContext(urlArr[i]); 116 | } 117 | } 118 | 119 | wx.postMessage({cmd:"loadRes"}); 120 | } 121 | this.loadResource(); 122 | } 123 | 124 | protected loadResource():void 125 | { 126 | let prefix = ""; 127 | let uiResArry:Array = [ 128 | { url: prefix + "res/atlas/comp.atlas", type:Laya.Loader.ATLAS}, 129 | ]; 130 | 131 | Laya.loader.load(uiResArry, Laya.Handler.create(this, this.loadEnd)); 132 | } 133 | 134 | protected loadEnd():void 135 | { 136 | let indexView = new views.Index(); 137 | Laya.stage.addChild(indexView); 138 | 139 | if (Laya.Browser.onMiniGame) { 140 | let wx = Laya.Browser.window.wx; 141 | wx.login({ 142 | success: (res) => { 143 | let code = res.code; 144 | wx.getSetting({ 145 | success: (resSetting) => { 146 | if (resSetting.authSetting["scope.userInfo"] == true) { 147 | indexView.showAll(); 148 | } else { 149 | indexView.hideAll(); 150 | let systemInfo = this.getWxSystemInfo(); 151 | //console.log(systemInfo); 152 | let button = wx.createUserInfoButton({ 153 | text: '登录', 154 | withCredentials: true, 155 | style: { 156 | left: systemInfo.windowWidth/2 - 64, 157 | top: systemInfo.windowHeight/2 + 99, 158 | width: 200, 159 | height: 40, 160 | lineHeight: 40, 161 | backgroundColor: '#ff0000', 162 | color: '#ffffff', 163 | textAlign: 'center', 164 | fontSize: 20, 165 | borderRadius: 4 166 | } 167 | }) 168 | button.onTap((res2) => { 169 | button.hide(); 170 | indexView.showAll(); 171 | }) 172 | } 173 | } 174 | }); 175 | } 176 | }); 177 | } 178 | } 179 | } 180 | 181 | Main.GetInstance().start(); -------------------------------------------------------------------------------- /main/src/ui/layaUI.max.all.ts: -------------------------------------------------------------------------------- 1 | 2 | import View=laya.ui.View; 3 | import Dialog=laya.ui.Dialog; 4 | module ui { 5 | export class indexUI extends View { 6 | public back:Laya.Box; 7 | public add:Laya.Button; 8 | public showButton:Laya.Button; 9 | public rankBox:Laya.Box; 10 | public openDataCanvas:Laya.Sprite; 11 | 12 | public static uiView:any ={"type":"View","props":{"width":1334,"height":750,"centerY":0.5,"centerX":0.5},"child":[{"type":"Box","props":{"y":0,"x":0,"var":"back"},"child":[{"type":"Rect","props":{"y":0,"x":0,"width":1334,"lineWidth":0,"height":750,"fillColor":"#938a8a"}}]},{"type":"Button","props":{"y":89,"x":17,"width":193,"var":"add","skin":"comp/button.png","labelSize":26,"labelFont":"SimSun","label":"增加小游戏分数","height":63}},{"type":"Button","props":{"y":88,"x":230,"width":208,"var":"showButton","skin":"comp/button.png","labelSize":26,"labelFont":"SimSun","label":"显示/隐藏排行榜","height":68}},{"type":"Box","props":{"y":185,"x":0,"visible":false,"var":"rankBox"},"child":[{"type":"Image","props":{"width":482,"skin":"comp/bg.png","sizeGrid":"33,26,20,24","height":442}}]},{"type":"Sprite","props":{"y":0,"x":0,"width":1334,"visible":false,"var":"openDataCanvas","height":750}}]}; 13 | constructor(){ super()} 14 | createChildren():void { 15 | 16 | super.createChildren(); 17 | this.createView(ui.indexUI.uiView); 18 | 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /main/src/views/Index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * name 3 | */ 4 | module views{ 5 | export class Index extends ui.indexUI{ 6 | constructor(){ 7 | super(); 8 | 9 | this.add.on(Laya.Event.CLICK, this, this.addScore); 10 | this.showButton.on(Laya.Event.CLICK, this, this.switchShow); 11 | 12 | if (Laya.Browser.onMiniGame) { 13 | let texture:Laya.Texture = new Laya.Texture(Laya.Browser.window.sharedCanvas); 14 | texture.bitmap.alwaysChange = true;//小程序使用,非常费,这个参数可以根据自己的需求适当调整,如果内容不变可以不用设置成true 15 | this.openDataCanvas.graphics.drawTexture(texture, 0, 0, texture.width, texture.height); 16 | } 17 | } 18 | 19 | public showAll():void 20 | { 21 | this.visible = true; 22 | } 23 | 24 | public hideAll():void 25 | { 26 | this.visible = false; 27 | } 28 | 29 | //增加分数 30 | protected addScore():void 31 | { 32 | this.postMessage({ 33 | cmd: 'addScore', 34 | }); 35 | } 36 | 37 | //显示/隐藏排行榜 38 | protected switchShow():void 39 | { 40 | if (this.rankBox.visible) { 41 | this.hideRankList(); 42 | } else { 43 | this.showRankList(); 44 | } 45 | } 46 | 47 | //向开放数据域发送消息 48 | protected postMessage(item:Object):void 49 | { 50 | if (Laya.Browser.onMiniGame) { 51 | let wx = Laya.Browser.window.wx; 52 | let openDataContext = wx.getOpenDataContext(); 53 | openDataContext.postMessage(item); 54 | } 55 | } 56 | 57 | public showRankList():void 58 | { 59 | this.rankBox.x = -480; 60 | this.openDataCanvas.x = -471; 61 | this.rankBox.visible = true; 62 | this.openDataCanvas.visible = true; 63 | 64 | Laya.Tween.to(this.rankBox, {"x": 0}, 200); 65 | Laya.Tween.to(this.openDataCanvas, {"x": 0}, 200); 66 | 67 | this.postMessage({ 68 | cmd: 'showRank', 69 | }); 70 | } 71 | 72 | public hideRankList():void 73 | { 74 | this.postMessage({ 75 | cmd: 'hideRank', 76 | }); 77 | Laya.Tween.to(this.rankBox, {"x": -480}, 200); 78 | Laya.Tween.to(this.openDataCanvas, {"x": -471}, 200, null, Laya.Handler.create(this, () => { 79 | this.rankBox.visible = false; 80 | this.openDataCanvas.visible = false; 81 | this.rankBox.x = 0; 82 | this.openDataCanvas.x = 0; 83 | })); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /main/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "sourceMap": true 6 | }, 7 | "exclude": [ 8 | "node_modules" 9 | ] 10 | } -------------------------------------------------------------------------------- /open-data/.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 | }, 16 | { 17 | "name": "chrome调试", 18 | "type": "chrome", 19 | "request": "launch", 20 | "file": "${workspaceRoot}/bin/index.html", 21 | // "换成自己的谷歌安装路径,": 比如 22 | //window 默认安装路径为: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" 23 | //mac 系统上的默认安装路径为 "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; 24 | // "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", 25 | "runtimeArgs": [ 26 | "--allow-file-access-from-files", 27 | "--allow-file-access-frome-files", 28 | " --disable-web-security" 29 | ], 30 | "sourceMaps": true, 31 | "webRoot": "${workspaceRoot}", 32 | //假如谷歌调试报userDataDir不可用,请把谷歌安装路径取得管理员权限,或者更换${tmpdir}为其他可以读写的文件夹,也可以删除。 33 | "userDataDir": "${workspaceRoot}/.laya/chrome", 34 | "fixedPort":false 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /open-data/.laya/pubset.json: -------------------------------------------------------------------------------- 1 | {"1":{"sourcePath":"E:\\laya_workspace\\laya-wx-rank-ts\\open-data\\bin","outPath":"E:\\laya_workspace\\laya-wx-rank-ts\\open-data\\release\\wxgame","pngQualityLow":"65","pngQualityHigh":"80","jpgQuality":"85","mergeJs":true,"compressPng":false,"compressJpg":false,"compressJson":false,"jsontypes":"json,atlas,ls,lh,lmat,lav","compressJs":false,"enableVersion":false,"excludeFiles":"","publishType":1,"projectType":"ts","copyOutFiles":"","copyOutPath":"","userCmd":"E:\\laya_workspace\\laya-wx-rank-ts\\open-data\\release_opendata.bat"},"pf":1} -------------------------------------------------------------------------------- /open-data/.laya/tasks.json: -------------------------------------------------------------------------------- 1 | {"version":"0.1.0","command":"tsc","isShellCommand":true,"args":["-p",".","--outDir","bin/js"],"showOutput":"silent","problemMatcher":"$tsc"} -------------------------------------------------------------------------------- /open-data/bin/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | www.layabox.com 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /open-data/bin/libs/LayaRender.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Matter.js 渲染器在 LayaAir 的实现。 3 | */ 4 | (function() 5 | { 6 | var LayaRender = {}; 7 | 8 | var Common = Matter.Common; 9 | var Composite = Matter.Composite; 10 | var Bounds = Matter.Bounds; 11 | var Events = Matter.Events; 12 | var Grid = Matter.Grid; 13 | var Vector = Matter.Vector; 14 | 15 | /** 16 | * 创建新的渲染器。 17 | * @param {object} options 所有属性都有默认值,options中的属性会覆盖默认属性。 18 | * @return {render} 返回创建的旋绕器 19 | */ 20 | LayaRender.create = function(options) 21 | { 22 | var defaults = { 23 | controller: LayaRender, 24 | engine: null, 25 | element: null, 26 | canvas: null, 27 | mouse: null, 28 | frameRequestId: null, 29 | options: 30 | { 31 | width: 800, 32 | height: 600, 33 | pixelRatio: 1, 34 | background: '#fafafa', 35 | wireframeBackground: '#222222', 36 | hasBounds: !!options.bounds, 37 | enabled: true, 38 | wireframes: true, 39 | showSleeping: true, 40 | showDebug: false, 41 | showBroadphase: false, 42 | showBounds: false, 43 | showVelocity: false, 44 | showCollisions: false, 45 | showSeparations: false, 46 | showAxes: false, 47 | showPositions: false, 48 | showAngleIndicator: false, 49 | showIds: false, 50 | showShadows: false, 51 | showVertexNumbers: false, 52 | showConvexHulls: false, 53 | showInternalEdges: false, 54 | showMousePosition: false 55 | } 56 | }; 57 | var render = Common.extend(defaults, options); 58 | render.mouse = options.mouse; 59 | render.engine = options.engine; 60 | // 如果用户没有指定contaienr,默认使用stage 61 | render.container = render.container || Laya.stage; 62 | render.bounds = render.bounds || 63 | { 64 | min: 65 | { 66 | x: 0, 67 | y: 0 68 | }, 69 | max: 70 | { 71 | x: render.width, 72 | y: render.height 73 | } 74 | }; 75 | 76 | return render; 77 | } 78 | 79 | /** 80 | * 运行渲染器。 81 | * @param {render} render 渲染的目标是LayaRender.create()返回的对象 82 | * @return {void} 83 | */ 84 | LayaRender.run = function(render) 85 | { 86 | Laya.timer.frameLoop(1, this, LayaRender.world, [render]); 87 | Events.on(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite); 88 | }; 89 | 90 | /** 91 | * 停止渲染器。 92 | * @param {render} LayaRender.create()返回的对象 93 | * @return {void} 94 | */ 95 | LayaRender.stop = function(render) 96 | { 97 | Laya.timer.clear(this, LayaRender.world); 98 | Events.off(render.engine.world, 'afterRemove', LayaRender.onRemoveSprite); 99 | } 100 | 101 | LayaRender.onRemoveSprite = function(args) 102 | { 103 | var sprite = args.object.layaSprite; 104 | if (sprite && sprite.parent) 105 | sprite.parent.removeChild(sprite); 106 | } 107 | 108 | /** 109 | * 渲染给定的 engine 的 Matter.World 对象。 110 | * 这是渲染的入口,每次场景改变时都应该被调用。 111 | * @param {render} render 112 | * @return {void} 113 | */ 114 | LayaRender.world = function(render) 115 | { 116 | var engine = render.engine, 117 | world = engine.world, 118 | renderer = render.renderer, 119 | container = render.container, 120 | options = render.options, 121 | bodies = Composite.allBodies(world), 122 | allConstraints = Composite.allConstraints(world), 123 | constraints = [], 124 | i; 125 | 126 | if (options.wireframes) 127 | { 128 | LayaRender.setBackground(render, options.wireframeBackground); 129 | } 130 | else 131 | { 132 | LayaRender.setBackground(render, options.background); 133 | } 134 | 135 | // 处理 bounds 136 | var boundsWidth = render.bounds.max.x - render.bounds.min.x, 137 | boundsHeight = render.bounds.max.y - render.bounds.min.y, 138 | boundsScaleX = boundsWidth / render.options.width, 139 | boundsScaleY = boundsHeight / render.options.height; 140 | 141 | if (options.hasBounds) 142 | { 143 | // 隐藏不在视口内的bodies 144 | for (i = 0; i < bodies.length; i++) 145 | { 146 | var body = bodies[i]; 147 | body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds); 148 | } 149 | 150 | // 过滤掉不在视口内的 constraints 151 | for (i = 0; i < allConstraints.length; i++) 152 | { 153 | var constraint = allConstraints[i], 154 | bodyA = constraint.bodyA, 155 | bodyB = constraint.bodyB, 156 | pointAWorld = constraint.pointA, 157 | pointBWorld = constraint.pointB; 158 | 159 | if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA); 160 | if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB); 161 | 162 | if (!pointAWorld || !pointBWorld) 163 | continue; 164 | 165 | if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld)) 166 | constraints.push(constraint); 167 | } 168 | 169 | // 改变视口 170 | container.scale(1 / boundsScaleX, 1 / boundsScaleY); 171 | container.pos(-render.bounds.min.x * (1 / boundsScaleX), -render.bounds.min.y * (1 / boundsScaleY)); 172 | } 173 | else 174 | { 175 | constraints = allConstraints; 176 | } 177 | 178 | for (i = 0; i < bodies.length; i++) 179 | LayaRender.body(render, bodies[i]); 180 | 181 | for (i = 0; i < constraints.length; i++) 182 | LayaRender.constraint(render, constraints[i]); 183 | }; 184 | 185 | /** 186 | * 设置背景色或者背景图片。 187 | * @param {render} render 188 | * @param {string} background 16进制颜色字符串或者图片路径 189 | */ 190 | LayaRender.setBackground = function(render, background) 191 | { 192 | if (render.currentBackground !== background) 193 | { 194 | var isColor = background.indexOf && background.indexOf('#') !== -1; 195 | 196 | render.container.graphics.clear(); 197 | 198 | if (isColor) 199 | { 200 | // 使用纯色背景 201 | render.container.bgColor = background; 202 | } 203 | else 204 | { 205 | render.container.loadImage(background); 206 | // 使用背景图片时把背景色设置为白色 207 | render.container.bgColor = "#FFFFFF"; 208 | } 209 | 210 | render.currentBackground = background; 211 | } 212 | } 213 | 214 | /** 215 | * 渲染 body 216 | * @param {render} render 217 | * @param {body} body 218 | * @return {void} 219 | */ 220 | LayaRender.body = function(render, body) 221 | { 222 | var engine = render.engine, 223 | bodyRender = body.render; 224 | 225 | if (!bodyRender.visible) 226 | return; 227 | 228 | // 有纹理的body 229 | if (bodyRender.sprite && bodyRender.sprite.texture) 230 | { 231 | var spriteId = 'b-' + body.id, 232 | sprite = body.layaSprite, 233 | container = render.container; 234 | 235 | // 如果sprite不存在,则初始化一个 236 | if (!sprite) 237 | sprite = body.layaSprite = _createBodySprite(render, body); 238 | 239 | // 如果sprite未在显示列表,则添加至显示列表 240 | if (!container.contains(sprite)) 241 | container.addChild(sprite); 242 | 243 | // 更新sprite位置 244 | sprite.x = body.position.x; 245 | sprite.y = body.position.y; 246 | sprite.rotation = body.angle * 180 / Math.PI; 247 | sprite.scaleX = bodyRender.sprite.xScale || 1; 248 | sprite.scaleY = bodyRender.sprite.yScale || 1; 249 | } 250 | else // 没有纹理的body 251 | { 252 | var primitiveId = 'b-' + body.id, 253 | sprite = body.layaSprite, 254 | container = render.container; 255 | 256 | // 如果sprite不存在,则初始化一个 257 | if (!sprite) 258 | { 259 | sprite = body.layaSprite = _createBodyPrimitive(render, body); 260 | sprite.initialAngle = body.angle; 261 | } 262 | 263 | // 如果sprite未在显示列表,则添加至显示列表 264 | if (!container.contains(sprite)) 265 | container.addChild(sprite); 266 | // 更新sprite位置 267 | sprite.x = body.position.x; 268 | sprite.y = body.position.y; 269 | sprite.rotation = (body.angle - sprite.initialAngle) * 180 / Math.PI; 270 | } 271 | }; 272 | 273 | /** 274 | * 创建使用纹理的Sprite对象。 275 | * @param {render} render 276 | * @param {body} body 277 | * @return {void} 278 | */ 279 | var _createBodySprite = function(render, body) 280 | { 281 | var bodyRender = body.render, 282 | texturePath = bodyRender.sprite.texture, 283 | sprite = new Laya.Sprite(); 284 | 285 | sprite.loadImage(texturePath); 286 | sprite.pivotX = body.render.sprite.xOffset; 287 | sprite.pivotY = body.render.sprite.yOffset; 288 | 289 | return sprite; 290 | }; 291 | 292 | /** 293 | * 创建使用矢量绘图的Sprite对象。 294 | * @param {render} render 295 | * @param {body} body 296 | * @return {void} 297 | */ 298 | var _createBodyPrimitive = function(render, body) 299 | { 300 | var bodyRender = body.render, 301 | options = render.options, 302 | sprite = new Laya.Sprite(), 303 | fillStyle, strokeStyle, lineWidth, 304 | part, points = []; 305 | 306 | var primitive = sprite.graphics; 307 | primitive.clear(); 308 | 309 | // 处理 compound parts 310 | for (var k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++) 311 | { 312 | part = body.parts[k]; 313 | 314 | if (!options.wireframes) 315 | { 316 | fillStyle = bodyRender.fillStyle; 317 | strokeStyle = bodyRender.strokeStyle; 318 | lineWidth = bodyRender.lineWidth; 319 | } 320 | else 321 | { 322 | fillStyle = null; 323 | strokeStyle = '#bbbbbb'; 324 | lineWidth = 1; 325 | } 326 | 327 | points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y); 328 | 329 | for (var j = 1; j < part.vertices.length; j++) 330 | { 331 | points.push(part.vertices[j].x - body.position.x, part.vertices[j].y - body.position.y); 332 | } 333 | 334 | points.push(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y); 335 | 336 | primitive.drawPoly(0, 0, points, fillStyle, strokeStyle, lineWidth); 337 | 338 | // 角度指示器 339 | if (options.showAngleIndicator || options.showAxes) 340 | { 341 | lineWidth = 1; 342 | if (options.wireframes) 343 | { 344 | strokeStyle = '#CD5C5C'; 345 | } 346 | else 347 | { 348 | strokeStyle = bodyRender.strokeStyle; 349 | } 350 | 351 | primitive.drawLine(part.position.x - body.position.x, part.position.y - body.position.y, 352 | ((part.vertices[0].x + part.vertices[part.vertices.length - 1].x) / 2 - body.position.x), 353 | ((part.vertices[0].y + part.vertices[part.vertices.length - 1].y) / 2 - body.position.y)); 354 | } 355 | } 356 | 357 | return sprite; 358 | }; 359 | 360 | /** 361 | * 绘制 constraint。 362 | * @param {render} render 363 | * @param {constraint} constraint 364 | * @return {void} 365 | */ 366 | LayaRender.constraint = function(render, constraint) 367 | { 368 | var engine = render.engine, 369 | bodyA = constraint.bodyA, 370 | bodyB = constraint.bodyB, 371 | pointA = constraint.pointA, 372 | pointB = constraint.pointB, 373 | container = render.container, 374 | constraintRender = constraint.render, 375 | primitiveId = 'c-' + constraint.id, 376 | sprite = constraint.layaSprite; 377 | 378 | // 如果sprite不存在,则初始化一个 379 | if (!sprite) 380 | sprite = constraint.layaSprite = new Laya.Sprite(); 381 | 382 | var primitive = sprite.graphics; 383 | 384 | // constraint 没有两个终点时不渲染 385 | if (!constraintRender.visible || !constraint.pointA || !constraint.pointB) 386 | { 387 | primitive.clear(); 388 | return; 389 | } 390 | 391 | // 如果sprite未在显示列表,则添加至显示列表 392 | if (!container.contains(sprite)) 393 | container.addChild(sprite); 394 | 395 | // 渲染 constraint 396 | primitive.clear(); 397 | 398 | var fromX, fromY, toX, toY; 399 | if (bodyA) 400 | { 401 | fromX = bodyA.position.x + pointA.x; 402 | fromY = bodyA.position.y + pointA.y; 403 | } 404 | else 405 | { 406 | fromX = pointA.x; 407 | fromY = pointA.y; 408 | } 409 | 410 | if (bodyB) 411 | { 412 | toX = bodyB.position.x + pointB.x; 413 | toY = bodyB.position.y + pointB.y; 414 | } 415 | else 416 | { 417 | toX = pointB.x; 418 | toY = pointB.y; 419 | } 420 | 421 | primitive.drawLine(fromX, fromY, toX, toY, constraintRender.strokeStyle, constraintRender.lineWidth); 422 | }; 423 | 424 | window.LayaRender = LayaRender; 425 | })(); -------------------------------------------------------------------------------- /open-data/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 Component3D=laya.d3.component.Component3D,ComponentNode=laya.d3.core.ComponentNode,MeshTerrainSprite3D=laya.d3.core.MeshTerrainSprite3D; 6 | var Sprite3D=laya.d3.core.Sprite3D; 7 | /** 8 | *PathFinding 类用于创建寻路。 9 | */ 10 | //class laya.d3.component.PathFind extends laya.d3.component.Component3D 11 | var PathFind=(function(_super){ 12 | function PathFind(){ 13 | /**@private */ 14 | this._meshTerrainSprite3D=null; 15 | /**@private */ 16 | this._finder=null; 17 | /**@private */ 18 | this._setting=null; 19 | /**寻路网格。*/ 20 | this.grid=null; 21 | PathFind.__super.call(this); 22 | } 23 | 24 | __class(PathFind,'laya.d3.component.PathFind',_super); 25 | var __proto=PathFind.prototype; 26 | /** 27 | *@private 28 | *初始化载入蒙皮动画组件。 29 | *@param owner 所属精灵对象。 30 | */ 31 | __proto._load=function(owner){ 32 | if (! (owner instanceof laya.d3.core.MeshTerrainSprite3D )) 33 | throw new Error("PathFinding: The owner must MeshTerrainSprite3D!"); 34 | _super.prototype._load.call(this,owner); 35 | this._meshTerrainSprite3D=owner; 36 | } 37 | 38 | /** 39 | *寻找路径。 40 | *@param startX 开始X。 41 | *@param startZ 开始Z。 42 | *@param endX 结束X。 43 | *@param endZ 结束Z。 44 | *@return 路径。 45 | */ 46 | __proto.findPath=function(startX,startZ,endX,endZ){ 47 | var minX=this._meshTerrainSprite3D.minX; 48 | var minZ=this._meshTerrainSprite3D.minZ; 49 | var cellX=this._meshTerrainSprite3D.width / this.grid.width; 50 | var cellZ=this._meshTerrainSprite3D.depth / this.grid.height; 51 | var halfCellX=cellX / 2; 52 | var halfCellZ=cellZ / 2; 53 | var gridStartX=Math.floor((startX-minX)/ cellX); 54 | var gridStartZ=Math.floor((startZ-minZ)/ cellZ); 55 | var gridEndX=Math.floor((endX-minX)/ cellX); 56 | var gridEndZ=Math.floor((endZ-minZ)/ cellZ); 57 | var boundWidth=this.grid.width-1; 58 | var boundHeight=this.grid.height-1; 59 | (gridStartX > boundWidth)&& (gridStartX=boundWidth); 60 | (gridStartZ > boundHeight)&& (gridStartZ=boundHeight); 61 | (gridStartX < 0)&& (gridStartX=0); 62 | (gridStartZ < 0)&& (gridStartZ=0); 63 | (gridEndX > boundWidth)&& (gridEndX=boundWidth); 64 | (gridEndZ > boundHeight)&& (gridEndZ=boundHeight); 65 | (gridEndX < 0)&& (gridEndX=0); 66 | (gridEndZ < 0)&& (gridEndZ=0); 67 | var path=this._finder.findPath(gridStartX,gridStartZ,gridEndX,gridEndZ,this.grid); 68 | this.grid.reset(); 69 | for (var i=1;i < path.length-1;i++){ 70 | var gridPos=path[i]; 71 | gridPos[0]=gridPos[0] *cellX+halfCellX+minX; 72 | gridPos[1]=gridPos[1] *cellZ+halfCellZ+minZ; 73 | } 74 | if (path.length==1){ 75 | path[0][0]=endX; 76 | path[0][1]=endX; 77 | }else if (path.length > 1){ 78 | path[0][0]=startX; 79 | path[0][1]=startZ; 80 | path[path.length-1][0]=endX; 81 | path[path.length-1][1]=endZ; 82 | } 83 | return path; 84 | } 85 | 86 | /** 87 | *设置寻路设置。 88 | *@param value 寻路设置。 89 | */ 90 | /** 91 | *获取寻路设置。 92 | *@return 寻路设置。 93 | */ 94 | __getset(0,__proto,'setting',function(){ 95 | return this._setting; 96 | },function(value){ 97 | (value)&& (this._finder=new PathFinding.finders.AStarFinder(value)); 98 | this._setting=value; 99 | }); 100 | 101 | return PathFind; 102 | })(Component3D) 103 | 104 | 105 | 106 | })(window,document,Laya); 107 | 108 | if (typeof define === 'function' && define.amd){ 109 | define('laya.core', ['require', "exports"], function(require, exports) { 110 | 'use strict'; 111 | Object.defineProperty(exports, '__esModule', { value: true }); 112 | for (var i in Laya) { 113 | var o = Laya[i]; 114 | o && o.__isclass && (exports[i] = o); 115 | } 116 | }); 117 | } -------------------------------------------------------------------------------- /open-data/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 Browser=laya.utils.Browser,Color=laya.utils.Color,ColorFilterAction=laya.filters.ColorFilterAction; 6 | var ColorFilterActionGL=laya.filters.webgl.ColorFilterActionGL,Filter=laya.filters.Filter,FilterActionGL=laya.filters.webgl.FilterActionGL; 7 | var Matrix=laya.maths.Matrix,Rectangle=laya.maths.Rectangle,Render=laya.renders.Render,RenderContext=laya.renders.RenderContext; 8 | var RenderTarget2D=laya.webgl.resource.RenderTarget2D,RunDriver=laya.utils.RunDriver,ShaderDefines2D=laya.webgl.shader.d2.ShaderDefines2D; 9 | var Sprite=laya.display.Sprite,Texture=laya.resource.Texture,Value2D=laya.webgl.shader.d2.value.Value2D; 10 | /** 11 | *默认的FILTER,什么都不做 12 | *@private 13 | */ 14 | //class laya.filters.FilterAction 15 | var FilterAction=(function(){ 16 | function FilterAction(){ 17 | this.data=null; 18 | } 19 | 20 | __class(FilterAction,'laya.filters.FilterAction'); 21 | var __proto=FilterAction.prototype; 22 | Laya.imps(__proto,{"laya.filters.IFilterAction":true}) 23 | __proto.apply=function(data){ 24 | return null; 25 | } 26 | 27 | return FilterAction; 28 | })() 29 | 30 | 31 | /** 32 | *@private 33 | */ 34 | //class laya.filters.WebGLFilter 35 | var WebGLFilter=(function(){ 36 | function WebGLFilter(){} 37 | __class(WebGLFilter,'laya.filters.WebGLFilter'); 38 | WebGLFilter.enable=function(){ 39 | if (WebGLFilter.isInit)return; 40 | WebGLFilter.isInit=true; 41 | if (!Render.isWebGL)return; 42 | RunDriver.createFilterAction=function (type){ 43 | var action; 44 | switch (type){ 45 | case /*laya.filters.Filter.COLOR*/0x20: 46 | action=new ColorFilterActionGL(); 47 | break ; 48 | case /*laya.filters.Filter.BLUR*/0x10: 49 | action=new BlurFilterActionGL(); 50 | break ; 51 | case /*laya.filters.Filter.GLOW*/0x08: 52 | action=new GlowFilterActionGL(); 53 | break ; 54 | } 55 | return action; 56 | } 57 | } 58 | 59 | WebGLFilter.isInit=false; 60 | WebGLFilter.__init$=function(){ 61 | BlurFilterActionGL; 62 | ColorFilterActionGL; 63 | GlowFilterActionGL; 64 | Render; 65 | RunDriver;{ 66 | RunDriver.createFilterAction=function (type){ 67 | var action; 68 | switch (type){ 69 | case /*laya.filters.Filter.BLUR*/0x10: 70 | action=new FilterAction(); 71 | break ; 72 | case /*laya.filters.Filter.GLOW*/0x08: 73 | action=new FilterAction(); 74 | break ; 75 | case /*laya.filters.Filter.COLOR*/0x20: 76 | action=new ColorFilterAction(); 77 | break ; 78 | } 79 | return action; 80 | } 81 | } 82 | } 83 | 84 | return WebGLFilter; 85 | })() 86 | 87 | 88 | /** 89 | *模糊滤镜 90 | */ 91 | //class laya.filters.BlurFilter extends laya.filters.Filter 92 | var BlurFilter=(function(_super){ 93 | function BlurFilter(strength){ 94 | /**模糊滤镜的强度(值越大,越不清晰 */ 95 | this.strength=NaN; 96 | this.strength_sig2_2sig2_gauss1=[]; 97 | BlurFilter.__super.call(this); 98 | (strength===void 0)&& (strength=4); 99 | if (Render.isWebGL)WebGLFilter.enable(); 100 | this.strength=strength; 101 | this._action=RunDriver.createFilterAction(0x10); 102 | this._action.data=this; 103 | } 104 | 105 | __class(BlurFilter,'laya.filters.BlurFilter',_super); 106 | var __proto=BlurFilter.prototype; 107 | /** 108 | *@private 通知微端 109 | */ 110 | __proto.callNative=function(sp){ 111 | sp.conchModel &&sp.conchModel.blurFilter&&sp.conchModel.blurFilter(this.strength); 112 | } 113 | 114 | /** 115 | *@private 116 | *当前滤镜对应的操作器 117 | */ 118 | __getset(0,__proto,'action',function(){ 119 | return this._action; 120 | }); 121 | 122 | /** 123 | *@private 124 | *当前滤镜的类型 125 | */ 126 | __getset(0,__proto,'type',function(){ 127 | return 0x10; 128 | }); 129 | 130 | return BlurFilter; 131 | })(Filter) 132 | 133 | 134 | /** 135 | *发光滤镜(也可以当成阴影滤使用) 136 | */ 137 | //class laya.filters.GlowFilter extends laya.filters.Filter 138 | var GlowFilter=(function(_super){ 139 | function GlowFilter(color,blur,offX,offY){ 140 | /**滤镜的颜色*/ 141 | this._color=null; 142 | GlowFilter.__super.call(this); 143 | this._elements=new Float32Array(9); 144 | (blur===void 0)&& (blur=4); 145 | (offX===void 0)&& (offX=6); 146 | (offY===void 0)&& (offY=6); 147 | if (Render.isWebGL){ 148 | WebGLFilter.enable(); 149 | } 150 | this._color=new Color(color); 151 | this.blur=Math.min(blur,20); 152 | this.offX=offX; 153 | this.offY=offY; 154 | this._action=RunDriver.createFilterAction(0x08); 155 | this._action.data=this; 156 | } 157 | 158 | __class(GlowFilter,'laya.filters.GlowFilter',_super); 159 | var __proto=GlowFilter.prototype; 160 | /**@private */ 161 | __proto.getColor=function(){ 162 | return this._color._color; 163 | } 164 | 165 | /** 166 | *@private 通知微端 167 | */ 168 | __proto.callNative=function(sp){ 169 | sp.conchModel &&sp.conchModel.glowFilter&&sp.conchModel.glowFilter(this._color.strColor,this._elements[4],this._elements[5],this._elements[6]); 170 | } 171 | 172 | /** 173 | *@private 174 | *滤镜类型 175 | */ 176 | __getset(0,__proto,'type',function(){ 177 | return 0x08; 178 | }); 179 | 180 | /**@private */ 181 | __getset(0,__proto,'action',function(){ 182 | return this._action; 183 | }); 184 | 185 | /**@private */ 186 | /**@private */ 187 | __getset(0,__proto,'offY',function(){ 188 | return this._elements[6]; 189 | },function(value){ 190 | this._elements[6]=value; 191 | }); 192 | 193 | /**@private */ 194 | /**@private */ 195 | __getset(0,__proto,'offX',function(){ 196 | return this._elements[5]; 197 | },function(value){ 198 | this._elements[5]=value; 199 | }); 200 | 201 | /**@private */ 202 | /**@private */ 203 | __getset(0,__proto,'blur',function(){ 204 | return this._elements[4]; 205 | },function(value){ 206 | this._elements[4]=value; 207 | }); 208 | 209 | return GlowFilter; 210 | })(Filter) 211 | 212 | 213 | /** 214 | *@private 215 | */ 216 | //class laya.filters.webgl.BlurFilterActionGL extends laya.filters.webgl.FilterActionGL 217 | var BlurFilterActionGL=(function(_super){ 218 | function BlurFilterActionGL(){ 219 | this.data=null; 220 | BlurFilterActionGL.__super.call(this); 221 | } 222 | 223 | __class(BlurFilterActionGL,'laya.filters.webgl.BlurFilterActionGL',_super); 224 | var __proto=BlurFilterActionGL.prototype; 225 | __proto.setValueMix=function(shader){ 226 | shader.defines.add(this.data.type); 227 | var o=shader; 228 | } 229 | 230 | __proto.apply3d=function(scope,sprite,context,x,y){ 231 | var b=scope.getValue("bounds"); 232 | var shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 233 | shaderValue.setFilters([this.data]); 234 | var tMatrix=Matrix.EMPTY; 235 | tMatrix.identity(); 236 | context.ctx.drawTarget(scope,0,0,b.width,b.height,Matrix.EMPTY,"src",shaderValue); 237 | shaderValue.setFilters(null); 238 | } 239 | 240 | __proto.setValue=function(shader){ 241 | shader.strength=this.data.strength; 242 | var sigma=this.data.strength/3.0; 243 | var sigma2=sigma*sigma; 244 | this.data.strength_sig2_2sig2_gauss1[0]=this.data.strength; 245 | this.data.strength_sig2_2sig2_gauss1[1]=sigma2; 246 | this.data.strength_sig2_2sig2_gauss1[2]=2.0*sigma2; 247 | this.data.strength_sig2_2sig2_gauss1[3]=1.0/(2.0*Math.PI*sigma2); 248 | shader.strength_sig2_2sig2_gauss1=this.data.strength_sig2_2sig2_gauss1; 249 | } 250 | 251 | __getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.BLUR*/0x10;}); 252 | return BlurFilterActionGL; 253 | })(FilterActionGL) 254 | 255 | 256 | /** 257 | *@private 258 | */ 259 | //class laya.filters.webgl.GlowFilterActionGL extends laya.filters.webgl.FilterActionGL 260 | var GlowFilterActionGL=(function(_super){ 261 | function GlowFilterActionGL(){ 262 | this.data=null; 263 | this._initKey=false; 264 | this._textureWidth=0; 265 | this._textureHeight=0; 266 | GlowFilterActionGL.__super.call(this); 267 | } 268 | 269 | __class(GlowFilterActionGL,'laya.filters.webgl.GlowFilterActionGL',_super); 270 | var __proto=GlowFilterActionGL.prototype; 271 | Laya.imps(__proto,{"laya.filters.IFilterActionGL":true}) 272 | __proto.setValueMix=function(shader){} 273 | __proto.apply3d=function(scope,sprite,context,x,y){ 274 | var b=scope.getValue("bounds"); 275 | scope.addValue("color",this.data.getColor()); 276 | var w=b.width,h=b.height; 277 | this._textureWidth=w; 278 | this._textureHeight=h; 279 | var shaderValue; 280 | var mat=Matrix.TEMP; 281 | mat.identity(); 282 | shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 283 | shaderValue.setFilters([this.data]); 284 | context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue,null); 285 | shaderValue=Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,0); 286 | context.ctx.drawTarget(scope,0,0,this._textureWidth,this._textureHeight,mat,"src",shaderValue); 287 | return null; 288 | } 289 | 290 | __proto.setSpriteWH=function(sprite){ 291 | this._textureWidth=sprite.width; 292 | this._textureHeight=sprite.height; 293 | } 294 | 295 | __proto.setValue=function(shader){ 296 | shader.u_offsetX=this.data.offX; 297 | shader.u_offsetY=-this.data.offY; 298 | shader.u_strength=1.0; 299 | shader.u_blurX=this.data.blur; 300 | shader.u_blurY=this.data.blur; 301 | shader.u_textW=this._textureWidth; 302 | shader.u_textH=this._textureHeight; 303 | shader.u_color=this.data.getColor(); 304 | } 305 | 306 | __getset(0,__proto,'typeMix',function(){return /*laya.filters.Filter.GLOW*/0x08;}); 307 | GlowFilterActionGL.tmpTarget=function(scope,sprite,context,x,y){ 308 | var b=scope.getValue("bounds"); 309 | var out=scope.getValue("out"); 310 | out.end(); 311 | var tmpTarget=RenderTarget2D.create(b.width,b.height); 312 | tmpTarget.start(); 313 | var color=scope.getValue("color"); 314 | if (color){ 315 | tmpTarget.clear(color[0],color[1],color[2],0); 316 | } 317 | scope.addValue("tmpTarget",tmpTarget); 318 | } 319 | 320 | GlowFilterActionGL.startOut=function(scope,sprite,context,x,y){ 321 | var tmpTarget=scope.getValue("tmpTarget"); 322 | tmpTarget.end(); 323 | var out=scope.getValue("out"); 324 | out.start(); 325 | var color=scope.getValue("color"); 326 | if (color){ 327 | out.clear(color[0],color[1],color[2],0); 328 | } 329 | } 330 | 331 | GlowFilterActionGL.recycleTarget=function(scope,sprite,context,x,y){ 332 | var src=scope.getValue("src"); 333 | var tmpTarget=scope.getValue("tmpTarget"); 334 | tmpTarget.recycle(); 335 | } 336 | 337 | return GlowFilterActionGL; 338 | })(FilterActionGL) 339 | 340 | 341 | Laya.__init([WebGLFilter]); 342 | })(window,document,Laya); 343 | 344 | if (typeof define === 'function' && define.amd){ 345 | define('laya.core', ['require', "exports"], function(require, exports) { 346 | 'use strict'; 347 | Object.defineProperty(exports, '__esModule', { value: true }); 348 | for (var i in Laya) { 349 | var o = Laya[i]; 350 | o && o.__isclass && (exports[i] = o); 351 | } 352 | }); 353 | } -------------------------------------------------------------------------------- /open-data/bin/libs/matter-RenderLaya.js: -------------------------------------------------------------------------------- 1 | var Browser = laya.utils.Browser; 2 | 3 | var Composite = Matter.Composite; 4 | var Events = Matter.Events; 5 | var Bounds = Matter.Bounds; 6 | var Common = Matter.Common; 7 | var Vertices = Matter.Vertices; 8 | var Vector = Matter.Vector; 9 | var Sleeping = Matter.Sleeping; 10 | var Axes = Matter.Axes; 11 | var Body = Matter.Body; 12 | var SAT = Matter.SAT; 13 | var Contact = Matter.Contact; 14 | var Pair = Matter.Pair; 15 | var Detector = Matter.Detector; 16 | var Grid = Matter.Grid; 17 | 18 | var LayaRender = {}; 19 | 20 | (function() 21 | { 22 | var graphics, 23 | spriteCon, 24 | graphicsCon; 25 | 26 | LayaRender.create = function(options) 27 | { 28 | var defaults = { 29 | controller: LayaRender, 30 | element: null, 31 | canvas: null, 32 | mouse: null, 33 | options: 34 | { 35 | width: 800, 36 | height: 600, 37 | pixelRatio: 1, 38 | background: '#fafafa', 39 | wireframeBackground: '#222', 40 | hasBounds: !!options.bounds, 41 | enabled: true, 42 | wireframes: true, 43 | showSleeping: true, 44 | showDebug: false, 45 | showBroadphase: false, 46 | showBounds: false, 47 | showVelocity: false, 48 | showCollisions: false, 49 | showSeparations: false, 50 | showAxes: false, 51 | showPositions: false, 52 | showAngleIndicator: false, 53 | showIds: false, 54 | showShadows: false, 55 | showVertexNumbers: false, 56 | showConvexHulls: false, 57 | showInternalEdges: false, 58 | showMousePosition: false 59 | } 60 | }; 61 | 62 | var render = Common.extend(defaults, options); 63 | 64 | render.canvas = laya.renders.Render.canvas; 65 | render.context = laya.renders.Render.context.ctx; 66 | 67 | render.textures = {}; 68 | 69 | render.bounds = render.bounds || 70 | { 71 | min: 72 | { 73 | x: 0, 74 | y: 0 75 | }, 76 | max: 77 | { 78 | x: Laya.stage.width, 79 | y: Laya.stage.height 80 | } 81 | }; 82 | 83 | createContainer(render); 84 | setBackground(render); 85 | setPixelRatio(); 86 | 87 | return render; 88 | }; 89 | 90 | function createContainer(render) 91 | { 92 | var con = render.container; 93 | 94 | spriteCon = new Laya.Sprite(); 95 | graphicsCon = new Laya.Sprite(); 96 | 97 | render.spriteContainer = spriteCon; 98 | render.graphicsContainer = graphicsCon; 99 | 100 | con.addChild(spriteCon); 101 | con.addChild(graphicsCon); 102 | 103 | graphics = graphicsCon.graphics; 104 | } 105 | 106 | // 设置背景 107 | function setBackground(render) 108 | { 109 | var bg = render.options.background; 110 | // 纯色背景 111 | if (bg.length == 7 && bg[0] == '#') 112 | { 113 | spriteCon.graphics.drawRect( 114 | 0, 0, 115 | render.options.width, render.options.height, 116 | bg); 117 | } 118 | // 图片背景 119 | else 120 | { 121 | spriteCon.loadImage(bg); 122 | } 123 | } 124 | 125 | function setPixelRatio() 126 | { 127 | var pixelRatio; 128 | pixelRatio = 1; 129 | Laya.Render.canvas.setAttribute('data-pixel-ratio', pixelRatio); 130 | } 131 | 132 | /** 133 | * Renders the given `engine`'s `Matter.World` object. 134 | * This is the entry point for all rendering and should be called every time the scene changes. 135 | * @method world 136 | * @param {engine} engine 137 | */ 138 | LayaRender.world = function(engine) 139 | { 140 | var render = engine.render, 141 | world = engine.world, 142 | options = render.options, 143 | allConstraints = Composite.allConstraints(world), 144 | bodies = Composite.allBodies(world), 145 | constraints = [], 146 | i; 147 | 148 | // handle bounds 149 | if (options.hasBounds) 150 | { 151 | var boundsWidth = render.bounds.max.x - render.bounds.min.x, 152 | boundsHeight = render.bounds.max.y - render.bounds.min.y, 153 | boundsScaleX = boundsWidth / options.width, 154 | boundsScaleY = boundsHeight / options.height; 155 | 156 | // filter out bodies that are not in view 157 | for (i = 0; i < bodies.length; i++) 158 | { 159 | var body = bodies[i]; 160 | body.render.sprite.visible = Bounds.overlaps(body.bounds, render.bounds); 161 | } 162 | 163 | // filter out constraints that are not in view 164 | for (i = 0; i < allConstraints.length; i++) 165 | { 166 | var constraint = allConstraints[i], 167 | bodyA = constraint.bodyA, 168 | bodyB = constraint.bodyB, 169 | pointAWorld = constraint.pointA, 170 | pointBWorld = constraint.pointB; 171 | 172 | if (bodyA) pointAWorld = Vector.add(bodyA.position, constraint.pointA); 173 | if (bodyB) pointBWorld = Vector.add(bodyB.position, constraint.pointB); 174 | 175 | if (!pointAWorld || !pointBWorld) 176 | continue; 177 | 178 | if (Bounds.contains(render.bounds, pointAWorld) || Bounds.contains(render.bounds, pointBWorld)) 179 | constraints.push(constraint); 180 | } 181 | 182 | // transform the view 183 | // context.scale(1 / boundsScaleX, 1 / boundsScaleY); 184 | // context.translate(-render.bounds.min.x, -render.bounds.min.y); 185 | } 186 | else 187 | { 188 | constraints = allConstraints; 189 | } 190 | 191 | graphics.clear(); 192 | for (i = 0; i < bodies.length; i++) 193 | LayaRender.body(engine, bodies[i]); 194 | 195 | for (i = 0; i < constraints.length; i++) 196 | LayaRender.constraint(engine, constraints[i]); 197 | }; 198 | LayaRender.body = function(engine, body) 199 | { 200 | var render = engine.render, 201 | bodyRender = body.render; 202 | 203 | if (!bodyRender.visible) 204 | { 205 | return; 206 | } 207 | 208 | var spInfo = bodyRender.sprite; 209 | var sp = body.sprite; 210 | if (bodyRender.sprite && bodyRender.sprite.texture) 211 | { 212 | // initialize body sprite if not existing 213 | if (!sp) 214 | { 215 | sp = body.sprite = createBodySprite(spInfo.xOffset, spInfo.yOffset); 216 | sp.loadImage(spInfo.texture); 217 | } 218 | 219 | sp.scale(spInfo.xScale, spInfo.yScale); 220 | sp.pos(body.position.x, body.position.y); 221 | sp.rotation = body.angle * 180 / Math.PI; 222 | } 223 | else 224 | { 225 | var options = render.options; 226 | // handle compound parts 227 | for (k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++) 228 | { 229 | part = body.parts[k]; 230 | 231 | if (!part.render.visible) 232 | continue; 233 | 234 | var fillStyle = options.wireframes ? null : part.render.fillStyle; 235 | var lineWidth = part.render.lineWidth; 236 | var strokeStyle = part.render.strokeStyle; 237 | // part polygon 238 | if (part.circleRadius) 239 | { 240 | graphics.drawCircle(part.position.x, part.position.y, part.circleRadius, fillStyle, strokeStyle, lineWidth); 241 | } 242 | else 243 | { 244 | var path = []; 245 | path.push(part.vertices[0].x, part.vertices[0].y); 246 | 247 | for (var j = 1; j < part.vertices.length; j++) 248 | { 249 | if (!part.vertices[j - 1].isInternal || showInternalEdges) 250 | { 251 | path.push(part.vertices[j].x, part.vertices[j].y); 252 | } 253 | else 254 | { 255 | path.push(part.vertices[j].x, part.vertices[j].y); 256 | } 257 | 258 | if (part.vertices[j].isInternal && !showInternalEdges) 259 | { 260 | path.push(part.vertices[(j + 1) % part.vertices.length].x, part.vertices[(j + 1) % part.vertices.length].y); 261 | } 262 | } 263 | 264 | graphics.drawPoly(0, 0, path, fillStyle, strokeStyle, lineWidth); 265 | } 266 | } 267 | } 268 | }; 269 | 270 | LayaRender.constraint = function(engine, constraint) 271 | { 272 | var sx, sy, ex, ey; 273 | if (!constraint.render.visible || !constraint.pointA || !constraint.pointB) 274 | { 275 | return; 276 | } 277 | 278 | var bodyA = constraint.bodyA, 279 | bodyB = constraint.bodyB; 280 | 281 | if (bodyA) 282 | { 283 | sx = bodyA.position.x + constraint.pointA.x; 284 | sy = bodyA.position.y + constraint.pointA.y; 285 | } 286 | else 287 | { 288 | sx = constraint.pointA.x; 289 | sy = constraint.pointA.y; 290 | } 291 | 292 | if (bodyB) 293 | { 294 | ex = bodyB.position.x + constraint.pointB.x; 295 | ey = bodyB.position.y + constraint.pointB.y; 296 | } 297 | else 298 | { 299 | ex = constraint.pointB.x; 300 | ey = constraint.pointB.y; 301 | } 302 | 303 | graphics.drawLine( 304 | sx, sy, ex, ey, 305 | constraint.render.strokeStyle, 306 | constraint.render.lineWidth); 307 | }; 308 | 309 | function createBodySprite(xOffset, yOffset) 310 | { 311 | var sp = new Laya.Sprite(); 312 | 313 | sp.pivot(xOffset, yOffset); 314 | sp.pos(-9999, -9999); 315 | spriteCon.addChild(sp); 316 | 317 | return sp; 318 | } 319 | })(); -------------------------------------------------------------------------------- /open-data/bin/libs/min/laya.d3Plugin.min.js: -------------------------------------------------------------------------------- 1 | !function(t,i,e){e.un,e.uns,e.static;var n=e.class,r=e.getset,a=(e.__newvec,laya.d3.component.Component3D);laya.d3.core.ComponentNode,laya.d3.core.MeshTerrainSprite3D,laya.d3.core.Sprite3D,function(i){function t(){this._meshTerrainSprite3D=null,this._finder=null,this._setting=null,this.grid=null,t.__super.call(this)}n(t,"laya.d3.component.PathFind",i);var e=t.prototype;e._load=function(t){if(!(t instanceof laya.d3.core.MeshTerrainSprite3D))throw new Error("PathFinding: The owner must MeshTerrainSprite3D!");i.prototype._load.call(this,t),this._meshTerrainSprite3D=t},e.findPath=function(t,i,e,n){var r=this._meshTerrainSprite3D.minX,a=this._meshTerrainSprite3D.minZ,h=this._meshTerrainSprite3D.width/this.grid.width,s=this._meshTerrainSprite3D.depth/this.grid.height,o=h/2,d=s/2,l=Math.floor((t-r)/h),f=Math.floor((i-a)/s),c=Math.floor((e-r)/h),u=Math.floor((n-a)/s),p=this.grid.width-1,_=this.grid.height-1;p"+(e=e.replace(/
/g,"
"))+"").replace(f.spacePattern,f.char255);var n=p.parseXMLFromString(e);f._parseXML(t,n.childNodes[0].childNodes,i)},f._parseXML=function(t,e,i,n){var h=0,l=0;if(e.join||e.item)for(h=0,l=e.length;ht.height&&(t.height=v),[g,v]},U._multiLineLayout2=function(t){var e=new Array;t._addChildsToLayout(e);var i,n,h,l,s,r=0,a=e.length,o=t._getCSSStyle(),d=o.letterSpacing,u=o.leading,c=o.lineHeight,f=o._widthAuto()||!o.wordWrap,_=f?999999:t.width,g=(t.height,0),y=o.italic?o.fontSize/3:0,p=2-o._getAlign(),m=o._getValign(),w=0!==m||0!==p||0!=c,x=0,v=0,S=0,L=0,T=new Array,C=T[0]=new P,E=!1,M=!1;C.h=0,o.italic&&(_-=o.fontSize/3);var H=0,I=!0;function A(){C.y=v,v+=C.h+u,0==C.h&&(v+=c),C.mWidth=H,H=0,C=new P,T.push(C),C.h=0,E=!(I=!(x=0))}for(r=0;rt.height&&(t.height=v),r=0,a=T.length;rt)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(); -------------------------------------------------------------------------------- /open-data/bin/unpack.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /open-data/bin/version.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /open-data/laya/.laya: -------------------------------------------------------------------------------- 1 | 2 | img,temp,sound 3 | embed 4 | png,jpg 5 | bin/res/atlas 6 | bin 7 | src/ui 8 | 9 | 11 | 0 12 | bin/ui.json 13 | Box,List,Tab,RadioGroup,ViewStack,Panel,HBox,VBox,Tree,Sprite 14 | View,Dialog 15 | 16 | 1 17 | 18 | 80 19 | 20 | 21 | 23 | 2048 24 | 2048 25 | 512 26 | 512 27 | false 28 | false 29 | -------------------------------------------------------------------------------- /open-data/laya/assets/rank/first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/open-data/laya/assets/rank/first.png -------------------------------------------------------------------------------- /open-data/laya/assets/rank/second.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/open-data/laya/assets/rank/second.png -------------------------------------------------------------------------------- /open-data/laya/assets/rank/third.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/open-data/laya/assets/rank/third.png -------------------------------------------------------------------------------- /open-data/laya/pages/rank.ui: -------------------------------------------------------------------------------- 1 | { 2 | "x":0, 3 | "type":"View", 4 | "selectedBox":1, 5 | "selecteID":4, 6 | "props":{"width":1334,"top":0,"sceneColor":"#000000","left":0,"height":750}, 7 | "nodeParent":-1, 8 | "label":"View", 9 | "isOpen":true, 10 | "isDirectory":true, 11 | "isAniNode":true, 12 | "hasChild":true, 13 | "compId":1, 14 | "child":[ 15 | { 16 | "x":15, 17 | "type":"List", 18 | "props":{"y":217,"x":9,"width":464,"var":"rankList","height":401}, 19 | "nodeParent":1, 20 | "label":"List(rankList)", 21 | "isOpen":true, 22 | "isDirectory":true, 23 | "isAniNode":true, 24 | "hasChild":true, 25 | "compId":11, 26 | "child":[ 27 | { 28 | "x":30, 29 | "type":"Box", 30 | "props":{"width":464,"renderType":"render","height":88}, 31 | "nodeParent":11, 32 | "label":"Box", 33 | "isOpen":true, 34 | "isDirectory":true, 35 | "isAniNode":false, 36 | "hasChild":true, 37 | "compId":2, 38 | "child":[ 39 | { 40 | "x":45, 41 | "type":"Rect", 42 | "props":{"y":0,"x":0,"width":464,"lineWidth":0,"height":86,"fillColor":"#c1c0ba"}, 43 | "nodeParent":2, 44 | "label":"Rect", 45 | "isDirectory":false, 46 | "isAniNode":false, 47 | "hasChild":false, 48 | "compId":3, 49 | "child":[ 50 | ] 51 | }, 52 | { 53 | "x":45, 54 | "type":"Image", 55 | "props":{"y":7,"x":4,"skin":"rank/first.png","name":"trophy"}, 56 | "nodeParent":2, 57 | "label":"Image(trophy)", 58 | "isDirectory":false, 59 | "isAniNode":false, 60 | "hasChild":false, 61 | "compId":4, 62 | "child":[ 63 | ] 64 | }, 65 | { 66 | "x":45, 67 | "type":"Image", 68 | "props":{"y":8,"x":89,"width":70,"name":"avatar","height":70}, 69 | "nodeParent":2, 70 | "label":"Image(avatar)", 71 | "isDirectory":false, 72 | "isAniNode":false, 73 | "hasChild":false, 74 | "compId":5, 75 | "child":[ 76 | ] 77 | }, 78 | { 79 | "x":45, 80 | "type":"Text", 81 | "props":{"y":30,"x":170,"width":120,"text":"1","overflow":"hidden","name":"nickname","height":26,"fontSize":26,"font":"SimSun","color":"#84592E","align":"left"}, 82 | "nodeParent":2, 83 | "label":"Text(nickname)", 84 | "isDirectory":false, 85 | "isAniNode":false, 86 | "hasChild":false, 87 | "compId":6, 88 | "child":[ 89 | ] 90 | }, 91 | { 92 | "x":45, 93 | "type":"Text", 94 | "props":{"y":10,"x":298,"width":81,"text":"总分:","name":"scoreText","height":26,"fontSize":26,"font":"SimSun","color":"#BA9F7B","align":"left"}, 95 | "nodeParent":2, 96 | "label":"Text(scoreText)", 97 | "isDirectory":false, 98 | "isAniNode":false, 99 | "hasChild":false, 100 | "compId":7, 101 | "child":[ 102 | ] 103 | }, 104 | { 105 | "x":45, 106 | "type":"Text", 107 | "props":{"y":10,"x":366,"width":89,"text":"99999","name":"scoreNum","height":26,"fontSize":26,"font":"SimSun","color":"#F07538","align":"center"}, 108 | "nodeParent":2, 109 | "label":"Text(scoreNum)", 110 | "isDirectory":false, 111 | "isAniNode":false, 112 | "hasChild":false, 113 | "compId":8, 114 | "child":[ 115 | ] 116 | }, 117 | { 118 | "x":45, 119 | "type":"Text", 120 | "props":{"y":47,"x":307,"width":134,"text":"2018/7/5","overflow":"hidden","name":"dateString","height":26,"fontSize":26,"font":"SimSun","color":"#BA9F7B","align":"right"}, 121 | "nodeParent":2, 122 | "label":"Text(dateString)", 123 | "isDirectory":false, 124 | "isAniNode":false, 125 | "hasChild":false, 126 | "compId":10, 127 | "child":[ 128 | ] 129 | }] 130 | }] 131 | }], 132 | "animations":[ 133 | { 134 | "nodes":[ 135 | ], 136 | "name":"ani1", 137 | "id":1, 138 | "frameRate":24, 139 | "action":0 140 | }] 141 | } -------------------------------------------------------------------------------- /open-data/open-data.laya: -------------------------------------------------------------------------------- 1 | {"proName":"open-data","engineType":2,"proType":1,"layaProType":1} -------------------------------------------------------------------------------- /open-data/release_opendata.bat: -------------------------------------------------------------------------------- 1 | cd /d %~dp0 2 | set srcDir=release\wxgame 3 | set dstDir=..\wxgame\src\openDataContext 4 | 5 | del /f /s /q %srcDir%\res\*.* 6 | rd /s /q %srcDir%\res 7 | del /f /s /q %srcDir%\libs\*.* 8 | rd /s /q %srcDir%\libs 9 | del /f /s /q %srcDir%\js\*.* 10 | rd /s /q %srcDir%\js 11 | move %srcDir%\game.js %srcDir%\index.js 12 | del /f /s /q %dstDir%\*.* 13 | Xcopy %srcDir% %dstDir% /s /e /y -------------------------------------------------------------------------------- /open-data/src/Main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * name; 3 | */ 4 | class Main{ 5 | protected wxSystemInfo:any = null; 6 | protected static instance:Main; 7 | protected needReload:boolean = true; 8 | //排行页 9 | protected rankView:laya.ui.View= null; 10 | 11 | public static GetInstance():Main 12 | { 13 | if(null == Main.instance) 14 | { 15 | Main.instance = new Main(); 16 | } 17 | return Main.instance; 18 | } 19 | 20 | constructor() 21 | { 22 | this.needReload = (this.versionCompare(Laya.version, '1.7.20') <= 0); 23 | } 24 | 25 | protected versionCompare(versionOne:string, versionTwo:string):number 26 | { 27 | let arrOne = versionOne.split('.'); 28 | let arrTwo = versionTwo.split('.'); 29 | for (let i = 0, len = arrOne.length; i < len; i++) { 30 | let numberOne = parseInt(arrOne[i]); 31 | let numberTwo = parseInt(arrTwo[i]); 32 | if (numberOne < numberTwo) { 33 | return -1; 34 | } else if (numberOne > numberTwo) { 35 | return 1; 36 | } 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | public getWxSystemInfo():any 43 | { 44 | if (Laya.Browser.onMiniGame) { 45 | if (this.wxSystemInfo == null) { 46 | this.wxSystemInfo = Laya.Browser.window.wx.getSystemInfoSync(); 47 | } 48 | } 49 | 50 | return this.wxSystemInfo; 51 | } 52 | 53 | public start() 54 | { 55 | Laya.MiniAdpter.init(true, true); 56 | Laya.init(1334, 750); 57 | 58 | this.initOpenData(); 59 | this.initStage(); 60 | } 61 | 62 | //初始化stage 63 | protected initStage(): void 64 | { 65 | if (Laya.Browser.onMiniGame) { 66 | let systemInfo = this.getWxSystemInfo(); 67 | if (systemInfo.windowWidth * 750 > systemInfo.windowHeight * 1334) { //宽屏,高度固定 68 | Laya.stage.scaleMode = Laya.Stage.SCALE_FIXED_HEIGHT; 69 | } else { 70 | Laya.stage.scaleMode = Laya.Stage.SCALE_FIXED_WIDTH; 71 | } 72 | } else { 73 | Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL; 74 | } 75 | 76 | //自动横屏 77 | Laya.stage.screenMode = Laya.Stage.SCREEN_HORIZONTAL; 78 | Laya.stage.alignV = Laya.Stage.ALIGN_CENTER; 79 | Laya.stage.alignH = Laya.Stage.ALIGN_CENTER; 80 | Laya.stage.bgColor = "#627069"; 81 | } 82 | 83 | public getMondayTimestamp():number 84 | { 85 | let newDate = new Date(); 86 | let day = newDate.getDay(); 87 | let hour = newDate.getHours(); 88 | let minute = newDate.getMinutes(); 89 | let second = newDate.getSeconds(); 90 | let diffSeconds = ((7 + day - 1) % 7) * 24 * 3600 + hour * 3600 + minute * 60 + second; 91 | let timestamp = newDate.valueOf()/1000 - diffSeconds; 92 | //console.log((new Date(timestamp * 1000)).toLocaleDateString()); 93 | return timestamp; 94 | } 95 | 96 | protected increaseWeekScore():void 97 | { 98 | if (Laya.Browser.onMiniGame) { 99 | let wx = Laya.Browser.window.wx; 100 | let mondayTimestamp = Main.GetInstance().getMondayTimestamp(); 101 | wx.getUserCloudStorage({ 102 | keyList: ['week_score'], // 你要获取的、托管在微信后台的key 103 | success: res => { 104 | let nowNum:number = 0; 105 | let kvLen = res["KVDataList"].length; 106 | for (let j = 0; j < kvLen; j++) { 107 | if (res["KVDataList"][j]["key"] == 'week_score') { 108 | let valueJson = JSON.parse(res["KVDataList"][j]["value"]); 109 | if (valueJson["wxgame"]["update_time"] >= mondayTimestamp) { //是本周的 110 | nowNum = valueJson["wxgame"]["score"]; 111 | } 112 | break; 113 | } 114 | } 115 | 116 | nowNum++; 117 | wx.setUserCloudStorage({ 118 | KVDataList: [{ "key": 'week_score', "value": JSON.stringify({"wxgame":{"score":nowNum,"update_time": Math.round((new Date()).valueOf()/1000)}}) }], 119 | success: res => { 120 | console.log("设置周数据成功," + res); 121 | }, 122 | fail: res => { 123 | console.log("设置周数据失败," + res); 124 | } 125 | }); 126 | } 127 | }); 128 | } 129 | } 130 | 131 | public initOpenData():void 132 | { 133 | if (Laya.Browser.onMiniGame) { 134 | let wx = Laya.Browser.window.wx; 135 | wx.onMessage(data => { 136 | let MiniFileMgr = laya.wx.mini.MiniFileMgr; 137 | //console.log(data); 138 | if (data.cmd != undefined) { 139 | if (data.cmd == 'addScore') { 140 | this.increaseWeekScore(); 141 | } else if (data.cmd == 'showRank') { 142 | (this.rankView as views.Rank).showRankList(); 143 | } else if (data.cmd == 'hideRank') { 144 | 145 | } else if (data.cmd == 'loadRes') { 146 | this.loadResource(); 147 | } 148 | } else { 149 | if (data['isLoad'] == "filedata") { 150 | MiniFileMgr.ziyuFileData[data.url] = data.data;//文本数据 151 | } else if(data['isLoad']=="opendatacontext"){ 152 | if(data.url){ 153 | MiniFileMgr.ziyuFileData[data.url]=data.atlasdata; 154 | (MiniFileMgr as any).ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl; 155 | } 156 | }else if(data['isLoad']=="openJsondatacontext"){ 157 | if(data.url){ 158 | MiniFileMgr.ziyuFileData[data.url]=data.atlasdata; 159 | } 160 | }else if(data['isLoad']=="openJsondatacontextPic"){ 161 | (MiniFileMgr as any).ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl; 162 | } else if (data['isLoad'] == "filenative") { 163 | if(data.isAdd) 164 | MiniFileMgr.filesListObj[data.url] = data.data; 165 | else 166 | delete MiniFileMgr.filesListObj[data.url]; 167 | } else if (data['type'] == "resizeShared") { 168 | let tempMatrix = data.data.matrix; 169 | let matrix:Laya.Matrix = new Laya.Matrix(); 170 | matrix.a = tempMatrix.a; 171 | matrix.b = tempMatrix.b; 172 | matrix.c = tempMatrix.c; 173 | matrix.d = tempMatrix.d; 174 | Laya.stage._canvasTransform = matrix;//重新设置矩阵 175 | } 176 | } 177 | }); 178 | } 179 | } 180 | 181 | protected loadResource():void 182 | { 183 | Laya.loader.load(this.needReload ? "rankRes/rank.atlas" : "res/atlas/rank.atlas", Laya.Handler.create(this, this.loadEnd), null, Laya.Loader.ATLAS); 184 | } 185 | 186 | protected loadEnd():void 187 | { 188 | this.rankView = new views.Rank(); 189 | Laya.stage.addChild(this.rankView); 190 | } 191 | } 192 | 193 | Main.GetInstance().start(); -------------------------------------------------------------------------------- /open-data/src/ui/layaUI.max.all.ts: -------------------------------------------------------------------------------- 1 | 2 | import View=laya.ui.View; 3 | import Dialog=laya.ui.Dialog; 4 | module ui { 5 | export class rankUI extends View { 6 | public rankList:Laya.List; 7 | 8 | public static uiView:any ={"type":"View","props":{"width":1334,"top":0,"left":0,"height":750},"child":[{"type":"List","props":{"y":217,"x":9,"width":464,"var":"rankList","height":401},"child":[{"type":"Box","props":{"width":464,"renderType":"render","height":88},"child":[{"type":"Rect","props":{"y":0,"x":0,"width":464,"lineWidth":0,"height":86,"fillColor":"#c1c0ba"}},{"type":"Image","props":{"y":7,"x":4,"skin":"rank/first.png","name":"trophy"}},{"type":"Image","props":{"y":8,"x":89,"width":70,"name":"avatar","height":70}},{"type":"Text","props":{"y":30,"x":170,"width":120,"text":"1","overflow":"hidden","name":"nickname","height":26,"fontSize":26,"font":"SimSun","color":"#84592E","align":"left"}},{"type":"Text","props":{"y":10,"x":298,"width":81,"text":"总分:","name":"scoreText","height":26,"fontSize":26,"font":"SimSun","color":"#BA9F7B","align":"left"}},{"type":"Text","props":{"y":10,"x":366,"width":89,"text":"99999","name":"scoreNum","height":26,"fontSize":26,"font":"SimSun","color":"#F07538","align":"center"}},{"type":"Text","props":{"y":47,"x":307,"width":134,"text":"2018/7/5","overflow":"hidden","name":"dateString","height":26,"fontSize":26,"font":"SimSun","color":"#BA9F7B","align":"right"}}]}]}]}; 9 | constructor(){ super()} 10 | createChildren():void { 11 | View.regComponent("Text",laya.display.Text); 12 | 13 | super.createChildren(); 14 | this.createView(ui.rankUI.uiView); 15 | 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /open-data/src/views/Rank.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * name 3 | */ 4 | module views{ 5 | export class Rank extends ui.rankUI{ 6 | protected trophyList = ["rank/first.png", "rank/second.png", "rank/third.png"]; 7 | constructor(){ 8 | super(); 9 | 10 | this.rankList.vScrollBarSkin = ""; 11 | this.rankList.renderHandler = new Laya.Handler(this,this.rankListRender); 12 | this.rankList.array = []; 13 | } 14 | 15 | public showInit():void 16 | { 17 | 18 | } 19 | 20 | public showRankList():void 21 | { 22 | //获取好友排行榜数据 23 | let wx = Laya.Browser.window.wx; 24 | wx.getFriendCloudStorage({ 25 | keyList: ['week_score'], // 你要获取的、托管在微信后台的key 26 | success: res => { 27 | this.processFriendDataList(res.data); 28 | this.rankList.scrollTo(0); 29 | } 30 | }); 31 | //展示 32 | //this.mockList(); 33 | } 34 | 35 | protected processFriendDataList(data:any):void 36 | { 37 | let mondayTimestamp = Main.GetInstance().getMondayTimestamp(); 38 | let resultArr = []; 39 | 40 | //console.log(data); 41 | let len = data.length; 42 | for (let i = 0; i < len; i++) { 43 | let kvLen = data[i]["KVDataList"].length; 44 | for (let j = 0; j < kvLen; j++) { 45 | if (data[i]["KVDataList"][j]["key"] == 'week_score') { 46 | let valueJson = JSON.parse(data[i]["KVDataList"][j]["value"]); 47 | if (valueJson["wxgame"]["update_time"] >= mondayTimestamp) { //是本周的 48 | let newDate = new Date(valueJson["wxgame"]["update_time"] * 1000); 49 | resultArr.push({ 50 | "avatar": data[i]["avatarUrl"], 51 | "nickname":data[i]["nickname"], 52 | "scoreNum": valueJson["wxgame"]["score"], 53 | "dateString": newDate.getFullYear() + "/" + (newDate.getMonth() + 1) + "/" + newDate.getDate() 54 | }); 55 | } 56 | break; 57 | } 58 | } 59 | } 60 | resultArr.sort(function(a:any, b:any):number{return b["scoreNum"] - a["scoreNum"];}) 61 | this.rankList.array = resultArr; 62 | } 63 | 64 | public mockList():void 65 | { 66 | let num = Math.round(1 + 10 * Math.random()); 67 | let arr = []; 68 | for (let i = 0; i < num; i++) { 69 | arr.push({"avatar": "", "nickname":"测试" + i, "scoreNum": Math.round(num * Math.random()), "dateString": "2018/9/30"}); 70 | } 71 | arr.sort(function(a:any, b:any):number{return b["scoreNum"] - a["scoreNum"];}) 72 | this.rankList.array = arr; 73 | } 74 | 75 | protected rankListRender(cell:Laya.Box,index:number) 76 | { 77 | let arr = this.rankList.array; 78 | if (index >= arr.length) { 79 | return; 80 | } 81 | (cell.getChildByName("avatar") as Laya.Image).skin = arr[index]["avatar"]; 82 | (cell.getChildByName("nickname") as Laya.Text).text = arr[index]["nickname"]; 83 | (cell.getChildByName("scoreNum") as Laya.Text).text = arr[index]["scoreNum"]; 84 | (cell.getChildByName("dateString") as Laya.Text).text = arr[index]["dateString"]; 85 | (cell.getChildByName("trophy") as Laya.Image).skin = (this.trophyList[index] != undefined ? this.trophyList[index] : ""); 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /open-data/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "sourceMap": true 6 | }, 7 | "exclude": [ 8 | "node_modules" 9 | ] 10 | } -------------------------------------------------------------------------------- /view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/view.png -------------------------------------------------------------------------------- /wxgame/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tianhe1986/laya-wx-rank-ts/66156771f6491ce1899e9effe6d68d35a49329e2/wxgame/.gitkeep --------------------------------------------------------------------------------