├── .gitignore ├── game.js ├── assets ├── arrow-d.png ├── arrow-l.png ├── arrow-r.png ├── arrow-u.png ├── arrow_left.png ├── basic │ ├── phaser.png │ ├── ra_einstein.jpg │ ├── running_bot.png │ └── running_bot.js └── plane │ ├── audio │ ├── bgm.mp3 │ ├── boom.mp3 │ └── bullet.mp3 │ └── images │ ├── bg.jpg │ ├── enemy.png │ ├── hero.png │ ├── bullet.png │ ├── common.png │ └── explosion.png ├── game.json ├── js ├── states │ ├── AnimationState.js │ ├── BootState.js │ ├── PreloadState.js │ ├── MenuState.js │ └── SubMenuState.js ├── libs │ ├── phaser-wx.js │ ├── phaser-wx-main.js │ └── weapp-adapter.js ├── game │ ├── index.js │ └── plane │ │ ├── atlas │ │ └── common.js │ │ └── states │ │ ├── PlanePreloadState.js │ │ └── PlaneGameState.js ├── base │ ├── BackToMenuState.js │ └── BackToSubMenuState.js ├── basic │ ├── BasicLoadAnImageState.js │ ├── BasicRenderTextState.js │ ├── BasicMoveAnImageState.js │ ├── BasicTweenAnImageState.js │ ├── BasicLoadAnAnimationState.js │ ├── BasicClickOnAnImageState.js │ ├── BasicImageFollowInputState.js │ └── index.js ├── objects │ ├── CaseRect.js │ ├── Arrow.js │ └── ExampleRect.js ├── open │ ├── OpenGetCloudScoreState.js │ ├── OpenGetFriendCloudScoreState.js │ ├── OpenShowOpenCanvasState.js │ ├── index.js │ ├── OpenSetCloudScoreState.js │ └── OpenShowRankingListState.js ├── main.js ├── plugins │ └── ChineseTextPlugin.js ├── config │ └── Examples.js └── openData │ └── index.js ├── README.md └── project.config.json /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /game.js: -------------------------------------------------------------------------------- 1 | import './js/libs/weapp-adapter.js' 2 | 3 | import './js/main.js' 4 | -------------------------------------------------------------------------------- /assets/arrow-d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/arrow-d.png -------------------------------------------------------------------------------- /assets/arrow-l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/arrow-l.png -------------------------------------------------------------------------------- /assets/arrow-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/arrow-r.png -------------------------------------------------------------------------------- /assets/arrow-u.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/arrow-u.png -------------------------------------------------------------------------------- /game.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceOrientation": "portrait", 3 | "openDataContext": "js/openData" 4 | } 5 | -------------------------------------------------------------------------------- /assets/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/arrow_left.png -------------------------------------------------------------------------------- /assets/basic/phaser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/basic/phaser.png -------------------------------------------------------------------------------- /assets/plane/audio/bgm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/audio/bgm.mp3 -------------------------------------------------------------------------------- /assets/plane/audio/boom.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/audio/boom.mp3 -------------------------------------------------------------------------------- /assets/plane/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/images/bg.jpg -------------------------------------------------------------------------------- /assets/basic/ra_einstein.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/basic/ra_einstein.jpg -------------------------------------------------------------------------------- /assets/basic/running_bot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/basic/running_bot.png -------------------------------------------------------------------------------- /assets/plane/audio/bullet.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/audio/bullet.mp3 -------------------------------------------------------------------------------- /assets/plane/images/enemy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/images/enemy.png -------------------------------------------------------------------------------- /assets/plane/images/hero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/images/hero.png -------------------------------------------------------------------------------- /assets/plane/images/bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/images/bullet.png -------------------------------------------------------------------------------- /assets/plane/images/common.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/images/common.png -------------------------------------------------------------------------------- /assets/plane/images/explosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/channingbreeze/phaser-wxdemo/HEAD/assets/plane/images/explosion.png -------------------------------------------------------------------------------- /js/states/AnimationState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | export default class AnimationState extends Phaser.State { 4 | 5 | constructor(game) { 6 | super(); 7 | this.game = game; 8 | } 9 | 10 | create() { 11 | console.log('animation') 12 | this.game.state.start('menu'); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phaser-wxdemo 2 | 3 | 基于arcadephysics编译出来的phaser,做了一些修改。 4 | 5 | 解决了以下移植问题: 6 | * PIXI not defined 7 | * canvas的指定 8 | * touch事件问题 9 | * 音频播放问题 10 | * atlas文件加载 11 | 12 | 飞机大战demo完工,源码目录:js/plane 13 | 14 | 完成了demo展示的基本框架 15 | 完成了主菜单和子菜单的功能 16 | 17 | basic移植完毕 18 | 开放域相关功能完毕 19 | 20 | 中文插件移植完工,源码目录:js/plugins/ChineseTextPlugin.js 21 | -------------------------------------------------------------------------------- /js/libs/phaser-wx.js: -------------------------------------------------------------------------------- 1 | import PIXI from './pixi-wx.js'; 2 | import Phaser from './phaser-wx-main.js'; 3 | import './phaser-wx-part1.js'; 4 | import './phaser-wx-part2.js'; 5 | import './phaser-wx-part3.js'; 6 | import './phaser-wx-part4.js'; 7 | import './phaser-wx-part5.js'; 8 | import './phaser-wx-part6.js'; 9 | import './phaser-wx-part7.js'; 10 | import './phaser-wx-part8.js'; 11 | 12 | module.exports = Phaser; 13 | -------------------------------------------------------------------------------- /js/game/index.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | import PlanePreloadState from './plane/states/PlanePreloadState.js' 4 | import PlaneGameState from './plane/states/PlaneGameState.js' 5 | 6 | export default class GameExamples { 7 | 8 | constructor(game) { 9 | 10 | game.state.add('planePreload', new PlanePreloadState(game)); 11 | game.state.add('planeGame', new PlaneGameState(game)); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /js/states/BootState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | export default class BootState extends Phaser.State { 4 | 5 | constructor(game) { 6 | super(); 7 | this.game = game; 8 | } 9 | 10 | create() { 11 | // this is very important 12 | this.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT; 13 | 14 | // invalid sound lock 15 | this.game.sound.touchLocked = false; 16 | 17 | this.game.state.start('preload'); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /js/base/BackToMenuState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import Arrow from '../objects/Arrow.js'; 3 | 4 | export default class BackToMenuState extends Phaser.State { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | create() { 12 | this.arrowBack = new Arrow(this.game, 26, 26, 'arrowBack'); 13 | this.arrowBack.addClick(this.backToMenu, this); 14 | } 15 | 16 | backToMenu() { 17 | this.game.state.start('menu'); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /js/game/plane/atlas/common.js: -------------------------------------------------------------------------------- 1 | var atlas = {"frames": [ 2 | { 3 | "filename": "dialog", 4 | "frame": {"x":0,"y":0,"w":119,"h":108}, 5 | "rotated": false, 6 | "trimmed": true, 7 | "spriteSourceSize": {"x":0,"y":0,"w":119,"h":108}, 8 | "sourceSize": {"w":119,"h":108} 9 | }, 10 | { 11 | "filename": "button", 12 | "frame": {"x":120,"y":6,"w":39,"h":24}, 13 | "rotated": false, 14 | "trimmed": true, 15 | "spriteSourceSize": {"x":0,"y":0,"w":39,"h":24}, 16 | "sourceSize": {"w":39,"h":24} 17 | } 18 | ]}; 19 | 20 | export default atlas; 21 | -------------------------------------------------------------------------------- /js/basic/BasicLoadAnImageState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToSubMenuState from '../base/BackToSubMenuState.js'; 3 | 4 | export default class BasicLoadAnImageState extends BackToSubMenuState { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | init(key) { 12 | super.init(key); 13 | } 14 | 15 | preload() { 16 | // 加载一个图片,之后可通过 einstein 来引用 17 | this.game.load.image('einstein', 'assets/basic/ra_einstein.jpg'); 18 | } 19 | 20 | create() { 21 | super.create(); 22 | 23 | // 在(100, 100)位置显示该图片 24 | this.game.add.sprite(100, 100, 'einstein'); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /js/states/PreloadState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | export default class PreloadState extends Phaser.State { 4 | 5 | constructor(game) { 6 | super(); 7 | this.game = game; 8 | } 9 | 10 | preload() { 11 | this.game.load.image('arrowBack', 'assets/arrow_left.png'); 12 | this.game.load.image('arrowLeft', 'assets/arrow-l.png'); 13 | this.game.load.image('arrowRight', 'assets/arrow-r.png'); 14 | this.game.load.image('arrowUp', 'assets/arrow-u.png'); 15 | this.game.load.image('arrowDown', 'assets/arrow-d.png'); 16 | } 17 | 18 | create() { 19 | this.game.state.start('animation'); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": false, 5 | "es6": true, 6 | "postcss": true, 7 | "minified": true, 8 | "newFeature": true 9 | }, 10 | "compileType": "game", 11 | "libVersion": "game", 12 | "appid": "wxb11b771731e848ed", 13 | "projectname": "phaser-wx", 14 | "isGameTourist": false, 15 | "condition": { 16 | "search": { 17 | "current": -1, 18 | "list": [] 19 | }, 20 | "conversation": { 21 | "current": -1, 22 | "list": [] 23 | }, 24 | "game": { 25 | "currentL": -1, 26 | "list": [] 27 | }, 28 | "miniprogram": { 29 | "current": -1, 30 | "list": [] 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /js/basic/BasicRenderTextState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToSubMenuState from '../base/BackToSubMenuState.js'; 3 | 4 | export default class BasicRenderTextState extends BackToSubMenuState { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | init(key) { 12 | super.init(key); 13 | } 14 | 15 | create() { 16 | super.create(); 17 | 18 | var text = "- phaser -\n with a sprinkle of \n pixi dust."; 19 | // 文字样式 20 | var style = { font: "32px Arial", fill: "#ff0044", align: "center" }; 21 | // 显示文字 22 | var t = this.game.add.text(this.game.world.centerX - 160, 300, text, style); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /js/basic/BasicMoveAnImageState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToSubMenuState from '../base/BackToSubMenuState.js'; 3 | 4 | export default class BasicMoveAnImageState extends BackToSubMenuState { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | init(key) { 12 | super.init(key); 13 | } 14 | 15 | preload() { 16 | // 加载一个图片,之后可通过 einstein 来引用 17 | this.game.load.image('einstein', 'assets/basic/ra_einstein.jpg'); 18 | } 19 | 20 | create() { 21 | super.create(); 22 | 23 | var sprite = this.game.add.sprite(0, 0, 'einstein'); 24 | // 精灵启动物理引擎 25 | this.game.physics.enable(sprite, Phaser.Physics.ARCADE); 26 | // 设置水平速度150 27 | sprite.body.velocity.x = 150; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /js/objects/CaseRect.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | export default class CaseRect extends Phaser.Sprite { 4 | 5 | constructor(game, x, y, properties) { 6 | 7 | var bmd = game.add.bitmapData(game.width - 100, 30); 8 | 9 | bmd.ctx.fillStyle = "#fff"; 10 | bmd.ctx.fillRect(0, 0, game.width - 100, 30); 11 | 12 | super(game, x, y, bmd); 13 | this.game = game; 14 | 15 | this.anchor.setTo(0.5, 0.5); 16 | 17 | var style = { font: "20px Arial", fill: "#000", align: "center" }; 18 | var text = this.game.make.text(0, 0, properties.name, style); 19 | text.anchor.setTo(0.5, 0.5); 20 | this.addChild(text); 21 | 22 | } 23 | 24 | addClick(clickFn, context) { 25 | 26 | this.events.onInputUp.add(clickFn, context); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /js/basic/BasicTweenAnImageState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToSubMenuState from '../base/BackToSubMenuState.js'; 3 | 4 | export default class BasicTweenAnImageState extends BackToSubMenuState { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | init(key) { 12 | super.init(key); 13 | } 14 | 15 | preload() { 16 | // 加载一个图片,之后可通过 einstein 来引用 17 | this.game.load.image('einstein', 'assets/basic/ra_einstein.jpg'); 18 | } 19 | 20 | create() { 21 | super.create(); 22 | 23 | this.sprite = this.game.add.sprite(0, 0, 'einstein'); 24 | // 添加一个Tween动画 25 | this.tween = this.game.add.tween(this.sprite); 26 | // 5秒内线性移动到x为100处 27 | this.tween.to({ x: 100 }, 5000, 'Linear', true, 0); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /js/base/BackToSubMenuState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import Arrow from '../objects/Arrow.js'; 3 | import Examples from '../config/Examples.js'; 4 | 5 | export default class BackToSubMenuState extends Phaser.State { 6 | 7 | constructor(game) { 8 | super(); 9 | this.game = game; 10 | 11 | this.map = {}; 12 | for(var i=0; i 8) { 32 | // 让精灵以300的速度靠近鼠标(或者Touch) 33 | this.game.physics.arcade.moveToPointer(this.sprite, 300); 34 | } else { 35 | // 精灵速度设为0 36 | this.sprite.body.velocity.set(0); 37 | } 38 | } 39 | 40 | render() { 41 | // 在(32,32)的地方打印输入的调试信息 42 | this.game.debug.inputInfo(32, 32); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /js/basic/index.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | import BasicLoadAnImageState from './BasicLoadAnImageState.js' 4 | import BasicClickOnAnImageState from './BasicClickOnAnImageState.js' 5 | import BasicMoveAnImageState from './BasicMoveAnImageState.js' 6 | import BasicImageFollowInputState from './BasicImageFollowInputState.js' 7 | import BasicLoadAnAnimationState from './BasicLoadAnAnimationState.js' 8 | import BasicRenderTextState from './BasicRenderTextState.js' 9 | import BasicTweenAnImageState from './BasicTweenAnImageState.js' 10 | 11 | export default class BasicExamples { 12 | 13 | constructor(game) { 14 | 15 | game.state.add('basicLoadAnImage', new BasicLoadAnImageState(game)); 16 | game.state.add('basicClickOnAnImageState', new BasicClickOnAnImageState(game)); 17 | game.state.add('basicMoveAnImageState', new BasicMoveAnImageState(game)); 18 | game.state.add('basicImageFollowInputState', new BasicImageFollowInputState(game)); 19 | game.state.add('basicLoadAnAnimationState', new BasicLoadAnAnimationState(game)); 20 | game.state.add('basicRenderTextState', new BasicRenderTextState(game)); 21 | game.state.add('basicTweenAnImageState', new BasicTweenAnImageState(game)); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /js/plugins/ChineseTextPlugin.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | Phaser.Plugin.ChineseTextPlugin = function(game, parent) { 4 | Phaser.Plugin.call(this, game, parent); 5 | } 6 | 7 | Phaser.Plugin.ChineseTextPlugin.prototype = Object.create(Phaser.Plugin.prototype); 8 | Phaser.Plugin.ChineseTextPlugin.prototype.constructor = Phaser.Plugin.ChineseTextPlugin; 9 | 10 | Phaser.Plugin.ChineseTextPlugin.prototype.forceWrap = function(x, y, str, style) { 11 | 12 | var newStr = ""; 13 | 14 | if(style.wordWrap && style.wordWrapWidth) { 15 | var tmp = this.game.add.text(x, y, str, style); 16 | 17 | var ratio = tmp.width / style.wordWrapWidth; 18 | var i = 0, j = 0; 19 | while(i < str.length) { 20 | tmp.text = str.substring(j, i); 21 | if(tmp.width > style.wordWrapWidth) { 22 | newStr += str.substring(j, i - 1); 23 | newStr += " "; 24 | j = i - 1; 25 | i = j; 26 | } else { 27 | i = i + 1; 28 | } 29 | } 30 | newStr += str.substring(j, str.length); 31 | tmp.destroy(); 32 | } else { 33 | newStr = str; 34 | } 35 | 36 | var text = this.game.add.text(x, y, newStr, style); 37 | return text; 38 | 39 | } 40 | 41 | export default Phaser.Plugin.ChineseTextPlugin; 42 | 43 | -------------------------------------------------------------------------------- /js/objects/ExampleRect.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | 3 | export default class ExampleRect extends Phaser.Sprite { 4 | 5 | constructor(game, x, y, properties) { 6 | 7 | var bmd = game.add.bitmapData(100, 100); 8 | 9 | bmd.ctx.beginPath(); 10 | bmd.ctx.arc(50, 50, 50, 0, Math.PI * 2); 11 | var radialGradient = bmd.ctx.createRadialGradient(50, 50, 40, 50, 50, 50); 12 | radialGradient.addColorStop(0, '#43d4d9'); 13 | radialGradient.addColorStop(1, '#4851ff'); 14 | bmd.ctx.fillStyle = radialGradient; 15 | bmd.ctx.fill(); 16 | 17 | super(game, x, y, bmd); 18 | this.game = game; 19 | 20 | this.anchor.setTo(0.5, 0.5); 21 | 22 | var style = { font: "32px Arial", fill: "#000", align: "center" }; 23 | var text = this.game.make.text(0, 0, properties.name, style); 24 | text.anchor.setTo(0.5, 0.5); 25 | this.addChild(text); 26 | 27 | this.events.onInputDown.add(this.onDown, this); 28 | this.events.onInputUp.add(this.onUp, this); 29 | 30 | } 31 | 32 | onDown() { 33 | this.scale.setTo(1.3, 1.3); 34 | } 35 | 36 | onUp() { 37 | this.scale.setTo(1, 1); 38 | } 39 | 40 | 41 | addClick(clickFn, context) { 42 | 43 | this.events.onInputUp.add(clickFn, context); 44 | 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /js/config/Examples.js: -------------------------------------------------------------------------------- 1 | var examples = [ 2 | { 3 | key: 'basic', 4 | name: '基础', 5 | children: [ 6 | { 7 | name: 'load an image', 8 | state: 'basicLoadAnImage' 9 | }, 10 | { 11 | name: 'click on an image', 12 | state: 'basicClickOnAnImageState' 13 | }, 14 | { 15 | name: 'move an image', 16 | state: 'basicMoveAnImageState' 17 | }, 18 | { 19 | name: 'image follow input', 20 | state: 'basicImageFollowInputState' 21 | }, 22 | { 23 | name: 'load an animation', 24 | state: 'basicLoadAnAnimationState' 25 | }, 26 | { 27 | name: 'render text', 28 | state: 'basicRenderTextState' 29 | }, 30 | { 31 | name: 'tween an image', 32 | state: 'basicTweenAnImageState' 33 | } 34 | ] 35 | }, 36 | { 37 | key: 'game', 38 | name: '游戏', 39 | children: [ 40 | { 41 | name: 'plane', 42 | state: 'planePreload' 43 | } 44 | ] 45 | }, 46 | { 47 | key: 'open', 48 | name: '开放域', 49 | children: [ 50 | { 51 | name: 'show open canvas', 52 | state: 'openShowOpenCanvas' 53 | }, 54 | { 55 | name: 'set your score', 56 | state: 'openSetCloudScore' 57 | }, 58 | { 59 | name: 'get your score', 60 | state: 'openGetCloudScore' 61 | }, 62 | { 63 | name: 'get friend score', 64 | state: 'openGetFriendCloudScore' 65 | }, 66 | { 67 | name: 'show ranking list', 68 | state: 'openShowRankingList' 69 | } 70 | ] 71 | } 72 | ]; 73 | 74 | export default examples; 75 | -------------------------------------------------------------------------------- /js/open/OpenSetCloudScoreState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToSubMenuState from '../base/BackToSubMenuState.js'; 3 | 4 | export default class OpenSetCloudScoreState extends BackToSubMenuState { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | init(key) { 12 | super.init(key); 13 | } 14 | 15 | preload() { 16 | } 17 | 18 | create() { 19 | super.create(); 20 | 21 | // 随机一个score 22 | this.score = this.game.rnd.integerInRange(0, 100) 23 | 24 | var text = "set score to " + this.score; 25 | // 文字样式 26 | var style = { font: "32px Arial", fill: "#ff0044", align: "center" }; 27 | // 显示文字 28 | this.t = this.game.add.text(this.game.world.centerX - 160, 300, text, style); 29 | // 开启输入 30 | this.t.inputEnabled = true; 31 | // 文字点击时回调listener,上下文为this 32 | this.t.events.onInputDown.add(this.listener, this); 33 | 34 | } 35 | 36 | listener() { 37 | 38 | var scoreValue = this.score; 39 | 40 | wx.setUserCloudStorage({ 41 | KVDataList: [{ 42 | key: "score", 43 | value: scoreValue + "" 44 | }], 45 | success: function() { 46 | console.log('save score ' + scoreValue + ' success'); 47 | }, 48 | fail: function() { 49 | console.log('save score ' + scoreValue + ' fail'); 50 | }, 51 | complete: function() { 52 | console.log('save score ' + scoreValue + ' complete'); 53 | } 54 | }); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /js/open/OpenShowRankingListState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToSubMenuState from '../base/BackToSubMenuState.js'; 3 | 4 | export default class OpenShowRankingListState extends BackToSubMenuState { 5 | 6 | constructor(game) { 7 | super(); 8 | this.game = game; 9 | } 10 | 11 | init(key) { 12 | super.init(key); 13 | } 14 | 15 | preload() { 16 | } 17 | 18 | create() { 19 | super.create(); 20 | 21 | this.openDataContext = wx.getOpenDataContext(); 22 | this.sharedCanvas = this.openDataContext.canvas; 23 | 24 | var text = "show ranking list"; 25 | // 文字样式 26 | var style = { font: "32px Arial", fill: "#ff0044", align: "center" }; 27 | // 显示文字 28 | this.t = this.game.add.text(this.game.world.centerX - 160, 300, text, style); 29 | // 开启输入 30 | this.t.inputEnabled = true; 31 | // 文字点击时回调listener,上下文为this 32 | this.t.events.onInputDown.add(this.listener, this); 33 | 34 | } 35 | 36 | update() { 37 | if(this.game.renderType === Phaser.HEADLESS) { 38 | 39 | wx.originContext.drawImage(this.sharedCanvas, 0, 0, 375, 667) 40 | } 41 | } 42 | 43 | listener() { 44 | 45 | var openDataContext = wx.getOpenDataContext(); 46 | var sharedCanvas = openDataContext.canvas; 47 | 48 | var openCanvas = this.game.add.sprite(0, 100, Phaser.XTexture(sharedCanvas, 0, 0, 375, 667)); 49 | 50 | this.openDataContext.postMessage({ 51 | action: 'SHOW_RANKING_LIST' 52 | }); 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /assets/basic/running_bot.js: -------------------------------------------------------------------------------- 1 | var atlas = {"frames": [ 2 | 3 | { 4 | "filename": "run00", 5 | "frame": {"x":34,"y":128,"w":56,"h":60}, 6 | "rotated": false, 7 | "trimmed": true, 8 | "spriteSourceSize": {"x":0,"y":2,"w":56,"h":60}, 9 | "sourceSize": {"w":56,"h":64} 10 | }, 11 | { 12 | "filename": "run01", 13 | "frame": {"x":54,"y":0,"w":56,"h":58}, 14 | "rotated": false, 15 | "trimmed": true, 16 | "spriteSourceSize": {"x":0,"y":3,"w":56,"h":58}, 17 | "sourceSize": {"w":56,"h":64} 18 | }, 19 | { 20 | "filename": "run02", 21 | "frame": {"x":54,"y":58,"w":56,"h":58}, 22 | "rotated": false, 23 | "trimmed": true, 24 | "spriteSourceSize": {"x":0,"y":3,"w":56,"h":58}, 25 | "sourceSize": {"w":56,"h":64} 26 | }, 27 | { 28 | "filename": "run03", 29 | "frame": {"x":0,"y":192,"w":34,"h":64}, 30 | "rotated": false, 31 | "trimmed": true, 32 | "spriteSourceSize": {"x":11,"y":0,"w":34,"h":64}, 33 | "sourceSize": {"w":56,"h":64} 34 | }, 35 | { 36 | "filename": "run04", 37 | "frame": {"x":0,"y":64,"w":54,"h":64}, 38 | "rotated": false, 39 | "trimmed": true, 40 | "spriteSourceSize": {"x":1,"y":0,"w":54,"h":64}, 41 | "sourceSize": {"w":56,"h":64} 42 | }, 43 | { 44 | "filename": "run05", 45 | "frame": {"x":196,"y":0,"w":56,"h":58}, 46 | "rotated": false, 47 | "trimmed": true, 48 | "spriteSourceSize": {"x":0,"y":3,"w":56,"h":58}, 49 | "sourceSize": {"w":56,"h":64} 50 | }, 51 | { 52 | "filename": "run06", 53 | "frame": {"x":0,"y":0,"w":54,"h":64}, 54 | "rotated": false, 55 | "trimmed": true, 56 | "spriteSourceSize": {"x":1,"y":0,"w":54,"h":64}, 57 | "sourceSize": {"w":56,"h":64} 58 | }, 59 | { 60 | "filename": "run07", 61 | "frame": {"x":140,"y":0,"w":56,"h":58}, 62 | "rotated": false, 63 | "trimmed": true, 64 | "spriteSourceSize": {"x":0,"y":3,"w":56,"h":58}, 65 | "sourceSize": {"w":56,"h":64} 66 | }, 67 | { 68 | "filename": "run08", 69 | "frame": {"x":34,"y":188,"w":50,"h":60}, 70 | "rotated": false, 71 | "trimmed": true, 72 | "spriteSourceSize": {"x":3,"y":2,"w":50,"h":60}, 73 | "sourceSize": {"w":56,"h":64} 74 | }, 75 | { 76 | "filename": "run09", 77 | "frame": {"x":0,"y":128,"w":34,"h":64}, 78 | "rotated": false, 79 | "trimmed": true, 80 | "spriteSourceSize": {"x":11,"y":0,"w":34,"h":64}, 81 | "sourceSize": {"w":56,"h":64} 82 | }, 83 | { 84 | "filename": "run10", 85 | "frame": {"x":84,"y":188,"w":56,"h":58}, 86 | "rotated": false, 87 | "trimmed": true, 88 | "spriteSourceSize": {"x":0,"y":3,"w":56,"h":58}, 89 | "sourceSize": {"w":56,"h":64} 90 | }], 91 | "meta": { 92 | "app": "http://www.texturepacker.com", 93 | "version": "1.0", 94 | "image": "running_bot.png", 95 | "format": "RGBA8888", 96 | "size": {"w":252,"h":256}, 97 | "scale": "0.2", 98 | "smartupdate": "$TexturePacker:SmartUpdate:fb56f261b1eb04e3215824426595f64c$" 99 | } 100 | }; 101 | 102 | export default atlas; 103 | -------------------------------------------------------------------------------- /js/states/MenuState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import Examples from '../config/Examples.js'; 3 | import ExampleRect from '../objects/ExampleRect.js'; 4 | import Arrow from '../objects/Arrow.js'; 5 | 6 | export default class MenuState extends Phaser.State { 7 | 8 | constructor(game) { 9 | super(); 10 | this.game = game; 11 | } 12 | 13 | create() { 14 | 15 | this.game.stage.backgroundColor = '#4851ff'; 16 | 17 | this.exampleGroup = this.game.add.group(); 18 | for(var i=0; i 1) { 46 | this.state.disablePageInput(this.state.curPage); 47 | this.state.curPage--; 48 | this.state.enablePageInput(this.state.curPage); 49 | this.changeArrow(this.curPage); 50 | } 51 | } else { 52 | if(this.state.curPage < this.state.maxPageSize) { 53 | this.state.disablePageInput(this.state.curPage); 54 | this.state.curPage++; 55 | this.state.enablePageInput(this.state.curPage); 56 | this.changeArrow(this.curPage); 57 | } 58 | } 59 | this.state.game.add.tween(this.state.exampleGroup).to({x: - (this.state.curPage - 1) * 252}, 200, "Linear", true); 60 | } 61 | 62 | clickRect() { 63 | this.state.game.state.start('submenu', true, false, this.properties); 64 | } 65 | 66 | enablePageInput(pageNum) { 67 | this.changePageInput(pageNum, true); 68 | } 69 | 70 | disablePageInput(pageNum) { 71 | this.changePageInput(pageNum, false); 72 | } 73 | 74 | changePageInput(pageNum, enabled) { 75 | for(var i = (pageNum - 1) * this.pageSize; i < pageNum * this.pageSize && i < this.exampleGroup.length; i++) { 76 | this.exampleGroup.getChildAt(i).inputEnabled = enabled; 77 | } 78 | } 79 | 80 | changeArrow(pageNum) { 81 | if(pageNum <= 1) { 82 | this.arrowLeft.showAndHide(false); 83 | } else { 84 | this.arrowLeft.showAndHide(true); 85 | } 86 | if(pageNum >= this.maxPageSize) { 87 | this.arrowRight.showAndHide(false); 88 | } else { 89 | this.arrowRight.showAndHide(true); 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /js/states/SubMenuState.js: -------------------------------------------------------------------------------- 1 | import Phaser from '../libs/phaser-wx.js'; 2 | import BackToMenuState from '../base/BackToMenuState.js'; 3 | import Arrow from '../objects/Arrow.js'; 4 | import CaseRect from '../objects/CaseRect.js'; 5 | 6 | export default class SubMenuState extends BackToMenuState { 7 | 8 | constructor(game) { 9 | super(); 10 | this.game = game; 11 | } 12 | 13 | init(properties) { 14 | this.key = properties.key; 15 | this.name = properties.name; 16 | this.list = properties.children; 17 | } 18 | 19 | create() { 20 | 21 | super.create(); 22 | 23 | this.caseGroup = this.game.add.group(); 24 | for(var i=0; i 1) { 51 | this.state.disablePageInput(this.state.curPage); 52 | this.state.curPage--; 53 | this.state.enablePageInput(this.state.curPage); 54 | this.changeArrow(this.curPage); 55 | } 56 | } else { 57 | if(this.state.curPage < this.state.maxPageSize) { 58 | this.state.disablePageInput(this.state.curPage); 59 | this.state.curPage++; 60 | this.state.enablePageInput(this.state.curPage); 61 | this.changeArrow(this.curPage); 62 | } 63 | } 64 | this.state.game.add.tween(this.state.caseGroup).to({y: - (this.state.curPage - 1) * 544}, 200, "Linear", true); 65 | } 66 | 67 | clickRect() { 68 | this.state.game.state.start(this.properties.state, true, false, this.key); 69 | } 70 | 71 | enablePageInput(pageNum) { 72 | this.changePageInput(pageNum, true); 73 | } 74 | 75 | disablePageInput(pageNum) { 76 | this.changePageInput(pageNum, false); 77 | } 78 | 79 | changePageInput(pageNum, enabled) { 80 | for(var i = (pageNum - 1) * this.pageSize; i < pageNum * this.pageSize && i < this.caseGroup.length; i++) { 81 | this.caseGroup.getChildAt(i).inputEnabled = enabled; 82 | } 83 | } 84 | 85 | changeArrow(pageNum) { 86 | if(pageNum <= 1) { 87 | this.arrowUp.showAndHide(false); 88 | } else { 89 | this.arrowUp.showAndHide(true); 90 | } 91 | if(pageNum >= this.maxPageSize) { 92 | this.arrowDown.showAndHide(false); 93 | } else { 94 | this.arrowDown.showAndHide(true); 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /js/openData/index.js: -------------------------------------------------------------------------------- 1 | let sharedCanvas = wx.getSharedCanvas() 2 | let context = sharedCanvas.getContext('2d') 3 | context.fillStyle = 'red' 4 | context.fillRect(0, 0, 375, 667) 5 | 6 | wx.onMessage(data => { 7 | console.log(data); 8 | if(data.action === "GET_SCORE") { 9 | wx.getUserCloudStorage({ 10 | keyList: ["score"], 11 | success: function(obj) { 12 | if(obj.KVDataList) { 13 | for(var i=0; i 4 | * @copyright 2016 Photon Storm Ltd. 5 | * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} 6 | */ 7 | 8 | //(function(){ 9 | 10 | // var root = this; 11 | 12 | /** 13 | * @author Richard Davey 14 | * @copyright 2016 Photon Storm Ltd. 15 | * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} 16 | */ 17 | 18 | /** 19 | * @namespace Phaser 20 | */ 21 | var Phaser = Phaser || { // jshint ignore:line 22 | 23 | /** 24 | * The Phaser version number. 25 | * @constant 26 | * @type {string} 27 | */ 28 | VERSION: '2.6.2', 29 | 30 | /** 31 | * An array of Phaser game instances. 32 | * @constant 33 | * @type {array} 34 | */ 35 | GAMES: [], 36 | 37 | /** 38 | * AUTO renderer - picks between WebGL or Canvas based on device. 39 | * @constant 40 | * @type {integer} 41 | */ 42 | AUTO: 0, 43 | 44 | /** 45 | * Canvas Renderer. 46 | * @constant 47 | * @type {integer} 48 | */ 49 | CANVAS: 1, 50 | 51 | /** 52 | * WebGL Renderer. 53 | * @constant 54 | * @type {integer} 55 | */ 56 | WEBGL: 2, 57 | 58 | /** 59 | * Headless renderer (not visual output) 60 | * @constant 61 | * @type {integer} 62 | */ 63 | HEADLESS: 3, 64 | 65 | /** 66 | * Direction constant. 67 | * @constant 68 | * @type {integer} 69 | */ 70 | NONE: 0, 71 | 72 | /** 73 | * Direction constant. 74 | * @constant 75 | * @type {integer} 76 | */ 77 | LEFT: 1, 78 | 79 | /** 80 | * Direction constant. 81 | * @constant 82 | * @type {integer} 83 | */ 84 | RIGHT: 2, 85 | 86 | /** 87 | * Direction constant. 88 | * @constant 89 | * @type {integer} 90 | */ 91 | UP: 3, 92 | 93 | /** 94 | * Direction constant. 95 | * @constant 96 | * @type {integer} 97 | */ 98 | DOWN: 4, 99 | 100 | /** 101 | * Game Object type. 102 | * @constant 103 | * @type {integer} 104 | */ 105 | SPRITE: 0, 106 | 107 | /** 108 | * Game Object type. 109 | * @constant 110 | * @type {integer} 111 | */ 112 | BUTTON: 1, 113 | 114 | /** 115 | * Game Object type. 116 | * @constant 117 | * @type {integer} 118 | */ 119 | IMAGE: 2, 120 | 121 | /** 122 | * Game Object type. 123 | * @constant 124 | * @type {integer} 125 | */ 126 | GRAPHICS: 3, 127 | 128 | /** 129 | * Game Object type. 130 | * @constant 131 | * @type {integer} 132 | */ 133 | TEXT: 4, 134 | 135 | /** 136 | * Game Object type. 137 | * @constant 138 | * @type {integer} 139 | */ 140 | TILESPRITE: 5, 141 | 142 | /** 143 | * Game Object type. 144 | * @constant 145 | * @type {integer} 146 | */ 147 | BITMAPTEXT: 6, 148 | 149 | /** 150 | * Game Object type. 151 | * @constant 152 | * @type {integer} 153 | */ 154 | GROUP: 7, 155 | 156 | /** 157 | * Game Object type. 158 | * @constant 159 | * @type {integer} 160 | */ 161 | RENDERTEXTURE: 8, 162 | 163 | /** 164 | * Game Object type. 165 | * @constant 166 | * @type {integer} 167 | */ 168 | TILEMAP: 9, 169 | 170 | /** 171 | * Game Object type. 172 | * @constant 173 | * @type {integer} 174 | */ 175 | TILEMAPLAYER: 10, 176 | 177 | /** 178 | * Game Object type. 179 | * @constant 180 | * @type {integer} 181 | */ 182 | EMITTER: 11, 183 | 184 | /** 185 | * Game Object type. 186 | * @constant 187 | * @type {integer} 188 | */ 189 | POLYGON: 12, 190 | 191 | /** 192 | * Game Object type. 193 | * @constant 194 | * @type {integer} 195 | */ 196 | BITMAPDATA: 13, 197 | 198 | /** 199 | * Game Object type. 200 | * @constant 201 | * @type {integer} 202 | */ 203 | CANVAS_FILTER: 14, 204 | 205 | /** 206 | * Game Object type. 207 | * @constant 208 | * @type {integer} 209 | */ 210 | WEBGL_FILTER: 15, 211 | 212 | /** 213 | * Game Object type. 214 | * @constant 215 | * @type {integer} 216 | */ 217 | ELLIPSE: 16, 218 | 219 | /** 220 | * Game Object type. 221 | * @constant 222 | * @type {integer} 223 | */ 224 | SPRITEBATCH: 17, 225 | 226 | /** 227 | * Game Object type. 228 | * @constant 229 | * @type {integer} 230 | */ 231 | RETROFONT: 18, 232 | 233 | /** 234 | * Game Object type. 235 | * @constant 236 | * @type {integer} 237 | */ 238 | POINTER: 19, 239 | 240 | /** 241 | * Game Object type. 242 | * @constant 243 | * @type {integer} 244 | */ 245 | ROPE: 20, 246 | 247 | /** 248 | * Game Object type. 249 | * @constant 250 | * @type {integer} 251 | */ 252 | CIRCLE: 21, 253 | 254 | /** 255 | * Game Object type. 256 | * @constant 257 | * @type {integer} 258 | */ 259 | RECTANGLE: 22, 260 | 261 | /** 262 | * Game Object type. 263 | * @constant 264 | * @type {integer} 265 | */ 266 | LINE: 23, 267 | 268 | /** 269 | * Game Object type. 270 | * @constant 271 | * @type {integer} 272 | */ 273 | MATRIX: 24, 274 | 275 | /** 276 | * Game Object type. 277 | * @constant 278 | * @type {integer} 279 | */ 280 | POINT: 25, 281 | 282 | /** 283 | * Game Object type. 284 | * @constant 285 | * @type {integer} 286 | */ 287 | ROUNDEDRECTANGLE: 26, 288 | 289 | /** 290 | * Game Object type. 291 | * @constant 292 | * @type {integer} 293 | */ 294 | CREATURE: 27, 295 | 296 | /** 297 | * Game Object type. 298 | * @constant 299 | * @type {integer} 300 | */ 301 | VIDEO: 28, 302 | 303 | /** 304 | * Game Object type. 305 | * @constant 306 | * @type {integer} 307 | */ 308 | PENDING_ATLAS: -1, 309 | 310 | /** 311 | * A horizontal orientation 312 | * @constant 313 | * @type {integer} 314 | */ 315 | HORIZONTAL: 0, 316 | 317 | /** 318 | * A vertical orientation 319 | * @constant 320 | * @type {integer} 321 | */ 322 | VERTICAL: 1, 323 | 324 | /** 325 | * A landscape orientation 326 | * @constant 327 | * @type {integer} 328 | */ 329 | LANDSCAPE: 0, 330 | 331 | /** 332 | * A portrait orientation 333 | * @constant 334 | * @type {integer} 335 | */ 336 | PORTRAIT: 1, 337 | 338 | /** 339 | * The Angle (in degrees) a Game Object needs to be set to in order to face up. 340 | * @constant 341 | * @type {integer} 342 | */ 343 | ANGLE_UP: 270, 344 | 345 | /** 346 | * The Angle (in degrees) a Game Object needs to be set to in order to face down. 347 | * @constant 348 | * @type {integer} 349 | */ 350 | ANGLE_DOWN: 90, 351 | 352 | /** 353 | * The Angle (in degrees) a Game Object needs to be set to in order to face left. 354 | * @constant 355 | * @type {integer} 356 | */ 357 | ANGLE_LEFT: 180, 358 | 359 | /** 360 | * The Angle (in degrees) a Game Object needs to be set to in order to face right. 361 | * @constant 362 | * @type {integer} 363 | */ 364 | ANGLE_RIGHT: 0, 365 | 366 | /** 367 | * The Angle (in degrees) a Game Object needs to be set to in order to face north east. 368 | * @constant 369 | * @type {integer} 370 | */ 371 | ANGLE_NORTH_EAST: 315, 372 | 373 | /** 374 | * The Angle (in degrees) a Game Object needs to be set to in order to face north west. 375 | * @constant 376 | * @type {integer} 377 | */ 378 | ANGLE_NORTH_WEST: 225, 379 | 380 | /** 381 | * The Angle (in degrees) a Game Object needs to be set to in order to face south east. 382 | * @constant 383 | * @type {integer} 384 | */ 385 | ANGLE_SOUTH_EAST: 45, 386 | 387 | /** 388 | * The Angle (in degrees) a Game Object needs to be set to in order to face south west. 389 | * @constant 390 | * @type {integer} 391 | */ 392 | ANGLE_SOUTH_WEST: 135, 393 | 394 | /** 395 | * A constant representing a top-left alignment or position. 396 | * @constant 397 | * @type {integer} 398 | */ 399 | TOP_LEFT: 0, 400 | 401 | /** 402 | * A constant representing a top-center alignment or position. 403 | * @constant 404 | * @type {integer} 405 | */ 406 | TOP_CENTER: 1, 407 | 408 | /** 409 | * A constant representing a top-right alignment or position. 410 | * @constant 411 | * @type {integer} 412 | */ 413 | TOP_RIGHT: 2, 414 | 415 | /** 416 | * A constant representing a left-top alignment or position. 417 | * @constant 418 | * @type {integer} 419 | */ 420 | LEFT_TOP: 3, 421 | 422 | /** 423 | * A constant representing a left-center alignment or position. 424 | * @constant 425 | * @type {integer} 426 | */ 427 | LEFT_CENTER: 4, 428 | 429 | /** 430 | * A constant representing a left-bottom alignment or position. 431 | * @constant 432 | * @type {integer} 433 | */ 434 | LEFT_BOTTOM: 5, 435 | 436 | /** 437 | * A constant representing a center alignment or position. 438 | * @constant 439 | * @type {integer} 440 | */ 441 | CENTER: 6, 442 | 443 | /** 444 | * A constant representing a right-top alignment or position. 445 | * @constant 446 | * @type {integer} 447 | */ 448 | RIGHT_TOP: 7, 449 | 450 | /** 451 | * A constant representing a right-center alignment or position. 452 | * @constant 453 | * @type {integer} 454 | */ 455 | RIGHT_CENTER: 8, 456 | 457 | /** 458 | * A constant representing a right-bottom alignment or position. 459 | * @constant 460 | * @type {integer} 461 | */ 462 | RIGHT_BOTTOM: 9, 463 | 464 | /** 465 | * A constant representing a bottom-left alignment or position. 466 | * @constant 467 | * @type {integer} 468 | */ 469 | BOTTOM_LEFT: 10, 470 | 471 | /** 472 | * A constant representing a bottom-center alignment or position. 473 | * @constant 474 | * @type {integer} 475 | */ 476 | BOTTOM_CENTER: 11, 477 | 478 | /** 479 | * A constant representing a bottom-right alignment or position. 480 | * @constant 481 | * @type {integer} 482 | */ 483 | BOTTOM_RIGHT: 12, 484 | 485 | /** 486 | * Various blend modes supported by Pixi. 487 | * 488 | * IMPORTANT: The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. 489 | * 490 | * @constant 491 | * @property {Number} blendModes.NORMAL 492 | * @property {Number} blendModes.ADD 493 | * @property {Number} blendModes.MULTIPLY 494 | * @property {Number} blendModes.SCREEN 495 | * @property {Number} blendModes.OVERLAY 496 | * @property {Number} blendModes.DARKEN 497 | * @property {Number} blendModes.LIGHTEN 498 | * @property {Number} blendModes.COLOR_DODGE 499 | * @property {Number} blendModes.COLOR_BURN 500 | * @property {Number} blendModes.HARD_LIGHT 501 | * @property {Number} blendModes.SOFT_LIGHT 502 | * @property {Number} blendModes.DIFFERENCE 503 | * @property {Number} blendModes.EXCLUSION 504 | * @property {Number} blendModes.HUE 505 | * @property {Number} blendModes.SATURATION 506 | * @property {Number} blendModes.COLOR 507 | * @property {Number} blendModes.LUMINOSITY 508 | * @static 509 | */ 510 | blendModes: { 511 | NORMAL:0, 512 | ADD:1, 513 | MULTIPLY:2, 514 | SCREEN:3, 515 | OVERLAY:4, 516 | DARKEN:5, 517 | LIGHTEN:6, 518 | COLOR_DODGE:7, 519 | COLOR_BURN:8, 520 | HARD_LIGHT:9, 521 | SOFT_LIGHT:10, 522 | DIFFERENCE:11, 523 | EXCLUSION:12, 524 | HUE:13, 525 | SATURATION:14, 526 | COLOR:15, 527 | LUMINOSITY:16 528 | }, 529 | 530 | /** 531 | * The scale modes that are supported by Pixi. 532 | * 533 | * The DEFAULT scale mode affects the default scaling mode of future operations. 534 | * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. 535 | * 536 | * @constant 537 | * @property {Object} Phaser.scaleModes 538 | * @property {Number} scaleModes.DEFAULT=LINEAR 539 | * @property {Number} scaleModes.LINEAR Smooth scaling 540 | * @property {Number} scaleModes.NEAREST Pixelating scaling 541 | * @static 542 | */ 543 | scaleModes: { 544 | DEFAULT:0, 545 | LINEAR:0, 546 | NEAREST:1 547 | }, 548 | 549 | PIXI: PIXI || {} 550 | 551 | }; 552 | 553 | module.exports = Phaser; 554 | 555 | /* 556 | * "What matters in this life is not what we do but what we do for others, the legacy we leave and the imprint we make." - Eric Meyer 557 | */ 558 | -------------------------------------------------------------------------------- /js/libs/weapp-adapter.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {} 4 | 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) 10 | /******/ return installedModules[moduleId].exports 11 | 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ exports: {}, 15 | /******/ id: moduleId, 16 | /******/ loaded: false 17 | /******/ } 18 | 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__) 21 | 22 | /******/ // Flag the module as loaded 23 | /******/ module.loaded = true 24 | 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports 27 | /******/ } 28 | 29 | 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules 32 | 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules 35 | 36 | /******/ // __webpack_public_path__ 37 | /******/ __webpack_require__.p = "" 38 | 39 | /******/ // Load entry module and return exports 40 | /******/ return __webpack_require__(0) 41 | /******/ }) 42 | /************************************************************************/ 43 | /******/ ([ 44 | /* 0 */ 45 | /***/ (function(module, exports, __webpack_require__) { 46 | 47 | 'use strict' 48 | 49 | var _window2 = __webpack_require__(1) 50 | 51 | var _window = _interopRequireWildcard(_window2) 52 | 53 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key] } } newObj.default = obj; return newObj } } 54 | 55 | var global = GameGlobal 56 | 57 | function inject() { 58 | _window.addEventListener = _window.canvas.addEventListener = function (type, listener) { 59 | _window.document.addEventListener(type, listener) 60 | } 61 | _window.removeEventListener = _window.canvas.removeEventListener = function (type, listener) { 62 | _window.document.removeEventListener(type, listener) 63 | } 64 | 65 | var _wx$getSystemInfoSync = wx.getSystemInfoSync(), 66 | platform = _wx$getSystemInfoSync.platform 67 | 68 | // 开发者工具无法重定义 window 69 | 70 | 71 | if (typeof __devtoolssubcontext === 'undefined' && platform === 'devtools') { 72 | for (var key in _window) { 73 | var descriptor = Object.getOwnPropertyDescriptor(global, key) 74 | 75 | if (!descriptor || descriptor.configurable === true) { 76 | Object.defineProperty(window, key, { 77 | value: _window[key] 78 | }) 79 | } 80 | } 81 | 82 | for (var _key in _window.document) { 83 | var _descriptor = Object.getOwnPropertyDescriptor(global.document, _key) 84 | 85 | if (!_descriptor || _descriptor.configurable === true) { 86 | Object.defineProperty(global.document, _key, { 87 | value: _window.document[_key] 88 | }) 89 | } 90 | } 91 | window.parent = window 92 | } else { 93 | for (var _key2 in _window) { 94 | global[_key2] = _window[_key2] 95 | } 96 | global.window = _window 97 | window = global 98 | window.top = window.parent = window 99 | } 100 | } 101 | 102 | if (!GameGlobal.__isAdapterInjected) { 103 | GameGlobal.__isAdapterInjected = true 104 | inject() 105 | } 106 | 107 | /***/ }), 108 | /* 1 */ 109 | /***/ (function(module, exports, __webpack_require__) { 110 | 111 | 'use strict' 112 | 113 | Object.defineProperty(exports, "__esModule", { 114 | value: true 115 | }) 116 | exports.cancelAnimationFrame = exports.requestAnimationFrame = exports.clearInterval = exports.clearTimeout = exports.setInterval = exports.setTimeout = exports.canvas = exports.location = exports.localStorage = exports.HTMLElement = exports.FileReader = exports.Audio = exports.Image = exports.WebSocket = exports.XMLHttpRequest = exports.navigator = exports.document = undefined 117 | 118 | var _WindowProperties = __webpack_require__(2) 119 | 120 | Object.keys(_WindowProperties).forEach(function (key) { 121 | if (key === "default" || key === "__esModule") return 122 | Object.defineProperty(exports, key, { 123 | enumerable: true, 124 | get: function get() { 125 | return _WindowProperties[key] 126 | } 127 | }) 128 | }) 129 | 130 | var _constructor = __webpack_require__(3) 131 | 132 | Object.keys(_constructor).forEach(function (key) { 133 | if (key === "default" || key === "__esModule") return 134 | Object.defineProperty(exports, key, { 135 | enumerable: true, 136 | get: function get() { 137 | return _constructor[key] 138 | } 139 | }) 140 | }) 141 | 142 | var _Canvas = __webpack_require__(9) 143 | 144 | var _Canvas2 = _interopRequireDefault(_Canvas) 145 | 146 | var _document2 = __webpack_require__(10) 147 | 148 | var _document3 = _interopRequireDefault(_document2) 149 | 150 | var _navigator2 = __webpack_require__(17) 151 | 152 | var _navigator3 = _interopRequireDefault(_navigator2) 153 | 154 | var _XMLHttpRequest2 = __webpack_require__(18) 155 | 156 | var _XMLHttpRequest3 = _interopRequireDefault(_XMLHttpRequest2) 157 | 158 | var _WebSocket2 = __webpack_require__(19) 159 | 160 | var _WebSocket3 = _interopRequireDefault(_WebSocket2) 161 | 162 | var _Image2 = __webpack_require__(11) 163 | 164 | var _Image3 = _interopRequireDefault(_Image2) 165 | 166 | var _Audio2 = __webpack_require__(12) 167 | 168 | var _Audio3 = _interopRequireDefault(_Audio2) 169 | 170 | var _FileReader2 = __webpack_require__(20) 171 | 172 | var _FileReader3 = _interopRequireDefault(_FileReader2) 173 | 174 | var _HTMLElement2 = __webpack_require__(4) 175 | 176 | var _HTMLElement3 = _interopRequireDefault(_HTMLElement2) 177 | 178 | var _localStorage2 = __webpack_require__(21) 179 | 180 | var _localStorage3 = _interopRequireDefault(_localStorage2) 181 | 182 | var _location2 = __webpack_require__(22) 183 | 184 | var _location3 = _interopRequireDefault(_location2) 185 | 186 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 187 | 188 | exports.document = _document3.default 189 | exports.navigator = _navigator3.default 190 | exports.XMLHttpRequest = _XMLHttpRequest3.default 191 | exports.WebSocket = _WebSocket3.default 192 | exports.Image = _Image3.default 193 | exports.Audio = _Audio3.default 194 | exports.FileReader = _FileReader3.default 195 | exports.HTMLElement = _HTMLElement3.default 196 | exports.localStorage = _localStorage3.default 197 | exports.location = _location3.default 198 | 199 | 200 | // 暴露全局的 canvas 201 | var canvas = new _Canvas2.default() 202 | 203 | exports.canvas = canvas 204 | exports.setTimeout = setTimeout 205 | exports.setInterval = setInterval 206 | exports.clearTimeout = clearTimeout 207 | exports.clearInterval = clearInterval 208 | exports.requestAnimationFrame = requestAnimationFrame 209 | exports.cancelAnimationFrame = cancelAnimationFrame 210 | 211 | /***/ }), 212 | /* 2 */ 213 | /***/ (function(module, exports) { 214 | 215 | "use strict" 216 | 217 | Object.defineProperty(exports, "__esModule", { 218 | value: true 219 | }) 220 | 221 | var _wx$getSystemInfoSync = wx.getSystemInfoSync(), 222 | screenWidth = _wx$getSystemInfoSync.screenWidth, 223 | screenHeight = _wx$getSystemInfoSync.screenHeight, 224 | devicePixelRatio = _wx$getSystemInfoSync.devicePixelRatio 225 | 226 | var innerWidth = exports.innerWidth = screenWidth 227 | var innerHeight = exports.innerHeight = screenHeight 228 | exports.devicePixelRatio = devicePixelRatio 229 | var screen = exports.screen = { 230 | availWidth: innerWidth, 231 | availHeight: innerHeight 232 | } 233 | var performance = exports.performance = { 234 | now: function now() { 235 | return Date.now() / 1000 236 | } 237 | } 238 | var ontouchstart = exports.ontouchstart = null 239 | var ontouchmove = exports.ontouchmove = null 240 | var ontouchend = exports.ontouchend = null 241 | 242 | /***/ }), 243 | /* 3 */ 244 | /***/ (function(module, exports, __webpack_require__) { 245 | 246 | 'use strict' 247 | 248 | Object.defineProperty(exports, "__esModule", { 249 | value: true 250 | }) 251 | exports.HTMLCanvasElement = exports.HTMLImageElement = undefined 252 | 253 | var _HTMLElement3 = __webpack_require__(4) 254 | 255 | var _HTMLElement4 = _interopRequireDefault(_HTMLElement3) 256 | 257 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 258 | 259 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 260 | 261 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 262 | 263 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 264 | 265 | var HTMLImageElement = exports.HTMLImageElement = function (_HTMLElement) { 266 | _inherits(HTMLImageElement, _HTMLElement) 267 | 268 | function HTMLImageElement() { 269 | _classCallCheck(this, HTMLImageElement) 270 | 271 | return _possibleConstructorReturn(this, (HTMLImageElement.__proto__ || Object.getPrototypeOf(HTMLImageElement)).call(this, 'img')) 272 | } 273 | 274 | return HTMLImageElement 275 | }(_HTMLElement4.default) 276 | 277 | var HTMLCanvasElement = exports.HTMLCanvasElement = function (_HTMLElement2) { 278 | _inherits(HTMLCanvasElement, _HTMLElement2) 279 | 280 | function HTMLCanvasElement() { 281 | _classCallCheck(this, HTMLCanvasElement) 282 | 283 | return _possibleConstructorReturn(this, (HTMLCanvasElement.__proto__ || Object.getPrototypeOf(HTMLCanvasElement)).call(this, 'canvas')) 284 | } 285 | 286 | return HTMLCanvasElement 287 | }(_HTMLElement4.default) 288 | 289 | /***/ }), 290 | /* 4 */ 291 | /***/ (function(module, exports, __webpack_require__) { 292 | 293 | 'use strict' 294 | 295 | Object.defineProperty(exports, "__esModule", { 296 | value: true 297 | }) 298 | 299 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 300 | 301 | var _Element2 = __webpack_require__(5) 302 | 303 | var _Element3 = _interopRequireDefault(_Element2) 304 | 305 | var _util = __webpack_require__(8) 306 | 307 | var _WindowProperties = __webpack_require__(2) 308 | 309 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 310 | 311 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 312 | 313 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 314 | 315 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 316 | 317 | var HTMLElement = function (_Element) { 318 | _inherits(HTMLElement, _Element) 319 | 320 | function HTMLElement() { 321 | var tagName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '' 322 | 323 | _classCallCheck(this, HTMLElement) 324 | 325 | var _this = _possibleConstructorReturn(this, (HTMLElement.__proto__ || Object.getPrototypeOf(HTMLElement)).call(this)) 326 | 327 | _this.className = '' 328 | _this.childern = [] 329 | _this.style = { 330 | width: _WindowProperties.innerWidth + 'px', 331 | height: _WindowProperties.innerHeight + 'px' 332 | } 333 | _this.insertBefore = _util.noop 334 | _this.innerHTML = '' 335 | 336 | _this.tagName = tagName.toUpperCase() 337 | return _this 338 | } 339 | 340 | _createClass(HTMLElement, [{ 341 | key: 'setAttribute', 342 | value: function setAttribute(name, value) { 343 | this[name] = value 344 | } 345 | }, { 346 | key: 'getAttribute', 347 | value: function getAttribute(name) { 348 | return this[name] 349 | } 350 | }, { 351 | key: 'getBoundingClientRect', 352 | value: function getBoundingClientRect() { 353 | return { 354 | top: 0, 355 | left: 0, 356 | width: _WindowProperties.innerWidth, 357 | height: _WindowProperties.innerHeight 358 | } 359 | } 360 | }, { 361 | key: 'focus', 362 | value: function focus() {} 363 | }, { 364 | key: 'clientWidth', 365 | get: function get() { 366 | var ret = parseInt(this.style.fontSize, 10) * this.innerHTML.length 367 | 368 | return Number.isNaN(ret) ? 0 : ret 369 | } 370 | }, { 371 | key: 'clientHeight', 372 | get: function get() { 373 | var ret = parseInt(this.style.fontSize, 10) 374 | 375 | return Number.isNaN(ret) ? 0 : ret 376 | } 377 | }]) 378 | 379 | return HTMLElement 380 | }(_Element3.default) 381 | 382 | exports.default = HTMLElement 383 | 384 | /***/ }), 385 | /* 5 */ 386 | /***/ (function(module, exports, __webpack_require__) { 387 | 388 | 'use strict' 389 | 390 | Object.defineProperty(exports, "__esModule", { 391 | value: true 392 | }) 393 | 394 | var _Node2 = __webpack_require__(6) 395 | 396 | var _Node3 = _interopRequireDefault(_Node2) 397 | 398 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 399 | 400 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 401 | 402 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 403 | 404 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 405 | 406 | var ELement = function (_Node) { 407 | _inherits(ELement, _Node) 408 | 409 | function ELement() { 410 | _classCallCheck(this, ELement) 411 | 412 | var _this = _possibleConstructorReturn(this, (ELement.__proto__ || Object.getPrototypeOf(ELement)).call(this)) 413 | 414 | _this.className = '' 415 | _this.children = [] 416 | return _this 417 | } 418 | 419 | return ELement 420 | }(_Node3.default) 421 | 422 | exports.default = ELement 423 | 424 | /***/ }), 425 | /* 6 */ 426 | /***/ (function(module, exports, __webpack_require__) { 427 | 428 | 'use strict' 429 | 430 | Object.defineProperty(exports, "__esModule", { 431 | value: true 432 | }) 433 | 434 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 435 | 436 | var _EventTarget2 = __webpack_require__(7) 437 | 438 | var _EventTarget3 = _interopRequireDefault(_EventTarget2) 439 | 440 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 441 | 442 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 443 | 444 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 445 | 446 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 447 | 448 | var Node = function (_EventTarget) { 449 | _inherits(Node, _EventTarget) 450 | 451 | function Node() { 452 | _classCallCheck(this, Node) 453 | 454 | var _this = _possibleConstructorReturn(this, (Node.__proto__ || Object.getPrototypeOf(Node)).call(this)) 455 | 456 | _this.childNodes = [] 457 | return _this 458 | } 459 | 460 | _createClass(Node, [{ 461 | key: 'appendChild', 462 | value: function appendChild(node) { 463 | if (node instanceof Node) { 464 | this.childNodes.push(node) 465 | } else { 466 | throw new TypeError('Failed to executed \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'.') 467 | } 468 | } 469 | }, { 470 | key: 'cloneNode', 471 | value: function cloneNode() { 472 | var copyNode = Object.create(this) 473 | 474 | Object.assign(copyNode, this) 475 | return copyNode 476 | } 477 | }, { 478 | key: 'removeChild', 479 | value: function removeChild(node) { 480 | var index = this.childNodes.findIndex(function (child) { 481 | return child === node 482 | }) 483 | 484 | if (index > -1) { 485 | return this.childNodes.splice(index, 1) 486 | } 487 | return null 488 | } 489 | }]) 490 | 491 | return Node 492 | }(_EventTarget3.default) 493 | 494 | exports.default = Node 495 | 496 | /***/ }), 497 | /* 7 */ 498 | /***/ (function(module, exports) { 499 | 500 | 'use strict' 501 | 502 | Object.defineProperty(exports, "__esModule", { 503 | value: true 504 | }) 505 | 506 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 507 | 508 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 509 | 510 | var _events = new WeakMap() 511 | 512 | var EventTarget = function () { 513 | function EventTarget() { 514 | _classCallCheck(this, EventTarget) 515 | 516 | _events.set(this, {}) 517 | } 518 | 519 | _createClass(EventTarget, [{ 520 | key: 'addEventListener', 521 | value: function addEventListener(type, listener) { 522 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {} 523 | 524 | var events = _events.get(this) 525 | 526 | if (!events) { 527 | events = {} 528 | _events.set(this, events) 529 | } 530 | if (!events[type]) { 531 | events[type] = [] 532 | } 533 | events[type].push(listener) 534 | 535 | if (options.capture) { 536 | console.warn('EventTarget.addEventListener: options.capture is not implemented.') 537 | } 538 | if (options.once) { 539 | console.warn('EventTarget.addEventListener: options.once is not implemented.') 540 | } 541 | if (options.passive) { 542 | console.warn('EventTarget.addEventListener: options.passive is not implemented.') 543 | } 544 | } 545 | }, { 546 | key: 'removeEventListener', 547 | value: function removeEventListener(type, listener) { 548 | var listeners = _events.get(this)[type] 549 | 550 | if (listeners && listeners.length > 0) { 551 | for (var i = listeners.length; i--; i > 0) { 552 | if (listeners[i] === listener) { 553 | listeners.splice(i, 1) 554 | break 555 | } 556 | } 557 | } 558 | } 559 | }, { 560 | key: 'dispatchEvent', 561 | value: function dispatchEvent() { 562 | var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {} 563 | 564 | var listeners = _events.get(this)[event.type] 565 | 566 | if (listeners) { 567 | for (var i = 0; i < listeners.length; i++) { 568 | listeners[i](event) 569 | } 570 | } 571 | } 572 | }]) 573 | 574 | return EventTarget 575 | }() 576 | 577 | exports.default = EventTarget 578 | 579 | /***/ }), 580 | /* 8 */ 581 | /***/ (function(module, exports) { 582 | 583 | "use strict" 584 | 585 | Object.defineProperty(exports, "__esModule", { 586 | value: true 587 | }) 588 | exports.noop = noop 589 | function noop() {} 590 | 591 | /***/ }), 592 | /* 9 */ 593 | /***/ (function(module, exports, __webpack_require__) { 594 | 595 | 'use strict' 596 | 597 | Object.defineProperty(exports, "__esModule", { 598 | value: true 599 | }) 600 | exports.default = Canvas 601 | 602 | var _constructor = __webpack_require__(3) 603 | 604 | var _HTMLElement = __webpack_require__(4) 605 | 606 | var _HTMLElement2 = _interopRequireDefault(_HTMLElement) 607 | 608 | var _document = __webpack_require__(10) 609 | 610 | var _document2 = _interopRequireDefault(_document) 611 | 612 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 613 | 614 | var hasModifiedCanvasPrototype = false 615 | var hasInit2DContextConstructor = false 616 | var hasInitWebGLContextConstructor = false 617 | 618 | function Canvas() { 619 | var canvas = wx.createCanvas() 620 | 621 | canvas.type = 'canvas' 622 | 623 | canvas.__proto__.__proto__ = new _HTMLElement2.default('canvas') 624 | 625 | var _getContext = canvas.getContext 626 | 627 | canvas.getBoundingClientRect = function () { 628 | var ret = { 629 | top: 0, 630 | left: 0, 631 | width: window.innerWidth, 632 | height: window.innerHeight 633 | } 634 | return ret 635 | } 636 | 637 | return canvas 638 | } 639 | 640 | /***/ }), 641 | /* 10 */ 642 | /***/ (function(module, exports, __webpack_require__) { 643 | 644 | 'use strict' 645 | 646 | Object.defineProperty(exports, "__esModule", { 647 | value: true 648 | }) 649 | 650 | var _window = __webpack_require__(1) 651 | 652 | var window = _interopRequireWildcard(_window) 653 | 654 | var _HTMLElement = __webpack_require__(4) 655 | 656 | var _HTMLElement2 = _interopRequireDefault(_HTMLElement) 657 | 658 | var _Image = __webpack_require__(11) 659 | 660 | var _Image2 = _interopRequireDefault(_Image) 661 | 662 | var _Audio = __webpack_require__(12) 663 | 664 | var _Audio2 = _interopRequireDefault(_Audio) 665 | 666 | var _Canvas = __webpack_require__(9) 667 | 668 | var _Canvas2 = _interopRequireDefault(_Canvas) 669 | 670 | __webpack_require__(15) 671 | 672 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 673 | 674 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key] } } newObj.default = obj; return newObj } } 675 | 676 | var events = {} 677 | 678 | var document = { 679 | readyState: 'complete', 680 | visibilityState: 'visible', 681 | documentElement: window, 682 | hidden: false, 683 | style: {}, 684 | location: window.location, 685 | ontouchstart: null, 686 | ontouchmove: null, 687 | ontouchend: null, 688 | 689 | head: new _HTMLElement2.default('head'), 690 | body: new _HTMLElement2.default('body'), 691 | 692 | createElement: function createElement(tagName) { 693 | if (tagName === 'canvas') { 694 | return new _Canvas2.default() 695 | } else if (tagName === 'audio') { 696 | return new _Audio2.default() 697 | } else if (tagName === 'img') { 698 | return new _Image2.default() 699 | } 700 | 701 | return new _HTMLElement2.default(tagName) 702 | }, 703 | getElementById: function getElementById(id) { 704 | if (id === window.canvas.id) { 705 | return window.canvas 706 | } 707 | return null 708 | }, 709 | getElementsByTagName: function getElementsByTagName(tagName) { 710 | if (tagName === 'head') { 711 | return [document.head] 712 | } else if (tagName === 'body') { 713 | return [document.body] 714 | } else if (tagName === 'canvas') { 715 | return [window.canvas] 716 | } 717 | return [] 718 | }, 719 | querySelector: function querySelector(query) { 720 | if (query === 'head') { 721 | return document.head 722 | } else if (query === 'body') { 723 | return document.body 724 | } else if (query === 'canvas') { 725 | return window.canvas 726 | } else if (query === '#' + window.canvas.id) { 727 | return window.canvas 728 | } 729 | return null 730 | }, 731 | querySelectorAll: function querySelectorAll(query) { 732 | if (query === 'head') { 733 | return [document.head] 734 | } else if (query === 'body') { 735 | return [document.body] 736 | } else if (query === 'canvas') { 737 | return [window.canvas] 738 | } 739 | return [] 740 | }, 741 | addEventListener: function addEventListener(type, listener) { 742 | if (!events[type]) { 743 | events[type] = [] 744 | } 745 | events[type].push(listener) 746 | }, 747 | removeEventListener: function removeEventListener(type, listener) { 748 | var listeners = events[type] 749 | 750 | if (listeners && listeners.length > 0) { 751 | for (var i = listeners.length; i--; i > 0) { 752 | if (listeners[i] === listener) { 753 | listeners.splice(i, 1) 754 | break 755 | } 756 | } 757 | } 758 | }, 759 | dispatchEvent: function dispatchEvent(event) { 760 | var listeners = events[event.type] 761 | 762 | if (listeners) { 763 | for (var i = 0; i < listeners.length; i++) { 764 | listeners[i](event) 765 | } 766 | } 767 | } 768 | } 769 | 770 | exports.default = document 771 | 772 | /***/ }), 773 | /* 11 */ 774 | /***/ (function(module, exports) { 775 | 776 | "use strict" 777 | 778 | Object.defineProperty(exports, "__esModule", { 779 | value: true 780 | }) 781 | exports.default = Image 782 | function Image() { 783 | var image = wx.createImage() 784 | 785 | return image 786 | } 787 | 788 | /***/ }), 789 | /* 12 */ 790 | /***/ (function(module, exports, __webpack_require__) { 791 | 792 | 'use strict' 793 | 794 | Object.defineProperty(exports, "__esModule", { 795 | value: true 796 | }) 797 | 798 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 799 | 800 | var _HTMLAudioElement2 = __webpack_require__(13) 801 | 802 | var _HTMLAudioElement3 = _interopRequireDefault(_HTMLAudioElement2) 803 | 804 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 805 | 806 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 807 | 808 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 809 | 810 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 811 | 812 | var HAVE_NOTHING = 0 813 | var HAVE_METADATA = 1 814 | var HAVE_CURRENT_DATA = 2 815 | var HAVE_FUTURE_DATA = 3 816 | var HAVE_ENOUGH_DATA = 4 817 | 818 | var _innerAudioContext = new WeakMap() 819 | var _src = new WeakMap() 820 | var _loop = new WeakMap() 821 | var _autoplay = new WeakMap() 822 | 823 | var Audio = function (_HTMLAudioElement) { 824 | _inherits(Audio, _HTMLAudioElement) 825 | 826 | function Audio(url) { 827 | _classCallCheck(this, Audio) 828 | 829 | var _this = _possibleConstructorReturn(this, (Audio.__proto__ || Object.getPrototypeOf(Audio)).call(this)) 830 | 831 | _this.HAVE_NOTHING = HAVE_NOTHING 832 | _this.HAVE_METADATA = HAVE_METADATA 833 | _this.HAVE_CURRENT_DATA = HAVE_CURRENT_DATA 834 | _this.HAVE_FUTURE_DATA = HAVE_FUTURE_DATA 835 | _this.HAVE_ENOUGH_DATA = HAVE_ENOUGH_DATA 836 | _this.readyState = HAVE_NOTHING 837 | 838 | 839 | _src.set(_this, '') 840 | 841 | var innerAudioContext = wx.createInnerAudioContext() 842 | 843 | _innerAudioContext.set(_this, innerAudioContext) 844 | 845 | innerAudioContext.onCanplay(function () { 846 | _this.dispatchEvent({ type: 'load' }) 847 | _this.dispatchEvent({ type: 'loadend' }) 848 | _this.dispatchEvent({ type: 'canplay' }) 849 | _this.dispatchEvent({ type: 'canplaythrough' }) 850 | _this.dispatchEvent({ type: 'loadedmetadata' }) 851 | _this.readyState = HAVE_CURRENT_DATA 852 | }) 853 | innerAudioContext.onPlay(function () { 854 | _this.dispatchEvent({ type: 'play' }) 855 | }) 856 | innerAudioContext.onPause(function () { 857 | _this.dispatchEvent({ type: 'pause' }) 858 | }) 859 | innerAudioContext.onEnded(function () { 860 | _this.dispatchEvent({ type: 'ended' }) 861 | _this.readyState = HAVE_ENOUGH_DATA 862 | }) 863 | innerAudioContext.onError(function () { 864 | _this.dispatchEvent({ type: 'error' }) 865 | }) 866 | 867 | if (url) { 868 | _innerAudioContext.get(_this).src = url 869 | } 870 | return _this 871 | } 872 | 873 | _createClass(Audio, [{ 874 | key: 'load', 875 | value: function load() { 876 | console.warn('HTMLAudioElement.load() is not implemented.') 877 | } 878 | }, { 879 | key: 'play', 880 | value: function play() { 881 | _innerAudioContext.get(this).play() 882 | } 883 | }, { 884 | key: 'pause', 885 | value: function pause() { 886 | _innerAudioContext.get(this).pause() 887 | } 888 | }, { 889 | key: 'canPlayType', 890 | value: function canPlayType() { 891 | var mediaType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '' 892 | 893 | if (typeof mediaType !== 'string') { 894 | return '' 895 | } 896 | 897 | if (mediaType.indexOf('audio/mpeg') > -1 || mediaType.indexOf('audio/mp4')) { 898 | return 'probably' 899 | } 900 | return '' 901 | } 902 | }, { 903 | key: 'cloneNode', 904 | value: function cloneNode() { 905 | var newAudio = new Audio() 906 | newAudio.loop = _innerAudioContext.get(this).loop 907 | newAudio.autoplay = _innerAudioContext.get(this).loop 908 | newAudio.src = this.src 909 | return newAudio 910 | } 911 | }, { 912 | key: 'currentTime', 913 | get: function get() { 914 | return _innerAudioContext.get(this).currentTime 915 | }, 916 | set: function set(value) { 917 | _innerAudioContext.get(this).seek(value) 918 | } 919 | }, { 920 | key: 'src', 921 | get: function get() { 922 | return _src.get(this) 923 | }, 924 | set: function set(value) { 925 | _src.set(this, value) 926 | _innerAudioContext.get(this).src = value 927 | } 928 | }, { 929 | key: 'loop', 930 | get: function get() { 931 | return _innerAudioContext.get(this).loop 932 | }, 933 | set: function set(value) { 934 | _innerAudioContext.get(this).loop = value 935 | } 936 | }, { 937 | key: 'autoplay', 938 | get: function get() { 939 | return _innerAudioContext.get(this).autoplay 940 | }, 941 | set: function set(value) { 942 | _innerAudioContext.get(this).autoplay = value 943 | } 944 | }, { 945 | key: 'paused', 946 | get: function get() { 947 | return _innerAudioContext.get(this).paused 948 | } 949 | }]) 950 | 951 | return Audio 952 | }(_HTMLAudioElement3.default) 953 | 954 | exports.default = Audio 955 | 956 | /***/ }), 957 | /* 13 */ 958 | /***/ (function(module, exports, __webpack_require__) { 959 | 960 | 'use strict' 961 | 962 | Object.defineProperty(exports, "__esModule", { 963 | value: true 964 | }) 965 | 966 | var _HTMLMediaElement2 = __webpack_require__(14) 967 | 968 | var _HTMLMediaElement3 = _interopRequireDefault(_HTMLMediaElement2) 969 | 970 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 971 | 972 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 973 | 974 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 975 | 976 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 977 | 978 | var HTMLAudioElement = function (_HTMLMediaElement) { 979 | _inherits(HTMLAudioElement, _HTMLMediaElement) 980 | 981 | function HTMLAudioElement() { 982 | _classCallCheck(this, HTMLAudioElement) 983 | 984 | return _possibleConstructorReturn(this, (HTMLAudioElement.__proto__ || Object.getPrototypeOf(HTMLAudioElement)).call(this, 'audio')) 985 | } 986 | 987 | return HTMLAudioElement 988 | }(_HTMLMediaElement3.default) 989 | 990 | exports.default = HTMLAudioElement 991 | 992 | /***/ }), 993 | /* 14 */ 994 | /***/ (function(module, exports, __webpack_require__) { 995 | 996 | 'use strict' 997 | 998 | Object.defineProperty(exports, "__esModule", { 999 | value: true 1000 | }) 1001 | 1002 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 1003 | 1004 | var _HTMLElement2 = __webpack_require__(4) 1005 | 1006 | var _HTMLElement3 = _interopRequireDefault(_HTMLElement2) 1007 | 1008 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 1009 | 1010 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 1011 | 1012 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return call && (typeof call === "object" || typeof call === "function") ? call : self } 1013 | 1014 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass) } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass } 1015 | 1016 | var HTMLMediaElement = function (_HTMLElement) { 1017 | _inherits(HTMLMediaElement, _HTMLElement) 1018 | 1019 | function HTMLMediaElement(type) { 1020 | _classCallCheck(this, HTMLMediaElement) 1021 | 1022 | return _possibleConstructorReturn(this, (HTMLMediaElement.__proto__ || Object.getPrototypeOf(HTMLMediaElement)).call(this, type)) 1023 | } 1024 | 1025 | _createClass(HTMLMediaElement, [{ 1026 | key: 'addTextTrack', 1027 | value: function addTextTrack() {} 1028 | }, { 1029 | key: 'captureStream', 1030 | value: function captureStream() {} 1031 | }, { 1032 | key: 'fastSeek', 1033 | value: function fastSeek() {} 1034 | }, { 1035 | key: 'load', 1036 | value: function load() {} 1037 | }, { 1038 | key: 'pause', 1039 | value: function pause() {} 1040 | }, { 1041 | key: 'play', 1042 | value: function play() {} 1043 | }]) 1044 | 1045 | return HTMLMediaElement 1046 | }(_HTMLElement3.default) 1047 | 1048 | exports.default = HTMLMediaElement 1049 | 1050 | /***/ }), 1051 | /* 15 */ 1052 | /***/ (function(module, exports, __webpack_require__) { 1053 | 1054 | 'use strict' 1055 | 1056 | __webpack_require__(16) 1057 | 1058 | /***/ }), 1059 | /* 16 */ 1060 | /***/ (function(module, exports, __webpack_require__) { 1061 | 1062 | 'use strict' 1063 | 1064 | var _window = __webpack_require__(1) 1065 | 1066 | var window = _interopRequireWildcard(_window) 1067 | 1068 | var _document = __webpack_require__(10) 1069 | 1070 | var _document2 = _interopRequireDefault(_document) 1071 | 1072 | var _util = __webpack_require__(8) 1073 | 1074 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } 1075 | 1076 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key] } } newObj.default = obj; return newObj } } 1077 | 1078 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 1079 | 1080 | var TouchEvent = function TouchEvent(type) { 1081 | _classCallCheck(this, TouchEvent) 1082 | 1083 | this.target = window.canvas 1084 | this.currentTarget = window.canvas 1085 | this.touches = [] 1086 | this.targetTouches = [] 1087 | this.changedTouches = [] 1088 | this.preventDefault = _util.noop 1089 | this.stopPropagation = _util.noop 1090 | 1091 | this.type = type 1092 | } 1093 | 1094 | function touchEventHandlerFactory(type) { 1095 | return function (event) { 1096 | var touchEvent = new TouchEvent(type) 1097 | 1098 | touchEvent.touches = event.touches 1099 | touchEvent.targetTouches = Array.prototype.slice.call(event.touches) 1100 | touchEvent.changedTouches = event.changedTouches 1101 | touchEvent.timeStamp = event.timeStamp 1102 | _document2.default.dispatchEvent(touchEvent) 1103 | } 1104 | } 1105 | 1106 | wx.onTouchStart(touchEventHandlerFactory('touchstart')) 1107 | wx.onTouchMove(touchEventHandlerFactory('touchmove')) 1108 | wx.onTouchEnd(touchEventHandlerFactory('touchend')) 1109 | wx.onTouchCancel(touchEventHandlerFactory('touchcancel')) 1110 | 1111 | /***/ }), 1112 | /* 17 */ 1113 | /***/ (function(module, exports, __webpack_require__) { 1114 | 1115 | 'use strict' 1116 | 1117 | Object.defineProperty(exports, "__esModule", { 1118 | value: true 1119 | }) 1120 | 1121 | var _util = __webpack_require__(8) 1122 | 1123 | // TODO 需要 wx.getSystemInfo 获取更详细信息 1124 | var _wx$getSystemInfoSync = wx.getSystemInfoSync(), 1125 | platform = _wx$getSystemInfoSync.platform 1126 | 1127 | var navigator = { 1128 | platform: platform, 1129 | language: 'zh-cn', 1130 | appVersion: '5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 1131 | userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 MicroMessenger/6.6.0 MiniGame NetType/WIFI Language/zh_CN', 1132 | onLine: true, // TODO 用 wx.getNetworkStateChange 和 wx.onNetworkStateChange 来返回真实的状态 1133 | 1134 | // TODO 用 wx.getLocation 来封装 geolocation 1135 | geolocation: { 1136 | getCurrentPosition: _util.noop, 1137 | watchPosition: _util.noop, 1138 | clearWatch: _util.noop 1139 | } 1140 | } 1141 | 1142 | exports.default = navigator 1143 | 1144 | /***/ }), 1145 | /* 18 */ 1146 | /***/ (function(module, exports) { 1147 | 1148 | 'use strict' 1149 | 1150 | Object.defineProperty(exports, "__esModule", { 1151 | value: true 1152 | }) 1153 | 1154 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 1155 | 1156 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 1157 | 1158 | var _url = new WeakMap() 1159 | var _method = new WeakMap() 1160 | var _requestHeader = new WeakMap() 1161 | var _responseHeader = new WeakMap() 1162 | var _requestTask = new WeakMap() 1163 | 1164 | function _triggerEvent(type) { 1165 | if (typeof this['on' + type] === 'function') { 1166 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1167 | args[_key - 1] = arguments[_key] 1168 | } 1169 | 1170 | this['on' + type].apply(this, args) 1171 | } 1172 | } 1173 | 1174 | function _changeReadyState(readyState) { 1175 | this.readyState = readyState 1176 | _triggerEvent.call(this, 'readystatechange') 1177 | } 1178 | 1179 | var XMLHttpRequest = function () { 1180 | // TODO 没法模拟 HEADERS_RECEIVED 和 LOADING 两个状态 1181 | function XMLHttpRequest() { 1182 | _classCallCheck(this, XMLHttpRequest) 1183 | 1184 | this.onabort = null 1185 | this.onerror = null 1186 | this.onload = null 1187 | this.onloadstart = null 1188 | this.onprogress = null 1189 | this.ontimeout = null 1190 | this.onloadend = null 1191 | this.onreadystatechange = null 1192 | this.readyState = 0 1193 | this.response = null 1194 | this.responseText = null 1195 | this.responseType = '' 1196 | this.responseXML = null 1197 | this.status = 0 1198 | this.statusText = '' 1199 | this.upload = {} 1200 | this.withCredentials = false 1201 | 1202 | _requestHeader.set(this, { 1203 | 'content-type': 'application/x-www-form-urlencoded' 1204 | }) 1205 | _responseHeader.set(this, {}) 1206 | } 1207 | 1208 | /* 1209 | * TODO 这一批事件应该是在 XMLHttpRequestEventTarget.prototype 上面的 1210 | */ 1211 | 1212 | 1213 | _createClass(XMLHttpRequest, [{ 1214 | key: 'abort', 1215 | value: function abort() { 1216 | var myRequestTask = _requestTask.get(this) 1217 | 1218 | if (myRequestTask) { 1219 | myRequestTask.abort() 1220 | } 1221 | } 1222 | }, { 1223 | key: 'getAllResponseHeaders', 1224 | value: function getAllResponseHeaders() { 1225 | var responseHeader = _responseHeader.get(this) 1226 | 1227 | return Object.keys(responseHeader).map(function (header) { 1228 | return header + ': ' + responseHeader[header] 1229 | }).join('\n') 1230 | } 1231 | }, { 1232 | key: 'getResponseHeader', 1233 | value: function getResponseHeader(header) { 1234 | return _responseHeader.get(this)[header] 1235 | } 1236 | }, { 1237 | key: 'open', 1238 | value: function open(method, url /* async, user, password 这几个参数在小程序内不支持*/) { 1239 | _method.set(this, method) 1240 | _url.set(this, url) 1241 | _changeReadyState.call(this, XMLHttpRequest.OPENED) 1242 | } 1243 | }, { 1244 | key: 'overrideMimeType', 1245 | value: function overrideMimeType() {} 1246 | }, { 1247 | key: 'send', 1248 | value: function send() { 1249 | var _this = this 1250 | 1251 | var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '' 1252 | 1253 | if (this.readyState !== XMLHttpRequest.OPENED) { 1254 | throw new Error("Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED.") 1255 | } else { 1256 | wx.request({ 1257 | data: data, 1258 | url: _url.get(this), 1259 | method: _method.get(this), 1260 | header: _requestHeader.get(this), 1261 | responseType: this.responseType, 1262 | success: function success(_ref) { 1263 | var data = _ref.data, 1264 | statusCode = _ref.statusCode, 1265 | header = _ref.header 1266 | 1267 | if (typeof data !== 'string' && !(data instanceof ArrayBuffer)) { 1268 | try { 1269 | data = JSON.stringify(data) 1270 | } catch (e) { 1271 | data = data 1272 | } 1273 | } 1274 | 1275 | _this.status = statusCode 1276 | _responseHeader.set(_this, header) 1277 | _triggerEvent.call(_this, 'loadstart') 1278 | _changeReadyState.call(_this, XMLHttpRequest.HEADERS_RECEIVED) 1279 | _changeReadyState.call(_this, XMLHttpRequest.LOADING) 1280 | 1281 | _this.response = data 1282 | 1283 | if (data instanceof ArrayBuffer) { 1284 | _this.responseText = '' 1285 | var bytes = new Uint8Array(data) 1286 | var len = bytes.byteLength 1287 | 1288 | for (var i = 0; i < len; i++) { 1289 | _this.responseText += String.fromCharCode(bytes[i]) 1290 | } 1291 | } else { 1292 | _this.responseText = data 1293 | } 1294 | _changeReadyState.call(_this, XMLHttpRequest.DONE) 1295 | _triggerEvent.call(_this, 'load') 1296 | _triggerEvent.call(_this, 'loadend') 1297 | }, 1298 | fail: function fail(_ref2) { 1299 | var errMsg = _ref2.errMsg 1300 | 1301 | // TODO 规范错误 1302 | if (errMsg.indexOf('abort') !== -1) { 1303 | _triggerEvent.call(_this, 'abort') 1304 | } else { 1305 | _triggerEvent.call(_this, 'error', errMsg) 1306 | } 1307 | _triggerEvent.call(_this, 'loadend') 1308 | } 1309 | }) 1310 | } 1311 | } 1312 | }, { 1313 | key: 'setRequestHeader', 1314 | value: function setRequestHeader(header, value) { 1315 | var myHeader = _requestHeader.get(this) 1316 | 1317 | myHeader[header] = value 1318 | _requestHeader.set(this, myHeader) 1319 | } 1320 | }]) 1321 | 1322 | return XMLHttpRequest 1323 | }() 1324 | 1325 | XMLHttpRequest.UNSEND = 0 1326 | XMLHttpRequest.OPENED = 1 1327 | XMLHttpRequest.HEADERS_RECEIVED = 2 1328 | XMLHttpRequest.LOADING = 3 1329 | XMLHttpRequest.DONE = 4 1330 | exports.default = XMLHttpRequest 1331 | 1332 | /***/ }), 1333 | /* 19 */ 1334 | /***/ (function(module, exports) { 1335 | 1336 | 'use strict' 1337 | 1338 | Object.defineProperty(exports, "__esModule", { 1339 | value: true 1340 | }) 1341 | 1342 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor) } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor } }() 1343 | 1344 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 1345 | 1346 | var _socketTask = new WeakMap() 1347 | 1348 | var WebSocket = function () { 1349 | // TODO 更新 binaryType 1350 | // The connection is in the process of closing. 1351 | // The connection is not yet open. 1352 | function WebSocket(url) { 1353 | var _this = this 1354 | 1355 | var protocols = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [] 1356 | 1357 | _classCallCheck(this, WebSocket) 1358 | 1359 | this.binaryType = '' 1360 | this.bufferedAmount = 0 1361 | this.extensions = '' 1362 | this.onclose = null 1363 | this.onerror = null 1364 | this.onmessage = null 1365 | this.onopen = null 1366 | this.protocol = '' 1367 | this.readyState = 3 1368 | 1369 | if (typeof url !== 'string' || !/(^ws:\/\/)|(^wss:\/\/)/.test(url)) { 1370 | throw new TypeError('Failed to construct \'WebSocket\': The URL \'' + url + '\' is invalid') 1371 | } 1372 | 1373 | this.url = url 1374 | this.readyState = WebSocket.CONNECTING 1375 | 1376 | var socketTask = wx.connectSocket({ 1377 | url: url, 1378 | protocols: Array.isArray(protocols) ? protocols : [protocols] 1379 | }) 1380 | 1381 | _socketTask.set(this, socketTask) 1382 | 1383 | socketTask.onClose(function (res) { 1384 | _this.readyState = WebSocket.CLOSED 1385 | if (typeof _this.onclose === 'function') { 1386 | _this.onclose(res) 1387 | } 1388 | }) 1389 | 1390 | socketTask.onMessage(function (res) { 1391 | if (typeof _this.onmessage === 'function') { 1392 | _this.onmessage(res) 1393 | } 1394 | }) 1395 | 1396 | socketTask.onOpen(function () { 1397 | _this.readyState = WebSocket.OPEN 1398 | if (typeof _this.onopen === 'function') { 1399 | _this.onopen() 1400 | } 1401 | }) 1402 | 1403 | socketTask.onError(function (res) { 1404 | if (typeof _this.onerror === 'function') { 1405 | _this.onerror(new Error(res.errMsg)) 1406 | } 1407 | }) 1408 | 1409 | return this 1410 | } // TODO 小程序内目前获取不到,实际上需要根据服务器选择的 sub-protocol 返回 1411 | // TODO 更新 bufferedAmount 1412 | // The connection is closed or couldn't be opened. 1413 | 1414 | // The connection is open and ready to communicate. 1415 | 1416 | 1417 | _createClass(WebSocket, [{ 1418 | key: 'close', 1419 | value: function close(code, reason) { 1420 | this.readyState = WebSocket.CLOSING 1421 | var socketTask = _socketTask.get(this) 1422 | 1423 | socketTask.close({ 1424 | code: code, 1425 | reason: reason 1426 | }) 1427 | } 1428 | }, { 1429 | key: 'send', 1430 | value: function send(data) { 1431 | if (typeof data !== 'string' && !(data instanceof ArrayBuffer)) { 1432 | throw new TypeError('Failed to send message: The data ' + data + ' is invalid') 1433 | } 1434 | 1435 | var socketTask = _socketTask.get(this) 1436 | 1437 | socketTask.send({ 1438 | data: data 1439 | }) 1440 | } 1441 | }]) 1442 | 1443 | return WebSocket 1444 | }() 1445 | 1446 | WebSocket.CONNECTING = 0 1447 | WebSocket.OPEN = 1 1448 | WebSocket.CLOSING = 2 1449 | WebSocket.CLOSED = 3 1450 | exports.default = WebSocket 1451 | 1452 | /***/ }), 1453 | /* 20 */ 1454 | /***/ (function(module, exports) { 1455 | 1456 | "use strict" 1457 | 1458 | Object.defineProperty(exports, "__esModule", { 1459 | value: true 1460 | }) 1461 | 1462 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } 1463 | 1464 | /* 1465 | * TODO 使用 wx.readFile 来封装 FileReader 1466 | */ 1467 | var FileReader = function FileReader() { 1468 | _classCallCheck(this, FileReader) 1469 | } 1470 | 1471 | exports.default = FileReader 1472 | 1473 | /***/ }), 1474 | /* 21 */ 1475 | /***/ (function(module, exports) { 1476 | 1477 | "use strict" 1478 | 1479 | Object.defineProperty(exports, "__esModule", { 1480 | value: true 1481 | }) 1482 | var localStorage = { 1483 | get length() { 1484 | var _wx$getStorageInfoSyn = wx.getStorageInfoSync(), 1485 | keys = _wx$getStorageInfoSyn.keys 1486 | 1487 | return keys.length 1488 | }, 1489 | 1490 | key: function key(n) { 1491 | var _wx$getStorageInfoSyn2 = wx.getStorageInfoSync(), 1492 | keys = _wx$getStorageInfoSyn2.keys 1493 | 1494 | return keys[n] 1495 | }, 1496 | getItem: function getItem(key) { 1497 | return wx.getStorageSync(key) 1498 | }, 1499 | setItem: function setItem(key, value) { 1500 | return wx.setStorageSync(key, value) 1501 | }, 1502 | removeItem: function removeItem(key) { 1503 | wx.removeStorageSync(key) 1504 | }, 1505 | clear: function clear() { 1506 | wx.clearStorageSync() 1507 | } 1508 | } 1509 | 1510 | exports.default = localStorage 1511 | 1512 | /***/ }), 1513 | /* 22 */ 1514 | /***/ (function(module, exports) { 1515 | 1516 | 'use strict' 1517 | 1518 | Object.defineProperty(exports, "__esModule", { 1519 | value: true 1520 | }) 1521 | var location = { 1522 | href: 'game.js', 1523 | reload: function reload() {} 1524 | } 1525 | 1526 | exports.default = location 1527 | 1528 | /***/ }) 1529 | /******/ ]) --------------------------------------------------------------------------------