Commit 4a2c995a by Nick An

mg

parents 875e8753 1f179fb6
fe/resource/assets/bg.jpg

136 KB | W: | H:

fe/resource/assets/bg.jpg

87.2 KB | W: | H:

fe/resource/assets/bg.jpg
fe/resource/assets/bg.jpg
fe/resource/assets/bg.jpg
fe/resource/assets/bg.jpg
  • 2-up
  • Swipe
  • Onion skin
fe/resource/assets/control.jpg

30.1 KB | W: | H:

fe/resource/assets/control.jpg

6 KB | W: | H:

fe/resource/assets/control.jpg
fe/resource/assets/control.jpg
fe/resource/assets/control.jpg
fe/resource/assets/control.jpg
  • 2-up
  • Swipe
  • Onion skin
fe/resource/assets/egret_icon.png

6.62 KB | W: | H:

fe/resource/assets/egret_icon.png

2.65 KB | W: | H:

fe/resource/assets/egret_icon.png
fe/resource/assets/egret_icon.png
fe/resource/assets/egret_icon.png
fe/resource/assets/egret_icon.png
  • 2-up
  • Swipe
  • Onion skin
fe/resource/assets/grid.jpg

333 Bytes | W: | H:

fe/resource/assets/grid.jpg

145 Bytes | W: | H:

fe/resource/assets/grid.jpg
fe/resource/assets/grid.jpg
fe/resource/assets/grid.jpg
fe/resource/assets/grid.jpg
  • 2-up
  • Swipe
  • Onion skin
fe/resource/assets/grid_select.jpg

331 Bytes | W: | H:

fe/resource/assets/grid_select.jpg

146 Bytes | W: | H:

fe/resource/assets/grid_select.jpg
fe/resource/assets/grid_select.jpg
fe/resource/assets/grid_select.jpg
fe/resource/assets/grid_select.jpg
  • 2-up
  • Swipe
  • Onion skin
fe/resource/assets/logo.jpg

16 KB | W: | H:

fe/resource/assets/logo.jpg

5.18 KB | W: | H:

fe/resource/assets/logo.jpg
fe/resource/assets/logo.jpg
fe/resource/assets/logo.jpg
fe/resource/assets/logo.jpg
  • 2-up
  • Swipe
  • Onion skin
fe/resource/assets/mask.jpg

141 KB | W: | H:

fe/resource/assets/mask.jpg

14.9 KB | W: | H:

fe/resource/assets/mask.jpg
fe/resource/assets/mask.jpg
fe/resource/assets/mask.jpg
fe/resource/assets/mask.jpg
  • 2-up
  • Swipe
  • Onion skin
{
"groups": [
{
"keys": "bg_jpg,egret_icon_png,description_json,control_jpg,grid_jpg,logo_jpg,mask_jpg,grid_select_jpg",
"keys": "bg_jpg,egret_icon_png,description_json,control_jpg,grid_jpg,logo_jpg,mask_jpg,grid_select_jpg,lighting_jpg,prop_heart_jpg,prop_light_jpg,catched_0_mp3,catched_1_mp3,catched_2_mp3,flirt_mp3,avatar_bg_jpg,bgm_mp3,transition_catcher_jpg,transition_runner_jpg",
"name": "preload"
}
],
......@@ -45,6 +45,61 @@
"name": "grid_select_jpg",
"type": "image",
"url": "assets/grid_select.jpg"
},
{
"name": "lighting_jpg",
"type": "image",
"url": "assets/lighting.jpg"
},
{
"name": "prop_heart_jpg",
"type": "image",
"url": "assets/prop_heart.jpg"
},
{
"name": "prop_light_jpg",
"type": "image",
"url": "assets/prop_light.jpg"
},
{
"name": "catched_0_mp3",
"type": "sound",
"url": "assets/catched_0.mp3"
},
{
"name": "catched_1_mp3",
"type": "sound",
"url": "assets/catched_1.mp3"
},
{
"name": "catched_2_mp3",
"type": "sound",
"url": "assets/catched_2.mp3"
},
{
"name": "flirt_mp3",
"type": "sound",
"url": "assets/flirt.mp3"
},
{
"name": "avatar_bg_jpg",
"type": "image",
"url": "assets/avatar_bg.jpg"
},
{
"name": "bgm_mp3",
"type": "sound",
"url": "assets/bgm.mp3"
},
{
"name": "transition_catcher_jpg",
"type": "image",
"url": "assets/transition_catcher.jpg"
},
{
"name": "transition_runner_jpg",
"type": "image",
"url": "assets/transition_runner.jpg"
}
]
}
\ No newline at end of file
class Avatar extends egret.Sprite {
public constructor(userData) {
super()
this.init(userData)
}
private avatar = new egret.Bitmap()
private bg = new egret.Bitmap()
private imageLoader = new egret.ImageLoader()
private init(userData) {
this.bg.width = 100
this.bg.height = 100
this.bg.texture = RES.getRes("avatar_bg_jpg")
this.addChild(this.bg)
this.avatar.x = 10
this.avatar.y = 10
this.avatar.width = 80
this.avatar.height = 80
this.imageLoader.addEventListener(egret.Event.COMPLETE,this.loadCompleteHandler,this)
this.imageLoader.load(userData.avatar_url || "http://www.insajderi.com/wp-content/uploads/2018/01/asdja.jpg")
this.addChild(this.avatar)
}
private loadCompleteHandler() {
let texture = new egret.Texture()
texture._setBitmapData(this.imageLoader.data)
this.avatar.texture = texture
}
}
class AvatarGroup extends egret.Sprite {
public constructor(userDatas) {
super()
this.init(userDatas)
}
private init(userDatas) {
userDatas.forEach((userData, index) => {
let avatar = new Avatar(userData)
avatar.x = index * 100
this.addChild(avatar)
})
}
}
\ No newline at end of file
class Controller extends egret.Sprite {
private myPosition = {}
public constructor() {
super();
this.init()
......@@ -61,6 +62,17 @@ class Controller extends egret.Sprite {
controlContainer.addChild(this.down)
controlContainer.addChild(this.left)
controlContainer.addChild(this.right)
const me = Store.getState().runners.find(runner => runner.t_cid === Store.getState().cid)
this.myPosition.x = me.x
this.myPosition.y = me.y
EventBus.addEventListener('moving', (payload) => {
if (payload.target.payload.t_cid === Store.getState().cid) {
this.myPosition.x = payload.target.payload.x
this.myPosition.y = payload.target.payload.y
}
})
}
private controlTouchBegin(e: egret.TouchEvent){
......@@ -74,8 +86,35 @@ class Controller extends egret.Sprite {
}else if(e.currentTarget === this.right){
delta.x += 1
}
this.dispatchEventWith("position_change", false, delta)
let newX = this.myPosition.x + delta.x
let newY = this.myPosition.y + delta.y
if(newX < 0){
newX = 0
}
if(newY < 0){
newY = 0
}
if(newX >= 13){
newX = 13
}
if(newY >= 9){
newY = 9
}
platform.sendSocketMessage({
data: JSON.stringify({
type: 'moving',
room_id: 'default_room',
cid: Store.getState().cid,
payload: {
x: newX,
y: newY,
avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
}
}),
})
}
public release() {
......
......@@ -32,6 +32,7 @@ class Main extends egret.DisplayObjectContainer {
public constructor() {
super();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}
private onAddToStage(event: egret.Event) {
......@@ -65,10 +66,20 @@ class Main extends egret.DisplayObjectContainer {
const userInfo = await platform.getUserInfo();
Store.onMessage({
type: 'setUserInfo',
data: userInfo
payload: userInfo
})
console.log(userInfo);
SoundManager.getInstance().play({soundName: "bgm_mp3", startTime: 0, loops: -1})
platform.onShareAppMessage((...args) => {
return {
title: "恶魔妈妈买面膜",
imageUrl: "https://ws3.sinaimg.cn/large/006tKfTcly1fr102d837jj31kw11un5h.jpg"
}
})
platform.showShareMenu({
withShareTicket: false
})
platform.connectSocket({
url: "ws://192.168.50.118:9090",
header: {
......@@ -76,11 +87,11 @@ class Main extends egret.DisplayObjectContainer {
},
method: "GET",
success: (...args) => {
console.error("success")
console.error("connectSocket success")
console.error(args)
},
fail: (...args) => {
console.error("fail")
console.error("connectSocket fail")
console.error(args)
}
})
......@@ -89,7 +100,7 @@ class Main extends egret.DisplayObjectContainer {
platform.sendSocketMessage({
data: JSON.stringify({
type: 'entry',
rid: 'default_room',
room_id: 'default_room',
payload: {
avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
......@@ -107,17 +118,25 @@ class Main extends egret.DisplayObjectContainer {
})
})
this.createGameScene();
platform.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data)
const state = Store.onMessage(res.data)
let data = res.data
if (typeof res.data === 'string') {
data = JSON.parse(res.data)
}
if(data.type === 'entry') {
SceneManager.getInstance().roomScene.update(data)
// data = { "type": "game_ready", "rid": "default_room", "payload": [{ "nick_name": "syfee", "avatar_url": "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIibqBbRLAe0AI9NvnzPdLEBx9mT0ZKXicbibYWLAJiaPs0EZtmDiazJ7kytEj4tzWiberUptkR1yg0Q28g/132", "cid": "1525524303u0my3", "role": "ghost", "t_cid": "1525524303u0my3", x: 1, y: 1 }, { "nick_name": "syfee1", "avatar_url": "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIibqBbRLAe0AI9NvnzPdLEBx9mT0ZKXicbibYWLAJiaPs0EZtmDiazJ7kytEj4tzWiberUptkR1yg0Q28g/132", "cid": "1525524303u0my4", "role": "runner", "t_cid": "1525524303u0my4", x: 1, y: 1 }], "cid": "1525524303u0my4" }
const state = Store.onMessage(data)
EventBus.dispatch(data.type, data)
switch (data.type) {
case 'entry':
Store.onMessage({
type: 'updateCid',
payload: data
})
SceneManager.getInstance().roomScene.update(data)
break;
case 'game_ready':
SceneManager.getInstance().roomScene.update(data)
}
})
platform.onSocketError((e) => {
......@@ -153,6 +172,8 @@ class Main extends egret.DisplayObjectContainer {
*/
private createGameScene() {
this.addChild(SceneManager.getInstance());
// SoundManager.getInstance().play({soundName: 'bgm_mp3', loops: -1})
// SoundManager.getInstance().playCatched(1)
}
/**
......@@ -165,5 +186,5 @@ class Main extends egret.DisplayObjectContainer {
result.texture = texture;
return result;
}
}
......@@ -5,6 +5,8 @@ const gridsInY = 10
class Map extends egret.Sprite {
private grids:any = []
private touchArea: egret.Bitmap
public isShowingTouchArea
private runnerMap:any = {}
public constructor() {
super();
this.init()
......@@ -27,11 +29,29 @@ class Map extends egret.Sprite {
this.touchArea.texture = RES.getRes('mask_jpg')
this.touchArea.alpha = 0
this.addChild(this.touchArea)
Store.getState().runners.forEach(runnerData => {
const runner = new Runner(runnerData)
this.addChild(runner)
this.runnerMap[runnerData.t_cid] = runner
})
EventBus.addEventListener('moving', (payload) => {
this.runnerMap[payload.target.payload.t_cid].x = payload.target.payload.x * gridWidth
this.runnerMap[payload.target.payload.t_cid].y = payload.target.payload.y * gridHeight
})
EventBus.addEventListener('clicking', (payload) => {
const x = payload.target.payload.x * gridWidth
const y = payload.target.payload.y * gridHeight
if (Store.isCatcher()) {
this.showSurroundedGrids(x, y)
} else {
this.showClickedGrid(x, y)
}
})
}
public getSurroundedGrids(x, y) {
const left = Math.max(x / gridWidth - 2)
const top = Math.max(y / gridHeight - 2)
const left = x / gridWidth - 2
const top = y / gridHeight - 2
const grids = []
for (let i = left; i < 5 + left; i++) {
for (let j = top; j < 5 + top; j++) {
......@@ -43,8 +63,21 @@ class Map extends egret.Sprite {
return grids
}
public showClickedGrid(x, y) {
const surroundedGrids = this.getSurroundedGrids(x, y)
const clickedGrid = surroundedGrids.find(grid => grid.x === x && grid.y === y)
clickedGrid.bg.texture = RES.getRes('grid_select_jpg')
setTimeout(() => {
clickedGrid.bg.texture = RES.getRes('grid_jpg')
}, 1000);
}
public showSurroundedGrids(x, y) {
this.isShowingTouchArea = true
const surroundedGrids = this.getSurroundedGrids(x, y)
const centerGrid = surroundedGrids.find(grid => grid.x === x && grid.y === y)
centerGrid.bg.texture = RES.getRes('grid_select_jpg')
surroundedGrids.forEach(grid => {
grid.alpha = 1
})
......@@ -53,10 +86,12 @@ class Map extends egret.Sprite {
this.touchArea.y = y - 2 * gridHeight
setTimeout(() => {
centerGrid.bg.texture = RES.getRes('grid_jpg')
surroundedGrids.forEach(grid => {
grid.alpha = 0
})
this.touchArea.alpha = 0
this.isShowingTouchArea = false
}, 1000);
}
......
class MapGrid extends egret.Sprite {
private bg:egret.Bitmap = new egret.Bitmap()
public bg:egret.Bitmap = new egret.Bitmap()
public constructor() {
super();
this.init()
......@@ -17,8 +17,20 @@ class MapGrid extends egret.Sprite {
}
private onTouchTap() {
if (Store.isCatcher()) {
this.parent.showSurroundedGrids(this.x, this.y)
if (Store.isCatcher() && !this.parent.isShowingTouchArea) {
platform.sendSocketMessage({
data: JSON.stringify({
type: 'clicking',
cid: Store.getState().cid,
room_id: 'default_room',
payload: {
x: this.x / 72,
y: this.y / 72,
avatar_url: Store.getMyInfo().avatarUrl,
nick_name: Store.getMyInfo().nickName
}
}),
})
}
}
......
......@@ -13,10 +13,14 @@ declare interface Platform {
connectSocket(options): void
onSocketOpen(callback): void
onSocketClose(callback): void
closeSocket(options): void
onSocketMessage(callback): void
onSocketError(callback): void
sendSocketMessage(callback): void
request(options): void
exitMiniProgram(options): void
onShareAppMessage(callback): any
showShareMenu(options): any
}
class DebugPlatform implements Platform {
......@@ -43,6 +47,10 @@ class DebugPlatform implements Platform {
}
closeSocket(options){
}
onSocketMessage(options){
}
......@@ -57,6 +65,15 @@ class DebugPlatform implements Platform {
request(){
}
exitMiniProgram(options){
}
onShareAppMessage(callback){
}
showShareMenu(options){
}
}
......
class Guy extends egret.Sprite {
class Runner extends egret.Sprite {
public constructor() {
public constructor(data) {
super()
this.init()
this.init(data)
}
private avatar = new egret.Bitmap()
private imageLoader = new egret.ImageLoader()
private init() {
private init(data) {
this.avatar.width = 72
this.avatar.height = 72
this.x = data.x * this.avatar.width
this.y = data.y * this.avatar.height
this.imageLoader.addEventListener(egret.Event.COMPLETE,this.loadCompleteHandler,this)
this.imageLoader.load("http://www.insajderi.com/wp-content/uploads/2018/01/asdja.jpg")
this.imageLoader.load(data.avatar_url)
this.addChild(this.avatar)
}
......@@ -39,4 +41,9 @@ class Guy extends egret.Sprite {
this.x = 72*13 + 10
}
}
public moveTo(x, y) {
this.x = x
this.y = y
}
}
\ No newline at end of file
......@@ -5,6 +5,10 @@ class SceneManager extends egret.DisplayObjectContainer {
public roomScene: RoomScene;
// 游戏场景
public gameScene: GameScene;
private sceneMap: any = {
roomScene: RoomScene,
gameScene: GameScene
}
public constructor() {
super();
......@@ -13,9 +17,9 @@ class SceneManager extends egret.DisplayObjectContainer {
private init() {
// 实例化两个场景
this.roomScene = new RoomScene();
this.gameScene = new GameScene();
// this.gameScene = new GameScene();
// 默认添加开始场景
this.addChild(this.gameScene);
this.addChild(this.roomScene);
}
// 实例化单例获取方法
public static getInstance(): SceneManager {
......@@ -26,10 +30,11 @@ class SceneManager extends egret.DisplayObjectContainer {
}
// 切换场景
public changeScene(type) {
// 释放资源
if (this[type] && typeof this[type].release === 'function') {
this[type].release()
if (!this[type]) {
const Scene = this.sceneMap[type]
this[type] = new Scene ()
}
// 移除所有显示列表中的对象
this.removeChildren();
// 添加下一个场景
......
class SoundManager {
private static instance: SoundManager;
private sounds: any
public constructor() {
this.init()
}
private init() {
this.sounds = {}
const soundNames = [
'catched_0_mp3',
'catched_1_mp3',
'catched_2_mp3',
'flirt_mp3',
'bgm_mp3',
]
soundNames.forEach(soundName => {
this.sounds[soundName] = RES.getRes(soundName)
})
}
// 实例化单例获取方法
public static getInstance(): SoundManager {
if (!SoundManager.instance) {
SoundManager.instance = new SoundManager();
}
return SoundManager.instance;
}
public play({soundName, startTime = 0, loops = 1}) {
this.sounds[soundName].play(startTime, loops)
}
// 随机播放被抓音频
public playCatched(num?) {
const soundName = [
'catched_0_mp3',
'catched_2_mp3',
][num || this.rnd(0, 1)]
this.play({soundName})
}
rnd(start, end) {
return Math.floor(Math.random() * (end - start) + start)
}
}
\ No newline at end of file
......@@ -2,35 +2,62 @@ let _state: any = {
role: null,
cid: null,
roomId: null,
userInfo: {},
runners: [],
catcher: {}
}
const listenners = []
class Store {
static getState() {
return _state
}
static onMessage(message) {
const { payload } = message
const { payload, room_id } = message
switch (message.type) {
case 'game_ready':
const { cid, room_id, payload: { role } } = payload
case 'game_ready': {
const runners = payload.filter(runner => runner.role !== 'ghost')
_state = {
..._state,
cid,
role,
roomId: room_id,
runners,
}
break;
}
case 'setUserInfo':
_state.userInfo = message.data
_state = {
..._state,
userInfo: payload
}
break;
case 'updateCid':
_state = {
..._state,
cid: payload.cid
}
break;
default:
break;
}
return _state
}
static subscribe(fn) {
}
static getMyInfo() {
return _state.userInfo
}
static getMyPosition
static isCatcher() {
return true
// return _state.role === 'ghost'
console.log('isCatcher_____', _state.runners, _state.cid)
return !_state.runners.some(runner => runner.t_cid === _state.cid)
}
}
\ No newline at end of file
}
window.Store = Store
\ No newline at end of file
......@@ -7,8 +7,6 @@ class GameScene extends egret.Sprite {
this.init()
}
private me = new Guy()
// 初始化(给开始按钮绑定点击事件)
private init() {
// put display object to this scene
......@@ -18,21 +16,15 @@ class GameScene extends egret.Sprite {
bg.graphics.drawRect(0,0,1334, 750)
bg.graphics.endFill()
this.addChild(bg)
this.controller = new Controller()
this.addChild(this.controller)
this.controller.addEventListener("position_change", this.onPositionChange, this)
if (!Store.isCatcher()) {
this.controller = new Controller()
this.addChild(this.controller)
}
this.map = new Map()
this.map.y = 15
this.map.x = 10
this.me.y = 15
this.me.x = 10
this.addChild(this.map)
this.map.addChild(this.me)
}
private onPositionChange(delta){
this.me.applyDelta(delta.data)
}
public release() {
......
......@@ -2,6 +2,10 @@ class RoomScene extends egret.Sprite {
private startLabel: egret.TextField
private players: Array<any>
private avatars: any
private transition_runner_jpg = "transition_runner_jpg"
private transition_catcher_jpg = "transition_catcher_jpg"
public constructor() {
super();
......@@ -13,18 +17,72 @@ class RoomScene extends egret.Sprite {
console.log('RoomScene.init')
this.initBg()
this.initStartLabel()
this.addChild(this.startLabel);
// var sound: egret.Sound = RES.getRes("catched_0_mp3");
// sound.play();
// put display object to this scene
}
public update(data) {
const payload = data.payload
if(payload.seat == 0) {
switch (data.type) {
case 'entry':
const payload = data.payload
this.updateStartLabelAndPlayers(payload)
break;
case 'game_ready':
this.countDown(payload)
default:
break;
}
}
private updateStartLabelAndPlayers(payload) {
if (payload.seat == 0) {
this.startLabel.text = '开始'
this.startLabel.touchEnabled = true
this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
} else {
this.startLabel.text = '等待房主点击开始'
this.startLabel.touchEnabled = false
}
const members = payload.members
if(this.avatars && this.avatars.parent){
this.avatars.parent.removeChild(this.avatars)
}
this.avatars = new AvatarGroup(members)
this.avatars.y = 330
this.avatars.x = 667 - (members.length * 100) / 2
this.addChild(this.avatars)
}
private countDown(res) {
this.startLabel.text = '3'
const timer = setInterval(() => {
if (this.startLabel.text == '1') {
return this.startLabel.text = 'Go!'
}
if (this.startLabel.text == 'Go!') {
clearInterval(timer)
const bg = Store.isCatcher ? this.transition_catcher_jpg : this.transition_runner_jpg
this.showTransition(bg, () => {
SceneManager.getInstance().changeScene('gameScene')
})
return
}
this.startLabel.text = `${Number(this.startLabel.text) - 1}`
}, 1000)
}
private showTransition(transition, callback){
let img = new egret.Bitmap()
img.texture = RES.getRes(transition)
this.addChild(img)
var tw = egret.Tween.get( img )
img.alpha = 0
tw.to( {alpha:1}, 1000 ).wait(2000).call(() => {
callback()
})
}
private initBg() {
......@@ -44,19 +102,37 @@ class RoomScene extends egret.Sprite {
this.startLabel = new egret.TextField()
this.startLabel.textColor = 0xF0D66D
this.startLabel.text = "请稍等..."
this.startLabel.width = 200
this.startLabel.anchorOffsetX = 100
this.startLabel.width = 300
this.startLabel.anchorOffsetX = 150
this.startLabel.x = 1334 / 2
this.startLabel.textAlign = egret.HorizontalAlign.CENTER;
this.startLabel.y = 1136 / 2
this.addChild(this.startLabel);
}
private startHandler() {
console.log('starthandler')
SceneManager.getInstance().changeScene('gameScene');
platform.sendSocketMessage({
data: JSON.stringify({
type: 'start',
rid: 'default_room',
cid: Store.getState().cid,
payload: {
avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
}
}),
success: res => {
},
fail: res => {
this.startLabel.text = '启动失败'
console.error('start error: ', res)
}
})
}
public release() {
// 移除事件
this.startLabel.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
}
}
\ No newline at end of file
}
class EventBusClass {
private listeners: any = {}
public addEventListener(type, callback, scope?) {
var args = [];
var numOfArgs = arguments.length;
for(var i=0; i<numOfArgs; i++){
args.push(arguments[i]);
}
args = args.length > 3 ? args.splice(3, args.length-1) : [];
if(typeof this.listeners[type] != "undefined") {
this.listeners[type].push({scope:scope, callback:callback, args:args});
} else {
this.listeners[type] = [{scope:scope, callback:callback, args:args}];
}
}
public removeEventListener(type, callback, scope) {
if(typeof this.listeners[type] != "undefined") {
var numOfCallbacks = this.listeners[type].length;
var newArray = [];
for(var i=0; i<numOfCallbacks; i++) {
var listener = this.listeners[type][i];
if(listener.scope == scope && listener.callback == callback) {
} else {
newArray.push(listener);
}
}
this.listeners[type] = newArray;
}
}
public hasEventListener(type, callback, scope) {
if(typeof this.listeners[type] != "undefined") {
var numOfCallbacks = this.listeners[type].length;
if(callback === undefined && scope === undefined){
return numOfCallbacks > 0;
}
for(var i=0; i<numOfCallbacks; i++) {
var listener = this.listeners[type][i];
if((scope ? listener.scope == scope : true) && listener.callback == callback) {
return true;
}
}
}
return false;
}
public dispatch(type, target) {
var event = {
type: type,
target: target
};
var args = [];
var numOfArgs = arguments.length;
for(var i=0; i<numOfArgs; i++){
args.push(arguments[i]);
};
args = args.length > 2 ? args.splice(2, args.length-1) : [];
args = [event].concat(args);
if(typeof this.listeners[type] != "undefined") {
var listeners = this.listeners[type].slice();
var numOfCallbacks = listeners.length;
for(var i=0; i<numOfCallbacks; i++) {
var listener = listeners[i];
if(listener && listener.callback) {
var concatArgs = args.concat(listener.args);
listener.callback.apply(listener.scope, concatArgs);
}
}
}
}
public getEvents() {
var str = "";
for(var type in this.listeners) {
var numOfCallbacks = this.listeners[type].length;
for(var i=0; i<numOfCallbacks; i++) {
var listener = this.listeners[type][i];
str += listener.scope && listener.scope.className ? listener.scope.className : "anonymous";
str += " listen for '" + type + "'\n";
}
}
return str;
}
}
if (!window.EventBus) {
window.EventBus = new EventBusClass()
}
declare let EventBus: EventBusClass;
declare interface Window {
EventBus: EventBusClass
}
......@@ -46,6 +46,10 @@ class WxgamePlatform {
wx.onSocketClose(callback)
}
closeSocket(options){
wx.closeSocket(options)
}
onSocketMessage(callback){
wx.onSocketMessage(callback)
}
......@@ -57,9 +61,21 @@ class WxgamePlatform {
sendSocketMessage(options){
wx.sendSocketMessage(options)
}
request(options){
wx.request(options)
}
exitMiniProgram(options){
wx.exitMiniProgram(options)
}
onShareAppMessage(callback){
return wx.onShareAppMessage(callback)
}
showShareMenu(options){
wx.showShareMenu(options)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment