Removes wx API invocations for JSB projects. (#2668)

* Removes wx API invocation for JSB projects.

* sys.openURL fix for JSB.

* touches, mouse, keyboard capabilities check.
This commit is contained in:
James Chen
2018-05-11 18:00:40 +08:00
committed by pandamicro
parent f326869f47
commit cd07d03b7d
8 changed files with 72 additions and 72 deletions
+57 -39
View File
@@ -512,7 +512,8 @@ function initSys () {
* Is native ? This is set to be true in jsb auto.
* @property {Boolean} isNative
*/
sys.isNative = false;
sys.isNative = CC_JSB;
/**
* Is web browser ?
@@ -538,41 +539,27 @@ function initSys () {
sys.__audioSupport = {};
}
else if (CC_JSB) {
var env = wx.getSystemInfoSync();
sys.isMobile = false; //FIXME:
sys.platform = sys.WECHAT_GAME;
sys.language = env.language.substr(0, 2);
if (env.platform === "android") {
sys.os = sys.OS_ANDROID;
}
else if (env.platform === "ios") {
sys.os = sys.OS_IOS;
}
else if (env.platform === 'mac') {
sys.os = sys.OS_OSX;
}
else if (env.platform === 'windows') {
sys.os = sys.OS_WINDOWS;
}
var platform = sys.platform = __getPlatform();
sys.isMobile = (platform === sys.ANDROID ||
platform === sys.IPAD ||
platform === sys.IPHONE ||
platform === sys.WP8 ||
platform === sys.TIZEN ||
platform === sys.BLACKBERRY);
var version = /[\d\.]+/.exec(env.system);
sys.osVersion = version[0];
sys.os = __getOS();
sys.language = __getCurrentLanguage();
sys.osVersion = __getOSVersion();
sys.osMainVersion = parseInt(sys.osVersion);
if (wx.getGroupCloudStorage && wx.getFriendCloudStorage) {
// wechagame subdomain
sys.browserType = sys.BROWSER_TYPE_WECHAT_GAME_SUB;
}
else {
sys.browserType = sys.BROWSER_TYPE_WECHAT_GAME;
}
sys.browserVersion = env.version;
sys.browserType = null;
sys.browserVersion = null;
var w = env.windowWidth;
var h = env.windowHeight;
var ratio = env.pixelRatio || 1;
var w = window.innerWidth;
var h = window.innerHeight;
var ratio = window.devicePixelRatio || 1;
sys.windowPixelResolution = {
width: ratio * w,
height: ratio * h
width: ratio * w,
height: ratio * h
};
sys.localStorage = window.localStorage;
@@ -580,17 +567,25 @@ function initSys () {
sys.capabilities = {
"canvas": false,
"opengl": true,
"webp": false
"webp": true,
};
if (sys.isMobile) {
capabilities["accelerometer"] = true;
capabilities["touches"] = true;
} else {
// desktop
capabilities["keyboard"] = true;
capabilities["mouse"] = false; //TODO: Change to true to support dispatching mouse event for desktop platforms, need to be done in cocos2d-x-lite repo.
capabilities["touches"] = true; //TODO: Switch to false after the above TODO is finised!
}
sys.__audioSupport = {
ONLY_ONE: false,
WEB_AUDIO: false,
DELAY_CREATE_CTX: false,
format: ['.mp3']
};
// Adaptation
wx.getOpenDataContext = function () {return {canvas: null};}
}
else if (CC_WECHATGAME) {
var env = wx.getSystemInfoSync();
@@ -1081,6 +1076,9 @@ function initSys () {
*/
sys.garbageCollect = function () {
// N/A in web
if (CC_JSB) {
__jsc__.garbageCollect();
}
};
/**
@@ -1089,6 +1087,9 @@ function initSys () {
*/
sys.dumpRoot = function () {
// N/A in web
if (CC_JSB) {
__jsc__.dumpRoot();
}
};
/**
@@ -1097,6 +1098,9 @@ function initSys () {
*/
sys.restartVM = function () {
// N/A in web
if (CC_JSB) {
__restartVM();
}
};
/**
@@ -1106,6 +1110,9 @@ function initSys () {
*/
sys.cleanScript = function (jsfile) {
// N/A in web
if (CC_JSB) {
__cleanScript(jsfile);
}
};
/**
@@ -1117,8 +1124,14 @@ function initSys () {
* @return {Boolean} Validity of the object
*/
sys.isObjectValid = function (obj) {
if (obj) return true;
else return false;
if (CC_JSB) {
return __isObjectValid(obj);
}
else if (obj) {
return true;
}
return false;
};
/**
@@ -1146,7 +1159,12 @@ function initSys () {
* @param {String} url
*/
sys.openURL = function (url) {
window.open(url);
if (CC_JSB) {
jsb.openURL(url);
}
else {
window.open(url);
}
};
/**
+2 -2
View File
@@ -407,7 +407,7 @@ View.prototype = {
},
_adjustViewportMeta: function () {
if (this._isAdjustViewport && !CC_WECHATGAME && !CC_QQPLAY) {
if (this._isAdjustViewport && !CC_JSB && !CC_WECHATGAME && !CC_QQPLAY) {
this._setViewportMeta(__BrowserGetter.meta, false);
this._isAdjustViewport = false;
}
@@ -817,7 +817,7 @@ View.prototype = {
* @param {ResolutionPolicy|Number} resolutionPolicy The resolution policy desired
*/
setRealPixelResolution: function (width, height, resolutionPolicy) {
if (!CC_WECHATGAME && !CC_QQPLAY) {
if (!CC_JSB && !CC_WECHATGAME && !CC_QQPLAY) {
// Set viewport's width
this._setViewportMeta({"width": width}, true);
-24
View File
@@ -24,30 +24,6 @@
****************************************************************************/
window.CC_JSB = true;
window.CC_WECHATGAME = true; //FIXME: remove CC_WECHATGAME
// Simulate wechat game API:
//FIXME: remove wx
window.wx = {
getSystemInfoSync() {
return {
platform: 'mac',
language: 'CN',
system: 1.0,
windowWidth: window.innerWidth,
windowHeight: window.innerHeight,
};
},
onShow() {
},
onHide() {
}
}
window.CanvasRenderingContext2D = cc.CanvasRenderingContext2D;
delete cc.CanvasRenderingContext2D;
+1 -1
View File
@@ -45,7 +45,7 @@ class Audio extends HTMLAudioElement {
//
// _src.set(this, '')
//
// const innerAudioContext = {};//cjh wx.createInnerAudioContext()
// const innerAudioContext = {};
//
// _innerAudioContext.set(this, innerAudioContext)
//
@@ -29,6 +29,12 @@ class HTMLVideoElement extends HTMLMediaElement {
constructor() {
super('video')
}
canPlayType(type) {
if (type === 'video/mp4')
return true;
return false;
}
}
module.exports = HTMLVideoElement;
+1
View File
@@ -29,6 +29,7 @@ class Node extends EventTarget {
constructor() {
super()
this.childNodes = []
this.parentNode = window.__cccanvas;
}
appendChild(node) {
+3 -6
View File
@@ -25,16 +25,13 @@
let { noop } = require('./util');
// TODO 需要 wx.getSystemInfo 获取更详细信息
// cjh const { platform } = wx.getSystemInfoSync()
const navigator = {
platform: 'wx', //cjh added wx
language: 'zh-cn',
platform: __getOS(),
language: __getCurrentLanguage(),
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',
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301 NetType/WIFI Language/zh_CN',
onLine: true, // TODO 用 wx.getNetworkStateChange 和 wx.onNetworkStateChange 来返回真实的状态
onLine: true, //FIXME:
// TODO 用 wx.getLocation 来封装 geolocation
geolocation: {
getCurrentPosition: noop,
watchPosition: noop,
+2
View File
@@ -45,6 +45,8 @@ function inject () {
window.HTMLAudioElement = require('./HTMLAudioElement');
window.HTMLVideoElement = require('./HTMLVideoElement');
window.__cccanvas = new HTMLCanvasElement();
window.__cccanvas._width = window.innerWidth;
window.__cccanvas._height = window.innerHeight;
window.__ccgl.canvas = window.__cccanvas;
window.navigator = require('./navigator');
window.Image = require('./Image');