Commit f959095d authored by zjz1994's avatar zjz1994

Merge branch 'dev' of http://gitlab2.dui88.com/laoqifeng/zeroing-libs into zjz

# Conflicts:
#	src/custom/food-fell/debug/main.js.map
合并dev
parents 29380685 b5cf2632
File added
...@@ -89,3 +89,4 @@ typings/ ...@@ -89,3 +89,4 @@ typings/
# DynamoDB Local files # DynamoDB Local files
.dynamodb/ .dynamodb/
.DS_Store
\ No newline at end of file
## 一、工程目录 http://gitlab2.dui88.com/laoqifeng/zeroing-libs
切换`dev`分支,在`dev`分支新增修改
## 二、文件路径及大概用途
- 1、`dist`文件下即为打包后的json用于发布版本使用
- 2、src为代码路径
* 1、`src/custom` 为所有自定义模块的源码,也是新增或修改的代码路径
* 2、`src/custom` 路径下每一个自定义模块单独一个项目名字文件夹
- 3、通用代码脚本
* 1、`meta.json`文件
- 1、`name`为项目名字
- 2、`desc` 为项目描述
- 3、`props` 为配置属性,提供对外可配置内容
- 4、`assets` 为资源加载属性,加载路径需跟`uuid`相匹配,注意对应类型
- 5、`events` 为事件属性,与外界用事件传递消息,注意每个模块的时间名
* 2、`debug文件`
- 1、该文件是本地运行使用文件
- 2、可修改`app.js`文件里的事件名,而去执行对应的模块代码
* 3、`src/custom/src`为每个模块的项目代码
- 1、`index.ts`为初始化脚本可以通用
- 2、`props.ts`为获取meta.json文件中的配置使用,可通用的脚本
- 3、`game`文件为自身项目的逻辑代码
## 三、本地运行
- 1、安装本地启动服务`game-cli` 地址:http://cf.dui88.com/display/dbyw/game-cli
- 2、运行http服务,执行src/custom下对应的自定义模块下的`debug`文件
- 3、`yarn build-custom -s 模块名 -w` 为保存档次代码修改也为打包指令
- 4、执行保存指令后在浏览器刷新图标处右键选择`清空缓存`并硬性重新加载,这样可以 保证运行最新修改的代码(劳工手工传授)
## 四、代码执行过程
- 1、入口为`app.js` 读取meta.json文件下的配置,加载对应资源,添加自定义模块
- 2、配置加载成功后使用引擎api将对应模块添加到显示到显示舞台
- 3、而后执行src/custom/对应模块`/src/index.ts` 初始化项目所需要的东西
- 4、而后执行props.ts获取meta.json中的props配置
- 5、而后创建项目逻辑入口脚本实例(例如GameWrapper)
- 6、而后即为对应模块逻辑代码
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"name": "拆礼盒",
"desc": "拆礼盒模块",
"props": {
"initX": {
"alias": "游戏场景初始X位置",
"type": "number",
"default": 0
},
"initY": {
"alias": "游戏场景初始Y位置",
"type": "number",
"default": 0
},
"gameStageWidth": {
"alias": "游戏场景宽度",
"type": "number",
"default": 534
},
"gameStageHeight": {
"alias": "游戏场景高度",
"type": "number",
"default": 408
}
},
"assets": [
{
"name": "底座",
"url": "//yun.duiba.com.cn/aurora/assets/d6ed718f0d236febaa4d1331950e5a190f225cb5.png",
"uuid": "7a0f8b48-449c-46d9-bd80-64455a30e641",
"ext": ".png"
},
{
"name": "点缀",
"url": "//yun.duiba.com.cn/aurora/assets/e08f680bbd26c4dcc47fd67ee2e145c46d6fcd1a.png",
"uuid": "c7426dc4-d631-4947-accc-015666277208",
"ext": ".png"
},
{
"name": "初始礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/b9bb4e52c3734025fc96a92cb574c92209927b61.svga",
"uuid": "947cb448-1992-49f1-a9ed-e359b944953a",
"ext": ".svga"
},
{
"name": "拆礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/8e86f8696710de414f0f36dc330db6e4bd0683d6.svga",
"uuid": "d9222991-064c-4816-85ee-6964ba78fbd0",
"ext": ".svga"
}
],
"events": {
"in": {
"open-gift-game-init": {
"alias": "重置"
},
"open-gift-game-start": {
"alias": "开始",
"data": {
"prize": true
}
}
},
"out": {
"open-gift-game-end": {
"alias": "动画完毕",
"data": null
}
}
},
"id": "open-gift",
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof define === 'function' && define.amd ? define(['tslib'], factory) :\n\t(global = global || self, global['open-gift'] = factory(global.tslib));\n}(this, (function (tslib) { 'use strict';\n\n\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\t//# sourceMappingURL=props.js.map\n\n\tfunction getTexture(uuid) {\n\t return engine.Texture.from(getAssetByUUID(uuid).uuid);\n\t}\n\tfunction getTextureByName(name) {\n\t return getTexture(engine.getAssetByName(name).uuid);\n\t}\n\tfunction createSvga(name, anchorName) {\n\t var inst = new svga.Svga();\n\t inst.source = 'asset://' + engine.getAssetByName(name).uuid;\n\t return inst;\n\t}\n\t//# sourceMappingURL=utils.js.map\n\n\tvar GameView = (function (_super) {\n\t tslib.__extends(GameView, _super);\n\t function GameView() {\n\t var _this = _super.call(this) || this;\n\t _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);\n\t return _this;\n\t }\n\t GameView.prototype.setup = function () {\n\t if (this._hasSetup) {\n\t return;\n\t }\n\t this._hasSetup = true;\n\t this.NpcBg = new engine.Container();\n\t this.NpcBg.x = props.initX;\n\t this.NpcBg.y = props.initY;\n\t this.addChild(this.NpcBg);\n\t this.bottomCircle = new engine.Sprite(getTextureByName('底座'));\n\t this.bottomCircle.x = 17;\n\t this.bottomCircle.y = 305;\n\t this.loveDot = new engine.Sprite(getTextureByName('点缀'));\n\t this.loveDot.x = 0;\n\t this.loveDot.y = 6;\n\t this.giftboxSvga = createSvga('初始礼盒');\n\t this.giftboxSvga.x = 105;\n\t this.giftboxSvga.y = 37;\n\t this.giftAfterSvga = createSvga(\"拆礼盒\");\n\t this.giftAfterSvga.x = 105;\n\t this.giftAfterSvga.y = 0;\n\t this.giftAfterSvga.visible = false;\n\t this.NpcBg.addChild(this.bottomCircle);\n\t this.NpcBg.addChild(this.giftboxSvga);\n\t this.NpcBg.addChild(this.giftAfterSvga);\n\t this.NpcBg.addChild(this.loveDot);\n\t this.giftboxSvga.play(false, true);\n\t };\n\t GameView.prototype.reset = function () {\n\t this.giftboxSvga.visible = true;\n\t this.giftAfterSvga.visible = false;\n\t };\n\t GameView.prototype.start = function () {\n\t this.giftAfterSvga.visible = true;\n\t this.giftboxSvga.visible = false;\n\t this.giftAfterSvga.play(false, false);\n\t this.giftAfterSvga.once(engine.Event.END_FRAME, function () {\n\t engine.globalEvent.dispatchEvent('open-gift-game-end');\n\t }, this);\n\t };\n\t GameView.prototype.resume = function () {\n\t this.reset();\n\t this.start();\n\t };\n\t return GameView;\n\t}(engine.Container));\n\n\tvar GameWrapper = (function (_super) {\n\t tslib.__extends(GameWrapper, _super);\n\t function GameWrapper() {\n\t var _this = _super.call(this) || this;\n\t engine.globalEvent.addEventListener('open-gift-game-init', _this.reset, _this);\n\t engine.globalEvent.addEventListener('open-gift-game-start', _this.start, _this);\n\t var gameView = _this._gameView = new GameView();\n\t _this.addChild(gameView);\n\t return _this;\n\t }\n\t GameWrapper.prototype.reset = function (event) {\n\t injectProps(event.data);\n\t this._gameView.visible = true;\n\t this._gameView.reset();\n\t };\n\t GameWrapper.prototype.start = function (event) {\n\t console.log('监听开始');\n\t injectProps(event.data);\n\t this._gameView.start();\n\t };\n\t GameWrapper.prototype.clear = function () {\n\t this._gameView.visible = false;\n\t };\n\t return GameWrapper;\n\t}(engine.Container));\n\t//# sourceMappingURL=GameWrapper.js.map\n\n\tfunction index (props) {\n\t prepareProps();\n\t injectProps(props);\n\t var instance = new GameWrapper();\n\t return instance;\n\t}\n\t//# sourceMappingURL=index.js.map\n\n\treturn index;\n\n})));\n"
}
{
"name": "拼图",
"desc": "拼图模块1.0",
"props": {
"MAX_COL": {
"alias": "图片分成几列",
"type": "number",
"default": 3
},
"MAX_ROW": {
"alias": "图片分成几行",
"type": "number",
"default": 4
},
"W": {
"alias": "图片的宽度",
"type": "number",
"default": 618
},
"H": {
"alias": "图片的高度",
"type": "number",
"default": 827
},
"OFFSET_X": {
"alias": "OFFSET_X",
"type": "number",
"default": 0
},
"OFFSET_Y": {
"alias": "OFFSET_Y",
"type": "number",
"default": 0
},
"GAP": {
"alias": "图片间隙",
"type": "number",
"default": 0
},
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 50
}
},
"assets": [
{
"name": "遮罩",
"url": "//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png",
"uuid": "888",
"ext": ".png"
}
],
"events": {
"in": {
"pictures-start": {
"alias": "开始",
"data": {
"picUrl": "图片路径",
"blockUrl": "blockUrl"
}
},
"pictures-stop": {
"alias": "停止"
}
},
"out": {
"pictures-time-update": {
"alias": "倒计时更新",
"data": {
"time": "剩余时间"
}
},
"pictures-game-fail": {
"alias": "游戏结束",
"data": {
"reason": "结束原因(1:时间到了)"
}
},
"pictures-game-success": {
"alias": "游戏成功",
"data": {
"time": "游戏消耗时间"
}
}
}
},
"id": "pictures",
"code": "\"use strict\";var tslib=require(\"tslib\"),props={};function prepareProps(){var t=getProps();engine.injectProp(props,t)}function injectProps(t){engine.injectProp(props,t)}var MAX_COL,MAX_ROW,W,H,GAP,GAME_TIME,w,h,picMap={},posMap={},qietu=function(n,r,o,a){if(picMap[r]){for(var t=0,e=picMap[r];t<e.length;t++){var i=e[t];n.addChild(i)}return[picMap[r],posMap[r]]}for(var p=props.W,h=props.H,c=props.GAP,d=[],u=[],s=function(s){for(var t=function(e){var i=engine.Sprite.fromImage(r);d.push(i),i.scaleX=1/o,i.scaleY=1/a,n.addChild(i),i.x=e*(p/o+c),i.y=s*(h/a+c),u.push([i.x,i.y]),i.addEventListener(engine.Event.COMPLETE,function(){var t=new Float32Array([e/o,s/a,(e+1)/o,s/a,(e+1)/o,(s+1)/a,e/o,(s+1)/a]);i.uvs=t})},e=0;e<o;e++)t(e)},g=0;g<a;g++)s(g);return picMap[r]=d.concat([]),posMap[r]=u.concat([]),[d,u]};function getIndexFromRC(t,e,i){return t*i+e}function getRandomArray(t){t.sort(function(){return.5-Math.random()})}var GameView=function(e){function t(){var t=e.call(this)||this;return t._timeCounter=0,t.listenStageOn=1,t.once(engine.Event.ADDED_TO_STAGE,t.setup,t),t}return tslib.__extends(t,e),t.prototype.start=function(){var t=this;if(this.guideHole||(this.guideHole=new engine.Image,this.guideHole.source=\"asset://\"+props.blockUrl,this.guideHole.mouseChildren=this.guideHole.mouseEnabled=!1),this.pictures)for(var e=0,i=this.pictures;e<i.length;e++){var s=i[e];s&&s.parent&&s.parent.removeChild(s)}console.log(\"on start\"),engine.globalEvent.dispatchEvent(\"pictures-time-update\",{second:this.getSecond()});var n=qietu(this.picturesWrapper,props.picUrl,MAX_COL,MAX_ROW);this.picturesWrapper.addChild(this.guideHole),console.log(this.picturesWrapper),this.pictures=n[0],this.rightList=this.pictures.concat([]);var r=n[1];getRandomArray(this.pictures);var o,a=0;for(o=this.pictures.length;a<o;a++){this.dragPic=this.pictures[a],this.pictures[a].addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onDown,this);var p=r[a],h=p[0],c=p[1];this.dragPic.x=h,this.dragPic.y=c}this._timer=setInterval(function(){t.onTimer()},10)},t.prototype.onTimer=function(){GAME_TIME-=.01,(GAME_TIME=(GAME_TIME=this.afterPointTwo(GAME_TIME)).toFixed(2))<10&&(GAME_TIME=\"0\"+GAME_TIME),engine.globalEvent.dispatchEvent(\"pictures-time-update\",{second:this.getSecond()}),0==this.getSecond()&&(this.stop(),engine.globalEvent.dispatchEvent(\"pictures-game-fail\",{reason:1}))},t.prototype.afterPointTwo=function(t){var e=parseFloat(t);if(!isNaN(e))return e=Math.round(100*e)/100},t.prototype.getSecond=function(){return GAME_TIME},t.prototype.stop=function(){GAME_TIME=props.GAME_TIME,clearInterval(this._timer)},t.prototype.createRects=function(){},t.prototype.setup=function(){MAX_COL=props.MAX_COL,MAX_ROW=props.MAX_ROW,GAME_TIME=props.GAME_TIME,W=props.W,H=props.H,GAP=props.GAP,w=W/MAX_COL,h=H/MAX_ROW,console.log(\"onSteup\",props);var t=new engine.Sprite;this.picturesWrapper=t,this.addChild(t)},t.prototype.onDown=function(t){this.dragPic=t.target,this.picturesWrapper.addChild(this.dragPic),this.localPicX=t.localX/MAX_COL,this.localPicY=t.localY/MAX_ROW,this.distanceX=this.dragPic.x,this.distanceY=this.dragPic.y,this.indexJ=Math.floor(this.distanceX/(w+GAP)),this.indexI=Math.floor(this.distanceY/(h+GAP)),this.index=this.indexI*MAX_COL+this.indexJ,this.centerX=Math.floor(t.clientX/w)*w+w/2,this.centerY=Math.floor(t.clientY/h)*h+h/2,this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),this.stage.addEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.stageOnUp=function(t){this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this),(this.centerY<0||this.centerX<0)&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY),this.picturesWrapper.addChild(this.guideHole);var e=Math.floor(this.centerX/(w+GAP)),i=Math.floor(this.centerY/(h+GAP));if(e<MAX_COL&&i<MAX_ROW){var s=getIndexFromRC(i,e,MAX_COL),n=this.pictures[s],r=n.x,o=n.y;n.x=this.distanceX,n.y=this.distanceY,this.dragPic.x=r,this.dragPic.y=o;var a=this.pictures.indexOf(n),p=this.pictures.indexOf(this.dragPic);this.pictures[a]=this.dragPic,this.pictures[p]=n,p===a&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY);for(var c=!0,d=0;d<this.rightList.length;d++)if(this.rightList[d]!=this.pictures[d]){c=!1;break}c&&this.onSuccess()}else this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY},t.prototype.onSuccess=function(){console.log(\"拼图成功!\"),engine.globalEvent.dispatchEvent(\"pictures-game-success\",{time:this._timeCounter}),this.stop()},t.prototype.onMove=function(t){this.dragPic.x=t.stageX-this.localPicX-(750-props.W)/2,this.dragPic.y=t.stageY-this.localPicY-(this.stage.height-props.H)/2,console.log(\"fuck on this.stage.height\",this.stage.height),this.centerX=this.dragPic.x+w/2,this.centerY=this.dragPic.y+h/2},t}(engine.Container),GameWrapper=function(i){function t(){var t=i.call(this)||this;engine.globalEvent.addEventListener(\"pictures-start\",t.start,t),engine.globalEvent.addEventListener(\"pictures-stop\",t.stop,t);var e=t._gameView=new GameView;return t.addChild(e),t}return tslib.__extends(t,i),t.prototype.start=function(t){injectProps(t.data),this._gameView.start()},t.prototype.stop=function(t){this._gameView.stop()},t}(engine.Container);function index(t){return prepareProps(),injectProps(t),new GameWrapper}module.exports=index;\n"
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
"metas": [ "metas": [
{ {
"id": "duiba-api-transform", "id": "duiba-api-transform",
"script": "if (args.success) {\n\tvar payload;\n\n\tif (typeof args.data === 'object') {\n\t\tpayload = engine.objClone(args.data);\n\n\t\tvar origin = engine.objClone(args);\n\t\tObject.defineProperty(payload, '__origin', {\n\t\t\tget: function () {\n\t\t\t\treturn origin\n\t\t\t},\n\t\t\tenumerable: false\n\t\t});\n\t} else {\n\t\tpayload = args.data;\n\t}\n\tnext('success', payload);\n}\nelse {\n\tengine.globalEvent.dispatchEvent('net-failed', args);\n\tnext('failed', args);\n}", "script": "if (args.success) {\n\tvar payload;\n\n\tif (args.data && typeof args.data === 'object') {\n\t\tpayload = engine.objClone(args.data);\n\n\t\tvar origin = engine.objClone(args);\n\t\tObject.defineProperty(payload, '__origin', {\n\t\t\tget: function () {\n\t\t\t\treturn origin\n\t\t\t},\n\t\t\tenumerable: false\n\t\t});\n\t} else {\n\t\tpayload = args.data;\n\t}\n\tnext('success', payload);\n}\nelse {\n\tengine.globalEvent.dispatchEvent('net-failed', args);\n\tnext('failed', args);\n}",
"props": {}, "props": {},
"isInline": true, "isInline": true,
"name": "兑吧接口转换", "name": "兑吧接口转换",
......
{
"script": "var bizIdMap = {\n\t'sharePage': '506',\n\t'pageRemain': '156'\n}\n\nvar bizId = bizIdMap[props.id];\n\nif(bizId){\n\tengine.accessLog(bizId);\n}\n\nnext('success');\n",
"props": {
"id": {
"type": "enum",
"enum": [
"sharePage",
"pageRemain"
],
"alias": "类型",
"default": "sharePage"
}
},
"name": "访问日志接口",
"output": [
"success"
],
"id": "access-log",
"group": "projectX",
"type": "builtin"
}
...@@ -66,6 +66,9 @@ ...@@ -66,6 +66,9 @@
}, },
"uri": { "uri": {
"type": "link" "type": "link"
},
"params": {
"type": "link"
} }
}, },
"output": { "output": {
...@@ -74,8 +77,8 @@ ...@@ -74,8 +77,8 @@
] ]
}, },
"design": { "design": {
"x": 160, "x": 275,
"y": 199 "y": 204
} }
}, },
"f9a32b46-aec1-4bd2-9b98-3d9a427d87db": { "f9a32b46-aec1-4bd2-9b98-3d9a427d87db": {
...@@ -105,8 +108,8 @@ ...@@ -105,8 +108,8 @@
}, },
"output": {}, "output": {},
"design": { "design": {
"x": 489, "x": 507,
"y": 107 "y": 115
} }
} }
}, },
...@@ -114,11 +117,15 @@ ...@@ -114,11 +117,15 @@
"metas": [ "metas": [
{ {
"id": "a4b27753-4cbb-47e3-9b31-51ced475e41a", "id": "a4b27753-4cbb-47e3-9b31-51ced475e41a",
"script": "var uri = engine.findVariable('uri', args, props);\nvar url;\n\nvar hash = window.location.hash;\ntry {\n\thash = top.location.hash;\n} catch (e) {\n}\nvar pathname = window.location.pathname;\ntry {\n\tpathname = top.location.pathname;\n} catch (e) {\n}\n\nif(uri.indexOf('//') !== 0 && uri.indexOf('://') < 0 && pathname === '/preview' || hash.indexOf('preview/') >= 0){\n\tvar projectX = 'projectx';\n\tvar projectID = engine.env.projectID;\n url = engine.joinPath(projectX, projectID, uri);\n}else{\n url = uri;\n}\n\nscope.url = url;\n\nnext('success', args);", "script": "var uri = engine.findVariable('uri', args, props);\nvar url;\n\nvar hash = window.location.hash;\ntry {\n\thash = top.location.hash;\n} catch (e) {\n}\nvar pathname = window.location.pathname;\ntry {\n\tpathname = top.location.pathname;\n} catch (e) {\n}\n\nif(uri.indexOf('//') !== 0 && uri.indexOf('://') < 0 && pathname === '/preview' || hash.indexOf('preview/') >= 0){\n\tvar projectX = 'projectx';\n\tvar projectID = engine.env.projectID;\n url = engine.joinPath(projectX, projectID, uri);\n}else{\n url = uri;\n}\n\nscope.url = url;\n\nvar params = engine.findVariable('params', args, props);\nif (!params) {\n\tparams = {};\n}\nparams.user_type = global.env.newUser ? '0' : '1';\nparams.is_from_share = global.env.fromShare ? '0' : '1';\nif(args === undefined || args === null){\n\targs = {}\n}\nargs.params = params;\n\nnext('success', args);",
"props": { "props": {
"uri": { "uri": {
"type": "string", "type": "string",
"alias": "URI" "alias": "URI"
},
"params": {
"type": "map",
"alias": "参数"
} }
}, },
"isInline": true, "isInline": true,
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"error" "error"
], ],
"id": "px-token", "id": "px-token",
"script": "if (window['getPxToken']) {\n window['getPxToken'](function (e, token) {\n switch (e) {\n case 'net error':\n next('error', { type: 'error' });\n break;\n case 'need login':\n next('failed', { type: 'failed' });\n break;\n case 'state invalid':\n next('invalid', { type: 'invalid' });\n break;\n default:\n if (token) {\n scope.token = token;\n next('success', args);\n }\n else {\n next('invalid', { type: 'invalid key' });\n }\n }\n });\n}\nelse {\n next('error', { type: 'no ready' });\n}\n", "script": "if (top.location.href.indexOf('preview') >= 0) {\n scope.token = 'dev-token';\n next('success', args);\n}\nelse {\n if (window['getPxToken']) {\n window['getPxToken'](function (e, token) {\n switch (e) {\n case 'net error':\n next('error', { type: 'error' });\n break;\n case 'need login':\n next('failed', { type: 'failed' });\n break;\n case 'state invalid':\n next('invalid', { type: 'invalid' });\n break;\n default:\n if (token) {\n scope.token = token;\n next('success', args);\n }\n else {\n next('invalid', { type: 'invalid key' });\n }\n }\n });\n }\n else {\n next('error', { type: 'no ready' });\n }\n}\n",
"group": "projectX", "group": "projectX",
"type": "builtin" "type": "builtin"
} }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"complete" "complete"
], ],
"id": "add-custom-module", "id": "add-custom-module",
"script": "var p = engine.findVariable('props', args, props);\nengine.addCustomModule(props.id, props.target || target, p);\nnext('complete');\n", "script": "var p = engine.findVariable('props', args, props);\nvar id = engine.findVariable('id', args, props);\nvar target2 = engine.findVariable('target', args, props);\nengine.addCustomModule(id, target2 || target, p);\nnext('complete');\n",
"group": "view", "group": "view",
"type": "builtin" "type": "builtin"
} }
...@@ -6,13 +6,45 @@ ...@@ -6,13 +6,45 @@
"alias": "是否关闭全部弹窗", "alias": "是否关闭全部弹窗",
"type": "boolean", "type": "boolean",
"default": false "default": false
},
"effect": {
"alias": "动效",
"type": "enum",
"enum": [
{
"label": "无动效",
"value": "simple"
},
{
"label": "渐隐渐现",
"value": "fade"
},
{
"label": "飞入飞出",
"value": "flew"
},
{
"label": "缩放",
"value": "zoom"
},
{
"label": "紫金葫芦",
"value": "hulu"
}
],
"default": "simple"
},
"effectParams": {
"alias": "动效参数",
"type": "map",
"default": {}
} }
}, },
"output": [ "output": [
"complete" "complete"
], ],
"id": "pop-dialog", "id": "pop-dialog",
"script": "if (props.closeAll) {\n engine.gameStage.popupContainer.popAll();\n}\nelse {\n engine.gameStage.popupContainer.pop();\n}\nnext('complete');\n", "script": "var effect = engine.findVariable('effect', args, props);\nvar effectParams = engine.findVariable('effectParams', args, props);\nvar options = {\n effect: effect,\n effectParams: effectParams,\n};\nif (props.closeAll) {\n engine.gameStage.popupContainer.popAll(null, options);\n}\nelse {\n engine.gameStage.popupContainer.pop(options);\n}\nnext('complete');\n",
"group": "view", "group": "view",
"type": "builtin" "type": "builtin"
} }
...@@ -10,6 +10,26 @@ ...@@ -10,6 +10,26 @@
"viewName": { "viewName": {
"alias": "目标视图名", "alias": "目标视图名",
"type": "string" "type": "string"
},
"effect": {
"alias": "动效",
"type": "enum",
"enum": [
{
"label": "无动效",
"value": "simple"
},
{
"label": "渐变",
"value": "fade"
}
],
"default": "simple"
},
"effectParams": {
"alias": "动效参数",
"type": "map",
"default": {}
} }
}, },
"output": [ "output": [
...@@ -17,7 +37,7 @@ ...@@ -17,7 +37,7 @@
"exception" "exception"
], ],
"id": "pop-scene", "id": "pop-scene",
"script": "if (props.popAll) {\n if (!props.viewName) {\n console.log('没有设置视图名');\n next('exception', '没有设置视图名');\n }\n else {\n var gameStage = engine.gameStage;\n var view = gameStage.instantiateView(props.viewName);\n if (view) {\n gameStage.sceneContainer.popAll(view);\n next('complete');\n }\n else {\n next('exception', '视图不存在');\n }\n }\n}\nelse {\n engine.gameStage.sceneContainer.pop();\n next('complete');\n}\n", "script": "var effect = engine.findVariable('effect', args, props);\nvar effectParams = engine.findVariable('effectParams', args, props);\nvar options = {\n effect: effect,\n effectParams: effectParams,\n};\nif (props.popAll) {\n if (!props.viewName) {\n console.log('没有设置视图名');\n next('exception', '没有设置视图名');\n }\n else {\n var gameStage_1 = engine.gameStage;\n gameStage_1.instantiateView(props.viewName).then(function (view) {\n if (view) {\n gameStage_1.sceneContainer.popAll(view, options);\n next('complete');\n }\n else {\n next('exception', '视图不存在');\n }\n });\n }\n}\nelse {\n engine.gameStage.sceneContainer.pop(options);\n next('complete');\n}\n",
"group": "view", "group": "view",
"type": "builtin" "type": "builtin"
} }
...@@ -6,17 +6,59 @@ ...@@ -6,17 +6,59 @@
"alias": "目标视图名", "alias": "目标视图名",
"type": "string" "type": "string"
}, },
"showLoading": {
"alias": "展示加载视图",
"type": "boolean",
"default": false
},
"center": { "center": {
"alias": "是否居中展示", "alias": "是否居中展示",
"type": "boolean", "type": "boolean",
"default": true "default": true
},
"modalAlpha": {
"alias": "模态层透明度",
"type": "number",
"default": 0.7
},
"effect": {
"alias": "动效",
"type": "enum",
"enum": [
{
"label": "无动效",
"value": "simple"
},
{
"label": "渐隐渐现",
"value": "fade"
},
{
"label": "飞入飞出",
"value": "flew"
},
{
"label": "缩放",
"value": "zoom"
},
{
"label": "紫金葫芦",
"value": "hulu"
}
],
"default": "simple"
},
"effectParams": {
"alias": "动效参数",
"type": "map",
"default": {}
} }
}, },
"output": [ "output": [
"complete" "complete"
], ],
"id": "push-dialog", "id": "push-dialog",
"script": "if (!props.viewName) {\n console.log('没有设置视图名');\n next('exception', '没有设置视图名');\n}\nelse {\n var gameStage = engine.gameStage;\n var view = gameStage.instantiateView(props.viewName);\n if (view) {\n gameStage.popupContainer.push(view, { center: props.center });\n }\n next('complete');\n}\n", "script": "var effect = engine.findVariable('effect', args, props);\nvar effectParams = engine.findVariable('effectParams', args, props);\nvar showLoading = engine.findVariable('showLoading', args, props);\nif (showLoading !== undefined) {\n showLoading = false;\n}\nif (!props.viewName) {\n console.log('没有设置视图名');\n next('exception', '没有设置视图名');\n}\nelse {\n var gameStage_1 = engine.gameStage;\n gameStage_1.instantiateView(props.viewName, true, showLoading).then(function (view) {\n if (view) {\n var options = {\n effect: effect,\n effectParams: effectParams,\n center: props.center,\n modalAlpha: props.modalAlpha,\n };\n gameStage_1.popupContainer.push(view, options);\n }\n });\n next('complete');\n}\n",
"group": "view", "group": "view",
"type": "builtin" "type": "builtin"
} }
...@@ -6,17 +6,42 @@ ...@@ -6,17 +6,42 @@
"alias": "目标视图名", "alias": "目标视图名",
"type": "string" "type": "string"
}, },
"showLoading": {
"alias": "展示加载视图",
"type": "boolean",
"default": true
},
"replace": { "replace": {
"alias": "是否替换场景", "alias": "是否替换场景",
"type": "boolean", "type": "boolean",
"default": false "default": false
},
"effect": {
"alias": "动效",
"type": "enum",
"enum": [
{
"label": "无动效",
"value": "simple"
},
{
"label": "渐变",
"value": "fade"
}
],
"default": "simple"
},
"effectParams": {
"alias": "动效参数",
"type": "map",
"default": {}
} }
}, },
"output": [ "output": [
"complete" "complete"
], ],
"id": "push-scene", "id": "push-scene",
"script": "var replace = engine.findVariable('replace', args, props);\nif (!props.viewName) {\n console.log('没有设置视图名');\n next('exception', '没有设置视图名');\n}\nelse {\n var gameStage = engine.gameStage;\n var view = gameStage.instantiateView(props.viewName);\n if (view) {\n if (replace) {\n gameStage.sceneContainer.replace(view);\n }\n else {\n gameStage.sceneContainer.push(view);\n }\n }\n next('complete');\n}\n", "script": "var replace = engine.findVariable('replace', args, props);\nvar effect = engine.findVariable('effect', args, props);\nvar effectParams = engine.findVariable('effectParams', args, props);\nvar showLoading = engine.findVariable('showLoading', args, props);\nif (!props.viewName) {\n console.log('没有设置视图名');\n next('exception', '没有设置视图名');\n}\nelse {\n var gameStage_1 = engine.gameStage;\n gameStage_1.instantiateView(props.viewName, true, showLoading).then(function (view) {\n if (view) {\n var options = {\n effect: effect,\n effectParams: effectParams,\n };\n if (replace) {\n gameStage_1.sceneContainer.replace(view, options);\n }\n else {\n gameStage_1.sceneContainer.push(view, options);\n }\n }\n });\n next('complete');\n}\n",
"group": "view", "group": "view",
"type": "builtin" "type": "builtin"
} }
...@@ -13,6 +13,19 @@ ...@@ -13,6 +13,19 @@
"default": 10, "default": 10,
"alias": "边距" "alias": "边距"
}, },
"paddingH": {
"type": "number",
"alias": "横向边距"
},
"paddingV": {
"type": "number",
"alias": "纵向边距"
},
"borderRadius": {
"type": "number",
"default": 10,
"alias": "圆角半径"
},
"duration": { "duration": {
"type": "number", "type": "number",
"default": 1000, "default": 1000,
......
...@@ -43,8 +43,13 @@ ...@@ -43,8 +43,13 @@
"alias": "点击自动触发", "alias": "点击自动触发",
"type": "boolean", "type": "boolean",
"default": true "default": true
},
"asSharePage": {
"alias": "作为分享页曝光",
"type": "boolean",
"default": false
} }
}, },
"id": "buried-point", "id": "buried-point",
"code": "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar BuriedPoint = (function (_super) {\n __extends(BuriedPoint, _super);\n function BuriedPoint() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.dpm = 'appID.0.0.0';\n _this.dcm = '202.projectID.0.0';\n _this.dom = '0.0.0.0';\n _this.autoExposure = true;\n _this.onceAutoExposure = false;\n _this.autoExposureType = 'visible';\n _this.autoClick = true;\n _this.checkFps = 5;\n _this._autoExposured = false;\n _this._hostVisible = false;\n _this.checkVisibility = function () {\n var worldVisible = _this.host.worldVisible;\n if (worldVisible !== _this._hostVisible) {\n _this._hostVisible = worldVisible;\n if (worldVisible) {\n _this._onVisible();\n }\n }\n };\n return _this;\n }\n BuriedPoint.prototype.onModify = function (value, key, oldValue) {\n switch (key) {\n case 'dpm':\n case 'dcm':\n case 'dom':\n this['__' + key] = fill(value);\n break;\n }\n };\n BuriedPoint.prototype.mounted = function () {\n this.host.addEventListener(engine.MouseEvent.CLICK, this._onClick, this);\n this._timer = setInterval(this.checkVisibility, 1000 / this.checkFps);\n };\n BuriedPoint.prototype.destroy = function () {\n this.host.removeEventListener(engine.MouseEvent.CLICK, this._onClick, this);\n if (this._timer) {\n clearInterval(this._timer);\n this._timer = null;\n }\n };\n BuriedPoint.prototype.awake = function () {\n if (this.autoExposure && this.autoExposureType === 'awake') {\n this.autoLogExposure();\n }\n };\n BuriedPoint.prototype._onVisible = function (e) {\n if (e === void 0) { e = null; }\n if (this.autoExposure && this.autoExposureType === 'visible') {\n this.autoLogExposure();\n }\n };\n BuriedPoint.prototype.autoLogExposure = function () {\n if (!this._autoExposured) {\n if (this.onceAutoExposure) {\n this._autoExposured = true;\n }\n this.logExposure();\n }\n };\n BuriedPoint.prototype._onClick = function (e) {\n if (this.autoClick) {\n this.logClick();\n }\n };\n BuriedPoint.prototype.logExposure = function () {\n this.log('exposure');\n };\n BuriedPoint.prototype.logClick = function () {\n this.log('click');\n };\n BuriedPoint.prototype.log = function (type) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4, log(type, {\n dpm: this['__dpm'],\n dcm: this['__dcm'],\n dom: this['__dom'],\n })];\n case 1:\n _a.sent();\n if (this.id !== undefined) {\n engine.globalEvent.dispatchEvent('buried-point-success', {\n type: type,\n id: this.id,\n });\n }\n return [2];\n }\n });\n });\n };\n BuriedPoint.id = 'buried-point';\n __decorate([\n engine.dirtyFieldTrigger\n ], BuriedPoint.prototype, \"dpm\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], BuriedPoint.prototype, \"dcm\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], BuriedPoint.prototype, \"dom\", void 0);\n return BuriedPoint;\n}(engine.ScriptBase));\nexports.default = BuriedPoint;\nfunction fill(src) {\n var result = src;\n for (var key in engine.env) {\n result = result.replace(key, engine.env[key]);\n }\n return result;\n}\nfunction log(type, data) {\n var dpm = data.dpm, dcm = data.dcm, dom = data.dom;\n var params = {\n dpm: dpm, dcm: dcm, appId: engine.env.appID\n };\n if (dom !== '0.0.0.0') {\n params.dom = dom;\n }\n var isExposure = type === 'exposure';\n return engine.httpRequest(isExposure ? '//embedlog.duiba.com.cn/exposure/standard' : '/log/click', 'get', params, isExposure ? 'jsonp' : 'text');\n}\n" "code": "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar injectProp = engine.injectProp;\nvar BuriedPoint = (function (_super) {\n __extends(BuriedPoint, _super);\n function BuriedPoint() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.dpm = 'appID.0.0.0';\n _this.dcm = '202.projectID.0.0';\n _this.dom = '0.0.0.0';\n _this.autoExposure = true;\n _this.onceAutoExposure = false;\n _this.autoExposureType = 'visible';\n _this.autoClick = true;\n _this.asSharePage = false;\n _this.checkFps = 5;\n _this._autoExposured = false;\n _this._hostVisible = false;\n _this.checkVisibility = function () {\n var worldVisible = _this.host.worldVisible;\n if (worldVisible !== _this._hostVisible) {\n _this._hostVisible = worldVisible;\n if (worldVisible) {\n _this._onVisible();\n }\n }\n };\n return _this;\n }\n BuriedPoint.prototype.onModify = function (value, key, oldValue) {\n switch (key) {\n case 'dpm':\n case 'dcm':\n case 'dom':\n this['__' + key] = fill(value);\n break;\n }\n };\n BuriedPoint.prototype.mounted = function () {\n this.host.addEventListener(engine.MouseEvent.CLICK, this._onClick, this);\n this._timer = setInterval(this.checkVisibility, 1000 / this.checkFps);\n };\n BuriedPoint.prototype.destroy = function () {\n this.host.removeEventListener(engine.MouseEvent.CLICK, this._onClick, this);\n if (this._timer) {\n clearInterval(this._timer);\n this._timer = null;\n }\n };\n BuriedPoint.prototype.awake = function () {\n if (this.autoExposure && this.autoExposureType === 'awake') {\n this.autoLogExposure();\n }\n };\n BuriedPoint.prototype._onVisible = function (e) {\n if (e === void 0) { e = null; }\n if (this.autoExposure && this.autoExposureType === 'visible') {\n this.autoLogExposure();\n }\n };\n BuriedPoint.prototype.autoLogExposure = function () {\n if (!this._autoExposured) {\n if (this.onceAutoExposure) {\n this._autoExposured = true;\n }\n this.logExposure();\n }\n };\n BuriedPoint.prototype._onClick = function (e) {\n if (this.autoClick) {\n this.logClick();\n }\n };\n BuriedPoint.prototype.logExposure = function () {\n this.log('exposure');\n };\n BuriedPoint.prototype.logClick = function () {\n this.log('click');\n };\n BuriedPoint.prototype.log = function (type) {\n return __awaiter(this, void 0, void 0, function () {\n var otherQuery;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n otherQuery = {\n appId: engine.env.appID,\n };\n if (this.asSharePage) {\n otherQuery.share = '1';\n }\n return [4, log(type, {\n dpm: this['__dpm'],\n dcm: this['__dcm'],\n dom: this['__dom'],\n }, otherQuery)];\n case 1:\n _a.sent();\n if (this.id !== undefined) {\n engine.globalEvent.dispatchEvent('buried-point-success', {\n type: type,\n id: this.id,\n });\n }\n return [2];\n }\n });\n });\n };\n BuriedPoint.id = 'buried-point';\n __decorate([\n engine.dirtyFieldTrigger\n ], BuriedPoint.prototype, \"dpm\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], BuriedPoint.prototype, \"dcm\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], BuriedPoint.prototype, \"dom\", void 0);\n return BuriedPoint;\n}(engine.ScriptBase));\nexports.default = BuriedPoint;\nfunction fill(src) {\n var result = src;\n for (var key in engine.env) {\n result = result.replace(key, engine.env[key]);\n }\n return result;\n}\nfunction log(type, data, otherQuery) {\n var dpm = data.dpm, dcm = data.dcm, dom = data.dom;\n var params = {\n dpm: dpm, dcm: dcm,\n };\n if (dom !== '0.0.0.0') {\n params.dom = dom;\n }\n injectProp(params, otherQuery);\n var isExposure = type === 'exposure';\n return engine.httpRequest(isExposure ? '//embedlog.duiba.com.cn/exposure/standard' : '/log/click', 'get', params, isExposure ? 'jsonp' : 'text');\n}\n"
} }
This diff is collapsed.
...@@ -407,6 +407,8 @@ var GameView = (function (_super) { ...@@ -407,6 +407,8 @@ var GameView = (function (_super) {
GameView.prototype.playShake = function () { GameView.prototype.playShake = function () {
var _this = this; var _this = this;
var _a = this.frontContainer, x = _a.x, y = _a.y; var _a = this.frontContainer, x = _a.x, y = _a.y;
let a = '';
a.substr
return new Promise(function (resolve) { return new Promise(function (resolve) {
var shakeOffset = 7; var shakeOffset = 7;
var duration = 30; var duration = 30;
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var GameObject = (function (_super) {
__extends(GameObject, _super);
function GameObject() {
var _this = _super.call(this) || this;
_this.name = "";
_this.componentList = [];
_this.mouseEnabled = false;
_this.mouseChildren = false;
return _this;
}
GameObject.prototype.addComponent = function (cls) {
if (this.getComponent(cls) != null) {
console.error("component is existent");
return;
}
var ins = new cls(this);
ins.enabled = true;
this.componentList.push(ins);
return ins;
};
GameObject.prototype.getComponent = function (cls) {
for (var _i = 0, _a = this.componentList; _i < _a.length; _i++) {
var i = _a[_i];
if (i instanceof cls) {
return i;
}
}
return null;
};
GameObject.prototype.removeComponent = function (cls) {
var _loop_1 = function (i) {
if (i instanceof cls) {
i.enabled = false;
this_1.componentList = this_1.componentList.filter(function (e) { return e != i; });
return { value: void 0 };
}
};
var this_1 = this;
for (var _i = 0, _a = this.componentList; _i < _a.length; _i++) {
var i = _a[_i];
var state_1 = _loop_1(i);
if (typeof state_1 === "object")
return state_1.value;
}
};
GameObject.prototype.dispose = function () {
this.destroy();
this.disableAllComponents();
};
GameObject.prototype.disableAllComponents = function () {
var _this = this;
Object.keys(this.componentList).forEach(function (e) { return _this.componentList[e].enabled = false; });
};
GameObject.prototype.enableAllComponents = function () {
var _this = this;
Object.keys(this.componentList).forEach(function (e) { return _this.componentList[e].enabled = true; });
};
GameObject.prototype.onCollisionEnter = function (other) {
};
GameObject.prototype.onCollisionStay = function (other) {
};
GameObject.prototype.onCollisionExit = function (other) {
};
return GameObject;
}(engine.Container));
exports.default = GameObject;
if (window['getPxToken']) { if (top.location.href.indexOf('preview') >= 0) {
window['getPxToken'](function (e, token) { scope.token = 'dev-token';
switch (e) { next('success', args);
case 'net error':
next('error', { type: 'error' });
break;
case 'need login':
next('failed', { type: 'failed' });
break;
case 'state invalid':
next('invalid', { type: 'invalid' });
break;
default:
if (token) {
scope.token = token;
next('success', args);
}
else {
next('invalid', { type: 'invalid key' });
}
}
});
} }
else { else {
next('error', { type: 'no ready' }); if (window['getPxToken']) {
window['getPxToken'](function (e, token) {
switch (e) {
case 'net error':
next('error', { type: 'error' });
break;
case 'need login':
next('failed', { type: 'failed' });
break;
case 'state invalid':
next('invalid', { type: 'invalid' });
break;
default:
if (token) {
scope.token = token;
next('success', args);
}
else {
next('invalid', { type: 'invalid key' });
}
}
});
}
else {
next('error', { type: 'no ready' });
}
} }
var p = engine.findVariable('props', args, props);
var id = engine.findVariable('id', args, props);
var target2 = engine.findVariable('target', args, props);
engine.addCustomModule(id, target2 || target, p);
next('complete');
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var injectProp = engine.injectProp;
var BuriedPoint = (function (_super) {
__extends(BuriedPoint, _super);
function BuriedPoint() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.dpm = 'appID.0.0.0';
_this.dcm = '202.projectID.0.0';
_this.dom = '0.0.0.0';
_this.autoExposure = true;
_this.onceAutoExposure = false;
_this.autoExposureType = 'visible';
_this.autoClick = true;
_this.checkFps = 5;
_this._autoExposured = false;
_this._hostVisible = false;
_this.checkVisibility = function () {
var worldVisible = _this.host.worldVisible;
if (worldVisible !== _this._hostVisible) {
_this._hostVisible = worldVisible;
if (worldVisible) {
_this._onVisible();
}
}
};
return _this;
}
BuriedPoint.prototype.onModify = function (value, key, oldValue) {
switch (key) {
case 'dpm':
case 'dcm':
case 'dom':
this['__' + key] = fill(value);
break;
}
};
BuriedPoint.prototype.mounted = function () {
this.host.addEventListener(engine.MouseEvent.CLICK, this._onClick, this);
this._timer = setInterval(this.checkVisibility, 1000 / this.checkFps);
};
BuriedPoint.prototype.destroy = function () {
this.host.removeEventListener(engine.MouseEvent.CLICK, this._onClick, this);
if (this._timer) {
clearInterval(this._timer);
this._timer = null;
}
};
BuriedPoint.prototype.awake = function () {
if (this.autoExposure && this.autoExposureType === 'awake') {
this.autoLogExposure();
}
};
BuriedPoint.prototype._onVisible = function (e) {
if (e === void 0) { e = null; }
if (this.autoExposure && this.autoExposureType === 'visible') {
this.autoLogExposure();
}
};
BuriedPoint.prototype.autoLogExposure = function () {
if (!this._autoExposured) {
if (this.onceAutoExposure) {
this._autoExposured = true;
}
this.logExposure();
}
};
BuriedPoint.prototype._onClick = function (e) {
if (this.autoClick) {
this.logClick();
}
};
BuriedPoint.prototype.logExposure = function () {
this.log('exposure');
};
BuriedPoint.prototype.logClick = function () {
this.log('click');
};
BuriedPoint.prototype.log = function (type) {
return __awaiter(this, void 0, void 0, function () {
var otherQuery;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
otherQuery = {
appId: engine.env.appID,
};
return [4, log(type, {
dpm: this['__dpm'],
dcm: this['__dcm'],
dom: this['__dom'],
}, otherQuery)];
case 1:
_a.sent();
if (this.id !== undefined) {
engine.globalEvent.dispatchEvent('buried-point-success', {
type: type,
id: this.id,
});
}
return [2];
}
});
});
};
BuriedPoint.id = 'buried-point';
__decorate([
engine.dirtyFieldTrigger
], BuriedPoint.prototype, "dpm", void 0);
__decorate([
engine.dirtyFieldTrigger
], BuriedPoint.prototype, "dcm", void 0);
__decorate([
engine.dirtyFieldTrigger
], BuriedPoint.prototype, "dom", void 0);
return BuriedPoint;
}(engine.ScriptBase));
exports.default = BuriedPoint;
function fill(src) {
var result = src;
for (var key_1 in engine.env) {
result = result.replace(key_1, engine.env[key_1]);
}
return result;
}
function log(type, data, otherQuery) {
var dpm = data.dpm, dcm = data.dcm, dom = data.dom;
var params = {
dpm: dpm, dcm: dcm,
};
if (dom !== '0.0.0.0') {
params.dom = dom;
}
injectProp(params, otherQuery);
var isExposure = type === 'exposure';
return engine.httpRequest(isExposure ? '//embedlog.duiba.com.cn/exposure/standard' : '/log/click', 'get', params, isExposure ? 'jsonp' : 'text');
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Wave = (function (_super) {
__extends(Wave, _super);
function Wave() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.duration = 1000;
_this.waveMethod = 'rotate';
_this.loop = -1;
_this.autoPlay = true;
_this.revert = false;
_this._oldProps = {};
return _this;
}
Wave.prototype.mounted = function () {
this._startTime = 0;
engine.copyProp(this._oldProps, this.host, oldPropFields);
if (this.autoPlay) {
this.play();
}
};
Wave.prototype.sleep = function () {
if (this.revert) {
this.revertProps();
}
};
Wave.prototype.update = function (t) {
if (this._playing) {
if (!this._startTime) {
this._startTime = t;
}
var _a = this, duration_1 = _a.duration, waveParams = _a.waveParams, _waveAlgorithm = _a._waveAlgorithm, host = _a.host, _oldProps = _a._oldProps;
var pass = (t - this._startTime) % duration_1;
var r = pass / duration_1 * PI2;
var loopCounting = Math.floor((t - this._startTime) / duration_1);
if (loopCounting != this._loopCounting) {
this._loopCounting = loopCounting;
if (this.onLoopEnd()) {
r = PI2;
}
}
var t2 = void 0;
if (this.ratio) {
var ratio = this.ratio.split(',').map(function (item) { return parseFloat(item); });
if (ratio.length === 2) {
var begin = ratio[0], end = ratio[1];
if (end >= begin) {
var tr = r / PI2;
if (tr >= begin && tr < end) {
t2 = r / (end - begin);
}
else {
t2 = 0;
}
}
else {
t2 = 0;
}
}
else {
t2 = 0;
}
}
else {
t2 = r;
}
var params_1 = waveParams ? (waveParams.split(',').map(function (item) { return parseFloat(item); })) : [];
var props_1 = _waveAlgorithm.apply(void 0, params_1.concat([t2]));
if (props_1.hasOwnProperty('x')) {
host.x = (props_1.x || 0) + _oldProps.x;
}
if (props_1.hasOwnProperty('y')) {
host.y = (props_1.y || 0) + _oldProps.y;
}
if (props_1.hasOwnProperty('sx')) {
host.scaleX = props_1.sx;
}
if (props_1.hasOwnProperty('sy')) {
host.scaleY = props_1.sy;
}
if (props_1.hasOwnProperty('r')) {
host.rotation = props_1.r;
}
if (props_1.hasOwnProperty('alpha')) {
host.alpha = props_1.alpha;
}
}
};
Wave.prototype.onLoopEnd = function () {
if (this.loop < 0) {
}
else if (this._loopCounting < this.loop) {
}
else {
this._playing = false;
return true;
}
};
Wave.prototype.play = function () {
this._loopCounting = 0;
this._playing = true;
this._startTime = 0;
};
Wave.prototype.stop = function (revert) {
if (revert === void 0) { revert = false; }
this._playing = false;
if (revert) {
this.revertProps();
}
};
Wave.prototype.revertProps = function () {
for (var key_1 in this._oldProps) {
var prop = this._oldProps[key_1];
if (typeof prop === 'object') {
engine.injectProp(this.host[key_1], prop);
}
else {
this.host[key_1] = prop;
}
}
};
Wave.prototype.onModify = function (value, key, oldValue) {
switch (key) {
case 'waveMethod':
this._waveAlgorithm = waveLibs[this.waveMethod];
break;
}
};
Wave.id = 'wave';
__decorate([
engine.dirtyFieldTrigger
], Wave.prototype, "waveMethod", void 0);
return Wave;
}(engine.ScriptBase));
exports.default = Wave;
var PI2 = Math.PI * 2;
var oldPropFields = {
x: 'x',
y: 'y',
scaleX: 'scaleX',
scaleY: 'scaleY',
alpha: 'alpha',
rotation: 'rotation',
};
var cos = Math.cos, sin = Math.sin, PI = Math.PI;
var waveLibs = {
round: function (radius, t) {
return { x: cos(t) * radius, y: sin(t) * radius };
},
cosWave: function (h, t) {
return { x: cos(t) * h, y: 0 };
},
sinWave: function (h, t) {
h = h || 1;
return { x: 0, y: sin(t) * h };
},
rotate: function (t) {
return { r: 360 * t / PI / 2 };
},
shake: function (angle, count, t) {
return { r: sin(t * count) * angle };
},
breath: function (scale, t) {
if (scale === void 0) { scale = 0.1; }
return { sx: sin(t) * scale + 1, sy: -sin(t + PI / 4) * scale + 1 };
},
zoom: function (scale, t) {
if (scale === void 0) { scale = 0.1; }
return { sx: sin(t) * scale + 1, sy: sin(t) * scale + 1 };
},
fade: function (base, scale, t) {
if (base === void 0) { base = 0; }
if (scale === void 0) { scale = 1; }
return { alpha: (sin(t) + 1) * 0.5 * scale + base };
},
};
...@@ -5564,7 +5564,7 @@ declare module engine { ...@@ -5564,7 +5564,7 @@ declare module engine {
export const dataCenter: DataCenter; export const dataCenter: DataCenter;
export let env: {}; export let env: any;
export function injectEnv(data: any): void; export function injectEnv(data: any): void;
......
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = 'circle';
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('food-fell-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
});
engine.globalEvent.dispatchEvent('food-fell-start');
}, 500);
});
engine.globalEvent.addEventListener('food-fell-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-game-over', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>套圈</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="full-screen" content="true" />
<meta name="screen-orientation" content="portrait" />
<meta name="x5-fullscreen" content="true" />
<meta name="360-fullscreen" content="true" />
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: grey;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous"
src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous"
src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/1cd03de560966bebafcee0b54a046b16fff52517.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/1cd03de560966bebafcee0b54a046b16fff52517.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/1cd03de560966bebafcee0b54a046b16fff52517.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/1cd03de560966bebafcee0b54a046b16fff52517.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
(global = global || self, global.circle = factory(global.tslib));
}(this, (function (tslib) { 'use strict';
function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
function getTextureByName(name) {
console.log('name', engine.getAssetByName(name));
return getTexture(engine.getAssetByName(name).uuid);
}
function createSvga(name, anchorName) {
var inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
//# sourceMappingURL=utils.js.map
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var Gameinit = (function (_super) {
tslib.__extends(Gameinit, _super);
function Gameinit() {
var _this = _super.call(this) || this;
_this._isSetUp = false;
_this.totleY = 1200;
_this.isMove = false;
_this.isChoose = true;
_this.isDid = true;
_this.listGift = [];
console.log("11111111111111");
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this;
}
Gameinit.prototype.setup = function () {
console.log("初始化加载000000000000000000000000!");
if (this._isSetUp) {
return;
}
else {
this.loadThings();
console.log("this._isSetUp=", this._isSetUp, '<<<<');
}
};
Gameinit.prototype.loadThings = function () {
var self = this;
var body;
body = this._body = new engine.Rect;
body.width = 0.0001;
body.height = 0.0001;
this.addChild(body);
var gift0 = this.addRes(body, '礼盒', 250, 100, 247, 188);
var gift1 = this.addRes(body, '礼盒', 485, 85, 247, 190);
var gift2 = this.addRes(body, '礼盒', 385, -15, 222, 170);
var gift3 = this.addRes(body, '礼盒', 165, -15, 222, 170);
var gift4 = this.addRes(body, '礼盒', 20, 85, 247, 190);
this.listGift = [gift0, gift1, gift2, gift3, gift4];
var circle = this.addRes(body, '圈', 260, 350, 240, 80);
var giftSvga = createSvga("套中动效");
giftSvga.visible = false;
body.addChild(giftSvga);
var _a = props.ferruleModuleGlobalPosition, v2X = _a[0], v2Y = _a[1];
body.x = v2X;
body.y = v2Y;
engine.globalEvent.addEventListener("circle-game-start", function () {
self.isMove = true;
console.log('this.isMove===', self.isMove);
}, this);
engine.globalEvent.addEventListener("circle-game-init", function () {
self.isChoose = true;
giftSvga.visible = false;
body.children[self.num].visible = true;
circle.x = 260;
circle.y = 350;
circle.width = 240;
circle.height = 80;
circle.visible = true;
}, this);
circle.addEventListener(engine.Event.ENTER_FRAME, function () {
if (self.isMove) {
console.log("物体移动");
if (self.isChoose) {
self.num = Math.floor(Math.random() * self.listGift.length);
self.isChoose = false;
}
self.nodeMove(circle, self.listGift[self.num], giftSvga);
}
});
};
Gameinit.prototype.aniPlay = function (node0, targetNode, bool) {
node0.scaleX = this.currentScale(targetNode.y, this.totleY) - 0.05 * this.currentScale(targetNode.y, this.totleY);
node0.scaleY = this.currentScale(targetNode.y, this.totleY) - 0.05 * this.currentScale(targetNode.y, this.totleY);
node0.x = targetNode.x;
node0.y = targetNode.y;
node0.visible = true;
node0.play(false, false);
node0.addEventListener(engine.Event.END_FRAME, function () {
console.log("播放到最后一帧", bool, '<<<');
engine.globalEvent.dispatchEvent("circle-game-end");
bool = false;
});
};
Gameinit.prototype.addRes = function (fatherNode, resName, v2X, v2Y, resW, resH) {
console.log("进行资源的添加");
var thing = new engine.Sprite(getTextureByName(resName));
thing.x = v2X;
thing.y = v2Y;
thing.width = resW;
thing.height = resH;
return fatherNode.addChild(thing);
};
Gameinit.prototype.nodeMove = function (moveNode, targetNode, nodePlay) {
console.log("moveNode.x=", moveNode.x, "targetNode.x=", targetNode.x);
var moveX = targetNode.x - moveNode.x;
var moveY = targetNode.y - moveNode.y;
console.log('moveX=', moveX, 'moveY=', moveY);
if (this.isDid) {
if (Math.abs(moveX) > 2) {
moveNode.x += moveX / Math.abs(moveX) * 5;
}
if (Math.abs(moveY) > 2) {
moveNode.y += moveY / Math.abs(moveY) * 5;
moveNode.scaleX = this.currentScale(moveNode.y, this.totleY) + 0.2;
moveNode.scaleY = moveNode.scaleX;
}
if (Math.abs(moveX) < 3 && Math.abs(moveY) < 3) {
targetNode.visible = false;
moveNode.visible = false;
this.aniPlay(nodePlay, targetNode, this.isDid);
this.isMove = false;
}
}
};
Gameinit.prototype.currentScale = function (currentY, totoleDisY) {
return (currentY + 830) / totoleDisY;
};
return Gameinit;
}(engine.Container));
function index (props) {
prepareProps();
injectProps(props);
var instance = new Gameinit();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
})));
//# sourceMappingURL=main.js.map
\ No newline at end of file
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "套圈",
"desc": "套圈模块",
"props": {
"ferruleModuleGlobalPosition": {
"alias": "套圈模块的位置",
"type": "array<number>",
"default": "0,0"
},
"ferruleModuleWidthHeight": {
"alias": "套圈模块的宽高",
"type": "array<number>",
"default": "750,450"
}
},
"assets": [
{
"name": "圈",
"url": "//yun.duiba.com.cn/aurora/assets/668313c9b296603cbfd24f92c3683c41df0aa1e9.png",
"uuid": "c1fc9984-900f-44e0-87e5-128e7ccdfb62",
"ext": ".png"
},
{
"name": "礼盒",
"url": "//yun.duiba.com.cn/aurora/assets/3b13cb2a324c05e3bef2c27f1fd27b5fe49a0ea3.png",
"uuid": "e3ee8791-880f-4408-9f31-2f5faa75d044",
"ext": ".png"
},
{
"name": "套中动效",
"url": "//yun.duiba.com.cn/aurora/assets/8b650dd07a82a1357f0572e1201a9834e8b7d302.svga",
"uuid": "5e569c9c-a1e4-44df-83eb-9249e00e228b",
"ext": ".svga"
}
],
"events": {
"in": {
"circle-game-start": {
"alias": "开始"
},
"circle-game-init": {
"alias": "初始化"
}
},
"out": {
"circle-game-end": {
"alias": "套圈完毕",
"data": {
"reason": "套圈结束,执行抽奖"
}
}
}
}
}
\ No newline at end of file
import { getTextureByName, createSvga } from './utils';
import { props } from "../props";
export default class Gameinit extends engine.Container {
private _isSetUp = false;
private totleY = 1200;
_body: engine.Rect;
isMove = false;
isChoose = true;
isDid = true;
num;
listGift = [];
constructor() {
super();
console.log("11111111111111");
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
}
/**首页加载 */
setup() {
console.log("初始化加载000000000000000000000000!");
if (this._isSetUp) {
return;
}
else {
this.loadThings();
console.log("this._isSetUp=", this._isSetUp, '<<<<');
}
}
/**套圈资源加载 */
loadThings() {
let self = this;
let body;
body = this._body = new engine.Rect;
body.width = 0.0001;
body.height = 0.0001;
this.addChild(body);
// let gift4 = this.addRes(body, '礼盒', 35, 115, 215, 122);
let gift0 = this.addRes(body, '礼盒', 250, 100, 247, 188);
let gift1 = this.addRes(body, '礼盒', 485, 85, 247, 190);
let gift2 = this.addRes(body, '礼盒', 385, -15, 222, 170);
let gift3 = this.addRes(body, '礼盒', 165, -15, 222, 170);
let gift4 = this.addRes(body, '礼盒', 20, 85, 247, 190);
this.listGift = [gift0, gift1, gift2, gift3, gift4];
let circle = this.addRes(body, '圈', 260, 350, 240, 80);
let giftSvga = createSvga("套中动效");
giftSvga.visible = false;
body.addChild(giftSvga);
let [v2X, v2Y] = props.ferruleModuleGlobalPosition;
body.x = v2X;
body.y = v2Y;
/* VVVVVVVVVVVVVVVV */
// let btn = this.addRes(body, '礼盒', 300, 900, 150, 150);
// btn.addEventListener(engine.MouseEvent.MOUSE_DOWN, function () {
// self.isMove = true;
// }, this);
// let btn1 = this.addRes(body, '礼盒', 500, 900, 200, 200);
// btn1.addEventListener(engine.MouseEvent.MOUSE_DOWN, function () {
// self.isChoose = true;
// giftSvga.visible = false;
// console.log(body.children[0], body.children[1], body.children[2], body.children[3], body.children[4], body.children[5]);
// body.children[self.num].visible = true;
// circle.x = 260; circle.y = 350; circle.width = 240; circle.height = 80;
// circle.visible = true;
// }, this);
/* AAAAAAAAAAAAAAAAA */
engine.globalEvent.addEventListener("circle-game-start", function () {
self.isMove = true;
console.log('this.isMove===', self.isMove);
}, this);
engine.globalEvent.addEventListener("circle-game-init", function () {
self.isChoose = true;
giftSvga.visible = false;
// console.log(body.children[0], body.children[1], body.children[2], body.children[3], body.children[4], body.children[5]);
body.children[self.num].visible = true;
circle.x = 260; circle.y = 350; circle.width = 240; circle.height = 80;
circle.visible = true;
}, this);
circle.addEventListener(engine.Event.ENTER_FRAME, function () {
if (self.isMove) {
console.log("物体移动");
if (self.isChoose) {
self.num = Math.floor(Math.random() * self.listGift.length);
self.isChoose = false;
}
self.nodeMove(circle, self.listGift[self.num], giftSvga);
}
});
}
/**套中动画播放 */
aniPlay(node0, targetNode, bool) {
node0.scaleX = this.currentScale(targetNode.y, this.totleY) - 0.05 * this.currentScale(targetNode.y, this.totleY);
node0.scaleY = this.currentScale(targetNode.y, this.totleY) - 0.05 * this.currentScale(targetNode.y, this.totleY);
// node0.anchor.x = node0.width / 2;
// node0.anchor.y = node0.height / 2;
node0.x = targetNode.x;
node0.y = targetNode.y;
node0.visible = true;
node0.play(false, false);
/**动画播放完毕,派发(执行)一个事件 */
node0.addEventListener(engine.Event.END_FRAME, function () {
console.log("播放到最后一帧", bool, '<<<');
engine.globalEvent.dispatchEvent("circle-game-end");
bool = false;
})
}
/**给场景添加图片,resName:资源名字,v2X:资源X位置, v2Y:资源Y位置, resW:资源Width, resH:资源Height */
addRes(fatherNode, resName, v2X, v2Y, resW, resH) {
console.log("进行资源的添加");
let thing = new engine.Sprite(getTextureByName(resName));
thing.x = v2X;
thing.y = v2Y;
thing.width = resW;
thing.height = resH;
return fatherNode.addChild(thing);
}
/** circle move */
nodeMove(moveNode, targetNode, nodePlay) {
console.log("moveNode.x=", moveNode.x, "targetNode.x=", targetNode.x);
let moveX = targetNode.x - moveNode.x;
let moveY = targetNode.y - moveNode.y;
console.log('moveX=', moveX, 'moveY=', moveY);
if (this.isDid) {
if (Math.abs(moveX) > 2) {
moveNode.x += moveX / Math.abs(moveX) * 5;
}
if (Math.abs(moveY) > 2) {
moveNode.y += moveY / Math.abs(moveY) * 5;
moveNode.scaleX = this.currentScale(moveNode.y, this.totleY) + 0.2;
moveNode.scaleY = moveNode.scaleX;
}
if (Math.abs(moveX) < 3 && Math.abs(moveY) < 3) {
targetNode.visible = false;
moveNode.visible = false;
this.aniPlay(nodePlay, targetNode, this.isDid);
this.isMove = false;
}
}
}
/**当前位置应该的尺寸大小 */
currentScale(currentY, totoleDisY) {
return (currentY + 830) / totoleDisY;
}
}
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
console.log('name',engine.getAssetByName(name));
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
/**
* Created by rockyl on 2019-11-20.
*/
import Gameinit from "./game/Gameinit";
import { injectProps, prepareProps } from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new Gameinit();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = "doll-machine";
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('food-fell-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
});
engine.globalEvent.dispatchEvent('food-fell-start');
}, 500);
});
engine.globalEvent.addEventListener('food-fell-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-game-over', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>美食从天而降</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: red;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
{
"name": "娃娃机",
"desc": "娃娃机模块",
"props": {
"frontmargin": {
"alias": "前排娃娃的间距",
"type": "number",
"default": 50
},
"backmargin": {
"alias": "后排娃娃的间距",
"type": "number",
"default": 50
},
"moveSpeed": {
"alias": "娃娃移动的速度",
"type": "number",
"default": 3
},
"bashouMoveDist": {
"alias": "爪子整体左右移动的范围",
"type": "number",
"default": 200
},
"ganMoveEndY": {
"alias": "杆子最后需要移动到的y值位置",
"type": "number",
"default": 820
},
"leftRotation": {
"alias": "左边爪子旋转角度",
"type": "number",
"default": 20
},
"rightRotation": {
"alias": "右边爪子旋转角度",
"type": "number",
"default": -20
}
},
"assets": [
{
"name": "游戏背景",
"url": "//yun.duiba.com.cn/aurora/assets/460fd0242aada85de5554391756db6ed2a232a9b.png",
"uuid": "05c378c3-bed0-4d5c-bed8-f05ae7920931",
"ext": ".png"
},
{
"name": "草泥马盒",
"url": "//yun.duiba.com.cn/aurora/assets/fde8c60981791e5136c7914274c2a2d0936626cd.png",
"uuid": "aa30ee7c-a6ad-4e10-9b6a-13b139664ab5",
"ext": ".png"
},
{
"name": "狗盒",
"url": "//yun.duiba.com.cn/aurora/assets/befb2c9ddfd8a5c4acd5126b2d793f7c1bcc40f2.png",
"uuid": "4483b626-697a-4aa4-ba57-0c22ddc7c0e6",
"ext": ".png"
},
{
"name": "猫盒",
"url": "///yun.duiba.com.cn/aurora/assets/50991e640e6bcc2eee02ba945d48a8430ddd2bee.png",
"uuid": "b70f2980-a2b3-4ef7-b060-b14dc7a8c9c8",
"ext": ".png"
},
{
"name": "后草泥马盒",
"url": "//yun.duiba.com.cn/aurora/assets/94884eafc876346e283efef2aa29bd6d2c36f627.png",
"uuid": "3f3feb30-6700-4ac7-a14e-6d7e41e8d4e8",
"ext": ".png"
},
{
"name": "后狗盒",
"url": "//yun.duiba.com.cn/aurora/assets/7deaaf45e03a626efbced90e4ad3d22373b01bd3.png",
"uuid": "b1422629-55d2-4b8b-bdd0-1b043f965248",
"ext": ".png"
},
{
"name": "后猫盒",
"url": "//yun.duiba.com.cn/aurora/assets/28a5b5b04c84d6acc86b7efb81dd6d7f717e0cda.png",
"uuid": "708da046-26e1-4ff7-abb6-35bf825a5d5b",
"ext": ".png"
},
{
"name": "中奖草泥马盒",
"url": "//yun.duiba.com.cn/aurora/assets/a47f438d016d1b178cdb5241651a78e4ea365e75.png",
"uuid": "c106cd1d-52a0-422a-976c-67151af0b484",
"ext": ".png"
},
{
"name": "中奖狗盒",
"url": "//yun.duiba.com.cn/aurora/assets/fd60c2da0ce78f7b7bed0e9c45644882a1a40d90.png",
"uuid": "3ff6fb20-4a2f-4789-998d-6078e3b603ec",
"ext": ".png"
},
{
"name": "中奖猫盒",
"url": "//yun.duiba.com.cn/aurora/assets/6211ab330a3768ff0a1920cff0ec41f29fa0903b.png",
"uuid": "04fa3325-87fc-4009-bfba-26a95d92d80c",
"ext": ".png"
},
{
"name": "前传输带",
"url": "//yun.duiba.com.cn/aurora/assets/7bccbc67b3f896176bed7d21c5f4d4307c3919be.png",
"uuid": "06bd03a4-43c3-49bb-94c5-6ef365f70291",
"ext": ".png"
},
{
"name": "后传输带",
"url": "//yun.duiba.com.cn/aurora/assets/df9b718f80747a1e21349d2b9ac35d5e19a61dad.png",
"uuid": "aa0c6ebc-164f-4767-90ca-a79be4316365",
"ext": ".png"
},
{
"name": "把手杆子",
"url": "//yun.duiba.com.cn/aurora/assets/5a9e4ba7ca6701eae85b6d6dcb0612ecb9a3eff9.png",
"uuid": "f2f1a937-00f4-442f-af4f-0bcb00656e69",
"ext": ".png"
},
{
"name": "把手",
"url": "//yun.duiba.com.cn/aurora/assets/71255a6f3cdf9f66d53589e46d72fcd20fef468d.png",
"uuid": "d9b395b5-4e46-43a5-aa2b-bfdd81c07fa7",
"ext": ".png"
},
{
"name": "伸缩杆",
"url": "//yun.duiba.com.cn/aurora/assets/a9cf8b147c52b7d4247e80e90e098f787808bfa9.png",
"uuid": "fddb4636-9c62-47b2-ba5e-f2cd820dbccc",
"ext": ".png"
},
{
"name": "左爪",
"url": "//yun.duiba.com.cn/aurora/assets/1e8634fd94bda455d11956c2847d3823e80701d3.png",
"uuid": "739014d2-3193-4853-bf8d-349bd3e8d990",
"ext": ".png"
},
{
"name": "右爪",
"url": "//yun.duiba.com.cn/aurora/assets/4bfc510e0d1fa1db77f5effa187294af38b74ff6.png",
"uuid": "4fb43b19-67e9-42cc-b461-35c005c714fb",
"ext": ".png"
},
{
"name": "连接点",
"url": "//yun.duiba.com.cn/aurora/assets/39f39234631f739e70e9ab8b713284379f4016fb.png",
"uuid": "2021124f-ffcb-487f-a24f-a00f3d8aae95",
"ext": ".png"
}
],
"events": {
"in": {
"doll-machine-reset": {
"alias": "重置"
},
"doll-machine-prize": {
"alias": "开始",
"data": {
"prize": true
}
}
},
"out": {
"doll-machine-gameover": {
"alias": "重置完毕",
"data": null
}
}
}
}
This diff is collapsed.
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class GameWrapper extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('doll-machine-reset', this.reset, this);
engine.globalEvent.addEventListener('doll-machine-prize', this.start, this);
// engine.globalEvent.addEventListener('food-fell-start', this.start, this);
// engine.globalEvent.addEventListener('food-fell-pause', this.pause, this);
// engine.globalEvent.addEventListener('food-fell-resume', this.resume, this);
// engine.globalEvent.addEventListener('food-fell-revive', this.revive, this);
// engine.globalEvent.addEventListener('food-fell-clear', this.clear, this);
// this.addEventListener(engine.MouseEvent.CLICK, this.onTap, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
// gameView.reset();
// gameView.start()
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
console.log('监听开始');
injectProps(event.data);
// this._status = 1;
this._gameView.start(event.data);
}
pause() {
this._gameView.pause();
}
resume() {
this._gameView.resume();
}
revive() {
this._gameView.revive();
}
clear() {
this._gameView.visible = false;
}
private onTap(event) {
// this._gameView.tap(event);
}
}
/**
* Created by rockyl on 2020-02-02.
*
* 掉落物品
*/
import { getTextureByName } from "./utils";
import { props } from "../props";
export class Goods extends engine.Container {
private _body: engine.Rect;
private _toY;
constructor() {
super();
let body;
body = this._body = new engine.Rect();
// let rain = new engine.Sprite(getTextureByName('雨滴'));
// rain["npcType"]="rain"
// let stone = new engine.Sprite(getTextureByName('石块'));
// stone["npcType"]="stone"
// let boom = new engine.Sprite(getTextureByName('炸弹'));
// boom["npcType"]="boom"
let box1 = new engine.Sprite(getTextureByName("草泥马盒"));
box1["npcType"] = "box1";
let box2 = new engine.Sprite(getTextureByName("狗盒"));
box2["npcType"] = "box2";
let box3 = new engine.Sprite(getTextureByName("猫盒"));
box3["npcType"] = "box3";
// rain.visible=false;
// stone.visible=false;
// boom.visible=false;
// body.addChild(rain)
// body.addChild(stone)
// body.addChild(boom)
box1.visible = false;
box2.visible = false;
box3.visible = false;
body.addChild(box1);
body.addChild(box2);
body.addChild(box3);
this.addChild(body);
body.width = 0.0001;
body.height = 0.0001;
body.mouseEnabled = false;
}
getRandomNumberByRange(start, end) {
return Math.floor(Math.random() * (end - start) + start);
}
// reset() {
// this.visible = true;
// this.rotation = 0;
// this.anchorOffsetY = 0;
// this.y = 0;
// this.x = (750-120)*Math.random()+30;
// this.rotation = 0;
// let random=Math.random()
// if(random<props.goodsProbability[0]){
// this.showNpc("box1")
// }else if(random>=props.goodsProbability[0]&&random<=(props.goodsProbability[0]+props.goodsProbability[1])){
// this.showNpc("box2")
// }else if(random>(props.goodsProbability[0]+props.goodsProbability[1])){
// this.showNpc("box3")
// }
// }
reset() {
this.visible = true;
this.y = 200;
this.x = 0;
this.rotation = 0;
let random = Math.random();
if (random < 0.3) {
this.showNpc("box1");
} else if (random < 0.6) {
this.showNpc("box2");
} else {
this.showNpc("box3");
}
// this.showNpc("box1");
// this.showNpc("box2");
// this.showNpc("box3");
}
showNpc(type) {
for (let i = 0; i < this._body.children.length; i++) {
this._body.children[i].visible = false;
this._body.children[i].mouseEnabled = false;
}
for (let i = 0; i < this._body.children.length; i++) {
if (this._body.children[i]["npcType"] == type) {
this["npcType"] = type;
console.log(type);
this._body.children[i].visible = true;
this._body.children[i].mouseEnabled = false;
}
}
}
set anchorOffsetY(v) {
this._body.y = v;
}
}
import { getTextureByName } from "./utils";
import { props } from "../props";
import GameView from './GameView';
export class Zhuazi extends engine.Container {
private bashouGan: engine.Sprite;
private bashou: engine.Sprite;
private ganzi: engine.Sprite;
private left_zhuazi: engine.Sprite;
private right_zhuazi: engine.Sprite;
private connect: engine.Sprite;
private ganNode: engine.Container;
private moveNode: engine.Container;
private moveArr = [];
private zhuaziY;
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
private itemShow: engine.Container;
private prizeBoxs = [];
public GameView: GameView;
constructor() {
super();
}
setup() {
this.ganNode = new engine.Container();
this.moveNode = new engine.Container();
this.ganNode.x = 280;
this.ganNode.y = 350;
this.bashouGan = new engine.Sprite(getTextureByName("把手杆子"));
this.bashouGan.x = 60;
this.bashouGan.y = 275;
this.bashou = new engine.Sprite(getTextureByName("把手"));
this.bashou.x = 0;
this.bashou.y = 263;
this.ganzi = new engine.Sprite(getTextureByName("伸缩杆"));
this.ganzi.x = 97;
this.ganzi.y = 290;
this.connect = new engine.Sprite(getTextureByName("连接点"));
this.connect.x = 18;
this.connect.y = -5;
this.left_zhuazi = new engine.Sprite(getTextureByName("左爪"));
this.left_zhuazi.x = -15;
this.left_zhuazi.y = 60;
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
this.right_zhuazi = new engine.Sprite(getTextureByName("右爪"));
this.right_zhuazi.x = 98;
this.right_zhuazi.y = 60;
this.ganNode.addChild(this.left_zhuazi);
this.ganNode.addChild(this.right_zhuazi);
this.ganNode.addChild(this.connect);
this.ganNode.x = 30;
this.zhuaziY = this.ganNode.y;
this.moveNode.addChild(this.ganzi);
this.moveNode.addChild(this.ganNode);
this.moveNode.addChild(this.bashou);
this.moveNode.x = 262;
// this.moveNode.
// this.moveArr = [this.bashou, this.ganzi, this.ganNode];
this.addChild(this.bashouGan);
// this.addChild(this.ganzi);
// this.addChild(this.bashou);
// this.addChild(this.ganNode);
this.addChild(this.moveNode);
this.createPrizeBox();
// setTimeout(() => {
// this.move();
// }, 2000)
}
createPrizeBox() {
this.box1 = new engine.Sprite(getTextureByName("中奖狗盒"));
this.box1["npcType"] = "box1";
this.box2 = new engine.Sprite(getTextureByName("中奖猫盒"));
this.box2["npcType"] = "box2";
this.box3 = new engine.Sprite(getTextureByName("中奖草泥马盒"));
this.box3["npcType"] = "box3";
this.box4 = new engine.Sprite(getTextureByName("中奖狗盒"));
this.box4["npcType"] = "box4";
this.box5 = new engine.Sprite(getTextureByName("中奖猫盒"));
this.box5["npcType"] = "box5";
this.prizeBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5];
this.prizeBoxs.forEach(item => {
this.ganNode.addChild(item);
item.visible = false;
item.x = 15;
item.y = 48;
})
}
showPrizeBox() {
this.prizeBoxs.forEach(item => {
console.log(this.GameView.getBox()['npcType']);
if (item['npcType'] === this.GameView.getBox()['npcType']) {
item.visible = true;
this.itemShow = item;
} else {
item.visible = false;
}
})
}
move() {
let rndist = Math.random();
let halfWidth = this.bashou.width / 2;
let randomX = rndist * (rndist > 0.5 ? 1 : -1) * props.bashouMoveDist;
console.log(randomX);
engine.Tween.get(this.moveNode).to({ x: 370 + halfWidth - 71}, 1000).call(() => {
this.zhangkai();
});
}
zhangkai() {
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: props.leftRotation}, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: props.rightRotation }, 1000);
setTimeout(() => {
this.getLong();
}, 500);
}
getLong() {
let droptime = Number((this.GameView.getMoveX() / 60 - 1).toFixed(2)) * 1000;
console.log('dr', droptime);
let times = (props.ganMoveEndY - this.ganzi.y ) / this.ganzi.height;
console.log(Number(times.toFixed(2)) );
engine.Tween.get(this.ganzi).to({ scaleY: Number(times.toFixed(2)) }, droptime).to({ scaleY: 1 }, droptime)
console.log('node', this.zhuaziY);
engine.Tween.get(this.ganNode).to({ y: props.ganMoveEndY }, droptime).call(() => {
this.GameView.stopMove();
if (this.GameView.ifPrize) {
this.showPrizeBox();
this.GameView.setVisible(false);
}
}).to({ y: this.zhuaziY }, droptime).call(() => {
// this.getReset();
if (this.GameView.ifPrize) {
this.itemShow.visible = false;
}
engine.globalEvent.dispatchEvent('doll-machine-gameover');
})
}
getReset() {
// if (this.GameView.ifPrize) {
// this.itemShow.visible = false;
// }
this.left_zhuazi.anchorX = this.left_zhuazi.width;
this.left_zhuazi.anchorY = 0;
engine.Tween.get(this.moveNode, {loop: false}).to({x: 262}, 1000);
engine.Tween.get(this.left_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
engine.Tween.get(this.right_zhuazi, { loop: false }).to({ rotation: 0 }, 1000);
this.GameView.resetMoveX();
}
}
\ No newline at end of file
import { getTextureByName } from "./utils";
import { props } from "../props";
export class BackBoxs extends engine.Container {
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
private backBoxs=[];
constructor() {
super();
}
setup() {
let initX , initY = 0;
this.box1 = new engine.Sprite(getTextureByName("后狗盒"));
initX = this.box1.x = 188;
initY = this.box1.y = 616;
this.box2 = new engine.Sprite(getTextureByName("后猫盒"));
this.box3 = new engine.Sprite(getTextureByName("后草泥马盒"));
this.box4 = new engine.Sprite(getTextureByName("后狗盒"));
this.box5 = new engine.Sprite(getTextureByName("后猫盒"));
this.backBoxs = [this.box1, this.box2, this.box3, this.box4, this.box5];
for (let i = 0; i < this.backBoxs.length; i++) {
// this.backBoxs[i].scaleX = 0.5;
// this.backBoxs[i].scaleY = 0.5;
if(i == 0) {
this.backBoxs[i].x = initX;
} else {
this.backBoxs[i].x = this.backBoxs[i - 1].x + this.backBoxs[i].width + props.backmargin;
}
this.backBoxs[i].y = initY;
this.addChild(this.backBoxs[i]);
}
this.addEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
frameMove() {
this.backBoxs.forEach((item) => {
item.x -= props.moveSpeed;
if (item.x <= 0) {
let lastitem = this.backBoxs.shift();
lastitem.x = this.backBoxs[this.backBoxs.length - 1].x + item.width + props.backmargin;
this.backBoxs.push(lastitem);
}
})
}
}
\ No newline at end of file
import { getTextureByName } from "./utils";
import GameView from './GameView';
import { props } from "../props";
export class FrontBoxs extends engine.Container {
//盒子1
private box1: engine.Container;
//盒子2
private box2: engine.Container;
//盒子3
private box3: engine.Container;
//盒子4
private box4: engine.Container;
//盒子5
private box5: engine.Container;
// 需隐藏的盒子
private hideBox: engine.Container;
private frontBoxs=[];
public GameView: GameView;
constructor() {
super();
}
setup() {
let initX , initY = 0;
this.box1 = new engine.Sprite(getTextureByName("狗盒"));
this.box1["npcType"] = "box1";
initX = this.box1.x = 435;
initY = this.box1.y = 614;
this.box2 = new engine.Sprite(getTextureByName("猫盒"));
this.box2["npcType"] = "box2";
this.box3 = new engine.Sprite(getTextureByName("草泥马盒"));
this.box3["npcType"] = "box3";
this.box4 = new engine.Sprite(getTextureByName("狗盒"));
this.box4["npcType"] = "box4";
this.box5 = new engine.Sprite(getTextureByName("猫盒"));
this.box5["npcType"] = "box5";
this.frontBoxs = [this.box1, this.box2, this.box3, this.box4];
for(let i = 0; i < this.frontBoxs.length; i++) {
if(i == 0) {
this.frontBoxs[i].x = initX ;
} else {
this.frontBoxs[i].x = this.frontBoxs[i - 1].x - this.box1.width - props.frontmargin;
}
this.frontBoxs[i].y = initY;
this.addChild(this.frontBoxs[i]);
}
this.addEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
frameMove() {
this.frontBoxs.forEach((item, index) => {
item.x += props.moveSpeed;
if(item.x <=0 && !item.visible) {
item.visible = true;
}
if(item.x >= 750) {
let lastitem = this.frontBoxs.shift();
lastitem.x = this.frontBoxs[this.frontBoxs.length - 1].x - this.box1.width - props.frontmargin;
if (!this.GameView.getMoveX() && item.x <= 0 && this.GameView.startstatus) {
this.GameView.setMoveX((370 - item.x - 13) / props.moveSpeed, item);
this.hideBox = item;
}
this.frontBoxs.push(lastitem);
}
})
}
stop() {
// this.removeEventListener(engine.Event.ENTER_FRAME, this.frameMove, this);
}
showHidePrizeBox(isshow) {
this.hideBox.visible = isshow
}
}
\ No newline at end of file
/**
* Created by rockyl on 2020-02-03.
*/
import {Goods} from "./Goods";
import ObjectPool = engine.ObjectPool;
export const PoolName: string = 'goods';
ObjectPool.registerPool(PoolName, function () {
return new Goods();
}, function (item: Goods, data) {
item.reset();
});
/**
* Created by rockyl on 2020-01-21.
*/
export function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid);
}
export function getTextureByName(name) {
return getTexture(engine.getAssetByName(name).uuid);
}
export function playSound(name) {
engine.playSound(engine.getAssetByName(name).uuid, {keep: true});
}
export function createSvga(name, anchorName?) {
let inst = new svga.Svga();
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
return inst;
}
\ No newline at end of file
/**
* Created by rockyl on 2019-11-20.
*/
import {GameWrapper} from "./game/GameWrapper";
import {injectProps, prepareProps} from "./props";
export default function (props) {
prepareProps();
injectProps(props);
let instance = new GameWrapper();
return instance;
}
/**
* Created by rockyl on 2020-01-21.
*/
export let props: any = {};
export function prepareProps() {
let metaProps = getProps();
engine.injectProp(props, metaProps);
}
export function injectProps(p) {
engine.injectProp(props, p);
}
/**
* Created by renjianfeng on 2020-03-13.
*/
const customId = "doll-machine2";
(async function () {
let customModule = await fetch(`../meta.json`);
customModule = await customModule.json();
console.log(customModule);
await loadAssets(customModule.assets);
launchWithCustomModule(customModule);
})();
function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
props,
assets,
};
engine.registerCustomModules([customModuleIns]);
engine.launchWithConfig({
options: {
entrySceneView: 'entry',
},
assets: [],
views: [{
name: 'entry',
type: 'node',
properties: {
x: 0,
y: 0,
}
}],
}, null, function () {
setTimeout(() => {
engine.addCustomModule(customId, engine.gameStage.sceneContainer.getChildAt(0));
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('food-fell-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
});
engine.globalEvent.dispatchEvent('food-fell-start');
}, 500);
});
engine.globalEvent.addEventListener('food-fell-time-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-score-update', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('food-fell-game-over', (e) => {
console.log(e.type, e.data);
});
}
function getAssetByUUID(uuid) {
return engine.resolveCustomAsset(customId, uuid);
}
function getProps() {
return engine.getProps(customId);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>美食从天而降</title>
<meta name="viewport"
content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="true"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<style>
html,
body {
padding: 0;
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: red;
}
</style>
</head>
<body>
<div id="game-container" style="line-height:0;font-size:0"></div>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"></script>
<script crossorigin="anonymous" src="//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script src="app.js"></script>
<script src="props.js"></script>
<script src="load-assets.js"></script>
<script src="main.js"></script>
<script>
</script>
</body>
\ No newline at end of file
/**
* Created by rockyl on 2020-01-21.
*/
const assets = [
{
"name": "玩家icon",
"url": "//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png",
"uuid": "66f23d13-82a5-4cec-9496-301ec240d087",
"ext": ".png"
},
{
"name": "雨滴",
"url": "//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png",
"uuid": "264a6192-d7bf-45e8-8f15-6ba2c439a532",
"ext": ".png"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png",
"uuid": "eb88b42d-e151-4c1b-94b9-7c16f7bfac29",
"ext": ".png"
},
{
"name": "石块",
"url": "//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png",
"uuid": "ab1bdabc-21ba-46bf-9299-6c638f766c88",
"ext": ".png"
},
{
"name": "水花",
"url": "//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga",
"uuid": "b521bf94-20e1-44dd-8eca-d24996cbaeae",
"ext": ".svga"
},
{
"name": "炸弹",
"url": "//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga",
"uuid": "322edf39-805b-4e84-9d07-5573dfeebc0e",
"ext": ".svga"
},
{
"name": "玩家",
"url": "//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga",
"uuid": "71d8dcbc-3931-471a-b585-b3ae01b25aa6",
"ext": ".svga"
}
];
function loadAssets(customModuleAssets, onProgress, onComplete){
return engine.loadAssets(assets.concat(...customModuleAssets), onProgress, onComplete);
}
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-09.
*/
import GameView from "./GameView";
import {injectProps} from "../props";
export class GameWrapper extends engine.Container {
private _status;
private _gameView: GameView;
constructor() {
super();
engine.globalEvent.addEventListener('doll-machine2-game-init', this.reset, this);
engine.globalEvent.addEventListener('doll-machine2-game-start', this.start, this);
let gameView = this._gameView = new GameView();
this.addChild(gameView);
// gameView.reset();
// gameView.start()
}
reset(event: engine.Event) {
injectProps(event.data);
this._gameView.visible = true;
this._gameView.reset();
}
start(event: engine.Event) {
console.log('监听开始');
injectProps(event.data);
// this._status = 1;
this._gameView.start(event.data);
}
pause() {
this._gameView.pause();
}
resume() {
this._gameView.resume();
}
revive() {
this._gameView.revive();
}
clear() {
this._gameView.visible = false;
}
private onTap(event) {
// this._gameView.tap(event);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Created by rockyl on 2020-01-21.
*/
let customModuleProps = {
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment