bili-small-game
Advanced tools
Comparing version 1.0.16 to 1.0.17
@@ -8,3 +8,3 @@ // This file is always executed before the App's index.js. It sets up most of | ||
// Make 'window' the global scope | ||
self = window = this; | ||
GameGlobal = self = window = this; | ||
window.top = window.parent = window; | ||
@@ -20,8 +20,35 @@ | ||
// Create the default screen canvas | ||
var screenCanvas = new BiliGame.Canvas.Instance(); | ||
var screenCanvas = window.canvas; | ||
screenCanvas.style = {}; | ||
window.canvas = screenCanvas; | ||
window.sharedCanvas = new BiliGame.Canvas.Instance(); | ||
sharedCanvas.style = {}; | ||
sharedCanvas.getContext('2d'); | ||
if (window.sharedCanvas) { | ||
var sharedCanvas = window.sharedCanvas; | ||
sharedCanvas.style = {}; | ||
var _realSharedCanvas = BiliUtils.getSharedCanvas(); | ||
sharedCanvas.getContext = _realSharedCanvas.getContext.bind(_realSharedCanvas); | ||
Object.defineProperties(sharedCanvas, { | ||
width: { | ||
get() { | ||
return _realSharedCanvas.width; | ||
}, | ||
set(value) { | ||
return _realSharedCanvas.width = value; | ||
}, | ||
enumerable: true, | ||
configurable: false, | ||
}, | ||
height: { | ||
get() { | ||
return _realSharedCanvas.height; | ||
}, | ||
set(value) { | ||
return _realSharedCanvas.height = value; | ||
}, | ||
enumerable: true, | ||
configurable: false, | ||
}, | ||
}); | ||
} else { | ||
window.sharedCanvas = new (function() {return this})(); | ||
} | ||
var onScreen = true; | ||
@@ -78,3 +105,16 @@ window.__SmallApp.fileSystemManager = new BiliGame.FileSystemManager.Instance(); | ||
var openDataContext = { | ||
canvas: sharedCanvas, | ||
postMessage: function(data) { | ||
if (window._postMessageToOpenDataContext) { | ||
_postMessageToOpenDataContext(JSON.stringify(data)); | ||
} | ||
}, | ||
}; | ||
var bl = (window.bl = { | ||
postMessage: openDataContext.postMessage, | ||
getOpenDataContext: function() { | ||
return openDataContext; | ||
}, | ||
createCanvas: function() { | ||
@@ -81,0 +121,0 @@ if (onScreen) { |
@@ -8,3 +8,3 @@ // This file is always executed before the App's index.js. It sets up most of | ||
// Make 'window' the global scope | ||
self = window = this; | ||
GameGlobal = self = window = this; | ||
window.top = window.parent = window; | ||
@@ -16,7 +16,53 @@ | ||
var IS_NEW_VERSION = !!_internalBL.hasOpenDataContext; | ||
// Create the default screen canvas | ||
var screenCanvas = _internalBL.createCanvas(); | ||
window.canvas = screenCanvas; | ||
window.sharedCanvas = _internalBL.createCanvas(); | ||
window.sharedCanvas.getContext('2d'); | ||
if (IS_NEW_VERSION) { | ||
// 5.43新增开放域 | ||
if (_internalBL.hasOpenDataContext()) { | ||
// 开启开放域 | ||
var _sharedCanvas = _internalBL.getRealOpenDataCanvas(); | ||
var fakeSharedCanvas = _internalBL.getFakeOpenDataCanvas(); | ||
fakeSharedCanvas.__proto__ = new (function() { | ||
return this; | ||
})(); | ||
fakeSharedCanvas.getContext = function(type) { | ||
return _sharedCanvas.getContext(type); | ||
}; | ||
Object.defineProperties(fakeSharedCanvas, { | ||
width: { | ||
get() { | ||
return _sharedCanvas.width; | ||
}, | ||
set(value) { | ||
return (_sharedCanvas.value = value); | ||
}, | ||
enumerable: true, | ||
configurable: false, | ||
}, | ||
height: { | ||
get() { | ||
return _sharedCanvas.height; | ||
}, | ||
set(value) { | ||
return (_sharedCanvas.height = value); | ||
}, | ||
enumerable: true, | ||
configurable: false, | ||
}, | ||
}); | ||
window.sharedCanvas = fakeSharedCanvas; | ||
} else { | ||
window.sharedCanvas = new (function() { | ||
return this; | ||
})(); | ||
} | ||
} else { | ||
window.sharedCanvas = _internalBL.createCanvas(); | ||
window.sharedCanvas.getContext('2d'); | ||
} | ||
var onScreen = true; | ||
@@ -168,2 +214,19 @@ | ||
if (IS_NEW_VERSION) { | ||
var postMessage = function(data) { | ||
_internalBL.postMessageToOpenData(JSON.stringify(data)); | ||
}; | ||
var openDataContext = { | ||
canvas: fakeSharedCanvas, | ||
postMessage: postMessage, | ||
}; | ||
bl.getOpenDataContext = function() { | ||
return openDataContext; | ||
}; | ||
bl.postMessage = postMessage; | ||
} | ||
window.localStorage = {}; | ||
@@ -170,0 +233,0 @@ // Timers |
{ | ||
"name": "bili-small-game", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "bilibili small game", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
498013
11
3731