mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #2476 from minggo/next-runtime
Native new renderer adaption
This commit is contained in:
+1
-1
@@ -106,7 +106,7 @@ cc._initDebugSetting = function (mode) {
|
||||
if (mode === cc.DebugMode.NONE)
|
||||
return;
|
||||
|
||||
if (!CC_JSB && mode > cc.DebugMode.ERROR) {
|
||||
if (mode > cc.DebugMode.ERROR) {
|
||||
//log to web page
|
||||
|
||||
function logToWebPage (msg) {
|
||||
|
||||
@@ -556,27 +556,7 @@ cc.Director.prototype = {
|
||||
var uuid = info.uuid;
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
this._loadingScene = sceneName;
|
||||
if (CC_JSB && cc.runtime && uuid !== this._launchSceneUuid) {
|
||||
var self = this;
|
||||
var groupName = cc.path.basename(info.url) + '_' + info.uuid;
|
||||
console.log('==> start preload: ' + groupName);
|
||||
var ensureAsync = false;
|
||||
cc.LoaderLayer.preload([groupName], function () {
|
||||
console.log('==> end preload: ' + groupName);
|
||||
if (ensureAsync) {
|
||||
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}
|
||||
else {
|
||||
setTimeout(function () {
|
||||
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
ensureAsync = true;
|
||||
}
|
||||
else {
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -31,7 +31,7 @@ if (!(CC_EDITOR && Editor.isMainProcess)) {
|
||||
}
|
||||
|
||||
require('../audio/CCAudioEngine');
|
||||
var renderer = require('./renderer');
|
||||
var renderer = require('./renderer/index.js');
|
||||
var inputManager = CC_QQPLAY ? require('./platform/BKInputManager') : require('./platform/CCInputManager');
|
||||
|
||||
/**
|
||||
@@ -695,7 +695,7 @@ var game = {
|
||||
isWeChatGame = cc.sys.platform === cc.sys.WECHAT_GAME,
|
||||
isQQPlay = cc.sys.platform === cc.sys.QQ_PLAY;
|
||||
|
||||
if (isWeChatGame) {
|
||||
if (isWeChatGame || CC_JSB) {
|
||||
this.container = localContainer = document.createElement("DIV");
|
||||
this.frame = localContainer.parentNode === document.body ? document.documentElement : localContainer.parentNode;
|
||||
this.canvas = localCanvas = canvas;
|
||||
|
||||
+3
-77
@@ -162,41 +162,22 @@ var _touchStartHandler = function (touch, event) {
|
||||
var node = this.owner;
|
||||
|
||||
if (node._hitTest(pos, this)) {
|
||||
if (CC_JSB) {
|
||||
event = Event.EventTouch.pool.get(event);
|
||||
}
|
||||
event.type = EventType.TOUCH_START;
|
||||
event.touch = touch;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
event.touch = null;
|
||||
event._touches = null;
|
||||
Event.EventTouch.pool.put(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var _touchMoveHandler = function (touch, event) {
|
||||
if (CC_JSB) {
|
||||
event = Event.EventTouch.pool.get(event);
|
||||
}
|
||||
var node = this.owner;
|
||||
event.type = EventType.TOUCH_MOVE;
|
||||
event.touch = touch;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
event.touch = null;
|
||||
event._touches = null;
|
||||
Event.EventTouch.pool.put(event);
|
||||
}
|
||||
};
|
||||
var _touchEndHandler = function (touch, event) {
|
||||
if (CC_JSB) {
|
||||
event = Event.EventTouch.pool.get(event);
|
||||
}
|
||||
var pos = touch.getLocation();
|
||||
var node = this.owner;
|
||||
|
||||
@@ -209,16 +190,8 @@ var _touchEndHandler = function (touch, event) {
|
||||
event.touch = touch;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
event.touch = null;
|
||||
event._touches = null;
|
||||
Event.EventTouch.pool.put(event);
|
||||
}
|
||||
};
|
||||
var _touchCancelHandler = function (touch, event) {
|
||||
if (CC_JSB) {
|
||||
event = Event.EventTouch.pool.get(event);
|
||||
}
|
||||
var pos = touch.getLocation();
|
||||
var node = this.owner;
|
||||
|
||||
@@ -226,11 +199,6 @@ var _touchCancelHandler = function (touch, event) {
|
||||
event.touch = touch;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
event.touch = null;
|
||||
event._touches = null;
|
||||
Event.EventTouch.pool.put(event);
|
||||
}
|
||||
};
|
||||
|
||||
var _mouseDownHandler = function (event) {
|
||||
@@ -238,31 +206,15 @@ var _mouseDownHandler = function (event) {
|
||||
var node = this.owner;
|
||||
|
||||
if (node._hitTest(pos, this)) {
|
||||
if (CC_JSB) {
|
||||
// jsb event will be replaced so can be stopped immediately
|
||||
event.stopPropagation();
|
||||
event = Event.EventMouse.pool.get(event);
|
||||
}
|
||||
event.type = EventType.MOUSE_DOWN;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
Event.EventMouse.pool.put(event);
|
||||
}
|
||||
else {
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
};
|
||||
var _mouseMoveHandler = function (event) {
|
||||
var pos = event.getLocation();
|
||||
var node = this.owner;
|
||||
var hit = node._hitTest(pos, this);
|
||||
if (CC_JSB && (hit || this._previousIn)) {
|
||||
// jsb event will be replaced so can be stopped immediately
|
||||
event.stopPropagation();
|
||||
event = Event.EventMouse.pool.get(event);
|
||||
}
|
||||
if (hit) {
|
||||
if (!this._previousIn) {
|
||||
// Fix issue when hover node switched, previous hovered node won't get MOUSE_LEAVE notification
|
||||
@@ -292,32 +244,17 @@ var _mouseMoveHandler = function (event) {
|
||||
}
|
||||
|
||||
// Event processed, cleanup
|
||||
if (CC_JSB) {
|
||||
Event.EventMouse.pool.put(event);
|
||||
}
|
||||
else {
|
||||
event.stopPropagation();
|
||||
}
|
||||
event.stopPropagation();
|
||||
};
|
||||
var _mouseUpHandler = function (event) {
|
||||
var pos = event.getLocation();
|
||||
var node = this.owner;
|
||||
|
||||
if (node._hitTest(pos, this)) {
|
||||
if (CC_JSB) {
|
||||
// jsb event will be replaced so can be stopped immediately
|
||||
event.stopPropagation();
|
||||
event = Event.EventMouse.pool.get(event);
|
||||
}
|
||||
event.type = EventType.MOUSE_UP;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
Event.EventMouse.pool.put(event);
|
||||
}
|
||||
else {
|
||||
event.stopPropagation();
|
||||
}
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
var _mouseWheelHandler = function (event) {
|
||||
@@ -325,21 +262,10 @@ var _mouseWheelHandler = function (event) {
|
||||
var node = this.owner;
|
||||
|
||||
if (node._hitTest(pos, this)) {
|
||||
//FIXME: separate wheel event and other mouse event.
|
||||
if (CC_JSB) {
|
||||
// jsb event will be replaced so can be stopped immediately
|
||||
event.stopPropagation();
|
||||
event = Event.EventMouse.pool.get(event);
|
||||
}
|
||||
event.type = EventType.MOUSE_WHEEL;
|
||||
event.bubbles = true;
|
||||
node.dispatchEvent(event);
|
||||
if (CC_JSB) {
|
||||
Event.EventMouse.pool.put(event);
|
||||
}
|
||||
else {
|
||||
event.stopPropagation();
|
||||
}
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -448,7 +448,7 @@ var widgetManager = cc._widgetManager = module.exports = {
|
||||
if (CC_EDITOR && cc.engine) {
|
||||
cc.engine.on('design-resolution-changed', this.onResized.bind(this));
|
||||
}
|
||||
else if (!CC_JSB) {
|
||||
else {
|
||||
if (cc.sys.isMobile) {
|
||||
window.addEventListener('resize', this.onResized.bind(this));
|
||||
}
|
||||
@@ -456,9 +456,6 @@ var widgetManager = cc._widgetManager = module.exports = {
|
||||
cc.eventManager.addCustomListener('canvas-resize', this.onResized.bind(this));
|
||||
}
|
||||
}
|
||||
else {
|
||||
cc.eventManager.addListener(this.onResized.bind(this), 1);
|
||||
}
|
||||
},
|
||||
add: function (widget) {
|
||||
widget.node._widget = widget;
|
||||
|
||||
@@ -124,16 +124,7 @@ var Canvas = cc.Class({
|
||||
},
|
||||
|
||||
ctor: function () {
|
||||
if (CC_JSB) {
|
||||
this._thisOnResized = cc.EventListener.create({
|
||||
event: cc.EventListener.CUSTOM,
|
||||
eventName: "window-resize",
|
||||
callback: this.onResized.bind(this)
|
||||
});
|
||||
}
|
||||
else {
|
||||
this._thisOnResized = this.onResized.bind(this);
|
||||
}
|
||||
this._thisOnResized = this.onResized.bind(this);
|
||||
},
|
||||
|
||||
__preload: function () {
|
||||
@@ -153,7 +144,7 @@ var Canvas = cc.Class({
|
||||
if (CC_EDITOR) {
|
||||
cc.engine.on('design-resolution-changed', this._thisOnResized);
|
||||
}
|
||||
else if (!CC_JSB) {
|
||||
else {
|
||||
if (cc.sys.isMobile) {
|
||||
window.addEventListener('resize', this._thisOnResized);
|
||||
}
|
||||
@@ -161,9 +152,6 @@ var Canvas = cc.Class({
|
||||
eventManager.addCustomListener('canvas-resize', this._thisOnResized);
|
||||
}
|
||||
}
|
||||
else {
|
||||
eventManager.addListener(this._thisOnResized, 1);
|
||||
}
|
||||
|
||||
this.applySettings();
|
||||
this.onResized();
|
||||
@@ -191,7 +179,7 @@ var Canvas = cc.Class({
|
||||
if (CC_EDITOR) {
|
||||
cc.engine.off('design-resolution-changed', this._thisOnResized);
|
||||
}
|
||||
else if (!CC_JSB) {
|
||||
else {
|
||||
if (cc.sys.isMobile) {
|
||||
window.removeEventListener('resize', this._thisOnResized);
|
||||
}
|
||||
@@ -199,9 +187,6 @@ var Canvas = cc.Class({
|
||||
eventManager.removeCustomListeners('canvas-resize', this._thisOnResized);
|
||||
}
|
||||
}
|
||||
else {
|
||||
eventManager.removeListener(this._thisOnResized);
|
||||
}
|
||||
|
||||
if (Canvas.instance === this) {
|
||||
Canvas.instance = null;
|
||||
|
||||
@@ -206,7 +206,7 @@ var RichText = cc.Class({
|
||||
if (this.font === oldValue) return;
|
||||
|
||||
this._layoutDirty = true;
|
||||
if (!CC_JSB && this.font) {
|
||||
if (this.font) {
|
||||
this._onTTFLoaded();
|
||||
}
|
||||
this._updateRichTextStatus();
|
||||
@@ -303,9 +303,7 @@ var RichText = cc.Class({
|
||||
},
|
||||
|
||||
start: function () {
|
||||
if (!CC_JSB) {
|
||||
this._onTTFLoaded();
|
||||
}
|
||||
this._onTTFLoaded();
|
||||
},
|
||||
|
||||
_addEventListeners: function () {
|
||||
@@ -430,18 +428,6 @@ var RichText = cc.Class({
|
||||
this.node.addChild(labelSegment);
|
||||
this._labelSegments.push(labelSegment);
|
||||
|
||||
//when lineHeight is less than the content size of labelSize
|
||||
//in Web platform, the extra pixels will be trimed.
|
||||
//so we need to set the overflow to clamp in JSB
|
||||
//FIXME: label in jsb should be refactored to keep the behavior the same as web platform.
|
||||
if (CC_JSB) {
|
||||
let labelComponent = labelSegment.getComponent(cc.Label);
|
||||
labelComponent.overflow = 1;
|
||||
var size = labelSegment.getContentSize();
|
||||
labelComponent.enableWrapText = false;
|
||||
labelSegment.setDimensions(size.width, this.lineHeight);
|
||||
}
|
||||
|
||||
return labelSegment;
|
||||
},
|
||||
|
||||
|
||||
@@ -254,9 +254,7 @@ var EditBox = cc.Class({
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.editbox.stay_on_top',
|
||||
default: false,
|
||||
notify () {
|
||||
if (!CC_JSB) {
|
||||
this._updateStayOnTop();
|
||||
}
|
||||
this._updateStayOnTop();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -546,10 +544,8 @@ var EditBox = cc.Class({
|
||||
},
|
||||
|
||||
_registerEvent () {
|
||||
if(!CC_JSB) {
|
||||
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
}
|
||||
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
},
|
||||
|
||||
_onTouchBegan(event) {
|
||||
@@ -600,16 +596,6 @@ var EditBox = cc.Class({
|
||||
|
||||
});
|
||||
|
||||
if(CC_JSB) {
|
||||
EditBox.prototype.editBoxEditingDidBegin = function (sender) {
|
||||
this.editBoxEditingDidBegan(sender);
|
||||
};
|
||||
|
||||
EditBox.prototype.editBoxEditingDidEnd = function (sender) {
|
||||
this.editBoxEditingDidEnded(sender);
|
||||
};
|
||||
}
|
||||
|
||||
cc.EditBox = module.exports = EditBox;
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,16 +25,10 @@
|
||||
****************************************************************************/
|
||||
|
||||
require('./CCEvent');
|
||||
require('./CCTouch');
|
||||
require('./CCEventListener');
|
||||
|
||||
var eventManager;
|
||||
if (CC_JSB) {
|
||||
eventManager = cc.eventManager;
|
||||
}
|
||||
else {
|
||||
require('./CCTouch');
|
||||
require('./CCEventListener');
|
||||
eventManager = require('./CCEventManager');
|
||||
}
|
||||
var eventManager = require('./CCEventManager');;
|
||||
|
||||
module.exports = eventManager;
|
||||
|
||||
|
||||
@@ -26,13 +26,7 @@
|
||||
|
||||
var EventTarget = require('../event/event-target');
|
||||
var eventManager = require('../event-manager');
|
||||
var inputManger;
|
||||
if (CC_JSB) {
|
||||
inputManger = cc.inputManager;
|
||||
}
|
||||
else {
|
||||
inputManger = require('../platform/CCInputManager');
|
||||
}
|
||||
var inputManger = require('../platform/CCInputManager');;
|
||||
|
||||
/**
|
||||
* !#en The event type supported by SystemEvent
|
||||
@@ -117,18 +111,10 @@ var SystemEvent = cc.Class({
|
||||
event: cc.EventListener.KEYBOARD,
|
||||
onKeyPressed: function (keyCode, event) {
|
||||
event.type = EventType.KEY_DOWN;
|
||||
if (CC_JSB) {
|
||||
event.keyCode = keyCode;
|
||||
event.isPressed = true;
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
},
|
||||
onKeyReleased: function (keyCode, event) {
|
||||
event.type = EventType.KEY_UP;
|
||||
if (CC_JSB) {
|
||||
event.keyCode = keyCode;
|
||||
event.isPressed = false;
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
@@ -149,9 +135,6 @@ var SystemEvent = cc.Class({
|
||||
event: cc.EventListener.ACCELERATION,
|
||||
callback: function (acc, event) {
|
||||
event.type = EventType.DEVICEMOTION;
|
||||
if (CC_JSB) {
|
||||
event.acc = acc;
|
||||
}
|
||||
cc.systemEvent.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -24,6 +24,20 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
if (CC_JSB) {
|
||||
module.exports = function (item, callback) {
|
||||
var url = item.url;
|
||||
|
||||
var result = jsb.fileUtils.getDataFromFile(url);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return new Error('Download binary file failed: ' + url);
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
function downloadBinary (item, callback) {
|
||||
var url = item.url;
|
||||
var self = this;
|
||||
@@ -50,4 +64,5 @@ function downloadBinary (item, callback) {
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
module.exports = downloadBinary;
|
||||
module.exports = downloadBinary;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ function loadDepends (pipeline, item, asset, depends, callback) {
|
||||
|
||||
// can deferred load raw assets in runtime
|
||||
function canDeferredLoad (asset, item, isScene) {
|
||||
if (CC_EDITOR || CC_JSB) {
|
||||
if (CC_EDITOR) {
|
||||
return false;
|
||||
}
|
||||
var res = item.deferredLoadRaw;
|
||||
|
||||
@@ -33,10 +33,7 @@ var pools = [];
|
||||
// temp world manifold
|
||||
var pointCache = [cc.v2(), cc.v2()];
|
||||
|
||||
var b2worldmanifold;
|
||||
if (!CC_JSB) {
|
||||
b2worldmanifold = new b2.WorldManifold();
|
||||
}
|
||||
var b2worldmanifold = new b2.WorldManifold();
|
||||
|
||||
/**
|
||||
* @class WorldManifold
|
||||
@@ -116,10 +113,7 @@ function ManifoldPoint () {
|
||||
|
||||
var manifoldPointCache = [new ManifoldPoint(), new ManifoldPoint()];
|
||||
|
||||
var b2manifold;
|
||||
if (!CC_JSB) {
|
||||
b2manifold = new b2.Manifold();
|
||||
}
|
||||
var b2manifold = new b2.Manifold();
|
||||
|
||||
/**
|
||||
* @class Manifold
|
||||
@@ -245,44 +239,24 @@ PhysicsContact.prototype.getWorldManifold = function () {
|
||||
var separations = worldmanifold.separations;
|
||||
var normal = worldmanifold.normal;
|
||||
|
||||
if (CC_JSB) {
|
||||
var wrapper = cc.PhysicsUtils.getContactWorldManifoldWrapper(this._b2contact);
|
||||
var count = wrapper.getCount();
|
||||
this._b2contact.GetWorldManifold(b2worldmanifold);
|
||||
var b2points = b2worldmanifold.points;
|
||||
var b2separations = b2worldmanifold.separations;
|
||||
|
||||
points.length = separations.length = count;
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
let p = pointCache[i];
|
||||
p.x = wrapper.getX(i);
|
||||
p.y = wrapper.getY(i);
|
||||
|
||||
points[i] = p;
|
||||
separations[i] = wrapper.getSeparation(i);
|
||||
}
|
||||
var count = this._b2contact.GetManifold().pointCount;
|
||||
points.length = separations.length = count;
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var p = pointCache[i];
|
||||
p.x = b2points[i].x * PTM_RATIO;
|
||||
p.y = b2points[i].y * PTM_RATIO;
|
||||
|
||||
normal.x = wrapper.getNormalX();
|
||||
normal.y = wrapper.getNormalY();
|
||||
points[i] = p;
|
||||
separations[i] = b2separations[i] * PTM_RATIO;
|
||||
}
|
||||
else {
|
||||
this._b2contact.GetWorldManifold(b2worldmanifold);
|
||||
var b2points = b2worldmanifold.points;
|
||||
var b2separations = b2worldmanifold.separations;
|
||||
|
||||
var count = this._b2contact.GetManifold().pointCount;
|
||||
points.length = separations.length = count;
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var p = pointCache[i];
|
||||
p.x = b2points[i].x * PTM_RATIO;
|
||||
p.y = b2points[i].y * PTM_RATIO;
|
||||
|
||||
points[i] = p;
|
||||
separations[i] = b2separations[i] * PTM_RATIO;
|
||||
}
|
||||
|
||||
normal.x = b2worldmanifold.normal.x;
|
||||
normal.y = b2worldmanifold.normal.y;
|
||||
}
|
||||
normal.x = b2worldmanifold.normal.x;
|
||||
normal.y = b2worldmanifold.normal.y;
|
||||
|
||||
if (this._inverted) {
|
||||
normal.x *= -1;
|
||||
@@ -305,48 +279,26 @@ PhysicsContact.prototype.getManifold = function () {
|
||||
var localNormal = manifold.localNormal;
|
||||
var localPoint = manifold.localPoint;
|
||||
|
||||
if (CC_JSB) {
|
||||
var wrapper = cc.PhysicsUtils.getContactManifoldWrapper();
|
||||
var count = points.length = wrapper.getCount();
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var p = manifoldPointCache[i];
|
||||
p.localPoint.x = wrapper.getX(i);
|
||||
p.localPoint.y = wrapper.getX(i);
|
||||
p.normalImpulse = wrapper.getNormalImpulse(i);
|
||||
p.tangentImpulse = wrapper.getTangentImpulse(i);
|
||||
var b2manifold = this._b2contact.GetManifold();
|
||||
var b2points = b2manifold.points;
|
||||
var count = points.length = b2manifold.pointCount;
|
||||
|
||||
points[i] = p;
|
||||
}
|
||||
for (var i = 0; i < count; i++) {
|
||||
var p = manifoldPointCache[i];
|
||||
var b2p = b2points[i];
|
||||
p.localPoint.x = b2p.localPoint.x * PTM_RATIO;
|
||||
p.localPoint.Y = b2p.localPoint.Y * PTM_RATIO;
|
||||
p.normalImpulse = b2p.normalImpulse * PTM_RATIO;
|
||||
p.tangentImpulse = b2p.tangentImpulse;
|
||||
|
||||
localNormal.x = wrapper.getLocalNormalX();
|
||||
localNormal.y = wrapper.getLocalNormalY();
|
||||
localPoint.x = wrapper.getLocalPointX();
|
||||
localPoint.y = wrapper.getLocalPointY();
|
||||
manifold.type = wrapper.getType();
|
||||
points[i] = p;
|
||||
}
|
||||
else {
|
||||
var b2manifold = this._b2contact.GetManifold();
|
||||
var b2points = b2manifold.points;
|
||||
var count = points.length = b2manifold.pointCount;
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var p = manifoldPointCache[i];
|
||||
var b2p = b2points[i];
|
||||
p.localPoint.x = b2p.localPoint.x * PTM_RATIO;
|
||||
p.localPoint.Y = b2p.localPoint.Y * PTM_RATIO;
|
||||
p.normalImpulse = b2p.normalImpulse * PTM_RATIO;
|
||||
p.tangentImpulse = b2p.tangentImpulse;
|
||||
|
||||
points[i] = p;
|
||||
}
|
||||
|
||||
localPoint.x = b2manifold.localPoint.x * PTM_RATIO;
|
||||
localPoint.y = b2manifold.localPoint.y * PTM_RATIO;
|
||||
localNormal.x = b2manifold.localNormal.x;
|
||||
localNormal.y = b2manifold.localNormal.y;
|
||||
manifold.type = b2manifold.type;
|
||||
}
|
||||
localPoint.x = b2manifold.localPoint.x * PTM_RATIO;
|
||||
localPoint.y = b2manifold.localPoint.y * PTM_RATIO;
|
||||
localNormal.x = b2manifold.localNormal.x;
|
||||
localNormal.y = b2manifold.localNormal.y;
|
||||
manifold.type = b2manifold.type;
|
||||
|
||||
if (this._inverted) {
|
||||
localNormal.x *= -1;
|
||||
@@ -372,21 +324,10 @@ PhysicsContact.prototype.getImpulse = function () {
|
||||
|
||||
var normalImpulses = impulse.normalImpulses;
|
||||
var tangentImpulses = impulse.tangentImpulses;
|
||||
var count;
|
||||
|
||||
if (CC_JSB) {
|
||||
count = b2impulse.getCount();
|
||||
for (var i = 0; i < count; i++) {
|
||||
normalImpulses[i] = b2impulse.getNormalImpulse(i);
|
||||
tangentImpulses[i] = b2impulse.getTangentImpulse(i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
count = b2impulse.count;
|
||||
for (var i = 0; i < count; i++) {
|
||||
normalImpulses[i] = b2impulse.normalImpulses[i] * PTM_RATIO;
|
||||
tangentImpulses[i] = b2impulse.tangentImpulses[i];
|
||||
}
|
||||
var count = b2impulse.count;
|
||||
for (var i = 0; i < count; i++) {
|
||||
normalImpulses[i] = b2impulse.normalImpulses[i] * PTM_RATIO;
|
||||
tangentImpulses[i] = b2impulse.tangentImpulses[i];
|
||||
}
|
||||
|
||||
tangentImpulses.length = normalImpulses.length = count;
|
||||
|
||||
@@ -310,7 +310,7 @@ var RigidBody = cc.Class({
|
||||
this._linearVelocity = value;
|
||||
var b2body = this._b2Body;
|
||||
if (b2body) {
|
||||
var temp = CC_JSB ? tempb2Vec21 : b2body.m_linearVelocity;
|
||||
var temp = b2body.m_linearVelocity;
|
||||
temp.Set(value.x/PTM_RATIO, value.y/PTM_RATIO);
|
||||
b2body.SetLinearVelocity(temp);
|
||||
}
|
||||
@@ -625,37 +625,28 @@ var RigidBody = cc.Class({
|
||||
getJointList: function () {
|
||||
if (!this._b2Body) return [];
|
||||
|
||||
if (CC_JSB) {
|
||||
var joints = this._b2Body.GetJointList();
|
||||
for (var i = 0; i < joints.length; i++) {
|
||||
joints[i] = joints[i]._joint;
|
||||
}
|
||||
return joints;
|
||||
var joints = [];
|
||||
|
||||
var list = this._b2Body.GetJointList();
|
||||
if (!list) return [];
|
||||
|
||||
joints.push(list.joint._joint);
|
||||
|
||||
// find prev joint
|
||||
var prev = list.prev;
|
||||
while (prev) {
|
||||
joints.push(prev.joint._joint);
|
||||
prev = prev.prev;
|
||||
}
|
||||
else {
|
||||
var joints = [];
|
||||
|
||||
var list = this._b2Body.GetJointList();
|
||||
if (!list) return [];
|
||||
|
||||
joints.push(list.joint._joint);
|
||||
|
||||
// find prev joint
|
||||
var prev = list.prev;
|
||||
while (prev) {
|
||||
joints.push(prev.joint._joint);
|
||||
prev = prev.prev;
|
||||
}
|
||||
|
||||
// find next joint
|
||||
var next = list.next;
|
||||
while (next) {
|
||||
joints.push(next.joint._joint);
|
||||
next = next.next;
|
||||
}
|
||||
|
||||
return joints;
|
||||
// find next joint
|
||||
var next = list.next;
|
||||
while (next) {
|
||||
joints.push(next.joint._joint);
|
||||
next = next.next;
|
||||
}
|
||||
|
||||
return joints;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -763,10 +754,7 @@ var RigidBody = cc.Class({
|
||||
var pos = this.node.convertToWorldSpaceAR(VEC2_ZERO);
|
||||
|
||||
var temp;
|
||||
if (CC_JSB) {
|
||||
temp = tempb2Vec21;
|
||||
}
|
||||
else if (this.type === BodyType.Animated) {
|
||||
if (this.type === BodyType.Animated) {
|
||||
temp = b2body.GetLinearVelocity();
|
||||
}
|
||||
else {
|
||||
@@ -821,7 +809,7 @@ var RigidBody = cc.Class({
|
||||
var b2body = this._b2Body;
|
||||
if (!b2body) return;
|
||||
|
||||
var temp = CC_JSB ? tempb2Vec21 : b2body.m_linearVelocity;
|
||||
var temp = b2body.m_linearVelocity;
|
||||
temp.Set(0, 0);
|
||||
|
||||
b2body.SetLinearVelocity(temp);
|
||||
|
||||
@@ -229,13 +229,7 @@ var PhysicsCollider = cc.Class({
|
||||
var fixture = fixtures[i];
|
||||
fixture.collider = null;
|
||||
|
||||
if (CC_JSB) {
|
||||
if (cc.sys.isObjectValid(fixture)) {
|
||||
manager._unregisterContactFixture(fixture);
|
||||
}
|
||||
} else {
|
||||
manager._unregisterContactFixture(fixture);
|
||||
}
|
||||
manager._unregisterContactFixture(fixture);
|
||||
|
||||
if (body) {
|
||||
body.DestroyFixture(fixture);
|
||||
|
||||
@@ -23,14 +23,13 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
if (!CC_JSB) {
|
||||
window.b2 = require('../../../external/box2d/box2d');
|
||||
if (CC_QQPLAY) {
|
||||
// can only define global variable in this way
|
||||
b2 = window.b2;
|
||||
}
|
||||
window.b2 = require('../../../external/box2d/box2d');
|
||||
if (CC_QQPLAY) {
|
||||
// can only define global variable in this way
|
||||
b2 = window.b2;
|
||||
}
|
||||
|
||||
|
||||
require('./CCPhysicsManager');
|
||||
require('./CCRigidBody');
|
||||
require('./CCPhysicsContact');
|
||||
@@ -51,8 +50,6 @@ require('./joint/CCWeldJoint');
|
||||
require('./joint/CCWheelJoint');
|
||||
require('./joint/CCRopeJoint');
|
||||
|
||||
if (!CC_JSB) {
|
||||
require('./platform/CCPhysicsContactListner');
|
||||
require('./platform/CCPhysicsAABBQueryCallback');
|
||||
require('./platform/CCPhysicsRayCastCallback');
|
||||
}
|
||||
require('./platform/CCPhysicsContactListner');
|
||||
require('./platform/CCPhysicsAABBQueryCallback');
|
||||
require('./platform/CCPhysicsRayCastCallback');
|
||||
|
||||
@@ -156,7 +156,7 @@ inputManager.didAccelerate = function (eventData) {
|
||||
mAcceleration.y = -mAcceleration.y;
|
||||
}
|
||||
// fix android acc values are opposite
|
||||
if (!CC_JSB && cc.sys.os === cc.sys.OS_ANDROID &&
|
||||
if (cc.sys.os === cc.sys.OS_ANDROID &&
|
||||
cc.sys.browserType !== cc.sys.BROWSER_TYPE_MOBILE_QQ) {
|
||||
mAcceleration.x = -mAcceleration.x;
|
||||
mAcceleration.y = -mAcceleration.y;
|
||||
|
||||
@@ -51,7 +51,7 @@ cc.macro = {
|
||||
* @property REPEAT_FOREVER
|
||||
* @type {Number}
|
||||
*/
|
||||
REPEAT_FOREVER: CC_JSB ? 0xffffffff : (Number.MAX_VALUE - 1),
|
||||
REPEAT_FOREVER: (Number.MAX_VALUE - 1),
|
||||
|
||||
/**
|
||||
* @property FLT_EPSILON
|
||||
|
||||
@@ -511,7 +511,7 @@ function initSys () {
|
||||
* Is web browser ?
|
||||
* @property {Boolean} isBrowser
|
||||
*/
|
||||
sys.isBrowser = typeof window === 'object' && typeof document === 'object' && !CC_WECHATGAME && !CC_QQPLAY;
|
||||
sys.isBrowser = typeof window === 'object' && typeof document === 'object' && !CC_WECHATGAME && !CC_QQPLAY && !CC_JSB;
|
||||
|
||||
if (CC_EDITOR && Editor.isMainProcess) {
|
||||
sys.isMobile = false;
|
||||
@@ -530,6 +530,52 @@ 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 version = /[\d\.]+/.exec(env.system);
|
||||
sys.osVersion = version[0];
|
||||
sys.osMainVersion = parseInt(sys.osVersion);
|
||||
sys.browserType = sys.BROWSER_TYPE_WECHAT_GAME;
|
||||
sys.browserVersion = env.version;
|
||||
|
||||
var w = env.windowWidth;
|
||||
var h = env.windowHeight;
|
||||
var ratio = env.pixelRatio || 1;
|
||||
sys.windowPixelResolution = {
|
||||
width: ratio * w,
|
||||
height: ratio * h
|
||||
};
|
||||
|
||||
sys.localStorage = window.localStorage;
|
||||
|
||||
sys.capabilities = {
|
||||
"canvas": false,
|
||||
"opengl": true,
|
||||
"webp": false
|
||||
};
|
||||
sys.__audioSupport = {
|
||||
ONLY_ONE: false,
|
||||
WEB_AUDIO: false,
|
||||
DELAY_CREATE_CTX: false,
|
||||
format: ['.mp3']
|
||||
};
|
||||
}
|
||||
else if (CC_WECHATGAME) {
|
||||
var env = wx.getSystemInfoSync();
|
||||
sys.isMobile = true;
|
||||
|
||||
@@ -40,7 +40,5 @@ require('./CCMacro');
|
||||
|
||||
if (!(CC_EDITOR && Editor.isMainProcess)) {
|
||||
require('./CCAssetLibrary');
|
||||
if (!CC_JSB) {
|
||||
require('./CCVisibleRect');
|
||||
}
|
||||
require('./CCVisibleRect');
|
||||
}
|
||||
@@ -126,7 +126,7 @@ function doInstantiate (obj, parent) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!CC_JSB && _isDomNode && _isDomNode(obj)) {
|
||||
if (_isDomNode && _isDomNode(obj)) {
|
||||
if (CC_DEV) {
|
||||
cc.errorID(6905);
|
||||
}
|
||||
|
||||
@@ -169,16 +169,9 @@ var js = {
|
||||
* @return {Function}
|
||||
*/
|
||||
getSuper (ctor) {
|
||||
if (CC_JSB && ctor.hasOwnProperty('$super')) {
|
||||
// babel runtime uses Object.setPrototypeOf to inherit static members,
|
||||
// so $super will always inheritable even if it is non-enumerable.
|
||||
return ctor.$super;
|
||||
}
|
||||
else {
|
||||
var proto = ctor.prototype; // binded function do not have prototype
|
||||
var dunderProto = proto && Object.getPrototypeOf(proto);
|
||||
return dunderProto && dunderProto.constructor;
|
||||
}
|
||||
var proto = ctor.prototype; // binded function do not have prototype
|
||||
var dunderProto = proto && Object.getPrototypeOf(proto);
|
||||
return dunderProto && dunderProto.constructor;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,22 +71,14 @@ module.exports = {
|
||||
}
|
||||
:
|
||||
(
|
||||
CC_JSB ?
|
||||
function (callback, p1, p2) {
|
||||
if (callback) {
|
||||
cc.director.once(cc.Director._EVENT_NEXT_TICK, function () {
|
||||
callback(p1, p2);
|
||||
});
|
||||
}
|
||||
}
|
||||
:
|
||||
function (callback, p1, p2) {
|
||||
if (callback) {
|
||||
setTimeout(function () {
|
||||
callback(p1, p2);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function (callback, p1, p2) {
|
||||
if (callback) {
|
||||
setTimeout(function () {
|
||||
callback(p1, p2);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +64,14 @@ module.exports = {
|
||||
this.Texture2D = renderEngine.Texture2D;
|
||||
|
||||
this.canvas = canvas;
|
||||
this.device = new renderEngine.Device(canvas, opts);
|
||||
if (CC_JSB) {
|
||||
// native codes will create an instance of Device, so just use the global instance.
|
||||
this.device = window.device;
|
||||
}
|
||||
else {
|
||||
this.device = new renderEngine.Device(canvas, opts);
|
||||
}
|
||||
|
||||
this.scene = new renderEngine.Scene();
|
||||
|
||||
this._walker = new RenderComponentWalker(this.device, this.scene);
|
||||
|
||||
@@ -353,9 +353,7 @@ var BaseNode = cc.Class({
|
||||
if (CC_DEBUG && (value._objFlags & Deactivating)) {
|
||||
cc.errorID(3821);
|
||||
}
|
||||
if (!CC_JSB) {
|
||||
eventManager._setDirtyForNode(this);
|
||||
}
|
||||
eventManager._setDirtyForNode(this);
|
||||
value._children.push(this);
|
||||
value.emit(CHILD_ADDED, this);
|
||||
}
|
||||
|
||||
+1
-3
@@ -39,9 +39,7 @@ else {
|
||||
require('./cocos2d/motion-streak');
|
||||
require('./cocos2d/core/components/CCStudioComponent');
|
||||
require('./extensions/ccpool/CCNodePool');
|
||||
if (!CC_JSB) {
|
||||
require('./cocos2d/actions');
|
||||
}
|
||||
require('./cocos2d/actions');
|
||||
}
|
||||
|
||||
require('./extensions/spine');
|
||||
|
||||
@@ -285,14 +285,7 @@ let ArmatureDisplay = cc.Class({
|
||||
|
||||
ctor () {
|
||||
this._inited = false;
|
||||
if (CC_JSB) {
|
||||
// TODO Fix me
|
||||
// If using the getFactory in JSB.
|
||||
// There may be throw errors when close the application.
|
||||
this._factory = new dragonBones.CCFactory();
|
||||
} else {
|
||||
this._factory = dragonBones.CCFactory.getInstance();
|
||||
}
|
||||
this._factory = dragonBones.CCFactory.getInstance();
|
||||
},
|
||||
|
||||
__preload () {
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
*/
|
||||
|
||||
var _global = typeof window === 'undefined' ? global : window;
|
||||
_global.dragonBones = CC_JSB ? dragonBones : require('./lib/dragonBones');
|
||||
_global.dragonBones = require('./lib/dragonBones');
|
||||
|
||||
dragonBones.DisplayType = {
|
||||
Image : 0,
|
||||
@@ -123,12 +123,9 @@ dragonBones.BoneType = {
|
||||
};
|
||||
|
||||
if (!CC_EDITOR || !Editor.isMainProcess) {
|
||||
|
||||
if (!CC_JSB) {
|
||||
require('./CCFactory');
|
||||
require('./CCSlot');
|
||||
require('./CCTextureData');
|
||||
}
|
||||
require('./CCFactory');
|
||||
require('./CCSlot');
|
||||
require('./CCTextureData');
|
||||
|
||||
// require the component for dragonbones
|
||||
require('./DragonBonesAsset');
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
*/
|
||||
|
||||
var _global = typeof window === 'undefined' ? global : window;
|
||||
_global.sp = CC_JSB ? sp : {};
|
||||
_global.sp = {};
|
||||
|
||||
// The attachment type of spine. It contains three type: REGION(0), BOUNDING_BOX(1), MESH(2) and SKINNED_MESH.
|
||||
sp.ATTACHMENT_TYPE = {
|
||||
@@ -99,10 +99,7 @@ sp.AnimationEventType = cc.Enum({
|
||||
*/
|
||||
if (!CC_EDITOR || !Editor.isMainProcess) {
|
||||
|
||||
if (!CC_JSB) {
|
||||
sp.spine = require('./lib/spine');
|
||||
}
|
||||
|
||||
sp.spine = require('./lib/spine');
|
||||
require('./skeleton-texture');
|
||||
require('./skeleton-data');
|
||||
require('./skeleton');
|
||||
|
||||
@@ -213,7 +213,7 @@ var SkeletonData = cc.Class({
|
||||
|
||||
// PRIVATE
|
||||
|
||||
_getTexture: !CC_JSB && function (line) {
|
||||
_getTexture: function (line) {
|
||||
var names = this.textureNames;
|
||||
for (var i = 0; i < names.length; i++) {
|
||||
if (names[i] === line) {
|
||||
|
||||
@@ -39,13 +39,8 @@ const HandleErrors = require('../util/handleErrors');
|
||||
const Optimizejs = require('gulp-optimize-js');
|
||||
|
||||
var jsbSkipModules = [
|
||||
'../../cocos2d/core/CCGame',
|
||||
'../../cocos2d/core/load-pipeline/audio-downloader',
|
||||
'../../cocos2d/core/platform/CCInputManager.js',
|
||||
'../../cocos2d/core/platform/CCVisibleRect.js',
|
||||
'../../cocos2d/core/graphics/helper.js',
|
||||
'../../cocos2d/audio/CCAudio',
|
||||
'../../external/box2d/box2d.js',
|
||||
// '../../external/box2d/box2d.js',
|
||||
];
|
||||
var aliasifyConfig = {
|
||||
replacements: {
|
||||
|
||||
+3
-3
@@ -59,19 +59,19 @@ gulp.task('build-html5', ['build-html5-preview', 'build-html5-dev', 'build-html5
|
||||
|
||||
gulp.task('build-jsb-dev', function (done) {
|
||||
Engine.buildJsb([
|
||||
'./index.js',
|
||||
'./jsb/index.js',
|
||||
], './bin/jsb_polyfill.dev.js', [], done);
|
||||
});
|
||||
|
||||
gulp.task('build-jsb-min', function (done) {
|
||||
Engine.buildJsbMin([
|
||||
'./index.js',
|
||||
'./jsb/index.js',
|
||||
], './bin/jsb_polyfill.js', [], done);
|
||||
});
|
||||
|
||||
gulp.task('build-jsb-preview', function (done) {
|
||||
Engine.buildJsbPreview([
|
||||
'./index.js',
|
||||
'./jsb/index.js',
|
||||
], './bin/jsb_polyfill-for-preview.js', [], done);
|
||||
});
|
||||
|
||||
|
||||
@@ -66,4 +66,8 @@ if (CC_EDITOR) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CC_JSB) {
|
||||
require('./jsb/jsb-loader.js');
|
||||
}
|
||||
|
||||
module.exports = cc;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets":["es2015"]
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import gulp from 'gulp';
|
||||
import sourcemaps from "gulp-sourcemaps";
|
||||
import babelify from "babelify";
|
||||
import browserify from 'browserify';
|
||||
import source from "vinyl-source-stream";
|
||||
import uglify from 'gulp-uglify';
|
||||
import buffer from 'vinyl-buffer';
|
||||
|
||||
gulp.task("default", ()=>{
|
||||
return browserify('./index.js')
|
||||
.transform(babelify)
|
||||
.bundle()
|
||||
.pipe(source('jsb.js'))
|
||||
.pipe(buffer())
|
||||
// .pipe(sourcemaps.init({ loadMaps: true }))
|
||||
// .pipe(uglify()) // Use any gulp plugins you want now
|
||||
// .pipe(sourcemaps.write('./'))
|
||||
.pipe(gulp.dest('./dist'));
|
||||
});
|
||||
@@ -0,0 +1,219 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// window.CC_JSB = true;
|
||||
window.CC_JSB = true;
|
||||
// console.log("CC_JSB:" + CC_JSB);
|
||||
window.CC_WECHATGAME = true;
|
||||
|
||||
// Simulate wechat game API:
|
||||
|
||||
window.wx = {
|
||||
getSystemInfoSync() {
|
||||
return {
|
||||
platform: 'mac',
|
||||
language: 'CN',
|
||||
system: 1.0,
|
||||
windowWidth: window.innerWidth,
|
||||
windowHeight: window.innerHeight,
|
||||
};
|
||||
},
|
||||
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
onHide() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let oldRequestFrameCallback = null;
|
||||
let requestAnimationFrameID = 0;
|
||||
let requestAnimationFrameCallbacks = {};
|
||||
|
||||
window.requestAnimationFrame = function(cb) {
|
||||
let id = ++requestAnimationFrameID;
|
||||
requestAnimationFrameCallbacks[id] = cb;
|
||||
return id;
|
||||
};
|
||||
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
delete requestAnimationFrameCallbacks[id];
|
||||
};
|
||||
|
||||
function tick(nowMilliSeconds) {
|
||||
fireTimeout(nowMilliSeconds);
|
||||
|
||||
for (let id in requestAnimationFrameCallbacks) {
|
||||
oldRequestFrameCallback = requestAnimationFrameCallbacks[id];
|
||||
if (oldRequestFrameCallback) {
|
||||
delete requestAnimationFrameCallbacks[id];
|
||||
oldRequestFrameCallback(nowMilliSeconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _timeoutIDIndex = 0;
|
||||
|
||||
class TimeoutInfo {
|
||||
constructor(cb, delay, isRepeat, target, args) {
|
||||
this.cb = cb;
|
||||
this.id = ++_timeoutIDIndex;
|
||||
this.start = performance.now();
|
||||
this.delay = delay;
|
||||
this.isRepeat = isRepeat;
|
||||
this.target = target;
|
||||
this.args = args;
|
||||
}
|
||||
}
|
||||
|
||||
let _timeoutInfos = {};
|
||||
|
||||
function fireTimeout(nowMilliSeconds) {
|
||||
let info;
|
||||
for (let id in _timeoutInfos) {
|
||||
info = _timeoutInfos[id];
|
||||
if (info && info.cb) {
|
||||
if ((nowMilliSeconds - info.start) >= info.delay) {
|
||||
// console.log(`fireTimeout: id ${id}, start: ${info.start}, delay: ${info.delay}, now: ${nowMilliSeconds}`);
|
||||
info.cb.apply(info.target, info.args);
|
||||
if (info.isRepeat) {
|
||||
info.start = nowMilliSeconds;
|
||||
}
|
||||
else {
|
||||
delete _timeoutInfos[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createTimeoutInfo(prevFuncArgs, isRepeat) {
|
||||
let cb = prevFuncArgs[0];
|
||||
if (!cb) {
|
||||
console.error("createTimeoutInfo doesn't pass a callback ...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let delay = prevFuncArgs.length > 1 ? prevFuncArgs[1] : 0;
|
||||
let args;
|
||||
|
||||
if (prevFuncArgs.length > 2) {
|
||||
args = Array.prototype.slice.call(prevFuncArgs, 2);
|
||||
}
|
||||
|
||||
let info = new TimeoutInfo(cb, delay, isRepeat, this, args);
|
||||
_timeoutInfos[info.id] = info;
|
||||
return info.id;
|
||||
}
|
||||
|
||||
window.setTimeout = function(cb) {
|
||||
return createTimeoutInfo(arguments, false);
|
||||
};
|
||||
|
||||
window.clearTimeout = function(id) {
|
||||
delete _timeoutInfos[id];
|
||||
};
|
||||
|
||||
window.setInterval = function(cb) {
|
||||
return createTimeoutInfo(arguments, true);
|
||||
}
|
||||
|
||||
window.clearInterval = window.clearTimeout;
|
||||
|
||||
window.alert = console.error.bind(console);
|
||||
|
||||
// File utils (Temporary, won't be accessible)
|
||||
cc.fileUtils = cc.FileUtils.getInstance();
|
||||
cc.fileUtils.setPopupNotify(false);
|
||||
|
||||
/**
|
||||
* @type {Object}
|
||||
* @name jsb.fileUtils
|
||||
* jsb.fileUtils is the native file utils singleton object,
|
||||
* please refer to Cocos2d-x API to know how to use it.
|
||||
* Only available in JSB
|
||||
*/
|
||||
jsb.fileUtils = cc.fileUtils;
|
||||
delete cc.FileUtils;
|
||||
delete cc.fileUtils;
|
||||
|
||||
window.CanvasRenderingContext2D = cc.CanvasRenderingContext2D;
|
||||
delete cc.CanvasRenderingContext2D;
|
||||
|
||||
jsb.urlRegExp = new RegExp("^(?:https?|ftp)://\\S*$", "i");
|
||||
|
||||
require('./jsb_prepare');
|
||||
require('./jsb_opengl');
|
||||
window.DOMParser = require('./xmldom/dom-parser').DOMParser;
|
||||
require('./jsb-adapter');
|
||||
require('./jsb_audioengine');
|
||||
|
||||
/**
|
||||
* @type {Object}
|
||||
* @name jsb.reflection
|
||||
* jsb.reflection is a bridge to let you invoke Java static functions.
|
||||
* please refer to this document to know how to use it: http://www.cocos2d-x.org/docs/manual/framework/html5/v3/reflection/en
|
||||
* Only available on Android platform
|
||||
*/
|
||||
jsb.reflection = {
|
||||
callStaticMethod : function(){
|
||||
cc.log("not supported on current platform");
|
||||
}
|
||||
};
|
||||
|
||||
XMLHttpRequest.prototype.addEventListener = function(eventName, listener, options) {
|
||||
this['on' + eventName] = listener;
|
||||
}
|
||||
|
||||
XMLHttpRequest.prototype.removeEventListener = function(eventName, listener, options) {
|
||||
this['on' + eventName] = null;
|
||||
}
|
||||
|
||||
//NOTE: Runtime API should not private Javascript bridge functionality for security issues.
|
||||
// JS to Native bridges
|
||||
// if(window.JavascriptJavaBridge && cc.sys.os == cc.sys.OS_ANDROID){
|
||||
// jsb.reflection = new JavascriptJavaBridge();
|
||||
// cc.sys.capabilities["keyboard"] = true;
|
||||
// }
|
||||
// else if(window.JavaScriptObjCBridge && (cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_OSX)){
|
||||
// jsb.reflection = new JavaScriptObjCBridge();
|
||||
// }
|
||||
|
||||
// SocketIO
|
||||
if (window.SocketIO) {
|
||||
window.io = window.SocketIO;
|
||||
SocketIO.prototype._jsbEmit = SocketIO.prototype.emit;
|
||||
SocketIO.prototype.emit = function (uri, delegate) {
|
||||
if (typeof delegate === 'object') {
|
||||
delegate = JSON.stringify(delegate);
|
||||
}
|
||||
this._jsbEmit(uri, delegate);
|
||||
};
|
||||
}
|
||||
|
||||
window.gameTick = tick;
|
||||
|
||||
Executable
+148
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let HTMLAudioElement = require('./HTMLAudioElement');
|
||||
|
||||
const HAVE_NOTHING = 0
|
||||
const HAVE_METADATA = 1
|
||||
const HAVE_CURRENT_DATA = 2
|
||||
const HAVE_FUTURE_DATA = 3
|
||||
const HAVE_ENOUGH_DATA = 4
|
||||
|
||||
const _innerAudioContext = new WeakMap()
|
||||
const _src = new WeakMap()
|
||||
const _loop = new WeakMap()
|
||||
const _autoplay = new WeakMap()
|
||||
|
||||
class Audio extends HTMLAudioElement {
|
||||
|
||||
// constructor(url) {
|
||||
// super()
|
||||
//
|
||||
// this.readyState = HAVE_NOTHING
|
||||
//
|
||||
// _src.set(this, '')
|
||||
//
|
||||
// const innerAudioContext = {};//cjh wx.createInnerAudioContext()
|
||||
//
|
||||
// _innerAudioContext.set(this, innerAudioContext)
|
||||
//
|
||||
// innerAudioContext.onCanplay(() => {
|
||||
// this.dispatchEvent({ type: 'load' })
|
||||
// this.dispatchEvent({ type: 'loadend' })
|
||||
// this.dispatchEvent({ type: 'canplay'})
|
||||
// this.dispatchEvent({ type: 'canplaythrough' })
|
||||
// this.dispatchEvent({ type: 'loadedmetadata' })
|
||||
// this.readyState = HAVE_CURRENT_DATA
|
||||
// })
|
||||
// innerAudioContext.onPlay(() => {
|
||||
// this.dispatchEvent({ type: 'play' })
|
||||
// })
|
||||
// innerAudioContext.onPause(() => {
|
||||
// this.dispatchEvent({ type: 'pause' })
|
||||
// })
|
||||
// innerAudioContext.onEnded(() => {
|
||||
// this.dispatchEvent({ type: 'ended' })
|
||||
// this.readyState = HAVE_ENOUGH_DATA
|
||||
// })
|
||||
// innerAudioContext.onError(() => {
|
||||
// this.dispatchEvent({ type: 'error' })
|
||||
// })
|
||||
//
|
||||
// if (url) {
|
||||
// _innerAudioContext.get(this).src = url
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// load() {
|
||||
// console.warn('HTMLAudioElement.load() is not implemented.')
|
||||
// }
|
||||
//
|
||||
// play() {
|
||||
// _innerAudioContext.get(this).play()
|
||||
// }
|
||||
//
|
||||
// pause() {
|
||||
// _innerAudioContext.get(this).pause()
|
||||
// }
|
||||
//
|
||||
// canPlayType(mediaType = '') {
|
||||
// if (typeof mediaType !== 'string') {
|
||||
// return ''
|
||||
// }
|
||||
//
|
||||
// if (mediaType.indexOf('audio/mpeg') > -1 || mediaType.indexOf('audio/mp4')) {
|
||||
// return 'probably'
|
||||
// }
|
||||
// return ''
|
||||
// }
|
||||
//
|
||||
// get currentTime() {
|
||||
// return _innerAudioContext.get(this).currentTime
|
||||
// }
|
||||
//
|
||||
// set currentTime(value) {
|
||||
// _innerAudioContext.get(this).seek(value)
|
||||
// }
|
||||
//
|
||||
// get src() {
|
||||
// return _src.get(this)
|
||||
// }
|
||||
//
|
||||
// set src(value) {
|
||||
// _src.set(this, value)
|
||||
// _innerAudioContext.get(this).src = value
|
||||
// }
|
||||
//
|
||||
// get loop() {
|
||||
// return _innerAudioContext.get(this).loop
|
||||
// }
|
||||
//
|
||||
// set loop(value) {
|
||||
// _innerAudioContext.get(this).loop = value
|
||||
// }
|
||||
//
|
||||
// get autoplay() {
|
||||
// return _innerAudioContext.get(this).autoplay
|
||||
// }
|
||||
//
|
||||
// set autoplay(value) {
|
||||
// _innerAudioContext.get(this).autoplay = value
|
||||
// }
|
||||
//
|
||||
// get paused() {
|
||||
// return _innerAudioContext.get(this).paused
|
||||
// }
|
||||
//
|
||||
// cloneNode() {
|
||||
// const newAudio = new Audio()
|
||||
// newAudio.loop = _innerAudioContext.get(this).loop
|
||||
// newAudio.autoplay = _innerAudioContext.get(this).autoplay
|
||||
// newAudio.src = this.src
|
||||
// return newAudio
|
||||
// }
|
||||
}
|
||||
|
||||
module.exports = Audio;
|
||||
|
||||
Regular → Executable
+14
-11
@@ -1,15 +1,15 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
@@ -22,11 +22,14 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let Node = require('./Node');
|
||||
|
||||
sp._SGSkeleton = sp.Skeleton;
|
||||
sp._SGSkeletonAnimation = sp.SkeletonAnimation;
|
||||
class Element extends Node {
|
||||
constructor() {
|
||||
super()
|
||||
this.className = ''
|
||||
this.children = []
|
||||
}
|
||||
}
|
||||
|
||||
sp._SGSkeleton.prototype.setPremultipliedAlpha = sp._SGSkeleton.prototype.setOpacityModifyRGB;
|
||||
|
||||
// 不能执行任何操作以免覆盖 premultiplied 属性
|
||||
sp._SGSkeleton.prototype.setOpacityModifyRGB = function () {};
|
||||
module.exports = Element;
|
||||
@@ -0,0 +1,199 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @see https://dom.spec.whatwg.org/#interface-event
|
||||
* @private
|
||||
*/
|
||||
/**
|
||||
* The event wrapper.
|
||||
* @constructor
|
||||
* @param {EventTarget} eventTarget The event target of this dispatching.
|
||||
* @param {Event|{type:string}} event The original event to wrap.
|
||||
*/
|
||||
class Event {
|
||||
|
||||
constructor(type, eventInit) {
|
||||
this._type = type
|
||||
this._eventTarget = null
|
||||
this._eventPhase = 2
|
||||
this._currentTarget = null
|
||||
this._canceled = false
|
||||
this._stopped = false // The flag to stop propagation immediately.
|
||||
this._passiveListener = null
|
||||
this._timeStamp = Date.now()
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of this event.
|
||||
* @type {string}
|
||||
*/
|
||||
get type() {
|
||||
return this._type
|
||||
}
|
||||
|
||||
/**
|
||||
* The target of this event.
|
||||
* @type {EventTarget}
|
||||
*/
|
||||
get target() {
|
||||
return this._eventTarget
|
||||
}
|
||||
|
||||
/**
|
||||
* The target of this event.
|
||||
* @type {EventTarget}
|
||||
*/
|
||||
get currentTarget() {
|
||||
return this._currentTarget
|
||||
}
|
||||
|
||||
get isTrusted() {
|
||||
// https://heycam.github.io/webidl/#Unforgeable
|
||||
return false
|
||||
}
|
||||
|
||||
get timeStamp() {
|
||||
return this._timeStamp
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {EventTarget[]} The composed path of this event.
|
||||
*/
|
||||
composedPath() {
|
||||
const currentTarget = this._currentTarget
|
||||
if (currentTarget === null) {
|
||||
return []
|
||||
}
|
||||
return [currentTarget]
|
||||
}
|
||||
|
||||
/**
|
||||
* The target of this event.
|
||||
* @type {number}
|
||||
*/
|
||||
get eventPhase() {
|
||||
return this._eventPhase
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop event bubbling.
|
||||
* @returns {void}
|
||||
*/
|
||||
stopPropagation() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop event bubbling.
|
||||
* @returns {void}
|
||||
*/
|
||||
stopImmediatePropagation() {
|
||||
this._stopped = true
|
||||
}
|
||||
|
||||
/**
|
||||
* The flag to be bubbling.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get bubbles() {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* The flag to be cancelable.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get cancelable() {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this event.
|
||||
* @returns {void}
|
||||
*/
|
||||
preventDefault() {
|
||||
if (this._passiveListener !== null) {
|
||||
console.warn("Event#preventDefault() was called from a passive listener:", this._passiveListener)
|
||||
return
|
||||
}
|
||||
if (!this.cancelable) {
|
||||
return
|
||||
}
|
||||
|
||||
this._canceled = true
|
||||
}
|
||||
|
||||
/**
|
||||
* The flag to indicate cancellation state.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get defaultPrevented() {
|
||||
return this._canceled
|
||||
}
|
||||
|
||||
/**
|
||||
* The flag to be composed.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get composed() {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* The unix time of this event.
|
||||
* @type {number}
|
||||
*/
|
||||
get timeStamp() {
|
||||
return this._timeStamp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant of NONE.
|
||||
* @type {number}
|
||||
*/
|
||||
Event.NONE = 0
|
||||
|
||||
/**
|
||||
* Constant of CAPTURING_PHASE.
|
||||
* @type {number}
|
||||
*/
|
||||
Event.CAPTURING_PHASE = 1
|
||||
|
||||
/**
|
||||
* Constant of AT_TARGET.
|
||||
* @type {number}
|
||||
*/
|
||||
Event.AT_TARGET = 2
|
||||
|
||||
/**
|
||||
* Constant of BUBBLING_PHASE.
|
||||
* @type {number}
|
||||
*/
|
||||
Event.BUBBLING_PHASE = 3
|
||||
|
||||
|
||||
module.exports = Event
|
||||
@@ -0,0 +1,219 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// Listener types
|
||||
const CAPTURE = 1
|
||||
const BUBBLE = 2
|
||||
const ATTRIBUTE = 3
|
||||
|
||||
/**
|
||||
* Check whether a given value is an object or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if the value is an object.
|
||||
*/
|
||||
function isObject(x) {
|
||||
return x && typeof x === "object" //eslint-disable-line no-restricted-syntax
|
||||
}
|
||||
|
||||
/**
|
||||
* EventTarget.
|
||||
*
|
||||
* - This is constructor if no arguments.
|
||||
* - This is a function which returns a CustomEventTarget constructor if there are arguments.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* class A extends EventTarget {}
|
||||
*/
|
||||
function EventTarget() {
|
||||
this._listeners = new Map();
|
||||
}
|
||||
|
||||
// Should be enumerable, but class methods are not enumerable.
|
||||
EventTarget.prototype = {
|
||||
/**
|
||||
* Add a given listener to this event target.
|
||||
* @param {string} eventName The event name to add.
|
||||
* @param {Function} listener The listener to add.
|
||||
* @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
|
||||
* @returns {boolean} `true` if the listener was added actually.
|
||||
*/
|
||||
addEventListener(eventName, listener, options) {
|
||||
if (!listener) {
|
||||
return false
|
||||
}
|
||||
if (typeof listener !== "function" && !isObject(listener)) {
|
||||
throw new TypeError("'listener' should be a function or an object.")
|
||||
}
|
||||
|
||||
const listeners = this._listeners
|
||||
const optionsIsObj = isObject(options)
|
||||
const capture = optionsIsObj ? Boolean(options.capture) : Boolean(options)
|
||||
const listenerType = (capture ? CAPTURE : BUBBLE)
|
||||
const newNode = {
|
||||
listener,
|
||||
listenerType,
|
||||
passive: optionsIsObj && Boolean(options.passive),
|
||||
once: optionsIsObj && Boolean(options.once),
|
||||
next: null,
|
||||
}
|
||||
|
||||
// Set it as the first node if the first node is null.
|
||||
let node = listeners.get(eventName)
|
||||
if (node === undefined) {
|
||||
listeners.set(eventName, newNode)
|
||||
return true
|
||||
}
|
||||
|
||||
// Traverse to the tail while checking duplication..
|
||||
let prev = null
|
||||
while (node) {
|
||||
if (node.listener === listener && node.listenerType === listenerType) {
|
||||
// Should ignore duplication.
|
||||
return false
|
||||
}
|
||||
prev = node
|
||||
node = node.next
|
||||
}
|
||||
|
||||
// Add it.
|
||||
prev.next = newNode
|
||||
return true
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a given listener from this event target.
|
||||
* @param {string} eventName The event name to remove.
|
||||
* @param {Function} listener The listener to remove.
|
||||
* @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
|
||||
* @returns {boolean} `true` if the listener was removed actually.
|
||||
*/
|
||||
removeEventListener(eventName, listener, options) {
|
||||
if (!listener) {
|
||||
return false
|
||||
}
|
||||
|
||||
const listeners = this._listeners
|
||||
const capture = isObject(options) ? Boolean(options.capture) : Boolean(options)
|
||||
const listenerType = (capture ? CAPTURE : BUBBLE)
|
||||
|
||||
let prev = null
|
||||
let node = listeners.get(eventName)
|
||||
while (node) {
|
||||
if (node.listener === listener && node.listenerType === listenerType) {
|
||||
if (prev) {
|
||||
prev.next = node.next
|
||||
}
|
||||
else if (node.next) {
|
||||
listeners.set(eventName, node.next)
|
||||
}
|
||||
else {
|
||||
listeners.delete(eventName)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
prev = node
|
||||
node = node.next
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispatch a given event.
|
||||
* @param {Event|{type:string}} event The event to dispatch.
|
||||
* @returns {boolean} `false` if canceled.
|
||||
*/
|
||||
dispatchEvent(event) {
|
||||
if (!event || typeof event.type !== "string") {
|
||||
throw new TypeError("\"event.type\" should be a string.")
|
||||
}
|
||||
|
||||
// If listeners aren't registered, terminate.
|
||||
const listeners = this._listeners
|
||||
const eventName = event.type
|
||||
let node = listeners.get(eventName)
|
||||
if (!node) {
|
||||
return true
|
||||
}
|
||||
|
||||
event._target = event._currentTarget = this;
|
||||
// This doesn't process capturing phase and bubbling phase.
|
||||
// This isn't participating in a tree.
|
||||
let prev = null
|
||||
while (node) {
|
||||
// Remove this listener if it's once
|
||||
if (node.once) {
|
||||
if (prev) {
|
||||
prev.next = node.next
|
||||
}
|
||||
else if (node.next) {
|
||||
listeners.set(eventName, node.next)
|
||||
}
|
||||
else {
|
||||
listeners.delete(eventName)
|
||||
}
|
||||
}
|
||||
else {
|
||||
prev = node
|
||||
}
|
||||
|
||||
// Call this listener
|
||||
event._passiveListener = node.passive ? node.listener : null
|
||||
if (typeof node.listener === "function") {
|
||||
node.listener.call(this, event)
|
||||
}
|
||||
else if (node.listenerType !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
|
||||
node.listener.handleEvent(event)
|
||||
}
|
||||
|
||||
// Break if `event.stopImmediatePropagation` was called.
|
||||
if (event._stopped) {
|
||||
break
|
||||
}
|
||||
|
||||
node = node.next
|
||||
}
|
||||
event._target = event._currentTarget = null
|
||||
event._eventPhase = 0
|
||||
event._passiveListener = null
|
||||
|
||||
return !event.defaultPrevented
|
||||
},
|
||||
}
|
||||
|
||||
// `constructor` is not enumerable.
|
||||
Object.defineProperty(EventTarget.prototype, "constructor", { value: EventTarget, configurable: true, writable: true })
|
||||
|
||||
// Ensure `eventTarget instanceof window.EventTarget` is `true`.
|
||||
if (typeof window !== "undefined" && typeof window.EventTarget !== "undefined") {
|
||||
Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype)
|
||||
}
|
||||
|
||||
// export { defineEventAttribute, EventTarget }
|
||||
// export default EventTarget
|
||||
module.exports = EventTarget
|
||||
|
||||
Regular → Executable
+8
-23
@@ -1,6 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
@@ -24,26 +23,12 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Enum for text alignment
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
/*
|
||||
* TODO 使用 wx.readFile 来封装 FileReader
|
||||
*/
|
||||
cc.TextAlignment = cc.Enum({
|
||||
LEFT: 0,
|
||||
CENTER: 1,
|
||||
RIGHT: 2
|
||||
});
|
||||
class FileReader {
|
||||
construct() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum for vertical text alignment
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
cc.VerticalTextAlignment = cc.Enum({
|
||||
TOP: 0,
|
||||
CENTER: 1,
|
||||
BOTTOM: 2
|
||||
});
|
||||
module.exports = FileReader;
|
||||
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
class FontFace {
|
||||
constructor(family, source, descriptors) {
|
||||
this.family = family
|
||||
this.source = source
|
||||
this.descriptors = descriptors
|
||||
|
||||
this._status = 'unloaded'
|
||||
|
||||
this._loaded = new Promise((resolve, reject) => {
|
||||
this._resolveCB = resolve
|
||||
this._rejectCB = reject
|
||||
})
|
||||
}
|
||||
|
||||
// Promise load() {
|
||||
// jsb.loadFont(this.source);
|
||||
// }
|
||||
|
||||
get status() {
|
||||
return this._status;
|
||||
}
|
||||
|
||||
get loaded() {
|
||||
return this._loaded;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FontFace;
|
||||
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let EventTarget = require('./EventTarget')
|
||||
let Event = require('./Event')
|
||||
|
||||
class FontFaceSet extends EventTarget {
|
||||
constructor() {
|
||||
super()
|
||||
this._status = 'loading'
|
||||
}
|
||||
|
||||
get status() {
|
||||
return this._status
|
||||
}
|
||||
|
||||
set onloading(listener) {
|
||||
this.addEventListener('loading', listener)
|
||||
}
|
||||
|
||||
set onloadingdone(listener) {
|
||||
this.addEventListener('loadingdone', listener)
|
||||
}
|
||||
|
||||
set onloadingerror(listener) {
|
||||
this.addEventListener('loadingerror', listener)
|
||||
}
|
||||
|
||||
add(fontFace) {
|
||||
this._status = fontFace._status = 'loading'
|
||||
this.dispatchEvent(new Event('loading'))
|
||||
// Call native binding method to set the ttf font to native platform.
|
||||
let family = jsb.loadFont(fontFace.family, fontFace.source)
|
||||
setTimeout(() => {
|
||||
if (family) {
|
||||
fontFace._status = this._status = 'loaded'
|
||||
fontFace._resolveCB()
|
||||
this.dispatchEvent(new Event('loadingdone'))
|
||||
}
|
||||
else {
|
||||
fontFace._status = this._status = 'error'
|
||||
fontFace._rejectCB()
|
||||
this.dispatchEvent(new Event('loadingerror'))
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
clear() {
|
||||
|
||||
}
|
||||
|
||||
delete() {
|
||||
|
||||
}
|
||||
|
||||
load() {
|
||||
|
||||
}
|
||||
|
||||
ready() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FontFaceSet
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let HTMLMediaElement = require('./HTMLMediaElement');
|
||||
|
||||
class HTMLAudioElement extends HTMLMediaElement {
|
||||
constructor() {
|
||||
super('audio')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HTMLAudioElement;
|
||||
@@ -0,0 +1,341 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
const HTMLElement = require('./HTMLElement');
|
||||
const ImageData = require('./ImageData');
|
||||
|
||||
class CanvasGradient {
|
||||
constructor() {
|
||||
console.log("==> CanvasGradient constructor");
|
||||
}
|
||||
|
||||
addColorStop(offset, color) {
|
||||
console.log("==> CanvasGradient addColorStop");
|
||||
}
|
||||
}
|
||||
|
||||
class TextMetrics {
|
||||
constructor(width) {
|
||||
this._width = width;
|
||||
}
|
||||
|
||||
get width() {
|
||||
return this._width;
|
||||
}
|
||||
}
|
||||
|
||||
// class CanvasRenderingContext2D {
|
||||
// constructor() {
|
||||
// console.log("==> CanvasRenderingContext2D constructor");
|
||||
|
||||
// // Line styles
|
||||
// this.lineWidth = 1;
|
||||
// this.lineCap = 'butt';
|
||||
// this.lineJoin = 'miter';
|
||||
// this.miterLimit = 10;
|
||||
// this.lineDashOffset = 0;
|
||||
|
||||
// // Text styles
|
||||
// this.font = '10px sans-serif';
|
||||
// this.textAlign = 'start';
|
||||
// this.textBaseline = 'alphabetic';
|
||||
|
||||
// // Fill and stroke styles
|
||||
// this.fillStyle = '#000';
|
||||
// this.strokeStyle = '#000';
|
||||
|
||||
// // Shadows
|
||||
// this.shadowBlur = 0;
|
||||
// this.shadowColor = 'black';
|
||||
// this.shadowOffsetX = 0;
|
||||
// this.shadowOffsetY = 0;
|
||||
|
||||
// // Compositing
|
||||
// this.globalAlpha = 1;
|
||||
// this.globalCompositeOperation = 'source-over';
|
||||
|
||||
// }
|
||||
|
||||
// clearRect(x, y, width, height) {
|
||||
// console.log(`==> CanvasRenderingContext2D clearRect: [${x}, ${y}, ${width}, ${height}]`);
|
||||
// }
|
||||
|
||||
// fillRect(x, y, width, height) {
|
||||
// console.log(`==> CanvasRenderingContext2D fillRect: [${x}, ${y}, ${width}, ${height}]`);
|
||||
// }
|
||||
|
||||
// strokeRect(x, y, width, height) {
|
||||
// console.log(`==> CanvasRenderingContext2D strokeRect: [${x}, ${y}, ${width}, ${height}]`);
|
||||
// }
|
||||
|
||||
// getLineDash() {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// setLineDash(segments) {
|
||||
|
||||
// }
|
||||
|
||||
// drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
||||
// console.log("==> CanvasRenderingContext2D drawImage");
|
||||
// }
|
||||
|
||||
// getImageData(sx, sy, sw, sh) {
|
||||
// console.log(`==> CanvasRenderingContext2D getImageData(${sx}, ${sy}, ${sw}, ${sh})`);
|
||||
// let data = new Uint8ClampedArray(sw * sh * 4);
|
||||
// for (let i = 0; i < data.length; ++i) {
|
||||
// data[i] = Math.floor(Math.random() * 255);
|
||||
// }
|
||||
// return {
|
||||
// width: sw,
|
||||
// height: sh,
|
||||
// data: data
|
||||
// };
|
||||
// }
|
||||
|
||||
// fillText(text, x, y, maxWidth) {
|
||||
// console.log("==> CanvasRenderingContext2D fillText: " + text
|
||||
// + ', font: ' + this.font + ', textAlign: ' + this.textAlign
|
||||
// + ', textBaseline: ' + this.textBaseline);
|
||||
// }
|
||||
|
||||
// strokeText(text, x, y, maxWidth) {
|
||||
// console.log("==> CanvasRenderingContext2D strokeText" + text
|
||||
// + ', font: ' + this.font + ', textAlign: ' + this.textAlign
|
||||
// + ', textBaseline: ' + this.textBaseline);
|
||||
// }
|
||||
|
||||
// measureText(text) {
|
||||
// console.log("==> CanvasRenderingContext2D measureText: " + text
|
||||
// + ', font: ' + this.font + ', textAlign: ' + this.textAlign
|
||||
// + ', textBaseline: ' + this.textBaseline);
|
||||
// if (text === '') {
|
||||
// new Error("measureText empty");
|
||||
// }
|
||||
// return new TextMetrics(100);
|
||||
// }
|
||||
|
||||
// // Gradients and patterns
|
||||
// createLinearGradient(x0, y0, x1, y1) {
|
||||
// console.log("==> CanvasRenderingContext2D createLinearGradient");
|
||||
// return new CanvasGradient();
|
||||
// }
|
||||
|
||||
// createRadialGradient(x0, y0, r0, x1, y1, r1) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// createPattern(image, repetition) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// save() {
|
||||
// console.log("==> CanvasRenderingContext2D save");
|
||||
// }
|
||||
|
||||
// // Paths
|
||||
// beginPath() {
|
||||
// console.log("==> CanvasRenderingContext2D beginPath");
|
||||
// }
|
||||
|
||||
// closePath() {
|
||||
|
||||
// }
|
||||
|
||||
// moveTo() {
|
||||
// console.log("==> CanvasRenderingContext2D moveTo");
|
||||
// }
|
||||
|
||||
// lineTo() {
|
||||
// console.log("==> CanvasRenderingContext2D lineTo");
|
||||
// }
|
||||
|
||||
// bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
||||
|
||||
// }
|
||||
|
||||
// quadraticCurveTo(cpx, cpy, x, y) {
|
||||
|
||||
// }
|
||||
|
||||
// arc(x, y, radius, startAngle, endAngle, anticlockwise) {
|
||||
|
||||
// }
|
||||
|
||||
// rect(x, y, width, height) {
|
||||
|
||||
// }
|
||||
|
||||
// // Drawing paths
|
||||
// stroke() {
|
||||
// console.log("==> CanvasRenderingContext2D stroke");
|
||||
// }
|
||||
|
||||
// /*
|
||||
// void ctx.fill([fillRule]);
|
||||
// void ctx.fill(path[, fillRule]);
|
||||
// */
|
||||
// fill() {
|
||||
|
||||
// }
|
||||
|
||||
// restore() {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
const __listenTouchEventCanvasMap = {};
|
||||
|
||||
class HTMLCanvasElement extends HTMLElement {
|
||||
constructor(width, height) {
|
||||
super('canvas')
|
||||
|
||||
this.id = 'glcanvas';
|
||||
this.type = 'canvas';
|
||||
|
||||
this.top = 0;
|
||||
this.left = 0;
|
||||
this._width = width ? width : window.innerWidth;
|
||||
this._height = height ? height : window.innerHeight;
|
||||
this._context2D = null;
|
||||
this._data = null;
|
||||
}
|
||||
|
||||
//TODO: implement opts.
|
||||
getContext(name, opts) {
|
||||
var self = this;
|
||||
console.log(`==> Canvas getContext(${name})`);
|
||||
if (name === 'webgl' || name === 'experimental-webgl') {
|
||||
return window.gl;
|
||||
} else if (name === '2d') {
|
||||
if (!this._context2D) {
|
||||
this._context2D = new CanvasRenderingContext2D(this._width, this._height);
|
||||
this._context2D._canvas = this;
|
||||
this._context2D.setCanvasBufferUpdatedCallback(function(data) {
|
||||
console.log('setCanvasBufferUpdatedCallback: dataLen: ' + data.length);
|
||||
self._data = new ImageData(data, self._width, self._height);
|
||||
});
|
||||
}
|
||||
return this._context2D;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
toDataURL() {
|
||||
console.log("==> Canvas toDataURL");
|
||||
return "";
|
||||
}
|
||||
|
||||
set width(width) {
|
||||
console.log(`==> HTMLCanvasElement.width = ${width}`);
|
||||
if (this._width !== width) {
|
||||
this._width = width;
|
||||
if (this._context2D) {
|
||||
this._context2D._width = width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get width() {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
set height(height) {
|
||||
console.log(`==> HTMLCanvasElement.height = ${height}`);
|
||||
if (this._height !== height) {
|
||||
this._height = height;
|
||||
if (this._context2D) {
|
||||
this._context2D._height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get height() {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
addEventListener(eventName, listener, options) {
|
||||
let ret = super.addEventListener(eventName, listener, options);
|
||||
if (ret) {
|
||||
if (eventName === 'touchstart') {
|
||||
__listenTouchEventCanvasMap[this._index] = this;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
removeEventListener(eventName, listener, options) {
|
||||
let ret = super.removeEventListener(eventName, listener, options);
|
||||
if (ret) {
|
||||
if (eventName === 'touchstart') {
|
||||
delete __listenTouchEventCanvasMap[this._index];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
var ctx2DProto = CanvasRenderingContext2D.prototype;
|
||||
ctx2DProto.createImageData = function(width, height) {
|
||||
return new ImageData(width, height);
|
||||
}
|
||||
|
||||
ctx2DProto.putImageData = function(imagedata, dx, dy) {
|
||||
this._canvas._data = imagedata; //TODO: consider dx, dy?
|
||||
}
|
||||
|
||||
ctx2DProto.getImageData = function(sx, sy, sw, sh) {
|
||||
//TODO:cjh
|
||||
return this._canvas._data;
|
||||
}
|
||||
|
||||
ctx2DProto.drawImage = function(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
||||
//TODO:cjh
|
||||
}
|
||||
|
||||
function touchEventHandlerFactory(type) {
|
||||
return (touches) => {
|
||||
const touchEvent = new TouchEvent(type)
|
||||
|
||||
touchEvent.touches = touches;
|
||||
// touchEvent.targetTouches = Array.prototype.slice.call(event.touches)
|
||||
touchEvent.changedTouches = touches;//event.changedTouches
|
||||
// touchEvent.timeStamp = event.timeStamp
|
||||
|
||||
for (let key in __listenTouchEventCanvasMap) {
|
||||
__listenTouchEventCanvasMap[key].dispatchEvent(touchEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jsb.onTouchStart = touchEventHandlerFactory('touchstart');
|
||||
jsb.onTouchMove = touchEventHandlerFactory('touchmove');
|
||||
jsb.onTouchEnd = touchEventHandlerFactory('touchend');
|
||||
jsb.onTouchCancel = touchEventHandlerFactory('touchcancel');
|
||||
|
||||
module.exports = HTMLCanvasElement;
|
||||
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
const Element = require('./Element');
|
||||
const { noop } = require('./util');
|
||||
const { innerWidth, innerHeight } = require('./WindowProperties');
|
||||
|
||||
class HTMLElement extends Element {
|
||||
|
||||
constructor(tagName = '') {
|
||||
super()
|
||||
this.tagName = tagName.toUpperCase()
|
||||
|
||||
this.className = ''
|
||||
this.children = []
|
||||
this.style = {
|
||||
width: `${innerWidth}px`,
|
||||
height: `${innerHeight}px`
|
||||
}
|
||||
|
||||
this.insertBefore = noop
|
||||
|
||||
this.innerHTML = ''
|
||||
this.parentElement = window.canvas
|
||||
}
|
||||
|
||||
setAttribute(name, value) {
|
||||
this[name] = value
|
||||
}
|
||||
|
||||
getAttribute(name) {
|
||||
return this[name]
|
||||
}
|
||||
|
||||
get clientWidth() {
|
||||
const ret = parseInt(this.style.fontSize, 10) * this.innerHTML.length
|
||||
|
||||
return Number.isNaN(ret) ? 0 : ret
|
||||
}
|
||||
|
||||
get clientHeight() {
|
||||
const ret = parseInt(this.style.fontSize, 10)
|
||||
|
||||
return Number.isNaN(ret) ? 0 : ret
|
||||
}
|
||||
|
||||
getBoundingClientRect() {
|
||||
return {
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: innerWidth,
|
||||
height: innerHeight
|
||||
}
|
||||
}
|
||||
|
||||
focus() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HTMLElement;
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
const HTMLElement = require('./HTMLElement');
|
||||
const Event = require('./Event');
|
||||
|
||||
class HTMLImageElement extends HTMLElement {
|
||||
constructor(width, height) {
|
||||
super('img')
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this._data = null;
|
||||
this.onload = null;
|
||||
this._src = null;
|
||||
this.complete = false;
|
||||
this._glFormat = this._glInternalFormat = gl.RGBA;
|
||||
this.crossOrigin = null;
|
||||
}
|
||||
|
||||
set src(src) {
|
||||
this._src = src;
|
||||
jsb.loadImage(src, (info) => {
|
||||
this.width = this.naturalWidth = info.width;
|
||||
this.height = this.naturalHeight = info.height;
|
||||
this._data = info.data;
|
||||
// console.log(`glFormat: ${info.glFormat}, glInternalFormat: ${info.glInternalFormat}, glType: ${info.glType}`);
|
||||
this._glFormat = info.glFormat;
|
||||
this._glInternalFormat = info.glInternalFormat;
|
||||
this._glType = info.glType;
|
||||
this._numberOfMipmaps = info.numberOfMipmaps;
|
||||
this._compressed = info.compressed;
|
||||
this._bpp = info.bpp;
|
||||
|
||||
this._alignment = 1;
|
||||
// Set the row align only when mipmapsNum == 1 and the data is uncompressed
|
||||
if (this._numberOfMipmaps == 1 && !this._compressed) {
|
||||
let bytesPerRow = this.width * this._bpp / 8;
|
||||
if (bytesPerRow % 8 == 0)
|
||||
_alignment = 8;
|
||||
else if (bytesPerRow % 4 == 0)
|
||||
_alignment = 4;
|
||||
else if (bytesPerRow % 2 == 0)
|
||||
_alignment = 2;
|
||||
}
|
||||
|
||||
this.complete = true;
|
||||
|
||||
this.dispatchEvent(new Event('load'));
|
||||
|
||||
if (this.onload) {
|
||||
this.onload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get src() {
|
||||
return this._src;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HTMLImageElement;
|
||||
Regular → Executable
+24
-12
@@ -1,6 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
@@ -23,17 +22,30 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let HTMLElement = require('./HTMLElement');
|
||||
|
||||
cc.WebView = ccui.WebView;
|
||||
class HTMLMediaElement extends HTMLElement {
|
||||
constructor(type) {
|
||||
super(type)
|
||||
}
|
||||
|
||||
//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows
|
||||
if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) {
|
||||
cc.WebView = {};
|
||||
addTextTrack() {
|
||||
}
|
||||
|
||||
captureStream() {
|
||||
}
|
||||
|
||||
fastSeek() {
|
||||
}
|
||||
|
||||
load() {
|
||||
}
|
||||
|
||||
pause() {
|
||||
}
|
||||
|
||||
play() {
|
||||
}
|
||||
}
|
||||
|
||||
cc.WebView.EventType = {
|
||||
LOADING: 0,
|
||||
LOADED: 1,
|
||||
ERROR: 2,
|
||||
JS_EVALUATED: 3
|
||||
};
|
||||
module.exports = HTMLMediaElement;
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let HTMLImageElement = require('./HTMLImageElement');
|
||||
|
||||
function Image (width, height) {
|
||||
return new HTMLImageElement(width, height);
|
||||
}
|
||||
|
||||
module.exports = Image;
|
||||
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
class ImageData {
|
||||
|
||||
// var imageData = new ImageData(array, width, height);
|
||||
// var imageData = new ImageData(width, height);
|
||||
constructor(array, width, height) {
|
||||
if (typeof array === 'number' && typeof width == 'number') {
|
||||
height = width;
|
||||
width = array;
|
||||
array = null;
|
||||
}
|
||||
if (array === null) {
|
||||
this._data = new Uint8ClampedArray(width * height * 4);
|
||||
}
|
||||
else {
|
||||
this._data = array;
|
||||
}
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
}
|
||||
|
||||
|
||||
get data() {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
get width() {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
get height() {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ImageData;
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let EventTarget = require('./EventTarget');
|
||||
|
||||
class Node extends EventTarget {
|
||||
constructor() {
|
||||
super()
|
||||
this.childNodes = []
|
||||
}
|
||||
|
||||
appendChild(node) {
|
||||
if (node instanceof Node) {
|
||||
this.childNodes.push(node)
|
||||
} else {
|
||||
throw new TypeError('Failed to executed \'appendChild\' on \'Node\': parameter 1 is not of type \'Node\'.')
|
||||
}
|
||||
}
|
||||
|
||||
cloneNode() {
|
||||
const copyNode = Object.create(this)
|
||||
|
||||
Object.assign(copyNode, this)
|
||||
return copyNode
|
||||
}
|
||||
|
||||
removeChild(node) {
|
||||
const index = this.childNodes.findIndex((child) => child === node)
|
||||
|
||||
if (index > -1) {
|
||||
return this.childNodes.splice(index, 1)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Node;
|
||||
Regular → Executable
+10
-15
@@ -1,6 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
@@ -23,20 +22,16 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let Event = require('./Event')
|
||||
|
||||
cc.VideoPlayer = ccui.VideoPlayer;
|
||||
class TouchEvent extends Event {
|
||||
|
||||
//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows
|
||||
if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) {
|
||||
cc.VideoPlayer = {};
|
||||
constructor(type, touchEventInit) {
|
||||
super(type)
|
||||
this.touches = []
|
||||
this.targetTouches = []
|
||||
this.changedTouches = []
|
||||
}
|
||||
}
|
||||
|
||||
cc.VideoPlayer.EventType = {
|
||||
PLAYING: 0,
|
||||
PAUSED: 1,
|
||||
STOPPED: 2,
|
||||
COMPLETED: 3,
|
||||
META_LOADED: 4,
|
||||
CLICKED: 5,
|
||||
READY_TO_PLAY: 6
|
||||
};
|
||||
module.exports = TouchEvent
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
const { screenWidth, screenHeight, devicePixelRatio } = {screenWidth: window.innerWidth, screenHeight: window.innerHeight, devicePixelRatio: 1};//cjh wx.getSystemInfoSync()
|
||||
|
||||
const innerWidth = screenWidth
|
||||
const innerHeight = screenHeight
|
||||
const screen = {
|
||||
availWidth: innerWidth,
|
||||
availHeight: innerHeight
|
||||
}
|
||||
const performance = null//cjh wx.getPerformance()
|
||||
const ontouchstart = null
|
||||
const ontouchmove = null
|
||||
const ontouchend = null
|
||||
|
||||
module.exports = {
|
||||
innerWidth: innerWidth,
|
||||
innerHeight: innerHeight,
|
||||
devicePixelRatio: devicePixelRatio,
|
||||
screen: screen,
|
||||
performance: performance,
|
||||
ontouchstart: ontouchstart,
|
||||
ontouchmove: ontouchmove,
|
||||
ontouchend: ontouchend
|
||||
};
|
||||
Executable
+127
@@ -0,0 +1,127 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let HTMLElement = require('./HTMLElement');
|
||||
let Image = require('./Image');
|
||||
let Audio = require('./Audio');
|
||||
let HTMLCanvasElement = require('./HTMLCanvasElement');
|
||||
let Node = require('./Node');
|
||||
let FontFaceSet = require('./FontFaceSet')
|
||||
|
||||
class Document extends Node {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.readyState = 'complete'
|
||||
this.visibilityState = 'visible'
|
||||
this.documentElement = window
|
||||
this.hidden = false
|
||||
this.style = {}
|
||||
this.location = window.location
|
||||
|
||||
this.head = new HTMLElement('head')
|
||||
this.body = new HTMLElement('body')
|
||||
|
||||
this.fonts = new FontFaceSet()
|
||||
}
|
||||
|
||||
createElement(tagName) {
|
||||
if (tagName === 'canvas') {
|
||||
return new HTMLCanvasElement()
|
||||
} else if (tagName === 'audio') {
|
||||
return new Audio()
|
||||
} else if (tagName === 'img') {
|
||||
return new Image()
|
||||
} else if (tagName === 'video') {
|
||||
return {
|
||||
canPlayType: () => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return new HTMLElement(tagName)
|
||||
}
|
||||
|
||||
getElementById(id) {
|
||||
if (id === window.canvas.id) {
|
||||
return window.canvas
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
getElementsByTagName(tagName) {
|
||||
if (tagName === 'head') {
|
||||
return [document.head]
|
||||
} else if (tagName === 'body') {
|
||||
return [document.body]
|
||||
} else if (tagName === 'canvas') {
|
||||
return [window.canvas]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
getElementsByName(tagName) {
|
||||
if (tagName === 'head') {
|
||||
return [document.head]
|
||||
} else if (tagName === 'body') {
|
||||
return [document.body]
|
||||
} else if (tagName === 'canvas') {
|
||||
return [window.canvas]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
querySelector(query) {
|
||||
if (query === 'head') {
|
||||
return document.head
|
||||
} else if (query === 'body') {
|
||||
return document.body
|
||||
} else if (query === 'canvas' || query === 'GameCanvas') {
|
||||
return window.canvas
|
||||
} else if (query === `#${window.canvas.id}`) {
|
||||
return window.canvas
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
querySelectorAll(query) {
|
||||
if (query === 'head') {
|
||||
return [document.head]
|
||||
} else if (query === 'body') {
|
||||
return [document.body]
|
||||
} else if (query === 'canvas') {
|
||||
return [window.canvas]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
createTextNode() {
|
||||
return new HTMLElement('text');
|
||||
}
|
||||
}
|
||||
|
||||
let document = new Document()
|
||||
|
||||
module.exports = document
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
require('./window')
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
const location = {
|
||||
href: 'game.js',
|
||||
reload() {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = location;
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
let { noop } = require('./util');
|
||||
|
||||
// TODO 需要 wx.getSystemInfo 获取更详细信息
|
||||
// cjh const { platform } = wx.getSystemInfoSync()
|
||||
const navigator = {
|
||||
platform: 'wx', //cjh added wx
|
||||
language: 'zh-cn',
|
||||
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 MicroMessenger/6.6.0 MiniGame NetType/WIFI Language/zh_CN',
|
||||
onLine: true, // TODO 用 wx.getNetworkStateChange 和 wx.onNetworkStateChange 来返回真实的状态
|
||||
|
||||
// TODO 用 wx.getLocation 来封装 geolocation
|
||||
geolocation: {
|
||||
getCurrentPosition: noop,
|
||||
watchPosition: noop,
|
||||
clearWatch: noop
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = navigator;
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
function noop() {}
|
||||
|
||||
module.exports = noop;
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
function inject () {
|
||||
window.top = window.parent = window
|
||||
|
||||
window.document = require('./document');
|
||||
window.HTMLElement = require('./HTMLElement');
|
||||
window.HTMLCanvasElement = require('./HTMLCanvasElement');
|
||||
window.HTMLImageElement = require('./HTMLImageElement');
|
||||
window.HTMLMediaElement = require('./HTMLMediaElement');
|
||||
window.HTMLAudioElement = require('./HTMLAudioElement');
|
||||
window.canvas = new HTMLCanvasElement();
|
||||
window.gl.canvas = window.canvas;
|
||||
window.WebGLRenderingContext = window.gl;
|
||||
window.navigator = require('./navigator');
|
||||
window.Image = require('./Image');
|
||||
window.Audio = require('./Audio');
|
||||
window.FileReader = require('./FileReader');
|
||||
window.location = require('./location');
|
||||
window.FontFace = require('./FontFace');
|
||||
window.FontFaceSet = require('./FontFaceSet');
|
||||
window.EventTarget = require('./EventTarget');
|
||||
window.Event = require('./Event');
|
||||
window.TouchEvent = require('./TouchEvent');
|
||||
|
||||
window.ontouchstart = null;
|
||||
window.ontouchmove = null;
|
||||
window.ontouchend = null;
|
||||
window.ontouchcancel = null;
|
||||
|
||||
window.addEventListener = function(eventName, listener, options) {
|
||||
window.canvas.addEventListener(eventName, listener, options);
|
||||
}
|
||||
|
||||
window.removeEventListener = function(eventName, listener, options) {
|
||||
window.canvas.removeEventListener(eventName, listener, options);
|
||||
}
|
||||
|
||||
window.dispatchEvent = function(event) {
|
||||
window.canvas.dispatchEvent(event);
|
||||
}
|
||||
|
||||
window._isInjected = true;
|
||||
}
|
||||
|
||||
if (!window._isInjected) {
|
||||
inject();
|
||||
}
|
||||
|
||||
window.canvas.getContext = function(name) {
|
||||
if (name === 'webgl' || name === 'experimental-webgl') {
|
||||
return window.gl;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
window.localStorage = sys.localStorage;
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 Chukong Technologies Inc.
|
||||
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
(function (jsb) {
|
||||
|
||||
if (!jsb || !jsb.AudioEngine)
|
||||
return
|
||||
|
||||
jsb.AudioEngine.AudioState = {
|
||||
ERROR: -1,
|
||||
INITIALZING: 0,
|
||||
PLAYING: 1,
|
||||
PAUSED: 2
|
||||
}
|
||||
|
||||
jsb.AudioEngine.INVALID_AUDIO_ID = -1
|
||||
jsb.AudioEngine.TIME_UNKNOWN = -1
|
||||
|
||||
})(jsb)
|
||||
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* OpenGL ES 2.0 / WebGL helper functions
|
||||
*
|
||||
* According to the WebGL specification ( For further info see:s http://www.khronos.org/registry/webgl/specs/latest/webgl.idl ),
|
||||
* the API should work with objects like WebGLTexture, WebGLBuffer, WebGLRenderBuffer, WebGLFramebuffer, WebGLProgram, WebGLShader.
|
||||
* OpenGL ES 2.0 doesn't have "objects" concepts: Instead it uses ids (GLints). So, these objects are emulated in this thin wrapper.
|
||||
*
|
||||
* Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
require('./jsb_opengl_constants');
|
||||
window.gl = window.gl || {};
|
||||
|
||||
gl.canvas = {
|
||||
clientWidth: window.innerWidth,
|
||||
clientHeight: window.innerHeight
|
||||
};
|
||||
|
||||
//
|
||||
// Create functions
|
||||
//
|
||||
gl.createTexture = function() {
|
||||
// Returns a "WebGLTexture" object
|
||||
var ret = gl._createTexture();
|
||||
return { texture_id:ret };
|
||||
};
|
||||
|
||||
gl.createBuffer = function() {
|
||||
// Returns a "WebGLBuffer" object
|
||||
var ret = gl._createBuffer();
|
||||
return { buffer_id:ret };
|
||||
};
|
||||
|
||||
gl.createRenderbuffer = function() {
|
||||
// Returns a "WebGLRenderBuffer" object
|
||||
var ret = gl._createRenderuffer();
|
||||
return { renderbuffer_id:ret};
|
||||
};
|
||||
|
||||
gl.createFramebuffer = function() {
|
||||
// Returns a "WebGLFramebuffer" object
|
||||
var ret = gl._createFramebuffer();
|
||||
return {framebuffer_id:ret};
|
||||
};
|
||||
|
||||
gl.createProgram = function() {
|
||||
// Returns a "WebGLProgram" object
|
||||
var ret = gl._createProgram();
|
||||
return {program_id:ret};
|
||||
};
|
||||
|
||||
gl.createShader = function(shaderType) {
|
||||
// Returns a "WebGLShader" object
|
||||
var ret = gl._createShader(shaderType);
|
||||
return {shader_id:ret};
|
||||
};
|
||||
|
||||
//
|
||||
// Delete Functions
|
||||
//
|
||||
gl.deleteTexture = function(texture) {
|
||||
var texture_id = texture.texture_id;
|
||||
// Accept numbers too. eg: gl.deleteTexture(0)
|
||||
if (typeof texture === 'number')
|
||||
texture_id = texture;
|
||||
|
||||
gl._deleteTexture(texture_id);
|
||||
};
|
||||
|
||||
gl.deleteBuffer = function(buffer) {
|
||||
var buffer_id = buffer.buffer_id;
|
||||
// Accept numbers too. eg: gl.deleteBuffer(0)
|
||||
if( typeof buffer === 'number' )
|
||||
buffer_id = buffer;
|
||||
|
||||
gl._deleteBuffer(buffer_id);
|
||||
};
|
||||
|
||||
gl.deleteRenderbuffer = function(buffer) {
|
||||
var buffer_id = buffer.renderbuffer_id;
|
||||
// Accept numbers too. eg: gl.deleteRenderbuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
|
||||
gl._deleteRenderbuffer(renderbuffer_id);
|
||||
};
|
||||
|
||||
gl.deleteFramebuffer = function(buffer) {
|
||||
var buffer_id;
|
||||
if (buffer)
|
||||
buffer_id = buffer.framebuffer_id;
|
||||
else
|
||||
buffer_id = null;
|
||||
gl._deleteFramebuffer(buffer_id);
|
||||
};
|
||||
|
||||
gl.deleteProgram = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.deleteShader(0)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
gl._deleteProgram(program_id);
|
||||
};
|
||||
|
||||
gl.deleteShader = function(shader) {
|
||||
var shader_id = shader.shader_id;
|
||||
// Accept numbers too. eg: gl.deleteShader(0)
|
||||
if (typeof shader === 'number')
|
||||
shader_id = shader;
|
||||
|
||||
gl._deleteShader(shader_id);
|
||||
};
|
||||
|
||||
//
|
||||
// Bind Related
|
||||
//
|
||||
// void bindTexture(GLenum target, WebGLTexture? texture);
|
||||
gl.bindTexture = function(target, texture) {
|
||||
|
||||
var texture_id;
|
||||
// Accept numbers too. eg: gl.bindTexture(0)
|
||||
if (typeof texture === 'number')
|
||||
texture_id = texture;
|
||||
else if( texture === null )
|
||||
texture_id = 0;
|
||||
else
|
||||
texture_id = texture.texture_id;
|
||||
|
||||
gl._bindTexture( target, texture_id );
|
||||
};
|
||||
|
||||
// void bindBuffer(GLenum target, WebGLBuffer? buffer);
|
||||
gl.bindBuffer = function(target, buffer) {
|
||||
var buffer_id;
|
||||
// Accept numbers too. eg: gl.bindBuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
else if (buffer === null)
|
||||
buffer_id = 0;
|
||||
else
|
||||
buffer_id = buffer.buffer_id;
|
||||
|
||||
gl._bindBuffer(target, buffer_id);
|
||||
};
|
||||
|
||||
// void bindRenderbuffer(GLenum target, WebGLRenderbuffer? renderbuffer);
|
||||
gl.bindRenderBuffer = function(target, buffer) {
|
||||
var buffer_id;
|
||||
|
||||
// Accept numbers too. eg: gl.bindRenderbuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
else if (buffer === null)
|
||||
buffer_id = 0;
|
||||
else
|
||||
buffer_id = buffer.buffer_id;
|
||||
|
||||
gl._bindRenderbuffer(target, buffer_id);
|
||||
};
|
||||
|
||||
// void bindFramebuffer(GLenum target, WebGLFramebuffer? framebuffer);
|
||||
gl.bindFramebuffer = function(target, buffer) {
|
||||
var buffer_id;
|
||||
|
||||
// Accept numbers too. eg: gl.bindFramebuffer(0)
|
||||
if (typeof buffer === 'number')
|
||||
buffer_id = buffer;
|
||||
else if( buffer === null )
|
||||
buffer_id = null;
|
||||
else
|
||||
buffer_id = buffer.buffer_id;
|
||||
|
||||
gl._bindFramebuffer(target, buffer_id);
|
||||
};
|
||||
|
||||
gl.framebufferTexture2D = function(target, attachment, textarget, texture, level) {
|
||||
gl._framebufferTexture2D(target, attachment, textarget, texture.texture_id, level);
|
||||
}
|
||||
|
||||
//
|
||||
// Uniform related
|
||||
//
|
||||
// any getUniform(WebGLProgram? program, WebGLUniformLocation? location);
|
||||
gl.getUniform = function(program, location) {
|
||||
var program_id;
|
||||
var location_id;
|
||||
|
||||
// Accept numbers too. eg: gl.bindFramebuffer(0)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
else
|
||||
program_id = program.program_id;
|
||||
|
||||
if (typeof location === 'number')
|
||||
location_id = location;
|
||||
else
|
||||
location_id = location.location_id;
|
||||
|
||||
return gl._getUniform(program_id, location_id);
|
||||
};
|
||||
|
||||
// gl.uniformMatrix2fv = function(location, bool, matrix) {
|
||||
// gl._uniformMatrix2fv(program.program_id, bool, matrix);
|
||||
// };
|
||||
|
||||
// gl.uniformMatrix3fv = function(program, bool, matrix) {
|
||||
// gl._uniformMatrix3fv(program.program_id, bool, matrix);
|
||||
// };
|
||||
|
||||
// gl.uniformMatrix4fv = function(program, bool, matrix) {
|
||||
// gl._uniformMatrix4fv(program.program_id, bool, matrix);
|
||||
// };
|
||||
|
||||
|
||||
//
|
||||
// Shader related
|
||||
//
|
||||
// void compileShader(WebGLShader? shader);
|
||||
gl.compileShader = function(shader) {
|
||||
gl._compileShader( shader.shader_id);
|
||||
};
|
||||
|
||||
// void shaderSource(WebGLShader? shader, DOMString source);
|
||||
gl.shaderSource = function(shader, source) {
|
||||
gl._shaderSource(shader.shader_id, source);
|
||||
};
|
||||
|
||||
// any getShaderParameter(WebGLShader? shader, GLenum pname);
|
||||
gl.getShaderParameter = function(shader, e) {
|
||||
return gl._getShaderParameter(shader.shader_id,e);
|
||||
};
|
||||
|
||||
// DOMString? getShaderInfoLog(WebGLShader? shader);
|
||||
gl.getShaderInfoLog = function(shader) {
|
||||
return gl._getShaderInfoLog(shader.shader_id);
|
||||
};
|
||||
|
||||
// DOMString gl.getShaderSource(shader);
|
||||
gl.getShaderSource = function(shader) {
|
||||
return gl._getShaderSource(shader.shader_id);
|
||||
};
|
||||
|
||||
//
|
||||
// program related
|
||||
//
|
||||
// void attachShader(WebGLProgram? program, WebGLShader? shader);
|
||||
gl.attachShader = function(program, shader) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.attachShader(17)
|
||||
if( typeof program === 'number' )
|
||||
program_id = program;
|
||||
|
||||
gl._attachShader(program_id, shader.shader_id);
|
||||
};
|
||||
|
||||
// void linkProgram(WebGLProgram? program);
|
||||
gl.linkProgram = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.linkProgram(17)
|
||||
if( typeof program === 'number' )
|
||||
program_id = program;
|
||||
|
||||
gl._linkProgram(program_id);
|
||||
};
|
||||
|
||||
gl.bindAttribLocation = function(program, index, name) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.linkProgram(17)
|
||||
if( typeof program === 'number' )
|
||||
program_id = program;
|
||||
|
||||
gl._bindAttribLocation(program_id, index, name);
|
||||
};
|
||||
|
||||
// any getProgramParameter(WebGLProgram? program, GLenum pname);
|
||||
gl.getProgramParameter = function(program, e) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getProgramParameter(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getProgramParameter(program_id, e);
|
||||
};
|
||||
|
||||
gl.getProgramInfoLog = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getProgramParameter(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getProgramInfoLog(program_id);
|
||||
};
|
||||
|
||||
// void useProgram(WebGLProgram? program);
|
||||
gl.useProgram = function(program) {
|
||||
var program_id;
|
||||
// Accept numbers too. eg: gl.useProgram(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
else
|
||||
program_id = program.program_id;
|
||||
|
||||
gl._useProgram (program_id);
|
||||
};
|
||||
|
||||
|
||||
// [WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram? program, DOMString name);
|
||||
gl.getAttribLocation = function(program, name) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getAttribLocation(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getAttribLocation(program_id, name);
|
||||
};
|
||||
|
||||
// WebGLUniformLocation? getUniformLocation(WebGLProgram? program, DOMString name);
|
||||
gl.getUniformLocation = function(program, name) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getUniformLocation(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
// XXX: it should return an object, not an integer
|
||||
return gl._getUniformLocation(program_id,name);
|
||||
};
|
||||
|
||||
|
||||
// WebGLActiveInfo? getActiveAttrib(WebGLProgram? program, GLuint index);
|
||||
gl.getActiveAttrib = function(program, index) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getActiveAttrib(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getActiveAttrib(program_id, index);
|
||||
};
|
||||
|
||||
// WebGLActiveInfo? getActiveUniform(WebGLProgram? program, GLuint index);
|
||||
gl.getActiveUniform = function(program, index) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getActiveUniform(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getActiveUniform(program_id, index);
|
||||
};
|
||||
|
||||
// sequence<WebGLShader>? getAttachedShaders(WebGLProgram? program);
|
||||
gl.getAttachedShaders = function(program) {
|
||||
var program_id = program.program_id;
|
||||
// Accept numbers too. eg: gl.getAttachedShaders(17)
|
||||
if (typeof program === 'number')
|
||||
program_id = program;
|
||||
|
||||
return gl._getAttachedShaders(program_id);
|
||||
};
|
||||
|
||||
//
|
||||
// Extensions
|
||||
//
|
||||
// From the WebGL spec:
|
||||
// Returns an object if, and only if, name is an ASCII case-insensitive match [HTML] for one of the names returned from getSupportedExtensions;
|
||||
// otherwise, returns null. The object returned from getExtension contains any constants or functions provided by the extension.
|
||||
// A returned object may have no constants or functions if the extension does not define any, but a unique object must still be returned.
|
||||
// That object is used to indicate that the extension has been enabled.
|
||||
// XXX: The returned object must return the functions and constants.
|
||||
gl.getExtension = function(extension) {
|
||||
var extensions = gl.getSupportedExtensions();
|
||||
if (extensions.indexOf(extension) > -1)
|
||||
return {};
|
||||
return null;
|
||||
};
|
||||
|
||||
let HTMLCanvasElement = require('./jsb-adapter/HTMLCanvasElement');
|
||||
let HTMLImageElement = require('./jsb-adapter/HTMLImageElement');
|
||||
let ImageData = require('./jsb-adapter/ImageData');
|
||||
|
||||
let _glTexImage2D = gl.texImage2D;
|
||||
|
||||
/*
|
||||
// WebGL1:
|
||||
void gl.texImage2D(target, level, internalformat, width, height, border, format, type, ArrayBufferView? pixels);
|
||||
void gl.texImage2D(target, level, internalformat, format, type, ImageData? pixels);
|
||||
void gl.texImage2D(target, level, internalformat, format, type, HTMLImageElement? pixels);
|
||||
void gl.texImage2D(target, level, internalformat, format, type, HTMLCanvasElement? pixels);
|
||||
void gl.texImage2D(target, level, internalformat, format, type, HTMLVideoElement? pixels);
|
||||
void gl.texImage2D(target, level, internalformat, format, type, ImageBitmap? pixels);
|
||||
*/
|
||||
gl.texImage2D = function(target, level, internalformat, width, height, border, format, type, pixels) {
|
||||
let argCount = arguments.length;
|
||||
if (argCount == 6) {
|
||||
var image = border;
|
||||
type = height;
|
||||
format = width;
|
||||
|
||||
if (image instanceof HTMLImageElement) {
|
||||
console.log(`==> texImage2D HTMLImageElement internalformat: ${image._glInternalFormat}, format: ${image._glFormat}, image: w:${image.width}, h:${image.height}, dataLen:${image._data.length}`);
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, image._alignment);
|
||||
|
||||
_glTexImage2D(target, level, image._glInternalFormat, image.width, image.height, 0, image._glFormat, image._glType, image._data);
|
||||
}
|
||||
else if (image instanceof HTMLCanvasElement) {
|
||||
console.log(`==> texImage2D HTMLCanvasElement internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);//, dataLen:${image._data.length}`);
|
||||
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data._data);
|
||||
}
|
||||
else if (image instanceof ImageData) {
|
||||
console.log(`==> texImage2D ImageData internalformat: ${internalformat}, format: ${format}, image: w:${image.width}, h:${image.height}`);
|
||||
_glTexImage2D(target, level, internalformat, image.width, image.height, 0, format, type, image._data);
|
||||
}
|
||||
else {
|
||||
console.error("Invalid pixel argument passed to gl.texImage2D!");
|
||||
}
|
||||
}
|
||||
else if (argCount == 9) {
|
||||
_glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
|
||||
} else {
|
||||
console.error("gl.texImage2D: invalid argument count!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let _glTexSubImage2D = gl.texSubImage2D;
|
||||
/*
|
||||
// WebGL 1:
|
||||
void gl.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, ArrayBufferView? pixels);
|
||||
void gl.texSubImage2D(target, level, xoffset, yoffset, format, type, ImageData? pixels);
|
||||
void gl.texSubImage2D(target, level, xoffset, yoffset, format, type, HTMLImageElement? pixels);
|
||||
void gl.texSubImage2D(target, level, xoffset, yoffset, format, type, HTMLCanvasElement? pixels);
|
||||
void gl.texSubImage2D(target, level, xoffset, yoffset, format, type, HTMLVideoElement? pixels);
|
||||
void gl.texSubImage2D(target, level, xoffset, yoffset, format, type, ImageBitmap? pixels);
|
||||
*/
|
||||
gl.texSubImage2D = function(target, level, xoffset, yoffset, width, height, format, type, pixels) {
|
||||
let argCount = arguments.length;
|
||||
if (argCount == 7) {
|
||||
var image = format;
|
||||
type = height;
|
||||
format = width;
|
||||
|
||||
//TODO: ImageData
|
||||
if (image instanceof HTMLImageElement) {
|
||||
gl.pixelStorei(gl.UNPACK_ALIGNMENT, image._alignment);
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, image._glFormat, image._glType, image._data);
|
||||
}
|
||||
else if (image instanceof HTMLCanvasElement) {
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data._data);
|
||||
}
|
||||
else if (image instanceof ImageData) {
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, image.width, image.height, format, type, image._data);
|
||||
}
|
||||
else {
|
||||
console.error("Invalid pixel argument passed to gl.texImage2D!");
|
||||
}
|
||||
}
|
||||
else if (argCount == 9) {
|
||||
_glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
||||
} else {
|
||||
console.error((new Error("gl.texImage2D: invalid argument count!").stack));
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:cjh get the real value
|
||||
gl.getContextAttributes = function() {
|
||||
return {
|
||||
alpha: true,
|
||||
antialias: true,
|
||||
depth: true,
|
||||
failIfMajorPerformanceCaveat: false,
|
||||
premultipliedAlpha: true,
|
||||
preserveDrawingBuffer: false,
|
||||
stencil: true
|
||||
}
|
||||
}
|
||||
|
||||
gl.isContextLost = function() {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,863 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* AUTOGENERATED FILE. DO NOT EDIT IT
|
||||
* Generated by "generate_jsb.py -c opengl_jsb.ini" on 2013-03-18
|
||||
* Script version: v0.6
|
||||
*/
|
||||
|
||||
window.gl = window.gl || {};
|
||||
|
||||
gl.GCCSO_SHADER_BINARY_FJ = 0x9260;
|
||||
gl._3DC_XY_AMD = 0x87fa;
|
||||
gl._3DC_X_AMD = 0x87f9;
|
||||
gl.ACTIVE_ATTRIBUTES = 0x8b89;
|
||||
gl.ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8b8a;
|
||||
gl.ACTIVE_PROGRAM_EXT = 0x8259;
|
||||
gl.ACTIVE_TEXTURE = 0x84e0;
|
||||
gl.ACTIVE_UNIFORMS = 0x8b86;
|
||||
gl.ACTIVE_UNIFORM_MAX_LENGTH = 0x8b87;
|
||||
gl.ALIASED_LINE_WIDTH_RANGE = 0x846e;
|
||||
gl.ALIASED_POINT_SIZE_RANGE = 0x846d;
|
||||
gl.ALL_COMPLETED_NV = 0x84f2;
|
||||
gl.ALL_SHADER_BITS_EXT = 0xffffffff;
|
||||
gl.ALPHA = 0x1906;
|
||||
gl.ALPHA16F_EXT = 0x881c;
|
||||
gl.ALPHA32F_EXT = 0x8816;
|
||||
gl.ALPHA8_EXT = 0x803c;
|
||||
gl.ALPHA8_OES = 0x803c;
|
||||
gl.ALPHA_BITS = 0xd55;
|
||||
gl.ALPHA_TEST_FUNC_QCOM = 0xbc1;
|
||||
gl.ALPHA_TEST_QCOM = 0xbc0;
|
||||
gl.ALPHA_TEST_REF_QCOM = 0xbc2;
|
||||
gl.ALREADY_SIGNALED_APPLE = 0x911a;
|
||||
gl.ALWAYS = 0x207;
|
||||
gl.AMD_compressed_3DC_texture = 0x1;
|
||||
gl.AMD_compressed_ATC_texture = 0x1;
|
||||
gl.AMD_performance_monitor = 0x1;
|
||||
gl.AMD_program_binary_Z400 = 0x1;
|
||||
gl.ANGLE_depth_texture = 0x1;
|
||||
gl.ANGLE_framebuffer_blit = 0x1;
|
||||
gl.ANGLE_framebuffer_multisample = 0x1;
|
||||
gl.ANGLE_instanced_arrays = 0x1;
|
||||
gl.ANGLE_pack_reverse_row_order = 0x1;
|
||||
gl.ANGLE_program_binary = 0x1;
|
||||
gl.ANGLE_texture_compression_dxt3 = 0x1;
|
||||
gl.ANGLE_texture_compression_dxt5 = 0x1;
|
||||
gl.ANGLE_texture_usage = 0x1;
|
||||
gl.ANGLE_translated_shader_source = 0x1;
|
||||
gl.ANY_SAMPLES_PASSED_CONSERVATIVE_EXT = 0x8d6a;
|
||||
gl.ANY_SAMPLES_PASSED_EXT = 0x8c2f;
|
||||
gl.APPLE_copy_texture_levels = 0x1;
|
||||
gl.APPLE_framebuffer_multisample = 0x1;
|
||||
gl.APPLE_rgb_422 = 0x1;
|
||||
gl.APPLE_sync = 0x1;
|
||||
gl.APPLE_texture_format_BGRA8888 = 0x1;
|
||||
gl.APPLE_texture_max_level = 0x1;
|
||||
gl.ARM_mali_program_binary = 0x1;
|
||||
gl.ARM_mali_shader_binary = 0x1;
|
||||
gl.ARM_rgba8 = 0x1;
|
||||
gl.ARRAY_BUFFER = 0x8892;
|
||||
gl.ARRAY_BUFFER_BINDING = 0x8894;
|
||||
gl.ATC_RGBA_EXPLICIT_ALPHA_AMD = 0x8c93;
|
||||
gl.ATC_RGBA_INTERPOLATED_ALPHA_AMD = 0x87ee;
|
||||
gl.ATC_RGB_AMD = 0x8c92;
|
||||
gl.ATTACHED_SHADERS = 0x8b85;
|
||||
gl.BACK = 0x405;
|
||||
gl.BGRA8_EXT = 0x93a1;
|
||||
gl.BGRA_EXT = 0x80e1;
|
||||
gl.BGRA_IMG = 0x80e1;
|
||||
gl.BINNING_CONTROL_HINT_QCOM = 0x8fb0;
|
||||
gl.BLEND = 0xbe2;
|
||||
gl.BLEND_COLOR = 0x8005;
|
||||
gl.BLEND_DST_ALPHA = 0x80ca;
|
||||
gl.BLEND_DST_RGB = 0x80c8;
|
||||
gl.BLEND_EQUATION = 0x8009;
|
||||
gl.BLEND_EQUATION_ALPHA = 0x883d;
|
||||
gl.BLEND_EQUATION_RGB = 0x8009;
|
||||
gl.BLEND_SRC_ALPHA = 0x80cb;
|
||||
gl.BLEND_SRC_RGB = 0x80c9;
|
||||
gl.BLUE_BITS = 0xd54;
|
||||
gl.BOOL = 0x8b56;
|
||||
gl.BOOL_VEC2 = 0x8b57;
|
||||
gl.BOOL_VEC3 = 0x8b58;
|
||||
gl.BOOL_VEC4 = 0x8b59;
|
||||
gl.BUFFER = 0x82e0;
|
||||
gl.BUFFER_ACCESS_OES = 0x88bb;
|
||||
gl.BUFFER_MAPPED_OES = 0x88bc;
|
||||
gl.BUFFER_MAP_POINTER_OES = 0x88bd;
|
||||
gl.BUFFER_OBJECT_EXT = 0x9151;
|
||||
gl.BUFFER_SIZE = 0x8764;
|
||||
gl.BUFFER_USAGE = 0x8765;
|
||||
gl.BYTE = 0x1400;
|
||||
gl.CCW = 0x901;
|
||||
gl.CLAMP_TO_BORDER_NV = 0x812d;
|
||||
gl.CLAMP_TO_EDGE = 0x812f;
|
||||
gl.COLOR_ATTACHMENT0 = 0x8ce0;
|
||||
gl.COLOR_ATTACHMENT0_NV = 0x8ce0;
|
||||
gl.COLOR_ATTACHMENT10_NV = 0x8cea;
|
||||
gl.COLOR_ATTACHMENT11_NV = 0x8ceb;
|
||||
gl.COLOR_ATTACHMENT12_NV = 0x8cec;
|
||||
gl.COLOR_ATTACHMENT13_NV = 0x8ced;
|
||||
gl.COLOR_ATTACHMENT14_NV = 0x8cee;
|
||||
gl.COLOR_ATTACHMENT15_NV = 0x8cef;
|
||||
gl.COLOR_ATTACHMENT1_NV = 0x8ce1;
|
||||
gl.COLOR_ATTACHMENT2_NV = 0x8ce2;
|
||||
gl.COLOR_ATTACHMENT3_NV = 0x8ce3;
|
||||
gl.COLOR_ATTACHMENT4_NV = 0x8ce4;
|
||||
gl.COLOR_ATTACHMENT5_NV = 0x8ce5;
|
||||
gl.COLOR_ATTACHMENT6_NV = 0x8ce6;
|
||||
gl.COLOR_ATTACHMENT7_NV = 0x8ce7;
|
||||
gl.COLOR_ATTACHMENT8_NV = 0x8ce8;
|
||||
gl.COLOR_ATTACHMENT9_NV = 0x8ce9;
|
||||
gl.COLOR_ATTACHMENT_EXT = 0x90f0;
|
||||
gl.COLOR_BUFFER_BIT = 0x4000;
|
||||
gl.COLOR_BUFFER_BIT0_QCOM = 0x1;
|
||||
gl.COLOR_BUFFER_BIT1_QCOM = 0x2;
|
||||
gl.COLOR_BUFFER_BIT2_QCOM = 0x4;
|
||||
gl.COLOR_BUFFER_BIT3_QCOM = 0x8;
|
||||
gl.COLOR_BUFFER_BIT4_QCOM = 0x10;
|
||||
gl.COLOR_BUFFER_BIT5_QCOM = 0x20;
|
||||
gl.COLOR_BUFFER_BIT6_QCOM = 0x40;
|
||||
gl.COLOR_BUFFER_BIT7_QCOM = 0x80;
|
||||
gl.COLOR_CLEAR_VALUE = 0xc22;
|
||||
gl.COLOR_EXT = 0x1800;
|
||||
gl.COLOR_WRITEMASK = 0xc23;
|
||||
gl.COMPARE_REF_TO_TEXTURE_EXT = 0x884e;
|
||||
gl.COMPILE_STATUS = 0x8b81;
|
||||
gl.COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93bb;
|
||||
gl.COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93b8;
|
||||
gl.COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93b9;
|
||||
gl.COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93ba;
|
||||
gl.COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93bc;
|
||||
gl.COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93bd;
|
||||
gl.COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93b0;
|
||||
gl.COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93b1;
|
||||
gl.COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93b2;
|
||||
gl.COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93b3;
|
||||
gl.COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93b4;
|
||||
gl.COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93b5;
|
||||
gl.COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93b6;
|
||||
gl.COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93b7;
|
||||
gl.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8c03;
|
||||
gl.COMPRESSED_RGBA_PVRTC_2BPPV2_IMG = 0x9137;
|
||||
gl.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8c02;
|
||||
gl.COMPRESSED_RGBA_PVRTC_4BPPV2_IMG = 0x9138;
|
||||
gl.COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83f1;
|
||||
gl.COMPRESSED_RGBA_S3TC_DXT3_ANGLE = 0x83f2;
|
||||
gl.COMPRESSED_RGBA_S3TC_DXT5_ANGLE = 0x83f3;
|
||||
gl.COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8c01;
|
||||
gl.COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8c00;
|
||||
gl.COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83f0;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93db;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93d8;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93d9;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93da;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93dc;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93dd;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93d0;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93d1;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93d2;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93d3;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93d4;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93d5;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93d6;
|
||||
gl.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93d7;
|
||||
gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV = 0x8c4d;
|
||||
gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV = 0x8c4e;
|
||||
gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV = 0x8c4f;
|
||||
gl.COMPRESSED_SRGB_S3TC_DXT1_NV = 0x8c4c;
|
||||
gl.COMPRESSED_TEXTURE_FORMATS = 0x86a3;
|
||||
gl.CONDITION_SATISFIED_APPLE = 0x911c;
|
||||
gl.CONSTANT_ALPHA = 0x8003;
|
||||
gl.CONSTANT_COLOR = 0x8001;
|
||||
gl.CONTEXT_FLAG_DEBUG_BIT = 0x2;
|
||||
gl.CONTEXT_ROBUST_ACCESS_EXT = 0x90f3;
|
||||
gl.COUNTER_RANGE_AMD = 0x8bc1;
|
||||
gl.COUNTER_TYPE_AMD = 0x8bc0;
|
||||
gl.COVERAGE_ALL_FRAGMENTS_NV = 0x8ed5;
|
||||
gl.COVERAGE_ATTACHMENT_NV = 0x8ed2;
|
||||
gl.COVERAGE_AUTOMATIC_NV = 0x8ed7;
|
||||
gl.COVERAGE_BUFFERS_NV = 0x8ed3;
|
||||
gl.COVERAGE_BUFFER_BIT_NV = 0x8000;
|
||||
gl.COVERAGE_COMPONENT4_NV = 0x8ed1;
|
||||
gl.COVERAGE_COMPONENT_NV = 0x8ed0;
|
||||
gl.COVERAGE_EDGE_FRAGMENTS_NV = 0x8ed6;
|
||||
gl.COVERAGE_SAMPLES_NV = 0x8ed4;
|
||||
gl.CPU_OPTIMIZED_QCOM = 0x8fb1;
|
||||
gl.CULL_FACE = 0xb44;
|
||||
gl.CULL_FACE_MODE = 0xb45;
|
||||
gl.CURRENT_PROGRAM = 0x8b8d;
|
||||
gl.CURRENT_QUERY_EXT = 0x8865;
|
||||
gl.CURRENT_VERTEX_ATTRIB = 0x8626;
|
||||
gl.CW = 0x900;
|
||||
gl.DEBUG_CALLBACK_FUNCTION = 0x8244;
|
||||
gl.DEBUG_CALLBACK_USER_PARAM = 0x8245;
|
||||
gl.DEBUG_GROUP_STACK_DEPTH = 0x826d;
|
||||
gl.DEBUG_LOGGED_MESSAGES = 0x9145;
|
||||
gl.DEBUG_NEXT_LOGGED_MESSAGE_LENGTH = 0x8243;
|
||||
gl.DEBUG_OUTPUT = 0x92e0;
|
||||
gl.DEBUG_OUTPUT_SYNCHRONOUS = 0x8242;
|
||||
gl.DEBUG_SEVERITY_HIGH = 0x9146;
|
||||
gl.DEBUG_SEVERITY_LOW = 0x9148;
|
||||
gl.DEBUG_SEVERITY_MEDIUM = 0x9147;
|
||||
gl.DEBUG_SEVERITY_NOTIFICATION = 0x826b;
|
||||
gl.DEBUG_SOURCE_API = 0x8246;
|
||||
gl.DEBUG_SOURCE_APPLICATION = 0x824a;
|
||||
gl.DEBUG_SOURCE_OTHER = 0x824b;
|
||||
gl.DEBUG_SOURCE_SHADER_COMPILER = 0x8248;
|
||||
gl.DEBUG_SOURCE_THIRD_PARTY = 0x8249;
|
||||
gl.DEBUG_SOURCE_WINDOW_SYSTEM = 0x8247;
|
||||
gl.DEBUG_TYPE_DEPRECATED_BEHAVIOR = 0x824d;
|
||||
gl.DEBUG_TYPE_ERROR = 0x824c;
|
||||
gl.DEBUG_TYPE_MARKER = 0x8268;
|
||||
gl.DEBUG_TYPE_OTHER = 0x8251;
|
||||
gl.DEBUG_TYPE_PERFORMANCE = 0x8250;
|
||||
gl.DEBUG_TYPE_POP_GROUP = 0x826a;
|
||||
gl.DEBUG_TYPE_PORTABILITY = 0x824f;
|
||||
gl.DEBUG_TYPE_PUSH_GROUP = 0x8269;
|
||||
gl.DEBUG_TYPE_UNDEFINED_BEHAVIOR = 0x824e;
|
||||
gl.DECR = 0x1e03;
|
||||
gl.DECR_WRAP = 0x8508;
|
||||
gl.DELETE_STATUS = 0x8b80;
|
||||
gl.DEPTH24_STENCIL8_OES = 0x88f0;
|
||||
gl.DEPTH_ATTACHMENT = 0x8d00;
|
||||
gl.DEPTH_BITS = 0xd56;
|
||||
gl.DEPTH_BUFFER_BIT = 0x100;
|
||||
gl.DEPTH_BUFFER_BIT0_QCOM = 0x100;
|
||||
gl.DEPTH_BUFFER_BIT1_QCOM = 0x200;
|
||||
gl.DEPTH_BUFFER_BIT2_QCOM = 0x400;
|
||||
gl.DEPTH_BUFFER_BIT3_QCOM = 0x800;
|
||||
gl.DEPTH_BUFFER_BIT4_QCOM = 0x1000;
|
||||
gl.DEPTH_BUFFER_BIT5_QCOM = 0x2000;
|
||||
gl.DEPTH_BUFFER_BIT6_QCOM = 0x4000;
|
||||
gl.DEPTH_BUFFER_BIT7_QCOM = 0x8000;
|
||||
gl.DEPTH_CLEAR_VALUE = 0xb73;
|
||||
gl.DEPTH_COMPONENT = 0x1902;
|
||||
gl.DEPTH_COMPONENT16 = 0x81a5;
|
||||
gl.DEPTH_COMPONENT16_NONLINEAR_NV = 0x8e2c;
|
||||
gl.DEPTH_COMPONENT16_OES = 0x81a5;
|
||||
gl.DEPTH_COMPONENT24_OES = 0x81a6;
|
||||
gl.DEPTH_COMPONENT32_OES = 0x81a7;
|
||||
gl.DEPTH_EXT = 0x1801;
|
||||
gl.DEPTH_FUNC = 0xb74;
|
||||
gl.DEPTH_RANGE = 0xb70;
|
||||
gl.DEPTH_STENCIL = 0x84f9;
|
||||
gl.DEPTH_STENCIL_OES = 0x84f9;
|
||||
gl.DEPTH_TEST = 0xb71;
|
||||
gl.DEPTH_WRITEMASK = 0xb72;
|
||||
gl.DITHER = 0xbd0;
|
||||
gl.DMP_shader_binary = 0x1;
|
||||
gl.DONT_CARE = 0x1100;
|
||||
gl.DRAW_BUFFER0_NV = 0x8825;
|
||||
gl.DRAW_BUFFER10_NV = 0x882f;
|
||||
gl.DRAW_BUFFER11_NV = 0x8830;
|
||||
gl.DRAW_BUFFER12_NV = 0x8831;
|
||||
gl.DRAW_BUFFER13_NV = 0x8832;
|
||||
gl.DRAW_BUFFER14_NV = 0x8833;
|
||||
gl.DRAW_BUFFER15_NV = 0x8834;
|
||||
gl.DRAW_BUFFER1_NV = 0x8826;
|
||||
gl.DRAW_BUFFER2_NV = 0x8827;
|
||||
gl.DRAW_BUFFER3_NV = 0x8828;
|
||||
gl.DRAW_BUFFER4_NV = 0x8829;
|
||||
gl.DRAW_BUFFER5_NV = 0x882a;
|
||||
gl.DRAW_BUFFER6_NV = 0x882b;
|
||||
gl.DRAW_BUFFER7_NV = 0x882c;
|
||||
gl.DRAW_BUFFER8_NV = 0x882d;
|
||||
gl.DRAW_BUFFER9_NV = 0x882e;
|
||||
gl.DRAW_BUFFER_EXT = 0xc01;
|
||||
gl.DRAW_FRAMEBUFFER_ANGLE = 0x8ca9;
|
||||
gl.DRAW_FRAMEBUFFER_APPLE = 0x8ca9;
|
||||
gl.DRAW_FRAMEBUFFER_BINDING_ANGLE = 0x8ca6;
|
||||
gl.DRAW_FRAMEBUFFER_BINDING_APPLE = 0x8ca6;
|
||||
gl.DRAW_FRAMEBUFFER_BINDING_NV = 0x8ca6;
|
||||
gl.DRAW_FRAMEBUFFER_NV = 0x8ca9;
|
||||
gl.DST_ALPHA = 0x304;
|
||||
gl.DST_COLOR = 0x306;
|
||||
gl.DYNAMIC_DRAW = 0x88e8;
|
||||
gl.ELEMENT_ARRAY_BUFFER = 0x8893;
|
||||
gl.ELEMENT_ARRAY_BUFFER_BINDING = 0x8895;
|
||||
gl.EQUAL = 0x202;
|
||||
gl.ES_VERSION_2_0 = 0x1;
|
||||
gl.ETC1_RGB8_OES = 0x8d64;
|
||||
gl.ETC1_SRGB8_NV = 0x88ee;
|
||||
gl.EXTENSIONS = 0x1f03;
|
||||
gl.EXT_blend_minmax = 0x1;
|
||||
gl.EXT_color_buffer_half_float = 0x1;
|
||||
gl.EXT_debug_label = 0x1;
|
||||
gl.EXT_debug_marker = 0x1;
|
||||
gl.EXT_discard_framebuffer = 0x1;
|
||||
gl.EXT_map_buffer_range = 0x1;
|
||||
gl.EXT_multi_draw_arrays = 0x1;
|
||||
gl.EXT_multisampled_render_to_texture = 0x1;
|
||||
gl.EXT_multiview_draw_buffers = 0x1;
|
||||
gl.EXT_occlusion_query_boolean = 0x1;
|
||||
gl.EXT_read_format_bgra = 0x1;
|
||||
gl.EXT_robustness = 0x1;
|
||||
gl.EXT_sRGB = 0x1;
|
||||
gl.EXT_separate_shader_objects = 0x1;
|
||||
gl.EXT_shader_framebuffer_fetch = 0x1;
|
||||
gl.EXT_shader_texture_lod = 0x1;
|
||||
gl.EXT_shadow_samplers = 0x1;
|
||||
gl.EXT_texture_compression_dxt1 = 0x1;
|
||||
gl.EXT_texture_filter_anisotropic = 0x1;
|
||||
gl.EXT_texture_format_BGRA8888 = 0x1;
|
||||
gl.EXT_texture_rg = 0x1;
|
||||
gl.EXT_texture_storage = 0x1;
|
||||
gl.EXT_texture_type_2_10_10_10_REV = 0x1;
|
||||
gl.EXT_unpack_subimage = 0x1;
|
||||
gl.FALSE = 0x0;
|
||||
gl.FASTEST = 0x1101;
|
||||
gl.FENCE_CONDITION_NV = 0x84f4;
|
||||
gl.FENCE_STATUS_NV = 0x84f3;
|
||||
gl.FIXED = 0x140c;
|
||||
gl.FJ_shader_binary_GCCSO = 0x1;
|
||||
gl.FLOAT = 0x1406;
|
||||
gl.FLOAT_MAT2 = 0x8b5a;
|
||||
gl.FLOAT_MAT3 = 0x8b5b;
|
||||
gl.FLOAT_MAT4 = 0x8b5c;
|
||||
gl.FLOAT_VEC2 = 0x8b50;
|
||||
gl.FLOAT_VEC3 = 0x8b51;
|
||||
gl.FLOAT_VEC4 = 0x8b52;
|
||||
gl.FRAGMENT_SHADER = 0x8b30;
|
||||
gl.FRAGMENT_SHADER_BIT_EXT = 0x2;
|
||||
gl.FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8b8b;
|
||||
gl.FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT = 0x8a52;
|
||||
gl.FRAMEBUFFER = 0x8d40;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_ANGLE = 0x93a3;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT = 0x8210;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT = 0x8211;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8cd1;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8cd0;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES = 0x8cd4;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8cd3;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8cd2;
|
||||
gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT = 0x8d6c;
|
||||
gl.FRAMEBUFFER_BINDING = 0x8ca6;
|
||||
gl.FRAMEBUFFER_COMPLETE = 0x8cd5;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8cd6;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8cd9;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8cd7;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE = 0x8d56;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE = 0x8d56;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT = 0x8d56;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG = 0x9134;
|
||||
gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_NV = 0x8d56;
|
||||
gl.FRAMEBUFFER_UNDEFINED_OES = 0x8219;
|
||||
gl.FRAMEBUFFER_UNSUPPORTED = 0x8cdd;
|
||||
gl.FRONT = 0x404;
|
||||
gl.FRONT_AND_BACK = 0x408;
|
||||
gl.FRONT_FACE = 0xb46;
|
||||
gl.FUNC_ADD = 0x8006;
|
||||
gl.FUNC_REVERSE_SUBTRACT = 0x800b;
|
||||
gl.FUNC_SUBTRACT = 0x800a;
|
||||
gl.GENERATE_MIPMAP_HINT = 0x8192;
|
||||
gl.GEQUAL = 0x206;
|
||||
gl.GPU_OPTIMIZED_QCOM = 0x8fb2;
|
||||
gl.GREATER = 0x204;
|
||||
gl.GREEN_BITS = 0xd53;
|
||||
gl.GUILTY_CONTEXT_RESET_EXT = 0x8253;
|
||||
gl.HALF_FLOAT_OES = 0x8d61;
|
||||
gl.HIGH_FLOAT = 0x8df2;
|
||||
gl.HIGH_INT = 0x8df5;
|
||||
gl.IMG_multisampled_render_to_texture = 0x1;
|
||||
gl.IMG_program_binary = 0x1;
|
||||
gl.IMG_read_format = 0x1;
|
||||
gl.IMG_shader_binary = 0x1;
|
||||
gl.IMG_texture_compression_pvrtc = 0x1;
|
||||
gl.IMG_texture_compression_pvrtc2 = 0x1;
|
||||
gl.IMPLEMENTATION_COLOR_READ_FORMAT = 0x8b9b;
|
||||
gl.IMPLEMENTATION_COLOR_READ_TYPE = 0x8b9a;
|
||||
gl.INCR = 0x1e02;
|
||||
gl.INCR_WRAP = 0x8507;
|
||||
gl.INFO_LOG_LENGTH = 0x8b84;
|
||||
gl.INNOCENT_CONTEXT_RESET_EXT = 0x8254;
|
||||
gl.INT = 0x1404;
|
||||
gl.INT_10_10_10_2_OES = 0x8df7;
|
||||
gl.INT_VEC2 = 0x8b53;
|
||||
gl.INT_VEC3 = 0x8b54;
|
||||
gl.INT_VEC4 = 0x8b55;
|
||||
gl.INVALID_ENUM = 0x500;
|
||||
gl.INVALID_FRAMEBUFFER_OPERATION = 0x506;
|
||||
gl.INVALID_OPERATION = 0x502;
|
||||
gl.INVALID_VALUE = 0x501;
|
||||
gl.INVERT = 0x150a;
|
||||
gl.KEEP = 0x1e00;
|
||||
gl.KHR_debug = 0x1;
|
||||
gl.KHR_texture_compression_astc_ldr = 0x1;
|
||||
gl.LEFT = 0x0406;
|
||||
gl.LEQUAL = 0x203;
|
||||
gl.LESS = 0x201;
|
||||
gl.LINEAR = 0x2601;
|
||||
gl.LINEAR_MIPMAP_LINEAR = 0x2703;
|
||||
gl.LINEAR_MIPMAP_NEAREST = 0x2701;
|
||||
gl.LINES = 0x1;
|
||||
gl.LINE_LOOP = 0x2;
|
||||
gl.LINE_STRIP = 0x3;
|
||||
gl.LINE_WIDTH = 0xb21;
|
||||
gl.LINK_STATUS = 0x8b82;
|
||||
gl.LOSE_CONTEXT_ON_RESET_EXT = 0x8252;
|
||||
gl.LOW_FLOAT = 0x8df0;
|
||||
gl.LOW_INT = 0x8df3;
|
||||
gl.LUMINANCE = 0x1909;
|
||||
gl.LUMINANCE16F_EXT = 0x881e;
|
||||
gl.LUMINANCE32F_EXT = 0x8818;
|
||||
gl.LUMINANCE4_ALPHA4_OES = 0x8043;
|
||||
gl.LUMINANCE8_ALPHA8_EXT = 0x8045;
|
||||
gl.LUMINANCE8_ALPHA8_OES = 0x8045;
|
||||
gl.LUMINANCE8_EXT = 0x8040;
|
||||
gl.LUMINANCE8_OES = 0x8040;
|
||||
gl.LUMINANCE_ALPHA = 0x190a;
|
||||
gl.LUMINANCE_ALPHA16F_EXT = 0x881f;
|
||||
gl.LUMINANCE_ALPHA32F_EXT = 0x8819;
|
||||
gl.MALI_PROGRAM_BINARY_ARM = 0x8f61;
|
||||
gl.MALI_SHADER_BINARY_ARM = 0x8f60;
|
||||
gl.MAP_FLUSH_EXPLICIT_BIT_EXT = 0x10;
|
||||
gl.MAP_INVALIDATE_BUFFER_BIT_EXT = 0x8;
|
||||
gl.MAP_INVALIDATE_RANGE_BIT_EXT = 0x4;
|
||||
gl.MAP_READ_BIT_EXT = 0x1;
|
||||
gl.MAP_UNSYNCHRONIZED_BIT_EXT = 0x20;
|
||||
gl.MAP_WRITE_BIT_EXT = 0x2;
|
||||
gl.MAX_3D_TEXTURE_SIZE_OES = 0x8073;
|
||||
gl.MAX_COLOR_ATTACHMENTS_NV = 0x8cdf;
|
||||
gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8b4d;
|
||||
gl.MAX_CUBE_MAP_TEXTURE_SIZE = 0x851c;
|
||||
gl.MAX_DEBUG_GROUP_STACK_DEPTH = 0x826c;
|
||||
gl.MAX_DEBUG_LOGGED_MESSAGES = 0x9144;
|
||||
gl.MAX_DEBUG_MESSAGE_LENGTH = 0x9143;
|
||||
gl.MAX_DRAW_BUFFERS_NV = 0x8824;
|
||||
gl.MAX_EXT = 0x8008;
|
||||
gl.MAX_FRAGMENT_UNIFORM_VECTORS = 0x8dfd;
|
||||
gl.MAX_LABEL_LENGTH = 0x82e8;
|
||||
gl.MAX_MULTIVIEW_BUFFERS_EXT = 0x90f2;
|
||||
gl.MAX_RENDERBUFFER_SIZE = 0x84e8;
|
||||
gl.MAX_SAMPLES_ANGLE = 0x8d57;
|
||||
gl.MAX_SAMPLES_APPLE = 0x8d57;
|
||||
gl.MAX_SAMPLES_EXT = 0x8d57;
|
||||
gl.MAX_SAMPLES_IMG = 0x9135;
|
||||
gl.MAX_SAMPLES_NV = 0x8d57;
|
||||
gl.MAX_SERVER_WAIT_TIMEOUT_APPLE = 0x9111;
|
||||
gl.MAX_TEXTURE_IMAGE_UNITS = 0x8872;
|
||||
gl.MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84ff;
|
||||
gl.MAX_TEXTURE_SIZE = 0xd33;
|
||||
gl.MAX_VARYING_VECTORS = 0x8dfc;
|
||||
gl.MAX_VERTEX_ATTRIBS = 0x8869;
|
||||
gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8b4c;
|
||||
gl.MAX_VERTEX_UNIFORM_VECTORS = 0x8dfb;
|
||||
gl.MAX_VIEWPORT_DIMS = 0xd3a;
|
||||
gl.MEDIUM_FLOAT = 0x8df1;
|
||||
gl.MEDIUM_INT = 0x8df4;
|
||||
gl.MIN_EXT = 0x8007;
|
||||
gl.MIRRORED_REPEAT = 0x8370;
|
||||
gl.MULTISAMPLE_BUFFER_BIT0_QCOM = 0x1000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT1_QCOM = 0x2000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT2_QCOM = 0x4000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT3_QCOM = 0x8000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT4_QCOM = 0x10000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT5_QCOM = 0x20000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT6_QCOM = 0x40000000;
|
||||
gl.MULTISAMPLE_BUFFER_BIT7_QCOM = 0x80000000;
|
||||
gl.MULTIVIEW_EXT = 0x90f1;
|
||||
gl.NEAREST = 0x2600;
|
||||
gl.NEAREST_MIPMAP_LINEAR = 0x2702;
|
||||
gl.NEAREST_MIPMAP_NEAREST = 0x2700;
|
||||
gl.NEVER = 0x200;
|
||||
gl.NICEST = 0x1102;
|
||||
gl.NONE = 0x0;
|
||||
gl.NOTEQUAL = 0x205;
|
||||
gl.NO_ERROR = 0x0;
|
||||
gl.NO_RESET_NOTIFICATION_EXT = 0x8261;
|
||||
gl.NUM_COMPRESSED_TEXTURE_FORMATS = 0x86a2;
|
||||
gl.NUM_PROGRAM_BINARY_FORMATS_OES = 0x87fe;
|
||||
gl.NUM_SHADER_BINARY_FORMATS = 0x8df9;
|
||||
gl.NV_coverage_sample = 0x1;
|
||||
gl.NV_depth_nonlinear = 0x1;
|
||||
gl.NV_draw_buffers = 0x1;
|
||||
gl.NV_draw_instanced = 0x1;
|
||||
gl.NV_fbo_color_attachments = 0x1;
|
||||
gl.NV_fence = 0x1;
|
||||
gl.NV_framebuffer_blit = 0x1;
|
||||
gl.NV_framebuffer_multisample = 0x1;
|
||||
gl.NV_generate_mipmap_sRGB = 0x1;
|
||||
gl.NV_instanced_arrays = 0x1;
|
||||
gl.NV_read_buffer = 0x1;
|
||||
gl.NV_read_buffer_front = 0x1;
|
||||
gl.NV_read_depth = 0x1;
|
||||
gl.NV_read_depth_stencil = 0x1;
|
||||
gl.NV_read_stencil = 0x1;
|
||||
gl.NV_sRGB_formats = 0x1;
|
||||
gl.NV_shadow_samplers_array = 0x1;
|
||||
gl.NV_shadow_samplers_cube = 0x1;
|
||||
gl.NV_texture_border_clamp = 0x1;
|
||||
gl.NV_texture_compression_s3tc_update = 0x1;
|
||||
gl.NV_texture_npot_2D_mipmap = 0x1;
|
||||
gl.OBJECT_TYPE_APPLE = 0x9112;
|
||||
gl.OES_EGL_image = 0x1;
|
||||
gl.OES_EGL_image_external = 0x1;
|
||||
gl.OES_compressed_ETC1_RGB8_texture = 0x1;
|
||||
gl.OES_compressed_paletted_texture = 0x1;
|
||||
gl.OES_depth24 = 0x1;
|
||||
gl.OES_depth32 = 0x1;
|
||||
gl.OES_depth_texture = 0x1;
|
||||
gl.OES_element_index_uint = 0x1;
|
||||
gl.OES_fbo_render_mipmap = 0x1;
|
||||
gl.OES_fragment_precision_high = 0x1;
|
||||
gl.OES_get_program_binary = 0x1;
|
||||
gl.OES_mapbuffer = 0x1;
|
||||
gl.OES_packed_depth_stencil = 0x1;
|
||||
gl.OES_required_internalformat = 0x1;
|
||||
gl.OES_rgb8_rgba8 = 0x1;
|
||||
gl.OES_standard_derivatives = 0x1;
|
||||
gl.OES_stencil1 = 0x1;
|
||||
gl.OES_stencil4 = 0x1;
|
||||
gl.OES_surfaceless_context = 0x1;
|
||||
gl.OES_texture_3D = 0x1;
|
||||
gl.OES_texture_float = 0x1;
|
||||
gl.OES_texture_float_linear = 0x1;
|
||||
gl.OES_texture_half_float = 0x1;
|
||||
gl.OES_texture_half_float_linear = 0x1;
|
||||
gl.OES_texture_npot = 0x1;
|
||||
gl.OES_vertex_array_object = 0x1;
|
||||
gl.OES_vertex_half_float = 0x1;
|
||||
gl.OES_vertex_type_10_10_10_2 = 0x1;
|
||||
gl.ONE = 0x1;
|
||||
gl.ONE_MINUS_CONSTANT_ALPHA = 0x8004;
|
||||
gl.ONE_MINUS_CONSTANT_COLOR = 0x8002;
|
||||
gl.ONE_MINUS_DST_ALPHA = 0x305;
|
||||
gl.ONE_MINUS_DST_COLOR = 0x307;
|
||||
gl.ONE_MINUS_SRC_ALPHA = 0x303;
|
||||
gl.ONE_MINUS_SRC_COLOR = 0x301;
|
||||
gl.OUT_OF_MEMORY = 0x505;
|
||||
gl.PACK_ALIGNMENT = 0xd05;
|
||||
gl.PACK_REVERSE_ROW_ORDER_ANGLE = 0x93a4;
|
||||
gl.PALETTE4_R5_G6_B5_OES = 0x8b92;
|
||||
gl.PALETTE4_RGB5_A1_OES = 0x8b94;
|
||||
gl.PALETTE4_RGB8_OES = 0x8b90;
|
||||
gl.PALETTE4_RGBA4_OES = 0x8b93;
|
||||
gl.PALETTE4_RGBA8_OES = 0x8b91;
|
||||
gl.PALETTE8_R5_G6_B5_OES = 0x8b97;
|
||||
gl.PALETTE8_RGB5_A1_OES = 0x8b99;
|
||||
gl.PALETTE8_RGB8_OES = 0x8b95;
|
||||
gl.PALETTE8_RGBA4_OES = 0x8b98;
|
||||
gl.PALETTE8_RGBA8_OES = 0x8b96;
|
||||
gl.PERCENTAGE_AMD = 0x8bc3;
|
||||
gl.PERFMON_GLOBAL_MODE_QCOM = 0x8fa0;
|
||||
gl.PERFMON_RESULT_AMD = 0x8bc6;
|
||||
gl.PERFMON_RESULT_AVAILABLE_AMD = 0x8bc4;
|
||||
gl.PERFMON_RESULT_SIZE_AMD = 0x8bc5;
|
||||
gl.POINTS = 0x0;
|
||||
gl.POLYGON_OFFSET_FACTOR = 0x8038;
|
||||
gl.POLYGON_OFFSET_FILL = 0x8037;
|
||||
gl.POLYGON_OFFSET_UNITS = 0x2a00;
|
||||
gl.PROGRAM = 0x82e2;
|
||||
gl.PROGRAM_BINARY_ANGLE = 0x93a6;
|
||||
gl.PROGRAM_BINARY_FORMATS_OES = 0x87ff;
|
||||
gl.PROGRAM_BINARY_LENGTH_OES = 0x8741;
|
||||
gl.PROGRAM_OBJECT_EXT = 0x8b40;
|
||||
gl.PROGRAM_PIPELINE_BINDING_EXT = 0x825a;
|
||||
gl.PROGRAM_PIPELINE_OBJECT_EXT = 0x8a4f;
|
||||
gl.PROGRAM_SEPARABLE_EXT = 0x8258;
|
||||
gl.QCOM_alpha_test = 0x1;
|
||||
gl.QCOM_binning_control = 0x1;
|
||||
gl.QCOM_driver_control = 0x1;
|
||||
gl.QCOM_extended_get = 0x1;
|
||||
gl.QCOM_extended_get2 = 0x1;
|
||||
gl.QCOM_perfmon_global_mode = 0x1;
|
||||
gl.QCOM_tiled_rendering = 0x1;
|
||||
gl.QCOM_writeonly_rendering = 0x1;
|
||||
gl.QUERY = 0x82e3;
|
||||
gl.QUERY_OBJECT_EXT = 0x9153;
|
||||
gl.QUERY_RESULT_AVAILABLE_EXT = 0x8867;
|
||||
gl.QUERY_RESULT_EXT = 0x8866;
|
||||
gl.R16F_EXT = 0x822d;
|
||||
gl.R32F_EXT = 0x822e;
|
||||
gl.R8_EXT = 0x8229;
|
||||
gl.READ_BUFFER_EXT = 0xc02;
|
||||
gl.READ_BUFFER_NV = 0xc02;
|
||||
gl.READ_FRAMEBUFFER_ANGLE = 0x8ca8;
|
||||
gl.READ_FRAMEBUFFER_APPLE = 0x8ca8;
|
||||
gl.READ_FRAMEBUFFER_BINDING_ANGLE = 0x8caa;
|
||||
gl.READ_FRAMEBUFFER_BINDING_APPLE = 0x8caa;
|
||||
gl.READ_FRAMEBUFFER_BINDING_NV = 0x8caa;
|
||||
gl.READ_FRAMEBUFFER_NV = 0x8ca8;
|
||||
gl.RED_BITS = 0xd52;
|
||||
gl.RED_EXT = 0x1903;
|
||||
gl.RENDERBUFFER = 0x8d41;
|
||||
gl.RENDERBUFFER_ALPHA_SIZE = 0x8d53;
|
||||
gl.RENDERBUFFER_BINDING = 0x8ca7;
|
||||
gl.RENDERBUFFER_BLUE_SIZE = 0x8d52;
|
||||
gl.RENDERBUFFER_DEPTH_SIZE = 0x8d54;
|
||||
gl.RENDERBUFFER_GREEN_SIZE = 0x8d51;
|
||||
gl.RENDERBUFFER_HEIGHT = 0x8d43;
|
||||
gl.RENDERBUFFER_INTERNAL_FORMAT = 0x8d44;
|
||||
gl.RENDERBUFFER_RED_SIZE = 0x8d50;
|
||||
gl.RENDERBUFFER_SAMPLES_ANGLE = 0x8cab;
|
||||
gl.RENDERBUFFER_SAMPLES_APPLE = 0x8cab;
|
||||
gl.RENDERBUFFER_SAMPLES_EXT = 0x8cab;
|
||||
gl.RENDERBUFFER_SAMPLES_IMG = 0x9133;
|
||||
gl.RENDERBUFFER_SAMPLES_NV = 0x8cab;
|
||||
gl.RENDERBUFFER_STENCIL_SIZE = 0x8d55;
|
||||
gl.RENDERBUFFER_WIDTH = 0x8d42;
|
||||
gl.RENDERER = 0x1f01;
|
||||
gl.RENDER_DIRECT_TO_FRAMEBUFFER_QCOM = 0x8fb3;
|
||||
gl.REPEAT = 0x2901;
|
||||
gl.REPLACE = 0x1e01;
|
||||
gl.REQUIRED_TEXTURE_IMAGE_UNITS_OES = 0x8d68;
|
||||
gl.RESET_NOTIFICATION_STRATEGY_EXT = 0x8256;
|
||||
gl.RG16F_EXT = 0x822f;
|
||||
gl.RG32F_EXT = 0x8230;
|
||||
gl.RG8_EXT = 0x822b;
|
||||
gl.RGB = 0x1907;
|
||||
gl.RGB10_A2_EXT = 0x8059;
|
||||
gl.RGB10_EXT = 0x8052;
|
||||
gl.RGB16F_EXT = 0x881b;
|
||||
gl.RGB32F_EXT = 0x8815;
|
||||
gl.RGB565 = 0x8d62;
|
||||
gl.RGB565_OES = 0x8d62;
|
||||
gl.RGB5_A1 = 0x8057;
|
||||
gl.RGB5_A1_OES = 0x8057;
|
||||
gl.RGB8_OES = 0x8051;
|
||||
gl.RGBA = 0x1908;
|
||||
gl.RGBA16F_EXT = 0x881a;
|
||||
gl.RGBA32F_EXT = 0x8814;
|
||||
gl.RGBA4 = 0x8056;
|
||||
gl.RGBA4_OES = 0x8056;
|
||||
gl.RGBA8_OES = 0x8058;
|
||||
gl.RGB_422_APPLE = 0x8a1f;
|
||||
gl.RG_EXT = 0x8227;
|
||||
gl.RIGHT = 0x0407;
|
||||
gl.SAMPLER = 0x82e6;
|
||||
gl.SAMPLER_2D = 0x8b5e;
|
||||
gl.SAMPLER_2D_ARRAY_SHADOW_NV = 0x8dc4;
|
||||
gl.SAMPLER_2D_SHADOW_EXT = 0x8b62;
|
||||
gl.SAMPLER_3D_OES = 0x8b5f;
|
||||
gl.SAMPLER_CUBE = 0x8b60;
|
||||
gl.SAMPLER_CUBE_SHADOW_NV = 0x8dc5;
|
||||
gl.SAMPLER_EXTERNAL_OES = 0x8d66;
|
||||
gl.SAMPLES = 0x80a9;
|
||||
gl.SAMPLE_ALPHA_TO_COVERAGE = 0x809e;
|
||||
gl.SAMPLE_BUFFERS = 0x80a8;
|
||||
gl.SAMPLE_COVERAGE = 0x80a0;
|
||||
gl.SAMPLE_COVERAGE_INVERT = 0x80ab;
|
||||
gl.SAMPLE_COVERAGE_VALUE = 0x80aa;
|
||||
gl.SCISSOR_BOX = 0xc10;
|
||||
gl.SCISSOR_TEST = 0xc11;
|
||||
gl.SGX_BINARY_IMG = 0x8c0a;
|
||||
gl.SGX_PROGRAM_BINARY_IMG = 0x9130;
|
||||
gl.SHADER = 0x82e1;
|
||||
gl.SHADER_BINARY_DMP = 0x9250;
|
||||
gl.SHADER_BINARY_FORMATS = 0x8df8;
|
||||
gl.SHADER_BINARY_VIV = 0x8fc4;
|
||||
gl.SHADER_COMPILER = 0x8dfa;
|
||||
gl.SHADER_OBJECT_EXT = 0x8b48;
|
||||
gl.SHADER_SOURCE_LENGTH = 0x8b88;
|
||||
gl.SHADER_TYPE = 0x8b4f;
|
||||
gl.SHADING_LANGUAGE_VERSION = 0x8b8c;
|
||||
gl.SHORT = 0x1402;
|
||||
gl.SIGNALED_APPLE = 0x9119;
|
||||
gl.SLUMINANCE8_ALPHA8_NV = 0x8c45;
|
||||
gl.SLUMINANCE8_NV = 0x8c47;
|
||||
gl.SLUMINANCE_ALPHA_NV = 0x8c44;
|
||||
gl.SLUMINANCE_NV = 0x8c46;
|
||||
gl.SRC_ALPHA = 0x302;
|
||||
gl.SRC_ALPHA_SATURATE = 0x308;
|
||||
gl.SRC_COLOR = 0x300;
|
||||
gl.SRGB8_ALPHA8_EXT = 0x8c43;
|
||||
gl.SRGB8_NV = 0x8c41;
|
||||
gl.SRGB_ALPHA_EXT = 0x8c42;
|
||||
gl.SRGB_EXT = 0x8c40;
|
||||
gl.STACK_OVERFLOW = 0x503;
|
||||
gl.STACK_UNDERFLOW = 0x504;
|
||||
gl.STATE_RESTORE = 0x8bdc;
|
||||
gl.STATIC_DRAW = 0x88e4;
|
||||
gl.STENCIL_ATTACHMENT = 0x8d20;
|
||||
gl.STENCIL_BACK_FAIL = 0x8801;
|
||||
gl.STENCIL_BACK_FUNC = 0x8800;
|
||||
gl.STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802;
|
||||
gl.STENCIL_BACK_PASS_DEPTH_PASS = 0x8803;
|
||||
gl.STENCIL_BACK_REF = 0x8ca3;
|
||||
gl.STENCIL_BACK_VALUE_MASK = 0x8ca4;
|
||||
gl.STENCIL_BACK_WRITEMASK = 0x8ca5;
|
||||
gl.STENCIL_BITS = 0xd57;
|
||||
gl.STENCIL_BUFFER_BIT = 0x400;
|
||||
gl.STENCIL_BUFFER_BIT0_QCOM = 0x10000;
|
||||
gl.STENCIL_BUFFER_BIT1_QCOM = 0x20000;
|
||||
gl.STENCIL_BUFFER_BIT2_QCOM = 0x40000;
|
||||
gl.STENCIL_BUFFER_BIT3_QCOM = 0x80000;
|
||||
gl.STENCIL_BUFFER_BIT4_QCOM = 0x100000;
|
||||
gl.STENCIL_BUFFER_BIT5_QCOM = 0x200000;
|
||||
gl.STENCIL_BUFFER_BIT6_QCOM = 0x400000;
|
||||
gl.STENCIL_BUFFER_BIT7_QCOM = 0x800000;
|
||||
gl.STENCIL_CLEAR_VALUE = 0xb91;
|
||||
gl.STENCIL_EXT = 0x1802;
|
||||
gl.STENCIL_FAIL = 0xb94;
|
||||
gl.STENCIL_FUNC = 0xb92;
|
||||
gl.STENCIL_INDEX1_OES = 0x8d46;
|
||||
gl.STENCIL_INDEX4_OES = 0x8d47;
|
||||
gl.STENCIL_INDEX8 = 0x8d48;
|
||||
gl.STENCIL_PASS_DEPTH_FAIL = 0xb95;
|
||||
gl.STENCIL_PASS_DEPTH_PASS = 0xb96;
|
||||
gl.STENCIL_REF = 0xb97;
|
||||
gl.STENCIL_TEST = 0xb90;
|
||||
gl.STENCIL_VALUE_MASK = 0xb93;
|
||||
gl.STENCIL_WRITEMASK = 0xb98;
|
||||
gl.STREAM_DRAW = 0x88e0;
|
||||
gl.SUBPIXEL_BITS = 0xd50;
|
||||
gl.SYNC_CONDITION_APPLE = 0x9113;
|
||||
gl.SYNC_FENCE_APPLE = 0x9116;
|
||||
gl.SYNC_FLAGS_APPLE = 0x9115;
|
||||
gl.SYNC_FLUSH_COMMANDS_BIT_APPLE = 0x1;
|
||||
gl.SYNC_GPU_COMMANDS_COMPLETE_APPLE = 0x9117;
|
||||
gl.SYNC_OBJECT_APPLE = 0x8a53;
|
||||
gl.SYNC_STATUS_APPLE = 0x9114;
|
||||
gl.TEXTURE = 0x1702;
|
||||
gl.TEXTURE0 = 0x84c0;
|
||||
gl.TEXTURE1 = 0x84c1;
|
||||
gl.TEXTURE10 = 0x84ca;
|
||||
gl.TEXTURE11 = 0x84cb;
|
||||
gl.TEXTURE12 = 0x84cc;
|
||||
gl.TEXTURE13 = 0x84cd;
|
||||
gl.TEXTURE14 = 0x84ce;
|
||||
gl.TEXTURE15 = 0x84cf;
|
||||
gl.TEXTURE16 = 0x84d0;
|
||||
gl.TEXTURE17 = 0x84d1;
|
||||
gl.TEXTURE18 = 0x84d2;
|
||||
gl.TEXTURE19 = 0x84d3;
|
||||
gl.TEXTURE2 = 0x84c2;
|
||||
gl.TEXTURE20 = 0x84d4;
|
||||
gl.TEXTURE21 = 0x84d5;
|
||||
gl.TEXTURE22 = 0x84d6;
|
||||
gl.TEXTURE23 = 0x84d7;
|
||||
gl.TEXTURE24 = 0x84d8;
|
||||
gl.TEXTURE25 = 0x84d9;
|
||||
gl.TEXTURE26 = 0x84da;
|
||||
gl.TEXTURE27 = 0x84db;
|
||||
gl.TEXTURE28 = 0x84dc;
|
||||
gl.TEXTURE29 = 0x84dd;
|
||||
gl.TEXTURE3 = 0x84c3;
|
||||
gl.TEXTURE30 = 0x84de;
|
||||
gl.TEXTURE31 = 0x84df;
|
||||
gl.TEXTURE4 = 0x84c4;
|
||||
gl.TEXTURE5 = 0x84c5;
|
||||
gl.TEXTURE6 = 0x84c6;
|
||||
gl.TEXTURE7 = 0x84c7;
|
||||
gl.TEXTURE8 = 0x84c8;
|
||||
gl.TEXTURE9 = 0x84c9;
|
||||
gl.TEXTURE_2D = 0xde1;
|
||||
gl.TEXTURE_3D_OES = 0x806f;
|
||||
gl.TEXTURE_BINDING_2D = 0x8069;
|
||||
gl.TEXTURE_BINDING_3D_OES = 0x806a;
|
||||
gl.TEXTURE_BINDING_CUBE_MAP = 0x8514;
|
||||
gl.TEXTURE_BINDING_EXTERNAL_OES = 0x8d67;
|
||||
gl.TEXTURE_BORDER_COLOR_NV = 0x1004;
|
||||
gl.TEXTURE_COMPARE_FUNC_EXT = 0x884d;
|
||||
gl.TEXTURE_COMPARE_MODE_EXT = 0x884c;
|
||||
gl.TEXTURE_CUBE_MAP = 0x8513;
|
||||
gl.TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
|
||||
gl.TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
|
||||
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
|
||||
gl.TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
|
||||
gl.TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
|
||||
gl.TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
|
||||
gl.TEXTURE_DEPTH_QCOM = 0x8bd4;
|
||||
gl.TEXTURE_EXTERNAL_OES = 0x8d65;
|
||||
gl.TEXTURE_FORMAT_QCOM = 0x8bd6;
|
||||
gl.TEXTURE_HEIGHT_QCOM = 0x8bd3;
|
||||
gl.TEXTURE_IMAGE_VALID_QCOM = 0x8bd8;
|
||||
gl.TEXTURE_IMMUTABLE_FORMAT_EXT = 0x912f;
|
||||
gl.TEXTURE_INTERNAL_FORMAT_QCOM = 0x8bd5;
|
||||
gl.TEXTURE_MAG_FILTER = 0x2800;
|
||||
gl.TEXTURE_MAX_ANISOTROPY_EXT = 0x84fe;
|
||||
gl.TEXTURE_MAX_LEVEL_APPLE = 0x813d;
|
||||
gl.TEXTURE_MIN_FILTER = 0x2801;
|
||||
gl.TEXTURE_NUM_LEVELS_QCOM = 0x8bd9;
|
||||
gl.TEXTURE_OBJECT_VALID_QCOM = 0x8bdb;
|
||||
gl.TEXTURE_SAMPLES_IMG = 0x9136;
|
||||
gl.TEXTURE_TARGET_QCOM = 0x8bda;
|
||||
gl.TEXTURE_TYPE_QCOM = 0x8bd7;
|
||||
gl.TEXTURE_USAGE_ANGLE = 0x93a2;
|
||||
gl.TEXTURE_WIDTH_QCOM = 0x8bd2;
|
||||
gl.TEXTURE_WRAP_R_OES = 0x8072;
|
||||
gl.TEXTURE_WRAP_S = 0x2802;
|
||||
gl.TEXTURE_WRAP_T = 0x2803;
|
||||
gl.TIMEOUT_EXPIRED_APPLE = 0x911b;
|
||||
gl.TIMEOUT_IGNORED_APPLE = 0xffffffffffffffff;
|
||||
gl.TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE = 0x93a0;
|
||||
gl.TRIANGLES = 0x4;
|
||||
gl.TRIANGLE_FAN = 0x6;
|
||||
gl.TRIANGLE_STRIP = 0x5;
|
||||
gl.TRUE = 0x1;
|
||||
gl.UNKNOWN_CONTEXT_RESET_EXT = 0x8255;
|
||||
gl.UNPACK_ALIGNMENT = 0xcf5;
|
||||
gl.UNPACK_ROW_LENGTH = 0xcf2;
|
||||
gl.UNPACK_SKIP_PIXELS = 0xcf4;
|
||||
gl.UNPACK_SKIP_ROWS = 0xcf3;
|
||||
gl.UNSIGNALED_APPLE = 0x9118;
|
||||
gl.UNSIGNED_BYTE = 0x1401;
|
||||
gl.UNSIGNED_INT = 0x1405;
|
||||
gl.UNSIGNED_INT64_AMD = 0x8bc2;
|
||||
gl.UNSIGNED_INT_10_10_10_2_OES = 0x8df6;
|
||||
gl.UNSIGNED_INT_24_8_OES = 0x84fa;
|
||||
gl.UNSIGNED_INT_2_10_10_10_REV_EXT = 0x8368;
|
||||
gl.UNSIGNED_NORMALIZED_EXT = 0x8c17;
|
||||
gl.UNSIGNED_SHORT = 0x1403;
|
||||
gl.UNSIGNED_SHORT_1_5_5_5_REV_EXT = 0x8366;
|
||||
gl.UNSIGNED_SHORT_4_4_4_4 = 0x8033;
|
||||
gl.UNSIGNED_SHORT_4_4_4_4_REV_EXT = 0x8365;
|
||||
gl.UNSIGNED_SHORT_4_4_4_4_REV_IMG = 0x8365;
|
||||
gl.UNSIGNED_SHORT_5_5_5_1 = 0x8034;
|
||||
gl.UNSIGNED_SHORT_5_6_5 = 0x8363;
|
||||
gl.UNSIGNED_SHORT_8_8_APPLE = 0x85ba;
|
||||
gl.UNSIGNED_SHORT_8_8_REV_APPLE = 0x85bb;
|
||||
gl.VALIDATE_STATUS = 0x8b83;
|
||||
gl.VENDOR = 0x1f00;
|
||||
gl.VERSION = 0x1f02;
|
||||
gl.VERTEX_ARRAY_BINDING_OES = 0x85b5;
|
||||
gl.VERTEX_ARRAY_OBJECT_EXT = 0x9154;
|
||||
gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889f;
|
||||
gl.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88fe;
|
||||
gl.VERTEX_ATTRIB_ARRAY_DIVISOR_NV = 0x88fe;
|
||||
gl.VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622;
|
||||
gl.VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886a;
|
||||
gl.VERTEX_ATTRIB_ARRAY_POINTER = 0x8645;
|
||||
gl.VERTEX_ATTRIB_ARRAY_SIZE = 0x8623;
|
||||
gl.VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624;
|
||||
gl.VERTEX_ATTRIB_ARRAY_TYPE = 0x8625;
|
||||
gl.VERTEX_SHADER = 0x8b31;
|
||||
gl.VERTEX_SHADER_BIT_EXT = 0x1;
|
||||
gl.VIEWPORT = 0xba2;
|
||||
gl.VIV_shader_binary = 0x1;
|
||||
gl.WAIT_FAILED_APPLE = 0x911d;
|
||||
gl.WRITEONLY_RENDERING_QCOM = 0x8823;
|
||||
gl.WRITE_ONLY_OES = 0x88b9;
|
||||
gl.Z400_BINARY_AMD = 0x8740;
|
||||
gl.ZERO = 0x0;
|
||||
|
||||
gl.UNPACK_FLIP_Y_WEBGL = 0x9240;
|
||||
gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241;
|
||||
gl.CONTEXT_LOST_WEBGL = 0x9242;
|
||||
gl.UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
|
||||
gl.BROWSER_DEFAULT_WEBGL = 0x9244;
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2016 Chukong Technologies Inc.
|
||||
* Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Prepare JSB environment
|
||||
window.cc = window.cc || {};
|
||||
/**
|
||||
* @namespace jsb
|
||||
* @name jsb
|
||||
*/
|
||||
window.jsb = window.jsb || {};
|
||||
|
||||
/**
|
||||
* Common getter setter configuration function
|
||||
* @function
|
||||
* @param {Object} proto A class prototype or an object to config
|
||||
* @param {String} prop Property name
|
||||
* @param {function} getter Getter function for the property
|
||||
* @param {function} setter Setter function for the property
|
||||
*/
|
||||
cc.defineGetterSetter = function (proto, prop, getter, setter){
|
||||
let desc = { enumerable: false, configurable: true };
|
||||
getter && (desc.get = getter);
|
||||
setter && (desc.set = setter);
|
||||
Object.defineProperty(proto, prop, desc);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new object and copy all properties in an exist object to the new object
|
||||
* @method clone
|
||||
* @param {Object|Array} obj - The source object
|
||||
* @return {Array|Object} The created object
|
||||
*/
|
||||
cc.clone = function (obj) {
|
||||
// Cloning is better if the new object is having the same prototype chain
|
||||
// as the copied obj (or otherwise, the cloned object is certainly going to
|
||||
// have a different hidden class). Play with C1/C2 of the
|
||||
// PerformanceVirtualMachineTests suite to see how this makes an impact
|
||||
// under extreme conditions.
|
||||
//
|
||||
// Object.create(Object.getPrototypeOf(obj)) doesn't work well because the
|
||||
// prototype lacks a link to the constructor (Carakan, V8) so the new
|
||||
// object wouldn't have the hidden class that's associated with the
|
||||
// constructor (also, for whatever reasons, utilizing
|
||||
// Object.create(Object.getPrototypeOf(obj)) + Object.defineProperty is even
|
||||
// slower than the original in V8). Therefore, we call the constructor, but
|
||||
// there is a big caveat - it is possible that the this.init() in the
|
||||
// constructor would throw with no argument. It is also possible that a
|
||||
// derived class forgets to set "constructor" on the prototype. We ignore
|
||||
// these possibities for and the ultimate solution is a standardized
|
||||
// Object.clone(<object>).
|
||||
let newObj = (obj.constructor) ? new obj.constructor : {};
|
||||
|
||||
// Assuming that the constuctor above initialized all properies on obj, the
|
||||
// following keyed assignments won't turn newObj into dictionary mode
|
||||
// becasue they're not *appending new properties* but *assigning existing
|
||||
// ones* (note that appending indexed properties is another story). See
|
||||
// CCClass.js for a link to the devils when the assumption fails.
|
||||
for (let key in obj) {
|
||||
let copy = obj[key];
|
||||
// Beware that typeof null == "object" !
|
||||
if (typeof copy === "object" &&
|
||||
copy &&
|
||||
!(copy instanceof _ccsg.Node) &&
|
||||
(CC_JSB || !(copy instanceof HTMLElement))) {
|
||||
newObj[key] = cc.clone(copy);
|
||||
} else {
|
||||
newObj[key] = copy;
|
||||
}
|
||||
}
|
||||
return newObj;
|
||||
};
|
||||
|
||||
|
||||
let ClassManager = {
|
||||
id : (0|(Math.random()*998)),
|
||||
|
||||
instanceId : (0|(Math.random()*998)),
|
||||
|
||||
getNewID : function(){
|
||||
return this.id++;
|
||||
},
|
||||
|
||||
getNewInstanceId : function(){
|
||||
return this.instanceId++;
|
||||
}
|
||||
};
|
||||
//
|
||||
// 2) Using "extend" subclassing
|
||||
// Simple JavaScript Inheritance By John Resig http://ejohn.org/
|
||||
//
|
||||
cc.Class = function(){};
|
||||
cc.Class.extend = function (prop) {
|
||||
let _super = this.prototype,
|
||||
prototype, Class, classId,
|
||||
className = prop._className || "",
|
||||
name, desc;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
prototype = Object.create(_super);
|
||||
initializing = false;
|
||||
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function (name, fn) {
|
||||
return function () {
|
||||
let tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
let ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
|
||||
Class = function () {
|
||||
if (!initializing) {
|
||||
this.__instanceId = ClassManager.getNewInstanceId();
|
||||
if (this.ctor) {
|
||||
switch (arguments.length) {
|
||||
case 0: this.ctor(); break;
|
||||
case 1: this.ctor(arguments[0]); break;
|
||||
case 2: this.ctor(arguments[0], arguments[1]); break;
|
||||
case 3: this.ctor(arguments[0], arguments[1], arguments[2]); break;
|
||||
case 4: this.ctor(arguments[0], arguments[1], arguments[2], arguments[3]); break;
|
||||
case 5: this.ctor(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); break;
|
||||
default: this.ctor.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = cc.Class.extend;
|
||||
|
||||
classId = ClassManager.getNewID();
|
||||
ClassManager[classId] = _super;
|
||||
desc = { writable: true, enumerable: false, configurable: true };
|
||||
Class.id = classId;
|
||||
desc.value = classId;
|
||||
Object.defineProperty(prototype, '__pid', desc);
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
jsb.__obj_ref_id = 0;
|
||||
|
||||
jsb.registerNativeRef = function (owner, target) {
|
||||
if (owner && target && owner !== target) {
|
||||
let targetID = target.__jsb_ref_id;
|
||||
if (targetID === undefined)
|
||||
targetID = target.__jsb_ref_id = jsb.__obj_ref_id++;
|
||||
|
||||
let refs = owner.__nativeRefs;
|
||||
if (!refs) {
|
||||
refs = owner.__nativeRefs = {};
|
||||
}
|
||||
|
||||
refs[targetID] = target;
|
||||
}
|
||||
};
|
||||
|
||||
jsb.unregisterNativeRef = function (owner, target) {
|
||||
if (owner && target && owner !== target) {
|
||||
let targetID = target.__jsb_ref_id;
|
||||
if (targetID === undefined)
|
||||
return;
|
||||
|
||||
let refs = owner.__nativeRefs;
|
||||
if (!refs) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete refs[targetID];
|
||||
}
|
||||
};
|
||||
|
||||
jsb.unregisterAllNativeRefs = function (owner) {
|
||||
if (!owner) return;
|
||||
delete owner.__nativeRefs;
|
||||
};
|
||||
|
||||
jsb.unregisterChildRefsForNode = function (node, recursive) {
|
||||
if (!(node instanceof cc.Node)) return;
|
||||
recursive = !!recursive;
|
||||
let children = node.getChildren(), i, l, child;
|
||||
for (i = 0, l = children.length; i < l; ++i) {
|
||||
child = children[i];
|
||||
jsb.unregisterNativeRef(node, child);
|
||||
if (recursive) {
|
||||
jsb.unregisterChildRefsForNode(child, recursive);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,276 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
function DOMParser(options){
|
||||
this.options = options ||{locator:{}};
|
||||
|
||||
}
|
||||
|
||||
DOMParser.prototype.parseFromString = function(source,mimeType){
|
||||
var options = this.options;
|
||||
var sax = new XMLReader();
|
||||
var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
|
||||
var errorHandler = options.errorHandler;
|
||||
var locator = options.locator;
|
||||
var defaultNSMap = options.xmlns||{};
|
||||
var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
|
||||
var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
|
||||
if(locator){
|
||||
domBuilder.setDocumentLocator(locator)
|
||||
}
|
||||
|
||||
sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
|
||||
sax.domBuilder = options.domBuilder || domBuilder;
|
||||
if(isHTML){
|
||||
defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
|
||||
}
|
||||
defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
|
||||
if(source){
|
||||
sax.parse(source,defaultNSMap,entityMap);
|
||||
}else{
|
||||
sax.errorHandler.error("invalid doc source");
|
||||
}
|
||||
return domBuilder.doc;
|
||||
}
|
||||
function buildErrorHandler(errorImpl,domBuilder,locator){
|
||||
if(!errorImpl){
|
||||
if(domBuilder instanceof DOMHandler){
|
||||
return domBuilder;
|
||||
}
|
||||
errorImpl = domBuilder ;
|
||||
}
|
||||
var errorHandler = {}
|
||||
var isCallback = errorImpl instanceof Function;
|
||||
locator = locator||{}
|
||||
function build(key){
|
||||
var fn = errorImpl[key];
|
||||
if(!fn && isCallback){
|
||||
fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
|
||||
}
|
||||
errorHandler[key] = fn && function(msg){
|
||||
fn('[xmldom '+key+']\t'+msg+_locator(locator));
|
||||
}||function(){};
|
||||
}
|
||||
build('warning');
|
||||
build('error');
|
||||
build('fatalError');
|
||||
return errorHandler;
|
||||
}
|
||||
|
||||
//console.log('#\n\n\n\n\n\n\n####')
|
||||
/**
|
||||
* +ContentHandler+ErrorHandler
|
||||
* +LexicalHandler+EntityResolver2
|
||||
* -DeclHandler-DTDHandler
|
||||
*
|
||||
* DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
|
||||
* DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
|
||||
*/
|
||||
function DOMHandler() {
|
||||
this.cdata = false;
|
||||
}
|
||||
function position(locator,node){
|
||||
node.lineNumber = locator.lineNumber;
|
||||
node.columnNumber = locator.columnNumber;
|
||||
}
|
||||
/**
|
||||
* @see org.xml.sax.ContentHandler#startDocument
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
|
||||
*/
|
||||
DOMHandler.prototype = {
|
||||
startDocument : function() {
|
||||
this.doc = new DOMImplementation().createDocument(null, null, null);
|
||||
if (this.locator) {
|
||||
this.doc.documentURI = this.locator.systemId;
|
||||
}
|
||||
},
|
||||
startElement:function(namespaceURI, localName, qName, attrs) {
|
||||
var doc = this.doc;
|
||||
var el = doc.createElementNS(namespaceURI, qName||localName);
|
||||
var len = attrs.length;
|
||||
appendElement(this, el);
|
||||
this.currentElement = el;
|
||||
|
||||
this.locator && position(this.locator,el)
|
||||
for (var i = 0 ; i < len; i++) {
|
||||
var namespaceURI = attrs.getURI(i);
|
||||
var value = attrs.getValue(i);
|
||||
var qName = attrs.getQName(i);
|
||||
var attr = doc.createAttributeNS(namespaceURI, qName);
|
||||
this.locator &&position(attrs.getLocator(i),attr);
|
||||
attr.value = attr.nodeValue = value;
|
||||
el.setAttributeNode(attr)
|
||||
}
|
||||
},
|
||||
endElement:function(namespaceURI, localName, qName) {
|
||||
var current = this.currentElement
|
||||
var tagName = current.tagName;
|
||||
this.currentElement = current.parentNode;
|
||||
},
|
||||
startPrefixMapping:function(prefix, uri) {
|
||||
},
|
||||
endPrefixMapping:function(prefix) {
|
||||
},
|
||||
processingInstruction:function(target, data) {
|
||||
var ins = this.doc.createProcessingInstruction(target, data);
|
||||
this.locator && position(this.locator,ins)
|
||||
appendElement(this, ins);
|
||||
},
|
||||
ignorableWhitespace:function(ch, start, length) {
|
||||
},
|
||||
characters:function(chars, start, length) {
|
||||
chars = _toString.apply(this,arguments)
|
||||
//console.log(chars)
|
||||
if(chars){
|
||||
if (this.cdata) {
|
||||
var charNode = this.doc.createCDATASection(chars);
|
||||
} else {
|
||||
var charNode = this.doc.createTextNode(chars);
|
||||
}
|
||||
if(this.currentElement){
|
||||
this.currentElement.appendChild(charNode);
|
||||
}else if(/^\s*$/.test(chars)){
|
||||
this.doc.appendChild(charNode);
|
||||
//process xml
|
||||
}
|
||||
this.locator && position(this.locator,charNode)
|
||||
}
|
||||
},
|
||||
skippedEntity:function(name) {
|
||||
},
|
||||
endDocument:function() {
|
||||
this.doc.normalize();
|
||||
},
|
||||
setDocumentLocator:function (locator) {
|
||||
if(this.locator = locator){// && !('lineNumber' in locator)){
|
||||
locator.lineNumber = 0;
|
||||
}
|
||||
},
|
||||
//LexicalHandler
|
||||
comment:function(chars, start, length) {
|
||||
chars = _toString.apply(this,arguments)
|
||||
var comm = this.doc.createComment(chars);
|
||||
this.locator && position(this.locator,comm)
|
||||
appendElement(this, comm);
|
||||
},
|
||||
|
||||
startCDATA:function() {
|
||||
//used in characters() methods
|
||||
this.cdata = true;
|
||||
},
|
||||
endCDATA:function() {
|
||||
this.cdata = false;
|
||||
},
|
||||
|
||||
startDTD:function(name, publicId, systemId) {
|
||||
var impl = this.doc.implementation;
|
||||
if (impl && impl.createDocumentType) {
|
||||
var dt = impl.createDocumentType(name, publicId, systemId);
|
||||
this.locator && position(this.locator,dt)
|
||||
appendElement(this, dt);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @see org.xml.sax.ErrorHandler
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
|
||||
*/
|
||||
warning:function(error) {
|
||||
console.warn('[xmldom warning]\t'+error,_locator(this.locator));
|
||||
},
|
||||
error:function(error) {
|
||||
console.error('[xmldom error]\t'+error,_locator(this.locator));
|
||||
},
|
||||
fatalError:function(error) {
|
||||
console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
function _locator(l){
|
||||
if(l){
|
||||
return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
|
||||
}
|
||||
}
|
||||
function _toString(chars,start,length){
|
||||
if(typeof chars == 'string'){
|
||||
return chars.substr(start,length)
|
||||
}else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
|
||||
if(chars.length >= start+length || start){
|
||||
return new java.lang.String(chars,start,length)+'';
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
|
||||
* used method of org.xml.sax.ext.LexicalHandler:
|
||||
* #comment(chars, start, length)
|
||||
* #startCDATA()
|
||||
* #endCDATA()
|
||||
* #startDTD(name, publicId, systemId)
|
||||
*
|
||||
*
|
||||
* IGNORED method of org.xml.sax.ext.LexicalHandler:
|
||||
* #endDTD()
|
||||
* #startEntity(name)
|
||||
* #endEntity(name)
|
||||
*
|
||||
*
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
|
||||
* IGNORED method of org.xml.sax.ext.DeclHandler
|
||||
* #attributeDecl(eName, aName, type, mode, value)
|
||||
* #elementDecl(name, model)
|
||||
* #externalEntityDecl(name, publicId, systemId)
|
||||
* #internalEntityDecl(name, value)
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
|
||||
* IGNORED method of org.xml.sax.EntityResolver2
|
||||
* #resolveEntity(String name,String publicId,String baseURI,String systemId)
|
||||
* #resolveEntity(publicId, systemId)
|
||||
* #getExternalSubset(name, baseURI)
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
|
||||
* IGNORED method of org.xml.sax.DTDHandler
|
||||
* #notationDecl(name, publicId, systemId) {};
|
||||
* #unparsedEntityDecl(name, publicId, systemId, notationName) {};
|
||||
*/
|
||||
"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
|
||||
DOMHandler.prototype[key] = function(){return null}
|
||||
})
|
||||
|
||||
/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
|
||||
function appendElement (hander,node) {
|
||||
if (!hander.currentElement) {
|
||||
hander.doc.appendChild(node);
|
||||
} else {
|
||||
hander.currentElement.appendChild(node);
|
||||
}
|
||||
}//appendChild and setAttributeNS are preformance key
|
||||
|
||||
//if(typeof require == 'function'){
|
||||
var htmlEntity = require('./entities');
|
||||
var XMLReader = require('./sax').XMLReader;
|
||||
var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
|
||||
exports.XMLSerializer = require('./dom').XMLSerializer ;
|
||||
exports.DOMParser = DOMParser;
|
||||
//}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,268 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
exports.entityMap = {
|
||||
lt: '<',
|
||||
gt: '>',
|
||||
amp: '&',
|
||||
quot: '"',
|
||||
apos: "'",
|
||||
Agrave: "À",
|
||||
Aacute: "Á",
|
||||
Acirc: "Â",
|
||||
Atilde: "Ã",
|
||||
Auml: "Ä",
|
||||
Aring: "Å",
|
||||
AElig: "Æ",
|
||||
Ccedil: "Ç",
|
||||
Egrave: "È",
|
||||
Eacute: "É",
|
||||
Ecirc: "Ê",
|
||||
Euml: "Ë",
|
||||
Igrave: "Ì",
|
||||
Iacute: "Í",
|
||||
Icirc: "Î",
|
||||
Iuml: "Ï",
|
||||
ETH: "Ð",
|
||||
Ntilde: "Ñ",
|
||||
Ograve: "Ò",
|
||||
Oacute: "Ó",
|
||||
Ocirc: "Ô",
|
||||
Otilde: "Õ",
|
||||
Ouml: "Ö",
|
||||
Oslash: "Ø",
|
||||
Ugrave: "Ù",
|
||||
Uacute: "Ú",
|
||||
Ucirc: "Û",
|
||||
Uuml: "Ü",
|
||||
Yacute: "Ý",
|
||||
THORN: "Þ",
|
||||
szlig: "ß",
|
||||
agrave: "à",
|
||||
aacute: "á",
|
||||
acirc: "â",
|
||||
atilde: "ã",
|
||||
auml: "ä",
|
||||
aring: "å",
|
||||
aelig: "æ",
|
||||
ccedil: "ç",
|
||||
egrave: "è",
|
||||
eacute: "é",
|
||||
ecirc: "ê",
|
||||
euml: "ë",
|
||||
igrave: "ì",
|
||||
iacute: "í",
|
||||
icirc: "î",
|
||||
iuml: "ï",
|
||||
eth: "ð",
|
||||
ntilde: "ñ",
|
||||
ograve: "ò",
|
||||
oacute: "ó",
|
||||
ocirc: "ô",
|
||||
otilde: "õ",
|
||||
ouml: "ö",
|
||||
oslash: "ø",
|
||||
ugrave: "ù",
|
||||
uacute: "ú",
|
||||
ucirc: "û",
|
||||
uuml: "ü",
|
||||
yacute: "ý",
|
||||
thorn: "þ",
|
||||
yuml: "ÿ",
|
||||
nbsp: " ",
|
||||
iexcl: "¡",
|
||||
cent: "¢",
|
||||
pound: "£",
|
||||
curren: "¤",
|
||||
yen: "¥",
|
||||
brvbar: "¦",
|
||||
sect: "§",
|
||||
uml: "¨",
|
||||
copy: "©",
|
||||
ordf: "ª",
|
||||
laquo: "«",
|
||||
not: "¬",
|
||||
shy: "",
|
||||
reg: "®",
|
||||
macr: "¯",
|
||||
deg: "°",
|
||||
plusmn: "±",
|
||||
sup2: "²",
|
||||
sup3: "³",
|
||||
acute: "´",
|
||||
micro: "µ",
|
||||
para: "¶",
|
||||
middot: "·",
|
||||
cedil: "¸",
|
||||
sup1: "¹",
|
||||
ordm: "º",
|
||||
raquo: "»",
|
||||
frac14: "¼",
|
||||
frac12: "½",
|
||||
frac34: "¾",
|
||||
iquest: "¿",
|
||||
times: "×",
|
||||
divide: "÷",
|
||||
forall: "∀",
|
||||
part: "∂",
|
||||
exist: "∃",
|
||||
empty: "∅",
|
||||
nabla: "∇",
|
||||
isin: "∈",
|
||||
notin: "∉",
|
||||
ni: "∋",
|
||||
prod: "∏",
|
||||
sum: "∑",
|
||||
minus: "−",
|
||||
lowast: "∗",
|
||||
radic: "√",
|
||||
prop: "∝",
|
||||
infin: "∞",
|
||||
ang: "∠",
|
||||
and: "∧",
|
||||
or: "∨",
|
||||
cap: "∩",
|
||||
cup: "∪",
|
||||
'int': "∫",
|
||||
there4: "∴",
|
||||
sim: "∼",
|
||||
cong: "≅",
|
||||
asymp: "≈",
|
||||
ne: "≠",
|
||||
equiv: "≡",
|
||||
le: "≤",
|
||||
ge: "≥",
|
||||
sub: "⊂",
|
||||
sup: "⊃",
|
||||
nsub: "⊄",
|
||||
sube: "⊆",
|
||||
supe: "⊇",
|
||||
oplus: "⊕",
|
||||
otimes: "⊗",
|
||||
perp: "⊥",
|
||||
sdot: "⋅",
|
||||
Alpha: "Α",
|
||||
Beta: "Β",
|
||||
Gamma: "Γ",
|
||||
Delta: "Δ",
|
||||
Epsilon: "Ε",
|
||||
Zeta: "Ζ",
|
||||
Eta: "Η",
|
||||
Theta: "Θ",
|
||||
Iota: "Ι",
|
||||
Kappa: "Κ",
|
||||
Lambda: "Λ",
|
||||
Mu: "Μ",
|
||||
Nu: "Ν",
|
||||
Xi: "Ξ",
|
||||
Omicron: "Ο",
|
||||
Pi: "Π",
|
||||
Rho: "Ρ",
|
||||
Sigma: "Σ",
|
||||
Tau: "Τ",
|
||||
Upsilon: "Υ",
|
||||
Phi: "Φ",
|
||||
Chi: "Χ",
|
||||
Psi: "Ψ",
|
||||
Omega: "Ω",
|
||||
alpha: "α",
|
||||
beta: "β",
|
||||
gamma: "γ",
|
||||
delta: "δ",
|
||||
epsilon: "ε",
|
||||
zeta: "ζ",
|
||||
eta: "η",
|
||||
theta: "θ",
|
||||
iota: "ι",
|
||||
kappa: "κ",
|
||||
lambda: "λ",
|
||||
mu: "μ",
|
||||
nu: "ν",
|
||||
xi: "ξ",
|
||||
omicron: "ο",
|
||||
pi: "π",
|
||||
rho: "ρ",
|
||||
sigmaf: "ς",
|
||||
sigma: "σ",
|
||||
tau: "τ",
|
||||
upsilon: "υ",
|
||||
phi: "φ",
|
||||
chi: "χ",
|
||||
psi: "ψ",
|
||||
omega: "ω",
|
||||
thetasym: "ϑ",
|
||||
upsih: "ϒ",
|
||||
piv: "ϖ",
|
||||
OElig: "Œ",
|
||||
oelig: "œ",
|
||||
Scaron: "Š",
|
||||
scaron: "š",
|
||||
Yuml: "Ÿ",
|
||||
fnof: "ƒ",
|
||||
circ: "ˆ",
|
||||
tilde: "˜",
|
||||
ensp: " ",
|
||||
emsp: " ",
|
||||
thinsp: " ",
|
||||
zwnj: "",
|
||||
zwj: "",
|
||||
lrm: "",
|
||||
rlm: "",
|
||||
ndash: "–",
|
||||
mdash: "—",
|
||||
lsquo: "‘",
|
||||
rsquo: "’",
|
||||
sbquo: "‚",
|
||||
ldquo: "“",
|
||||
rdquo: "”",
|
||||
bdquo: "„",
|
||||
dagger: "†",
|
||||
Dagger: "‡",
|
||||
bull: "•",
|
||||
hellip: "…",
|
||||
permil: "‰",
|
||||
prime: "′",
|
||||
Prime: "″",
|
||||
lsaquo: "‹",
|
||||
rsaquo: "›",
|
||||
oline: "‾",
|
||||
euro: "€",
|
||||
trade: "™",
|
||||
larr: "←",
|
||||
uarr: "↑",
|
||||
rarr: "→",
|
||||
darr: "↓",
|
||||
harr: "↔",
|
||||
crarr: "↵",
|
||||
lceil: "⌈",
|
||||
rceil: "⌉",
|
||||
lfloor: "⌊",
|
||||
rfloor: "⌋",
|
||||
loz: "◊",
|
||||
spades: "♠",
|
||||
clubs: "♣",
|
||||
hearts: "♥",
|
||||
diams: "♦"
|
||||
};
|
||||
//for(var n in exports.entityMap){console.log(exports.entityMap[n].charCodeAt())}
|
||||
@@ -0,0 +1,641 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
//[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
||||
//[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
||||
//[5] Name ::= NameStartChar (NameChar)*
|
||||
var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
|
||||
var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
|
||||
var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
|
||||
//var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
|
||||
//var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
|
||||
|
||||
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
||||
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
||||
var S_TAG = 0;//tag name offerring
|
||||
var S_ATTR = 1;//attr name offerring
|
||||
var S_ATTR_SPACE=2;//attr name end and space offer
|
||||
var S_EQ = 3;//=space?
|
||||
var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
|
||||
var S_ATTR_END = 5;//attr value end and no space(quot end)
|
||||
var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
|
||||
var S_TAG_CLOSE = 7;//closed el<el />
|
||||
|
||||
function XMLReader(){
|
||||
|
||||
}
|
||||
|
||||
XMLReader.prototype = {
|
||||
parse:function(source,defaultNSMap,entityMap){
|
||||
var domBuilder = this.domBuilder;
|
||||
domBuilder.startDocument();
|
||||
_copy(defaultNSMap ,defaultNSMap = {})
|
||||
parse(source,defaultNSMap,entityMap,
|
||||
domBuilder,this.errorHandler);
|
||||
domBuilder.endDocument();
|
||||
}
|
||||
}
|
||||
function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
function fixedFromCharCode(code) {
|
||||
// String.prototype.fromCharCode does not supports
|
||||
// > 2 bytes unicode chars directly
|
||||
if (code > 0xffff) {
|
||||
code -= 0x10000;
|
||||
var surrogate1 = 0xd800 + (code >> 10)
|
||||
, surrogate2 = 0xdc00 + (code & 0x3ff);
|
||||
|
||||
return String.fromCharCode(surrogate1, surrogate2);
|
||||
} else {
|
||||
return String.fromCharCode(code);
|
||||
}
|
||||
}
|
||||
function entityReplacer(a){
|
||||
var k = a.slice(1,-1);
|
||||
if(k in entityMap){
|
||||
return entityMap[k];
|
||||
}else if(k.charAt(0) === '#'){
|
||||
return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
|
||||
}else{
|
||||
errorHandler.error('entity not found:'+a);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
function appendText(end){//has some bugs
|
||||
if(end>start){
|
||||
var xt = source.substring(start,end).replace(/&#?\w+;/g,entityReplacer);
|
||||
locator&&position(start);
|
||||
domBuilder.characters(xt,0,end-start);
|
||||
start = end
|
||||
}
|
||||
}
|
||||
function position(p,m){
|
||||
while(p>=lineEnd && (m = linePattern.exec(source))){
|
||||
lineStart = m.index;
|
||||
lineEnd = lineStart + m[0].length;
|
||||
locator.lineNumber++;
|
||||
//console.log('line++:',locator,startPos,endPos)
|
||||
}
|
||||
locator.columnNumber = p-lineStart+1;
|
||||
}
|
||||
var lineStart = 0;
|
||||
var lineEnd = 0;
|
||||
var linePattern = /.*(?:\r\n?|\n)|.*$/g
|
||||
var locator = domBuilder.locator;
|
||||
|
||||
var parseStack = [{currentNSMap:defaultNSMapCopy}]
|
||||
var closeMap = {};
|
||||
var start = 0;
|
||||
while(true){
|
||||
try{
|
||||
var tagStart = source.indexOf('<',start);
|
||||
if(tagStart<0){
|
||||
if(!source.substr(start).match(/^\s*$/)){
|
||||
var doc = domBuilder.doc;
|
||||
var text = doc.createTextNode(source.substr(start));
|
||||
doc.appendChild(text);
|
||||
domBuilder.currentElement = text;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(tagStart>start){
|
||||
appendText(tagStart);
|
||||
}
|
||||
switch(source.charAt(tagStart+1)){
|
||||
case '/':
|
||||
var end = source.indexOf('>',tagStart+3);
|
||||
var tagName = source.substring(tagStart+2,end);
|
||||
var config = parseStack.pop();
|
||||
if(end<0){
|
||||
|
||||
tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
|
||||
//console.error('#@@@@@@'+tagName)
|
||||
errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
|
||||
end = tagStart+1+tagName.length;
|
||||
}else if(tagName.match(/\s</)){
|
||||
tagName = tagName.replace(/[\s<].*/,'');
|
||||
errorHandler.error("end tag name: "+tagName+' maybe not complete');
|
||||
end = tagStart+1+tagName.length;
|
||||
}
|
||||
//console.error(parseStack.length,parseStack)
|
||||
//console.error(config);
|
||||
var localNSMap = config.localNSMap;
|
||||
var endMatch = config.tagName == tagName;
|
||||
var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
|
||||
if(endIgnoreCaseMach){
|
||||
domBuilder.endElement(config.uri,config.localName,tagName);
|
||||
if(localNSMap){
|
||||
for(var prefix in localNSMap){
|
||||
domBuilder.endPrefixMapping(prefix) ;
|
||||
}
|
||||
}
|
||||
if(!endMatch){
|
||||
errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
|
||||
}
|
||||
}else{
|
||||
parseStack.push(config)
|
||||
}
|
||||
|
||||
end++;
|
||||
break;
|
||||
// end elment
|
||||
case '?':// <?...?>
|
||||
locator&&position(tagStart);
|
||||
end = parseInstruction(source,tagStart,domBuilder);
|
||||
break;
|
||||
case '!':// <!doctype,<![CDATA,<!--
|
||||
locator&&position(tagStart);
|
||||
end = parseDCC(source,tagStart,domBuilder,errorHandler);
|
||||
break;
|
||||
default:
|
||||
locator&&position(tagStart);
|
||||
var el = new ElementAttributes();
|
||||
var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
//elStartEnd
|
||||
var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
|
||||
var len = el.length;
|
||||
|
||||
|
||||
if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
|
||||
el.closed = true;
|
||||
if(!entityMap.nbsp){
|
||||
errorHandler.warning('unclosed xml attribute');
|
||||
}
|
||||
}
|
||||
if(locator && len){
|
||||
var locator2 = copyLocator(locator,{});
|
||||
//try{//attribute position fixed
|
||||
for(var i = 0;i<len;i++){
|
||||
var a = el[i];
|
||||
position(a.offset);
|
||||
a.locator = copyLocator(locator,{});
|
||||
}
|
||||
//}catch(e){console.error('@@@@@'+e)}
|
||||
domBuilder.locator = locator2
|
||||
if(appendElement(el,domBuilder,currentNSMap)){
|
||||
parseStack.push(el)
|
||||
}
|
||||
domBuilder.locator = locator;
|
||||
}else{
|
||||
if(appendElement(el,domBuilder,currentNSMap)){
|
||||
parseStack.push(el)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
|
||||
end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
|
||||
}else{
|
||||
end++;
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
errorHandler.error('element parse error: '+e)
|
||||
//errorHandler.error('element parse error: '+e);
|
||||
end = -1;
|
||||
//throw e;
|
||||
}
|
||||
if(end>start){
|
||||
start = end;
|
||||
}else{
|
||||
//TODO: 这里有可能sax回退,有位置错误风险
|
||||
appendText(Math.max(tagStart,start)+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
function copyLocator(f,t){
|
||||
t.lineNumber = f.lineNumber;
|
||||
t.columnNumber = f.columnNumber;
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
|
||||
* @return end of the elementStartPart(end of elementEndPart for selfClosed el)
|
||||
*/
|
||||
function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
|
||||
var attrName;
|
||||
var value;
|
||||
var p = ++start;
|
||||
var s = S_TAG;//status
|
||||
while(true){
|
||||
var c = source.charAt(p);
|
||||
switch(c){
|
||||
case '=':
|
||||
if(s === S_ATTR){//attrName
|
||||
attrName = source.slice(start,p);
|
||||
s = S_EQ;
|
||||
}else if(s === S_ATTR_SPACE){
|
||||
s = S_EQ;
|
||||
}else{
|
||||
//fatalError: equal must after attrName or space after attrName
|
||||
throw new Error('attribute equal must after attrName');
|
||||
}
|
||||
break;
|
||||
case '\'':
|
||||
case '"':
|
||||
if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
|
||||
){//equal
|
||||
if(s === S_ATTR){
|
||||
errorHandler.warning('attribute value must after "="')
|
||||
attrName = source.slice(start,p)
|
||||
}
|
||||
start = p+1;
|
||||
p = source.indexOf(c,start)
|
||||
if(p>0){
|
||||
value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
el.add(attrName,value,start-1);
|
||||
s = S_ATTR_END;
|
||||
}else{
|
||||
//fatalError: no end quot match
|
||||
throw new Error('attribute value no end \''+c+'\' match');
|
||||
}
|
||||
}else if(s == S_ATTR_NOQUOT_VALUE){
|
||||
value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
//console.log(attrName,value,start,p)
|
||||
el.add(attrName,value,start);
|
||||
//console.dir(el)
|
||||
errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
|
||||
start = p+1;
|
||||
s = S_ATTR_END
|
||||
}else{
|
||||
//fatalError: no equal before
|
||||
throw new Error('attribute value must after "="');
|
||||
}
|
||||
break;
|
||||
case '/':
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));
|
||||
case S_ATTR_END:
|
||||
case S_TAG_SPACE:
|
||||
case S_TAG_CLOSE:
|
||||
s =S_TAG_CLOSE;
|
||||
el.closed = true;
|
||||
case S_ATTR_NOQUOT_VALUE:
|
||||
case S_ATTR:
|
||||
case S_ATTR_SPACE:
|
||||
break;
|
||||
//case S_EQ:
|
||||
default:
|
||||
throw new Error("attribute invalid close char('/')")
|
||||
}
|
||||
break;
|
||||
case ''://end document
|
||||
//throw new Error('unexpected end of input')
|
||||
errorHandler.error('unexpected end of input');
|
||||
if(s == S_TAG){
|
||||
el.setTagName(source.slice(start,p));
|
||||
}
|
||||
return p;
|
||||
case '>':
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));
|
||||
case S_ATTR_END:
|
||||
case S_TAG_SPACE:
|
||||
case S_TAG_CLOSE:
|
||||
break;//normal
|
||||
case S_ATTR_NOQUOT_VALUE://Compatible state
|
||||
case S_ATTR:
|
||||
value = source.slice(start,p);
|
||||
if(value.slice(-1) === '/'){
|
||||
el.closed = true;
|
||||
value = value.slice(0,-1)
|
||||
}
|
||||
case S_ATTR_SPACE:
|
||||
if(s === S_ATTR_SPACE){
|
||||
value = attrName;
|
||||
}
|
||||
if(s == S_ATTR_NOQUOT_VALUE){
|
||||
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
||||
el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
|
||||
}else{
|
||||
if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
|
||||
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
|
||||
}
|
||||
el.add(value,value,start)
|
||||
}
|
||||
break;
|
||||
case S_EQ:
|
||||
throw new Error('attribute value missed!!');
|
||||
}
|
||||
// console.log(tagName,tagNamePattern,tagNamePattern.test(tagName))
|
||||
return p;
|
||||
/*xml space '\x20' | #x9 | #xD | #xA; */
|
||||
case '\u0080':
|
||||
c = ' ';
|
||||
default:
|
||||
if(c<= ' '){//space
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));//tagName
|
||||
s = S_TAG_SPACE;
|
||||
break;
|
||||
case S_ATTR:
|
||||
attrName = source.slice(start,p)
|
||||
s = S_ATTR_SPACE;
|
||||
break;
|
||||
case S_ATTR_NOQUOT_VALUE:
|
||||
var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
||||
el.add(attrName,value,start)
|
||||
case S_ATTR_END:
|
||||
s = S_TAG_SPACE;
|
||||
break;
|
||||
//case S_TAG_SPACE:
|
||||
//case S_EQ:
|
||||
//case S_ATTR_SPACE:
|
||||
// void();break;
|
||||
//case S_TAG_CLOSE:
|
||||
//ignore warning
|
||||
}
|
||||
}else{//not space
|
||||
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
||||
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
||||
switch(s){
|
||||
//case S_TAG:void();break;
|
||||
//case S_ATTR:void();break;
|
||||
//case S_ATTR_NOQUOT_VALUE:void();break;
|
||||
case S_ATTR_SPACE:
|
||||
var tagName = el.tagName;
|
||||
if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
|
||||
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
|
||||
}
|
||||
el.add(attrName,attrName,start);
|
||||
start = p;
|
||||
s = S_ATTR;
|
||||
break;
|
||||
case S_ATTR_END:
|
||||
errorHandler.warning('attribute space is required"'+attrName+'"!!')
|
||||
case S_TAG_SPACE:
|
||||
s = S_ATTR;
|
||||
start = p;
|
||||
break;
|
||||
case S_EQ:
|
||||
s = S_ATTR_NOQUOT_VALUE;
|
||||
start = p;
|
||||
break;
|
||||
case S_TAG_CLOSE:
|
||||
throw new Error("elements closed character '/' and '>' must be connected to");
|
||||
}
|
||||
}
|
||||
}//end outer switch
|
||||
//console.log('p++',p)
|
||||
p++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return true if has new namespace define
|
||||
*/
|
||||
function appendElement(el,domBuilder,currentNSMap){
|
||||
var tagName = el.tagName;
|
||||
var localNSMap = null;
|
||||
//var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
var i = el.length;
|
||||
while(i--){
|
||||
var a = el[i];
|
||||
var qName = a.qName;
|
||||
var value = a.value;
|
||||
var nsp = qName.indexOf(':');
|
||||
if(nsp>0){
|
||||
var prefix = a.prefix = qName.slice(0,nsp);
|
||||
var localName = qName.slice(nsp+1);
|
||||
var nsPrefix = prefix === 'xmlns' && localName
|
||||
}else{
|
||||
localName = qName;
|
||||
prefix = null
|
||||
nsPrefix = qName === 'xmlns' && ''
|
||||
}
|
||||
//can not set prefix,because prefix !== ''
|
||||
a.localName = localName ;
|
||||
//prefix == null for no ns prefix attribute
|
||||
if(nsPrefix !== false){//hack!!
|
||||
if(localNSMap == null){
|
||||
localNSMap = {}
|
||||
//console.log(currentNSMap,0)
|
||||
_copy(currentNSMap,currentNSMap={})
|
||||
//console.log(currentNSMap,1)
|
||||
}
|
||||
currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
|
||||
a.uri = 'http://www.w3.org/2000/xmlns/'
|
||||
domBuilder.startPrefixMapping(nsPrefix, value)
|
||||
}
|
||||
}
|
||||
var i = el.length;
|
||||
while(i--){
|
||||
a = el[i];
|
||||
var prefix = a.prefix;
|
||||
if(prefix){//no prefix attribute has no namespace
|
||||
if(prefix === 'xml'){
|
||||
a.uri = 'http://www.w3.org/XML/1998/namespace';
|
||||
}if(prefix !== 'xmlns'){
|
||||
a.uri = currentNSMap[prefix || '']
|
||||
|
||||
//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
|
||||
}
|
||||
}
|
||||
}
|
||||
var nsp = tagName.indexOf(':');
|
||||
if(nsp>0){
|
||||
prefix = el.prefix = tagName.slice(0,nsp);
|
||||
localName = el.localName = tagName.slice(nsp+1);
|
||||
}else{
|
||||
prefix = null;//important!!
|
||||
localName = el.localName = tagName;
|
||||
}
|
||||
//no prefix element has default namespace
|
||||
var ns = el.uri = currentNSMap[prefix || ''];
|
||||
domBuilder.startElement(ns,localName,tagName,el);
|
||||
//endPrefixMapping and startPrefixMapping have not any help for dom builder
|
||||
//localNSMap = null
|
||||
if(el.closed){
|
||||
domBuilder.endElement(ns,localName,tagName);
|
||||
if(localNSMap){
|
||||
for(prefix in localNSMap){
|
||||
domBuilder.endPrefixMapping(prefix)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
el.currentNSMap = currentNSMap;
|
||||
el.localNSMap = localNSMap;
|
||||
//parseStack.push(el);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
|
||||
if(/^(?:script|textarea)$/i.test(tagName)){
|
||||
var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
|
||||
var text = source.substring(elStartEnd+1,elEndStart);
|
||||
if(/[&<]/.test(text)){
|
||||
if(/^script$/i.test(tagName)){
|
||||
//if(!/\]\]>/.test(text)){
|
||||
//lexHandler.startCDATA();
|
||||
domBuilder.characters(text,0,text.length);
|
||||
//lexHandler.endCDATA();
|
||||
return elEndStart;
|
||||
//}
|
||||
}//}else{//text area
|
||||
text = text.replace(/&#?\w+;/g,entityReplacer);
|
||||
domBuilder.characters(text,0,text.length);
|
||||
return elEndStart;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
return elStartEnd+1;
|
||||
}
|
||||
function fixSelfClosed(source,elStartEnd,tagName,closeMap){
|
||||
//if(tagName in closeMap){
|
||||
var pos = closeMap[tagName];
|
||||
if(pos == null){
|
||||
//console.log(tagName)
|
||||
pos = source.lastIndexOf('</'+tagName+'>')
|
||||
if(pos<elStartEnd){//忘记闭合
|
||||
pos = source.lastIndexOf('</'+tagName)
|
||||
}
|
||||
closeMap[tagName] =pos
|
||||
}
|
||||
return pos<elStartEnd;
|
||||
//}
|
||||
}
|
||||
function _copy(source,target){
|
||||
for(var n in source){target[n] = source[n]}
|
||||
}
|
||||
function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
|
||||
var next= source.charAt(start+2)
|
||||
switch(next){
|
||||
case '-':
|
||||
if(source.charAt(start + 3) === '-'){
|
||||
var end = source.indexOf('-->',start+4);
|
||||
//append comment source.substring(4,end)//<!--
|
||||
if(end>start){
|
||||
domBuilder.comment(source,start+4,end-start-4);
|
||||
return end+3;
|
||||
}else{
|
||||
errorHandler.error("Unclosed comment");
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
//error
|
||||
return -1;
|
||||
}
|
||||
default:
|
||||
if(source.substr(start+3,6) == 'CDATA['){
|
||||
var end = source.indexOf(']]>',start+9);
|
||||
domBuilder.startCDATA();
|
||||
domBuilder.characters(source,start+9,end-start-9);
|
||||
domBuilder.endCDATA()
|
||||
return end+3;
|
||||
}
|
||||
//<!DOCTYPE
|
||||
//startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
|
||||
var matchs = split(source,start);
|
||||
var len = matchs.length;
|
||||
if(len>1 && /!doctype/i.test(matchs[0][0])){
|
||||
var name = matchs[1][0];
|
||||
var pubid = len>3 && /^public$/i.test(matchs[2][0]) && matchs[3][0]
|
||||
var sysid = len>4 && matchs[4][0];
|
||||
var lastMatch = matchs[len-1]
|
||||
domBuilder.startDTD(name,pubid && pubid.replace(/^(['"])(.*?)\1$/,'$2'),
|
||||
sysid && sysid.replace(/^(['"])(.*?)\1$/,'$2'));
|
||||
domBuilder.endDTD();
|
||||
|
||||
return lastMatch.index+lastMatch[0].length
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function parseInstruction(source,start,domBuilder){
|
||||
var end = source.indexOf('?>',start);
|
||||
if(end){
|
||||
var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
|
||||
if(match){
|
||||
var len = match[0].length;
|
||||
domBuilder.processingInstruction(match[1], match[2]) ;
|
||||
return end+2;
|
||||
}else{//error
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param source
|
||||
*/
|
||||
function ElementAttributes(source){
|
||||
|
||||
}
|
||||
ElementAttributes.prototype = {
|
||||
setTagName:function(tagName){
|
||||
if(!tagNamePattern.test(tagName)){
|
||||
throw new Error('invalid tagName:'+tagName)
|
||||
}
|
||||
this.tagName = tagName
|
||||
},
|
||||
add:function(qName,value,offset){
|
||||
if(!tagNamePattern.test(qName)){
|
||||
throw new Error('invalid attribute:'+qName)
|
||||
}
|
||||
this[this.length++] = {qName:qName,value:value,offset:offset}
|
||||
},
|
||||
length:0,
|
||||
getLocalName:function(i){return this[i].localName},
|
||||
getLocator:function(i){return this[i].locator},
|
||||
getQName:function(i){return this[i].qName},
|
||||
getURI:function(i){return this[i].uri},
|
||||
getValue:function(i){return this[i].value}
|
||||
// ,getIndex:function(uri, localName)){
|
||||
// if(localName){
|
||||
//
|
||||
// }else{
|
||||
// var qName = uri
|
||||
// }
|
||||
// },
|
||||
// getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
|
||||
// getType:function(uri,localName){}
|
||||
// getType:function(i){},
|
||||
}
|
||||
|
||||
|
||||
|
||||
function split(source,start){
|
||||
var match;
|
||||
var buf = [];
|
||||
var reg = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
|
||||
reg.lastIndex = start;
|
||||
reg.exec(source);//skip <
|
||||
while(match = reg.exec(source)){
|
||||
buf.push(match);
|
||||
if(match[1])return buf;
|
||||
}
|
||||
}
|
||||
|
||||
exports.XMLReader = XMLReader;
|
||||
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
const GL_NEAREST = 9728; // gl.NEAREST
|
||||
const GL_LINEAR = 9729; // gl.LINEAR
|
||||
const GL_NEAREST_MIPMAP_NEAREST = 9984; // gl.NEAREST_MIPMAP_NEAREST
|
||||
const GL_LINEAR_MIPMAP_NEAREST = 9985; // gl.LINEAR_MIPMAP_NEAREST
|
||||
const GL_NEAREST_MIPMAP_LINEAR = 9986; // gl.NEAREST_MIPMAP_LINEAR
|
||||
const GL_LINEAR_MIPMAP_LINEAR = 9987; // gl.LINEAR_MIPMAP_LINEAR
|
||||
|
||||
// const GL_BYTE = 5120; // gl.BYTE
|
||||
const GL_UNSIGNED_BYTE = 5121; // gl.UNSIGNED_BYTE
|
||||
// const GL_SHORT = 5122; // gl.SHORT
|
||||
const GL_UNSIGNED_SHORT = 5123; // gl.UNSIGNED_SHORT
|
||||
const GL_UNSIGNED_INT = 5125; // gl.UNSIGNED_INT
|
||||
const GL_FLOAT = 5126; // gl.FLOAT
|
||||
const GL_UNSIGNED_SHORT_5_6_5 = 33635; // gl.UNSIGNED_SHORT_5_6_5
|
||||
const GL_UNSIGNED_SHORT_4_4_4_4 = 32819; // gl.UNSIGNED_SHORT_4_4_4_4
|
||||
const GL_UNSIGNED_SHORT_5_5_5_1 = 32820; // gl.UNSIGNED_SHORT_5_5_5_1
|
||||
const GL_HALF_FLOAT_OES = 36193; // gl.HALF_FLOAT_OES
|
||||
|
||||
const GL_DEPTH_COMPONENT = 6402; // gl.DEPTH_COMPONENT
|
||||
const GL_DEPTH_COMPONENT16 = 0x81A5;
|
||||
const GL_DEPTH_COMPONENT24 = 0x81A6;
|
||||
|
||||
const GL_ALPHA = 6406; // gl.ALPHA
|
||||
const GL_RGB = 6407; // gl.RGB
|
||||
const GL_RGBA = 6408; // gl.RGBA
|
||||
const GL_LUMINANCE = 6409; // gl.LUMINANCE
|
||||
const GL_LUMINANCE_ALPHA = 6410; // gl.LUMINANCE_ALPHA
|
||||
|
||||
const GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0; // ext.COMPRESSED_RGB_S3TC_DXT1_EXT
|
||||
const GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1; // ext.COMPRESSED_RGBA_S3TC_DXT1_EXT
|
||||
const GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2; // ext.COMPRESSED_RGBA_S3TC_DXT3_EXT
|
||||
const GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3; // ext.COMPRESSED_RGBA_S3TC_DXT5_EXT
|
||||
|
||||
const GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00; // ext.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
|
||||
const GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01; // ext.COMPRESSED_RGB_PVRTC_2BPPV1_IMG
|
||||
const GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02; // ext.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
|
||||
const GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03; // ext.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
|
||||
|
||||
const GL_COMPRESSED_RGB_ETC1_WEBGL = 0x8D64; // ext.COMPRESSED_RGB_ETC1_WEBGL
|
||||
|
||||
const _filterGL = [
|
||||
[ GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR ],
|
||||
[ GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR ],
|
||||
];
|
||||
|
||||
const _textureFmtGL = [
|
||||
// TEXTURE_FMT_RGB_DXT1: 0
|
||||
{ format: GL_RGB, internalFormat: GL_COMPRESSED_RGB_S3TC_DXT1_EXT, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGBA_DXT1: 1
|
||||
{ format: GL_RGBA, internalFormat: GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGBA_DXT3: 2
|
||||
{ format: GL_RGBA, internalFormat: GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGBA_DXT5: 3
|
||||
{ format: GL_RGBA, internalFormat: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGB_ETC1: 4
|
||||
{ format: GL_RGB, internalFormat: GL_COMPRESSED_RGB_ETC1_WEBGL, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGB_PVRTC_2BPPV1: 5
|
||||
{ format: GL_RGB, internalFormat: GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGBA_PVRTC_2BPPV1: 6
|
||||
{ format: GL_RGBA, internalFormat: GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGB_PVRTC_4BPPV1: 7
|
||||
{ format: GL_RGB, internalFormat: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_RGBA_PVRTC_4BPPV1: 8
|
||||
{ format: GL_RGBA, internalFormat: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_A8: 9
|
||||
{ format: GL_ALPHA, internalFormat: GL_ALPHA, pixelType: GL_UNSIGNED_BYTE },
|
||||
|
||||
// TEXTURE_FMT_L8: 10
|
||||
{ format: GL_LUMINANCE, internalFormat: GL_LUMINANCE, pixelType: GL_UNSIGNED_BYTE },
|
||||
|
||||
// TEXTURE_FMT_L8_A8: 11
|
||||
{ format: GL_LUMINANCE_ALPHA, internalFormat: GL_LUMINANCE_ALPHA, pixelType: GL_UNSIGNED_BYTE },
|
||||
|
||||
// TEXTURE_FMT_R5_G6_B5: 12
|
||||
{ format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_UNSIGNED_SHORT_5_6_5 },
|
||||
|
||||
// TEXTURE_FMT_R5_G5_B5_A1: 13
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_SHORT_5_5_5_1 },
|
||||
|
||||
// TEXTURE_FMT_R4_G4_B4_A4: 14
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_SHORT_4_4_4_4 },
|
||||
|
||||
// TEXTURE_FMT_RGB8: 15
|
||||
{ format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_UNSIGNED_BYTE },
|
||||
|
||||
// TEXTURE_FMT_RGBA8: 16
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_BYTE },
|
||||
|
||||
// TEXTURE_FMT_RGB16F: 17
|
||||
{ format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_HALF_FLOAT_OES },
|
||||
|
||||
// TEXTURE_FMT_RGBA16F: 18
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_HALF_FLOAT_OES },
|
||||
|
||||
// TEXTURE_FMT_RGB32F: 19
|
||||
{ format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_FLOAT },
|
||||
|
||||
// TEXTURE_FMT_RGBA32F: 20
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_FLOAT },
|
||||
|
||||
// TEXTURE_FMT_R32F: 21
|
||||
{ format: null, internalFormat: null, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_111110F: 22
|
||||
{ format: null, internalFormat: null, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_SRGB: 23
|
||||
{ format: null, internalFormat: null, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_SRGBA: 24
|
||||
{ format: null, internalFormat: null, pixelType: null },
|
||||
|
||||
// TEXTURE_FMT_D16: 25
|
||||
{ format: GL_DEPTH_COMPONENT, internalFormat: GL_DEPTH_COMPONENT16, pixelType: GL_UNSIGNED_SHORT },
|
||||
|
||||
// TEXTURE_FMT_D24: 26
|
||||
{ format: GL_DEPTH_COMPONENT, internalFormat: GL_DEPTH_COMPONENT24, pixelType: GL_FLOAT },
|
||||
|
||||
// TEXTURE_FMT_D24S8: 27
|
||||
{ format: null, internalFormat: null, pixelType: null },
|
||||
];
|
||||
|
||||
/**
|
||||
* enums
|
||||
*/
|
||||
const enums = {
|
||||
// buffer usage
|
||||
USAGE_STATIC: 35044, // gl.STATIC_DRAW
|
||||
USAGE_DYNAMIC: 35048, // gl.DYNAMIC_DRAW
|
||||
USAGE_STREAM: 35040, // gl.STREAM_DRAW
|
||||
|
||||
// index buffer format
|
||||
INDEX_FMT_UINT8: 5121, // gl.UNSIGNED_BYTE
|
||||
INDEX_FMT_UINT16: 5123, // gl.UNSIGNED_SHORT
|
||||
INDEX_FMT_UINT32: 5125, // gl.UNSIGNED_INT (OES_element_index_uint)
|
||||
|
||||
// vertex attribute semantic
|
||||
ATTR_POSITION: 'a_position',
|
||||
ATTR_NORMAL: 'a_normal',
|
||||
ATTR_TANGENT: 'a_tangent',
|
||||
ATTR_BITANGENT: 'a_bitangent',
|
||||
ATTR_WEIGHTS: 'a_weights',
|
||||
ATTR_JOINTS: 'a_joints',
|
||||
ATTR_COLOR: 'a_color',
|
||||
ATTR_COLOR0: 'a_color0',
|
||||
ATTR_COLOR1: 'a_color1',
|
||||
ATTR_UV: 'a_uv',
|
||||
ATTR_UV0: 'a_uv0',
|
||||
ATTR_UV1: 'a_uv1',
|
||||
ATTR_UV2: 'a_uv2',
|
||||
ATTR_UV3: 'a_uv3',
|
||||
ATTR_UV4: 'a_uv4',
|
||||
ATTR_UV5: 'a_uv5',
|
||||
ATTR_UV6: 'a_uv6',
|
||||
ATTR_UV7: 'a_uv7',
|
||||
|
||||
// vertex attribute type
|
||||
ATTR_TYPE_INT8: 5120, // gl.BYTE
|
||||
ATTR_TYPE_UINT8: 5121, // gl.UNSIGNED_BYTE
|
||||
ATTR_TYPE_INT16: 5122, // gl.SHORT
|
||||
ATTR_TYPE_UINT16: 5123, // gl.UNSIGNED_SHORT
|
||||
ATTR_TYPE_INT32: 5124, // gl.INT
|
||||
ATTR_TYPE_UINT32: 5125, // gl.UNSIGNED_INT
|
||||
ATTR_TYPE_FLOAT32: 5126, // gl.FLOAT
|
||||
|
||||
// texture filter
|
||||
FILTER_NEAREST: 0,
|
||||
FILTER_LINEAR: 1,
|
||||
|
||||
// texture wrap mode
|
||||
WRAP_REPEAT: 10497, // gl.REPEAT
|
||||
WRAP_CLAMP: 33071, // gl.CLAMP_TO_EDGE
|
||||
WRAP_MIRROR: 33648, // gl.MIRRORED_REPEAT
|
||||
|
||||
// texture format
|
||||
// compress formats
|
||||
TEXTURE_FMT_RGB_DXT1: 0,
|
||||
TEXTURE_FMT_RGBA_DXT1: 1,
|
||||
TEXTURE_FMT_RGBA_DXT3: 2,
|
||||
TEXTURE_FMT_RGBA_DXT5: 3,
|
||||
TEXTURE_FMT_RGB_ETC1: 4,
|
||||
TEXTURE_FMT_RGB_PVRTC_2BPPV1: 5,
|
||||
TEXTURE_FMT_RGBA_PVRTC_2BPPV1: 6,
|
||||
TEXTURE_FMT_RGB_PVRTC_4BPPV1: 7,
|
||||
TEXTURE_FMT_RGBA_PVRTC_4BPPV1: 8,
|
||||
|
||||
// normal formats
|
||||
TEXTURE_FMT_A8: 9,
|
||||
TEXTURE_FMT_L8: 10,
|
||||
TEXTURE_FMT_L8_A8: 11,
|
||||
TEXTURE_FMT_R5_G6_B5: 12,
|
||||
TEXTURE_FMT_R5_G5_B5_A1: 13,
|
||||
TEXTURE_FMT_R4_G4_B4_A4: 14,
|
||||
TEXTURE_FMT_RGB8: 15,
|
||||
TEXTURE_FMT_RGBA8: 16,
|
||||
TEXTURE_FMT_RGB16F: 17,
|
||||
TEXTURE_FMT_RGBA16F: 18,
|
||||
TEXTURE_FMT_RGB32F: 19,
|
||||
TEXTURE_FMT_RGBA32F: 20,
|
||||
TEXTURE_FMT_R32F: 21,
|
||||
TEXTURE_FMT_111110F: 22,
|
||||
TEXTURE_FMT_SRGB: 23,
|
||||
TEXTURE_FMT_SRGBA: 24,
|
||||
|
||||
// depth formats
|
||||
TEXTURE_FMT_D16: 25,
|
||||
TEXTURE_FMT_D24: 26,
|
||||
TEXTURE_FMT_D24S8: 27,
|
||||
|
||||
// depth and stencil function
|
||||
DS_FUNC_NEVER: 512, // gl.NEVER
|
||||
DS_FUNC_LESS: 513, // gl.LESS
|
||||
DS_FUNC_EQUAL: 514, // gl.EQUAL
|
||||
DS_FUNC_LEQUAL: 515, // gl.LEQUAL
|
||||
DS_FUNC_GREATER: 516, // gl.GREATER
|
||||
DS_FUNC_NOTEQUAL: 517, // gl.NOTEQUAL
|
||||
DS_FUNC_GEQUAL: 518, // gl.GEQUAL
|
||||
DS_FUNC_ALWAYS: 519, // gl.ALWAYS
|
||||
|
||||
// render-buffer format
|
||||
RB_FMT_RGBA4: 32854, // gl.RGBA4
|
||||
RB_FMT_RGB5_A1: 32855, // gl.RGB5_A1
|
||||
RB_FMT_RGB565: 36194, // gl.RGB565
|
||||
RB_FMT_D16: 33189, // gl.DEPTH_COMPONENT16
|
||||
RB_FMT_S8: 36168, // gl.STENCIL_INDEX8
|
||||
RB_FMT_D24S8: 34041, // gl.DEPTH_STENCIL
|
||||
|
||||
// blend-equation
|
||||
BLEND_FUNC_ADD: 32774, // gl.FUNC_ADD
|
||||
BLEND_FUNC_SUBTRACT: 32778, // gl.FUNC_SUBTRACT
|
||||
BLEND_FUNC_REVERSE_SUBTRACT: 32779, // gl.FUNC_REVERSE_SUBTRACT
|
||||
|
||||
// blend
|
||||
BLEND_ZERO: 0, // gl.ZERO
|
||||
BLEND_ONE: 1, // gl.ONE
|
||||
BLEND_SRC_COLOR: 768, // gl.SRC_COLOR
|
||||
BLEND_ONE_MINUS_SRC_COLOR: 769, // gl.ONE_MINUS_SRC_COLOR
|
||||
BLEND_DST_COLOR: 774, // gl.DST_COLOR
|
||||
BLEND_ONE_MINUS_DST_COLOR: 775, // gl.ONE_MINUS_DST_COLOR
|
||||
BLEND_SRC_ALPHA: 770, // gl.SRC_ALPHA
|
||||
BLEND_ONE_MINUS_SRC_ALPHA: 771, // gl.ONE_MINUS_SRC_ALPHA
|
||||
BLEND_DST_ALPHA: 772, // gl.DST_ALPHA
|
||||
BLEND_ONE_MINUS_DST_ALPHA: 773, // gl.ONE_MINUS_DST_ALPHA
|
||||
BLEND_CONSTANT_COLOR: 32769, // gl.CONSTANT_COLOR
|
||||
BLEND_ONE_MINUS_CONSTANT_COLOR: 32770, // gl.ONE_MINUS_CONSTANT_COLOR
|
||||
BLEND_CONSTANT_ALPHA: 32771, // gl.CONSTANT_ALPHA
|
||||
BLEND_ONE_MINUS_CONSTANT_ALPHA: 32772, // gl.ONE_MINUS_CONSTANT_ALPHA
|
||||
BLEND_SRC_ALPHA_SATURATE: 776, // gl.SRC_ALPHA_SATURATE
|
||||
|
||||
// stencil operation
|
||||
STENCIL_OP_KEEP: 7680, // gl.KEEP
|
||||
STENCIL_OP_ZERO: 0, // gl.ZERO
|
||||
STENCIL_OP_REPLACE: 7681, // gl.REPLACE
|
||||
STENCIL_OP_INCR: 7682, // gl.INCR
|
||||
STENCIL_OP_INCR_WRAP: 34055, // gl.INCR_WRAP
|
||||
STENCIL_OP_DECR: 7683, // gl.DECR
|
||||
STENCIL_OP_DECR_WRAP: 34056, // gl.DECR_WRAP
|
||||
STENCIL_OP_INVERT: 5386, // gl.INVERT
|
||||
|
||||
// cull
|
||||
CULL_NONE: 0,
|
||||
CULL_FRONT: 1028,
|
||||
CULL_BACK: 1029,
|
||||
CULL_FRONT_AND_BACK: 1032,
|
||||
|
||||
// primitive type
|
||||
PT_POINTS: 0, // gl.POINTS
|
||||
PT_LINES: 1, // gl.LINES
|
||||
PT_LINE_LOOP: 2, // gl.LINE_LOOP
|
||||
PT_LINE_STRIP: 3, // gl.LINE_STRIP
|
||||
PT_TRIANGLES: 4, // gl.TRIANGLES
|
||||
PT_TRIANGLE_STRIP: 5, // gl.TRIANGLE_STRIP
|
||||
PT_TRIANGLE_FAN: 6, // gl.TRIANGLE_FAN
|
||||
};
|
||||
|
||||
/**
|
||||
* @method attrTypeBytes
|
||||
* @param {ATTR_TYPE_*} attrType
|
||||
*/
|
||||
function attrTypeBytes(attrType) {
|
||||
if (attrType === enums.ATTR_TYPE_INT8) {
|
||||
return 1;
|
||||
} else if (attrType === enums.ATTR_TYPE_UINT8) {
|
||||
return 1;
|
||||
} else if (attrType === enums.ATTR_TYPE_INT16) {
|
||||
return 2;
|
||||
} else if (attrType === enums.ATTR_TYPE_UINT16) {
|
||||
return 2;
|
||||
} else if (attrType === enums.ATTR_TYPE_INT32) {
|
||||
return 4;
|
||||
} else if (attrType === enums.ATTR_TYPE_UINT32) {
|
||||
return 4;
|
||||
} else if (attrType === enums.ATTR_TYPE_FLOAT32) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
console.warn(`Unknown ATTR_TYPE: ${attrType}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method glFilter
|
||||
* @param {WebGLContext} gl
|
||||
* @param {FILTER_*} filter
|
||||
* @param {FILTER_*} mipFilter
|
||||
*/
|
||||
function glFilter(gl, filter, mipFilter = -1) {
|
||||
let result = _filterGL[filter][mipFilter+1];
|
||||
if (result === undefined) {
|
||||
console.warn(`Unknown FILTER: ${filter}`);
|
||||
return mipFilter === -1 ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method glTextureFmt
|
||||
* @param {TEXTURE_FMT_*} fmt
|
||||
*/
|
||||
function glTextureFmt(fmt) {
|
||||
let result = _textureFmtGL[fmt];
|
||||
if (result === undefined) {
|
||||
console.warn(`Unknown TEXTURE_FMT: ${fmt}`);
|
||||
return _textureFmtGL[enums.TEXTURE_FMT_RGBA8];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
glFilter: glFilter,
|
||||
glTextureFmt: glTextureFmt,
|
||||
attrTypeBytes: attrTypeBytes,
|
||||
enums : enums
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
let {enums, glTextureFmt} = require("./enums");
|
||||
let VertexFormat = require("./vertex-format-jsb");
|
||||
|
||||
window.device = gfx.Device.getInstance();
|
||||
window.device._gl = window.gl;
|
||||
|
||||
//FIXME:
|
||||
window.device._stats = { vb: 0 };
|
||||
window.device._caps = {
|
||||
maxVextexTextures: 16,
|
||||
maxFragUniforms: 1024,
|
||||
maxTextureUints: 8,
|
||||
maxVertexAttributes: 16,
|
||||
maxDrawBuffers: 8,
|
||||
maxColorAttatchments: 8
|
||||
};
|
||||
|
||||
device.setBlendColor32 = device.setBlendColor;
|
||||
|
||||
_p = gfx.Program.prototype;
|
||||
_p._ctor = function(device, options) {
|
||||
this.init(device, options.vert, options.frag);
|
||||
};
|
||||
|
||||
_p = gfx.VertexBuffer.prototype;
|
||||
_p._ctor = function(device, format, usage, data, numVertices) {
|
||||
this.init(device, format, usage, data, numVertices);
|
||||
};
|
||||
cc.defineGetterSetter(_p, "count", _p.getCount);
|
||||
|
||||
_p = gfx.IndexBuffer.prototype;
|
||||
_p._ctor = function(device, format, usage, data, numIndices) {
|
||||
this.init(device, format, usage, data, numIndices);
|
||||
};
|
||||
cc.defineGetterSetter(_p, "count", _p.getCount);
|
||||
|
||||
gfx.VertexFormat = VertexFormat;
|
||||
Object.assign(gfx, enums);
|
||||
|
||||
function convertImages(images) {
|
||||
if (images) {
|
||||
for (let i = 0, len = images.length; i < len; ++i) {
|
||||
let image = images[i];
|
||||
if (image !== null) {
|
||||
if (image instanceof window.HTMLCanvasElement) {
|
||||
if (image._data) {
|
||||
images[i] = image._data._data;
|
||||
}
|
||||
else {
|
||||
images[i] = null;
|
||||
}
|
||||
}
|
||||
else if (image instanceof window.HTMLImageElement) {
|
||||
images[i] = image._data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_p = gfx.Texture2D.prototype;
|
||||
_p._ctor = function(device, options) {
|
||||
convertImages(options.images);
|
||||
this.init(device, options);
|
||||
};
|
||||
_p.destroy = function() {
|
||||
};
|
||||
_p.update = function(options) {
|
||||
convertImages(options.images);
|
||||
this.updateBinding(options);
|
||||
};
|
||||
cc.defineGetterSetter(_p, "_width", _p.getWidth);
|
||||
cc.defineGetterSetter(_p, "_height", _p.getHeight);
|
||||
|
||||
_p = gfx.FrameBuffer.prototype;
|
||||
_p._ctor = function(device, width, height, options) {
|
||||
this.init(device, width, height, options);
|
||||
};
|
||||
|
||||
var TextHAlignment = {
|
||||
LEFT : 0,
|
||||
CENTER : 1,
|
||||
RIGHT : 2
|
||||
};
|
||||
|
||||
var TextVAlignment = {
|
||||
TOP : 0,
|
||||
CENTER : 1,
|
||||
BOTTOM : 2
|
||||
};
|
||||
|
||||
var DeviceTextAlign = {
|
||||
CENTER : 0x33, /** Horizontal center and vertical center. */
|
||||
TOP : 0x13, /** Horizontal center and vertical top. */
|
||||
TOP_RIGHT : 0x12, /** Horizontal right and vertical top. */
|
||||
RIGHT : 0x32, /** Horizontal right and vertical center. */
|
||||
BOTTOM_RIGHT : 0x22, /** Horizontal right and vertical bottom. */
|
||||
BOTTOM : 0x23, /** Horizontal center and vertical bottom. */
|
||||
BOTTOM_LEFT : 0x21, /** Horizontal left and vertical bottom. */
|
||||
LEFT : 0x31, /** Horizontal left and vertical center. */
|
||||
TOP_LEFT : 0x11 /** Horizontal left and vertical top. */
|
||||
}
|
||||
|
||||
gfx.RB_FMT_D16 = 0x81A5; // GL_DEPTH_COMPONENT16 hack for JSB
|
||||
+6
-4
@@ -1,6 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
@@ -23,6 +22,9 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
require('./gfx');
|
||||
require('./renderer');
|
||||
require('../index')
|
||||
require('./jsb-audio')
|
||||
require('./jsb-loader')
|
||||
|
||||
|
||||
@@ -1,441 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var ENABLE_GC_FOR_NATIVE_OBJECTS = cc.macro.ENABLE_GC_FOR_NATIVE_OBJECTS;
|
||||
|
||||
cc.Action.prototype._getSgTarget = cc.Action.prototype.getTarget;
|
||||
cc.Action.prototype.getTarget = function () {
|
||||
var sgNode = this._getSgTarget();
|
||||
return sgNode._owner || sgNode;
|
||||
};
|
||||
|
||||
cc.targetedAction = function (target, action) {
|
||||
return new cc.TargetedAction(target, action);
|
||||
};
|
||||
|
||||
cc.TargetedAction.prototype._ctor = function(target, action) {
|
||||
var node = target._sgNode || target;
|
||||
node._owner = target;
|
||||
action && this.initWithTarget(node, action);
|
||||
};
|
||||
|
||||
cc.follow = function (followedNode, rect) {
|
||||
return new cc.Follow(followedNode, rect);
|
||||
};
|
||||
|
||||
cc.Follow = cc.BaseJSAction.extend({
|
||||
_followedNode:null,
|
||||
_boundarySet:false,
|
||||
_boundaryFullyCovered:false,
|
||||
_halfScreenSize:null,
|
||||
_fullScreenSize:null,
|
||||
_worldRect:null,
|
||||
|
||||
leftBoundary:0.0,
|
||||
rightBoundary:0.0,
|
||||
topBoundary:0.0,
|
||||
bottomBoundary:0.0,
|
||||
|
||||
ctor:function (followedNode, rect) {
|
||||
cc.BaseJSAction.prototype.ctor.call(this);
|
||||
this._followedNode = null;
|
||||
this._boundarySet = false;
|
||||
|
||||
this._boundaryFullyCovered = false;
|
||||
this._halfScreenSize = null;
|
||||
this._fullScreenSize = null;
|
||||
|
||||
this.leftBoundary = 0.0;
|
||||
this.rightBoundary = 0.0;
|
||||
this.topBoundary = 0.0;
|
||||
this.bottomBoundary = 0.0;
|
||||
this._worldRect = cc.rect(0, 0, 0, 0);
|
||||
|
||||
if(followedNode)
|
||||
rect ? this.initWithTarget(followedNode, rect)
|
||||
: this.initWithTarget(followedNode);
|
||||
},
|
||||
|
||||
clone:function () {
|
||||
var action = new cc.Follow();
|
||||
var locRect = this._worldRect;
|
||||
var rect = new cc.Rect(locRect.x, locRect.y, locRect.width, locRect.height);
|
||||
action.initWithTarget(this._followedNode, rect);
|
||||
return action;
|
||||
},
|
||||
|
||||
isBoundarySet:function () {
|
||||
return this._boundarySet;
|
||||
},
|
||||
|
||||
setBoudarySet:function (value) {
|
||||
this._boundarySet = value;
|
||||
},
|
||||
|
||||
initWithTarget:function (followedNode, rect) {
|
||||
if(!followedNode)
|
||||
throw new Error("cc.Follow.initWithAction(): followedNode must be non nil");
|
||||
|
||||
var _this = this;
|
||||
rect = rect || cc.rect(0, 0, 0, 0);
|
||||
_this._followedNode = followedNode;
|
||||
_this._worldRect = rect;
|
||||
|
||||
_this._boundarySet = !cc._rectEqualToZero(rect);
|
||||
|
||||
_this._boundaryFullyCovered = false;
|
||||
|
||||
var winSize = cc.director.getWinSize();
|
||||
_this._fullScreenSize = cc.p(winSize.width, winSize.height);
|
||||
_this._halfScreenSize = cc.pMult(_this._fullScreenSize, 0.5);
|
||||
|
||||
if (_this._boundarySet) {
|
||||
_this.leftBoundary = -((rect.x + rect.width) - _this._fullScreenSize.x);
|
||||
_this.rightBoundary = -rect.x;
|
||||
_this.topBoundary = -rect.y;
|
||||
_this.bottomBoundary = -((rect.y + rect.height) - _this._fullScreenSize.y);
|
||||
|
||||
if (_this.rightBoundary < _this.leftBoundary) {
|
||||
_this.rightBoundary = _this.leftBoundary = (_this.leftBoundary + _this.rightBoundary) / 2;
|
||||
}
|
||||
if (_this.topBoundary < _this.bottomBoundary) {
|
||||
_this.topBoundary = _this.bottomBoundary = (_this.topBoundary + _this.bottomBoundary) / 2;
|
||||
}
|
||||
|
||||
if ((_this.topBoundary === _this.bottomBoundary) && (_this.leftBoundary === _this.rightBoundary))
|
||||
_this._boundaryFullyCovered = true;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
step:function (dt) {
|
||||
var target = this.getTarget();
|
||||
var targetWorldPos = target.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
||||
var followedWorldPos = this._followedNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
||||
var delta = cc.pSub(targetWorldPos, followedWorldPos);
|
||||
var tempPos = target.parent.convertToNodeSpaceAR(cc.pAdd(delta, this._halfScreenSize));
|
||||
|
||||
if (this._boundarySet) {
|
||||
if (this._boundaryFullyCovered)
|
||||
return;
|
||||
|
||||
target.setPosition(cc.clampf(tempPos.x, this.leftBoundary, this.rightBoundary), cc.clampf(tempPos.y, this.bottomBoundary, this.topBoundary));
|
||||
} else {
|
||||
target.setPosition(tempPos.x, tempPos.y);
|
||||
}
|
||||
},
|
||||
|
||||
isDone:function () {
|
||||
return ( !this._followedNode.isRunning() );
|
||||
},
|
||||
|
||||
stop:function () {
|
||||
this.setTarget(null);
|
||||
cc.Action.prototype.stop.call(this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var _FlipX = cc.FlipX;
|
||||
cc.FlipX = _FlipX.extend({
|
||||
_flippedX:false,
|
||||
|
||||
ctor:function(flip){
|
||||
_FlipX.prototype.ctor.call(this);
|
||||
this.initWithFlipX(flip);
|
||||
},
|
||||
|
||||
initWithFlipX:function (flip) {
|
||||
this._flippedX = !!flip;
|
||||
return true;
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
var target = this._getSgTarget();
|
||||
target.scaleX = Math.abs(target.scaleX) * (this._flippedX ? -1 : 1);
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
return new cc.FlipX(!this._flippedX);
|
||||
},
|
||||
|
||||
clone:function(){
|
||||
return new cc.FlipX(this._flippedX);
|
||||
}
|
||||
});
|
||||
|
||||
cc.flipX = function (flip) {
|
||||
return new cc.FlipX(flip);
|
||||
};
|
||||
|
||||
var _FlipY = cc.FlipY;
|
||||
cc.FlipY = _FlipY.extend({
|
||||
_flippedY:false,
|
||||
|
||||
ctor: function(flip){
|
||||
_FlipY.prototype.ctor.call(this);
|
||||
this.initWithFlipY(flip);
|
||||
},
|
||||
|
||||
initWithFlipY:function (flip) {
|
||||
this._flippedY = !!flip;
|
||||
return true;
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
var target = this._getSgTarget();
|
||||
target.scaleY = Math.abs(target.scaleY) * (this._flippedY ? -1 : 1);
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
return new cc.FlipY(!this._flippedY);
|
||||
},
|
||||
|
||||
clone:function(){
|
||||
return new cc.FlipY(this._flippedY);
|
||||
}
|
||||
});
|
||||
|
||||
cc.flipY = function (flip) {
|
||||
return new cc.FlipY(flip);
|
||||
};
|
||||
|
||||
function setRendererVisibility (sgNode, toggleVisible, visible) {
|
||||
if (!sgNode) { return; }
|
||||
var _renderComps = sgNode._owner.getComponentsInChildren(cc._SGComponent);
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = toggleVisible ? !render.enabled : visible;
|
||||
}
|
||||
}
|
||||
|
||||
cc.Show.prototype.update = function (dt) {
|
||||
setRendererVisibility(this._getSgTarget(), false, true);
|
||||
};
|
||||
|
||||
cc.Hide.prototype.update = function (dt) {
|
||||
setRendererVisibility(this._getSgTarget(), false, false);
|
||||
};
|
||||
|
||||
cc.ToggleVisibility.prototype.update = function (dt) {
|
||||
setRendererVisibility(this._getSgTarget(), true);
|
||||
};
|
||||
|
||||
// Special call func
|
||||
cc.callFunc = function (selector, selectorTarget, data) {
|
||||
var callback = function (sender) {
|
||||
if (sender) {
|
||||
sender = sender._owner || sender;
|
||||
}
|
||||
selector.call(this, sender, data);
|
||||
};
|
||||
var action = selectorTarget ? cc.CallFunc.create(callback, selectorTarget) : cc.CallFunc.create(callback);
|
||||
return action;
|
||||
};
|
||||
|
||||
cc.CallFunc.prototype._ctor = function (selector, selectorTarget, data) {
|
||||
if(selector !== undefined){
|
||||
var callback = function (sender) {
|
||||
if (sender) {
|
||||
sender = sender._owner || sender;
|
||||
}
|
||||
selector.call(this, sender, data);
|
||||
};
|
||||
if (selectorTarget === undefined) {
|
||||
this.initWithFunction(callback);
|
||||
}
|
||||
else {
|
||||
this.initWithFunction(callback, selectorTarget);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function getSGTarget (target) {
|
||||
if (target instanceof cc.Component) {
|
||||
target = target.node._sgNode;
|
||||
}
|
||||
else if (target instanceof cc.Node) {
|
||||
target = target._sgNode;
|
||||
}
|
||||
else if (!(target instanceof _ccsg.Node)) {
|
||||
target = null;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
var jsbAddAction = cc.ActionManager.prototype.addAction;
|
||||
cc.ActionManager.prototype.addAction = function (action, target, paused) {
|
||||
target = getSGTarget(target);
|
||||
if (target) {
|
||||
jsbAddAction.call(this, action, target, paused);
|
||||
}
|
||||
};
|
||||
|
||||
function actionMgrFuncReplacer (funcName, targetPos) {
|
||||
var proto = cc.ActionManager.prototype;
|
||||
var oldFunc = proto[funcName];
|
||||
proto[funcName] = function () {
|
||||
var args = [];
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
if (i === targetPos)
|
||||
args[i] = getSGTarget(arguments[i]);
|
||||
else
|
||||
args[i] = arguments[i];
|
||||
}
|
||||
if (!args[targetPos]) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return oldFunc.apply(this, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var targetRelatedFuncs = [
|
||||
['removeAllActionsFromTarget', 0],
|
||||
['removeActionByTag', 1],
|
||||
['getActionByTag', 1],
|
||||
['getNumberOfRunningActionsInTarget', 0],
|
||||
['pauseTarget', 0],
|
||||
['resumeTarget', 0]
|
||||
];
|
||||
|
||||
for (var i = 0; i < targetRelatedFuncs.length; ++i) {
|
||||
actionMgrFuncReplacer.apply(null, targetRelatedFuncs[i]);
|
||||
}
|
||||
|
||||
cc.ActionManager.prototype.resumeTargets = function (targetsToResume) {
|
||||
if (!targetsToResume)
|
||||
return;
|
||||
|
||||
for (var i = 0; i< targetsToResume.length; i++) {
|
||||
if (targetsToResume[i])
|
||||
this.resumeTarget(targetsToResume[i]);
|
||||
}
|
||||
};
|
||||
|
||||
cc.ActionManager.prototype.pauseTargets = function (targetsToPause) {
|
||||
if (!targetsToPause)
|
||||
return;
|
||||
|
||||
for (var i = 0; i< targetsToPause.length; i++) {
|
||||
if (targetsToPause[i])
|
||||
this.pauseTarget(targetsToPause[i]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function syncPositionUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.x = target.getPositionX();
|
||||
target._owner.y = target.getPositionY();
|
||||
}
|
||||
}
|
||||
|
||||
function syncRotationUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.rotationX = target.getRotationX();
|
||||
target._owner.rotationY = target.getRotationY();
|
||||
}
|
||||
}
|
||||
|
||||
function syncScaleUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.scaleX = target.getScaleX();
|
||||
target._owner.scaleY = target.getScaleY();
|
||||
}
|
||||
}
|
||||
|
||||
function syncRemoveSelfUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
function syncSkewUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.skewX = target.getSkewX();
|
||||
target._owner.skewY = target.getSkewY();
|
||||
}
|
||||
}
|
||||
|
||||
function syncOpacityUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
target._owner.opacity = target.getOpacity();
|
||||
}
|
||||
}
|
||||
|
||||
function syncColorUpdate (dt) {
|
||||
var target = this._getSgTarget();
|
||||
if (target._owner) {
|
||||
var color = target.getColor();
|
||||
target._owner.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
// Sub classes must be registered before their super class.
|
||||
// Otherwise, JSB there will be internal Error: "too much recursion".
|
||||
var actionUpdate = {
|
||||
'MoveBy': syncPositionUpdate,
|
||||
'JumpBy': syncPositionUpdate,
|
||||
'Place': syncPositionUpdate,
|
||||
'CardinalSplineTo': syncPositionUpdate,
|
||||
'RotateTo': syncRotationUpdate,
|
||||
'RotateBy': syncRotationUpdate,
|
||||
'ScaleTo': syncScaleUpdate,
|
||||
'RemoveSelf': syncRemoveSelfUpdate,
|
||||
'SkewTo': syncSkewUpdate,
|
||||
'Blink': syncOpacityUpdate,
|
||||
'FadeIn': syncOpacityUpdate,
|
||||
'FadeOut': syncOpacityUpdate,
|
||||
'FadeTo': syncOpacityUpdate,
|
||||
'TintTo': syncColorUpdate,
|
||||
'TintBy': syncColorUpdate,
|
||||
'BezierBy': syncPositionUpdate
|
||||
};
|
||||
|
||||
for (var key in actionUpdate) {
|
||||
var action = cc[key];
|
||||
var prototype = action.prototype;
|
||||
prototype.update = actionUpdate[key];
|
||||
|
||||
// polyfill to preserve chainable binding object
|
||||
prototype.speed = function (speed) {
|
||||
return new cc.Speed(this, speed);
|
||||
};
|
||||
prototype.repeat = function (times) {
|
||||
return new cc.Repeat(this, times);
|
||||
};
|
||||
prototype.repeatForever = function () {
|
||||
return new cc.RepeatForever(this);
|
||||
};
|
||||
}
|
||||
-620
@@ -1,620 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* The namespace for jsb exclusive APIs, all APIs in this namespace should never be used in Web engine.
|
||||
* So please check whether the running environment is native or not before any usage.
|
||||
* @namespace
|
||||
* @name jsb
|
||||
* @example
|
||||
*
|
||||
* if(cc.sys.isNative) {
|
||||
* cc.log(cc.fileUtils.fullPathForFilename("test.js"));
|
||||
* }
|
||||
*/
|
||||
var jsb = jsb || {};
|
||||
|
||||
/**
|
||||
* ATTENTION: USE jsb.fileUtils INSTEAD OF jsb.FileUtils.<br/>
|
||||
* jsb.fileUtils is the native file utils' singleton object,<br/>
|
||||
* please refer to Cocos2d-x's API to know how to use it.<br/>
|
||||
* Only available in JSB
|
||||
* @class
|
||||
* @name jsb.fileUtils
|
||||
* @extend cc._Class
|
||||
*/
|
||||
jsb.fileUtils = /** @lends jsb.fileUtils# */{
|
||||
|
||||
/**
|
||||
* @function fullPathForFilename
|
||||
* @param {String} arg0
|
||||
* @return {String}
|
||||
*/
|
||||
fullPathForFilename : function (str)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getStringFromFile
|
||||
* @param {String} arg0
|
||||
* @return {String}
|
||||
*/
|
||||
getStringFromFile : function (str)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function removeFile
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
removeFile : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function isAbsolutePath
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
isAbsolutePath : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function renameFile
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
* @param {String} arg2
|
||||
* @return {bool}
|
||||
*/
|
||||
renameFile : function (str, str, str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function loadFilenameLookupDictionaryFromFile
|
||||
* @param {String} arg0
|
||||
*/
|
||||
loadFilenameLookupDictionaryFromFile : function (str)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function isPopupNotify
|
||||
* @return {bool}
|
||||
*/
|
||||
isPopupNotify : function ()
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getValueVectorFromFile
|
||||
* @param {String} arg0
|
||||
* @return {Array}
|
||||
*/
|
||||
getValueVectorFromFile : function (str)
|
||||
{
|
||||
return new Array();
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getSearchPaths
|
||||
* @return {Array}
|
||||
*/
|
||||
getSearchPaths : function ()
|
||||
{
|
||||
return new Array();
|
||||
},
|
||||
|
||||
/**
|
||||
* @function writeToFile
|
||||
* @param {map_object} arg0
|
||||
* @param {String} arg1
|
||||
* @return {bool}
|
||||
*/
|
||||
writeToFile : function (map, str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getValueMapFromFile
|
||||
* @param {String} arg0
|
||||
* @return {map_object}
|
||||
*/
|
||||
getValueMapFromFile : function (str)
|
||||
{
|
||||
return map_object;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getFileSize
|
||||
* @param {String} arg0
|
||||
* @return {long}
|
||||
*/
|
||||
getFileSize : function (str)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function removeDirectory
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
removeDirectory : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function setSearchPaths
|
||||
* @param {Array} arg0
|
||||
*/
|
||||
setSearchPaths : function (array)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function writeStringToFile
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
* @return {bool}
|
||||
*/
|
||||
writeStringToFile : function (str, str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function setSearchResolutionsOrder
|
||||
* @param {Array} arg0
|
||||
*/
|
||||
setSearchResolutionsOrder : function (array)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function addSearchResolutionsOrder
|
||||
* @param {String} arg0
|
||||
*/
|
||||
addSearchResolutionsOrder : function (str)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function addSearchPath
|
||||
* @param {String} arg0
|
||||
*/
|
||||
addSearchPath : function (str)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function isFileExist
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
isFileExist : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function purgeCachedEntries
|
||||
*/
|
||||
purgeCachedEntries : function ()
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function fullPathFromRelativeFile
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
* @return {String}
|
||||
*/
|
||||
fullPathFromRelativeFile : function (str, str)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function isDirectoryExist
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
isDirectoryExist : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getSearchResolutionsOrder
|
||||
* @return {Array}
|
||||
*/
|
||||
getSearchResolutionsOrder : function ()
|
||||
{
|
||||
return new Array();
|
||||
},
|
||||
|
||||
/**
|
||||
* @function createDirectory
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
createDirectory : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function createDirectories
|
||||
* @param {String} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
createDirectories : function (str)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getWritablePath
|
||||
* @return {String}
|
||||
*/
|
||||
getWritablePath : function ()
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
jsb.EventAssetsManager = cc._Class.extend(/** @lends jsb.EventAssetsManager# */{
|
||||
|
||||
/**
|
||||
* @function getAssetsManager
|
||||
* @return {cc.AssetsManager}
|
||||
*/
|
||||
getAssetsManager : function (
|
||||
)
|
||||
{
|
||||
return cc.AssetsManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getAssetId
|
||||
* @return {String}
|
||||
*/
|
||||
getAssetId : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getCURLECode
|
||||
* @return {int}
|
||||
*/
|
||||
getCURLECode : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getMessage
|
||||
* @return {String}
|
||||
*/
|
||||
getMessage : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getCURLMCode
|
||||
* @return {int}
|
||||
*/
|
||||
getCURLMCode : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getPercentByFile
|
||||
* @return {float}
|
||||
*/
|
||||
getPercentByFile : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getEventCode
|
||||
* @return {cc.EventAssetsManager::EventCode}
|
||||
*/
|
||||
getEventCode : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getPercent
|
||||
* @return {float}
|
||||
*/
|
||||
getPercent : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function EventAssetsManager
|
||||
*
|
||||
* @param {String} arg0
|
||||
* @param {cc.AssetsManager} arg1
|
||||
* @param {cc.EventAssetsManager::EventCode} arg2
|
||||
* @param {float} arg3
|
||||
* @param {float} arg4
|
||||
* @param {String} arg5
|
||||
* @param {String} arg6
|
||||
* @param {int} arg7
|
||||
* @param {int} arg8
|
||||
*/
|
||||
EventAssetsManager : function (
|
||||
str,
|
||||
assetsmanager,
|
||||
eventcode,
|
||||
float,
|
||||
float,
|
||||
str,
|
||||
str,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
jsb.EventListenerAssetsManager = cc._Class.extend(/** @lends jsb.EventListenerAssetsManager# */{
|
||||
|
||||
/**
|
||||
* @function init
|
||||
* @param {cc.AssetsManager} arg0
|
||||
* @param {function} arg1
|
||||
* @return {bool}
|
||||
*/
|
||||
init : function (
|
||||
assetsmanager,
|
||||
func
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function create
|
||||
* @param {cc.AssetsManager} arg0
|
||||
* @param {function} arg1
|
||||
* @return {cc.EventListenerAssetsManager}
|
||||
*/
|
||||
create : function (
|
||||
assetsmanager,
|
||||
func
|
||||
)
|
||||
{
|
||||
return cc.EventListenerAssetsManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function EventListenerAssetsManager
|
||||
*
|
||||
*/
|
||||
EventListenerAssetsManager : function (
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @class
|
||||
* jsb.AssetsManager is the native AssetsManager for your game resources or scripts.
|
||||
* please refer to this document to know how to use it: http://www.cocos2d-x.org/docs/manual/framework/html5/v3/assets-manager/en
|
||||
* Only available in JSB
|
||||
*/
|
||||
jsb.AssetsManager = cc._Class.extend(/** @lends jsb.AssetsManager# */{
|
||||
|
||||
/**
|
||||
* @function getState
|
||||
* @return {jsb.AssetsManager::State}
|
||||
*/
|
||||
getState : function ()
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function checkUpdate
|
||||
*/
|
||||
checkUpdate : function ()
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getStoragePath
|
||||
* @return {String}
|
||||
*/
|
||||
getStoragePath : function ()
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function update
|
||||
*/
|
||||
update : function ()
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getLocalManifest
|
||||
* @return {jsb.Manifest}
|
||||
*/
|
||||
getLocalManifest : function ()
|
||||
{
|
||||
return cc.Manifest;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getRemoteManifest
|
||||
* @return {jsb.Manifest}
|
||||
*/
|
||||
getRemoteManifest : function ()
|
||||
{
|
||||
return cc.Manifest;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function downloadFailedAssets
|
||||
*/
|
||||
downloadFailedAssets : function ()
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @function create
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
* @return {jsb.AssetsManager}
|
||||
*/
|
||||
create : function (str, str)
|
||||
{
|
||||
return cc.AssetsManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function AssetsManager
|
||||
*
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
*/
|
||||
ctor : function (str, str)
|
||||
{
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
jsb.Manifest = cc._Class.extend(/** @lends jsb.Manifest# */{
|
||||
|
||||
/**
|
||||
* @function getManifestFileUrl
|
||||
* @return {String}
|
||||
*/
|
||||
getManifestFileUrl : function ()
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function isVersionLoaded
|
||||
* @return {bool}
|
||||
*/
|
||||
isVersionLoaded : function ()
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function isLoaded
|
||||
* @return {bool}
|
||||
*/
|
||||
isLoaded : function ()
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getPackageUrl
|
||||
* @return {String}
|
||||
*/
|
||||
getPackageUrl : function ()
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getVersion
|
||||
* @return {String}
|
||||
*/
|
||||
getVersion : function ()
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @function getVersionFileUrl
|
||||
* @return {String}
|
||||
*/
|
||||
getVersionFileUrl : function ()
|
||||
{
|
||||
return ;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* jsb.reflection is a bridge to let you invoke Java static functions.
|
||||
* please refer to this document to know how to use it: http://www.cocos2d-x.org/docs/manual/framework/html5/v3/reflection/en
|
||||
* Only available on iOS/Mac/Android platform
|
||||
* @class
|
||||
* @name jsb.reflection
|
||||
*/
|
||||
jsb.reflection = /** @lends jsb.reflection# */{
|
||||
/**
|
||||
* @function
|
||||
*/
|
||||
callStaticMethod : function(){
|
||||
}
|
||||
};
|
||||
+5
-85
@@ -6,7 +6,7 @@
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
@@ -48,6 +48,10 @@ cc.Audio.Type = {
|
||||
cc.audioEngine = audioEngine;
|
||||
audioEngine.play = audioEngine.play2d;
|
||||
audioEngine.setMaxWebAudioSize = function () {};
|
||||
// deprecated
|
||||
// var Module = require('../cocos2d/audio/deprecated');
|
||||
// Module.removed(audioEngine);
|
||||
// Module.deprecated(audioEngine);
|
||||
|
||||
proto.State = audioEngine.AudioState;
|
||||
|
||||
@@ -145,88 +149,4 @@ cc.Audio.Type = {
|
||||
return true;
|
||||
};
|
||||
|
||||
var _music = {
|
||||
id: -1,
|
||||
url: '',
|
||||
volume: 1
|
||||
};
|
||||
var _effect = {
|
||||
volume: 1
|
||||
};
|
||||
audioEngine.playMusic = function (filePath, loop) {
|
||||
audioEngine.stop(_music.id);
|
||||
_music.id = audioEngine.play(filePath, loop, _music.volume);
|
||||
_music.loop = loop;
|
||||
_music.url = filePath;
|
||||
return _music.id;
|
||||
};
|
||||
audioEngine.stopMusic = function () {
|
||||
audioEngine.stop(_music.id);
|
||||
};
|
||||
audioEngine.pauseMusic = function () {
|
||||
audioEngine.pause(_music.id);
|
||||
return _music.id;
|
||||
};
|
||||
audioEngine.resumeMusic = function () {
|
||||
audioEngine.resume(_music.id);
|
||||
return _music.id;
|
||||
};
|
||||
audioEngine.getMusicVolume = function () {
|
||||
return _music.volume;
|
||||
};
|
||||
audioEngine.setMusicVolume = function (volume) {
|
||||
_music.volume = volume;
|
||||
audioEngine.setVolume(_music.id, _music.volume);
|
||||
return _music.volume;
|
||||
};
|
||||
audioEngine.isMusicPlaying = function () {
|
||||
return audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING;
|
||||
};
|
||||
audioEngine.playEffect = function (filePath, loop) {
|
||||
return audioEngine.play(filePath, loop || false, _effect.volume);
|
||||
};
|
||||
audioEngine.setEffectsVolume = function (volume) {
|
||||
_effect.volume = volume;
|
||||
};
|
||||
audioEngine.getEffectsVolume = function () {
|
||||
return _effect.volume;
|
||||
};
|
||||
audioEngine.pauseEffect = function (audioID) {
|
||||
return audioEngine.pause(audioID);
|
||||
};
|
||||
audioEngine.pauseAllEffects = function () {
|
||||
var musicPlay = audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING;
|
||||
audioEngine.pauseAll();
|
||||
if (musicPlay) {
|
||||
audioEngine.resume(_music.id);
|
||||
}
|
||||
};
|
||||
audioEngine.resumeEffect = function (id) {
|
||||
audioEngine.resume(id);
|
||||
};
|
||||
audioEngine.resumeAllEffects = function () {
|
||||
var musicPaused = audioEngine.getState(_music.id) === audioEngine.AudioState.PAUSED;
|
||||
audioEngine.resumeAll();
|
||||
if (musicPaused && audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING) {
|
||||
audioEngine.pause(_music.id);
|
||||
}
|
||||
};
|
||||
audioEngine.stopEffect = function (id) {
|
||||
return audioEngine.stop(id);
|
||||
};
|
||||
audioEngine.stopAllEffects = function () {
|
||||
var musicPlay = audioEngine.getState(_music.id) === audioEngine.AudioState.PLAYING;
|
||||
var currentTime = audioEngine.getCurrentTime(_music.id);
|
||||
audioEngine.stopAll();
|
||||
if (musicPlay) {
|
||||
_music.id = audioEngine.play(_music.url, _music.loop);
|
||||
audioEngine.setCurrentTime(_music.id, currentTime);
|
||||
}
|
||||
};
|
||||
|
||||
// deprecated
|
||||
var Module = require('../cocos2d/audio/deprecated');
|
||||
Module.removed(audioEngine);
|
||||
Module.deprecated(audioEngine);
|
||||
|
||||
})(cc.Audio.prototype, jsb.AudioEngine);
|
||||
@@ -1,485 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
if (!window.b2) {
|
||||
window.b2 = {};
|
||||
}
|
||||
|
||||
// Vec2
|
||||
var Vec2 = b2.Vec2 = function (x_, y_) {
|
||||
if (x_ === undefined) x_ = 0;
|
||||
if (y_ === undefined) y_ = 0;
|
||||
this.x = x_;
|
||||
this.y = y_;
|
||||
};
|
||||
Vec2.Make = function (x_, y_) {
|
||||
if (x_ === undefined) x_ = 0;
|
||||
if (y_ === undefined) y_ = 0;
|
||||
return new Vec2(x_, y_);
|
||||
};
|
||||
Vec2.prototype.SetZero = function () {
|
||||
this.x = 0.0;
|
||||
this.y = 0.0;
|
||||
};
|
||||
Vec2.prototype.Set = function (x_, y_) {
|
||||
if (x_ === undefined) x_ = 0;
|
||||
if (y_ === undefined) y_ = 0;
|
||||
this.x = x_;
|
||||
this.y = y_;
|
||||
};
|
||||
Vec2.prototype.SetV = function (v) {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
};
|
||||
Vec2.prototype.GetNegative = function () {
|
||||
return new Vec2((-this.x), (-this.y));
|
||||
};
|
||||
Vec2.prototype.NegativeSelf = function () {
|
||||
this.x = (-this.x);
|
||||
this.y = (-this.y);
|
||||
};
|
||||
Vec2.prototype.Copy = function () {
|
||||
return new Vec2(this.x, this.y);
|
||||
};
|
||||
Vec2.prototype.Add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
};
|
||||
Vec2.prototype.Subtract = function (v) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
};
|
||||
Vec2.prototype.Multiply = function (a) {
|
||||
if (a === undefined) a = 0;
|
||||
this.x *= a;
|
||||
this.y *= a;
|
||||
};
|
||||
// Vec2.prototype.MulM = function (A) {
|
||||
// var tX = this.x;
|
||||
// this.x = A.col1.x * tX + A.col2.x * this.y;
|
||||
// this.y = A.col1.y * tX + A.col2.y * this.y;
|
||||
// };
|
||||
// Vec2.prototype.MulTM = function (A) {
|
||||
// var tX = b2Math.Dot(this, A.col1);
|
||||
// this.y = b2Math.Dot(this, A.col2);
|
||||
// this.x = tX;
|
||||
// };
|
||||
Vec2.prototype.CrossVF = function (s) {
|
||||
if (s === undefined) s = 0;
|
||||
var tX = this.x;
|
||||
this.x = s * this.y;
|
||||
this.y = (-s * tX);
|
||||
};
|
||||
Vec2.prototype.CrossFV = function (s) {
|
||||
if (s === undefined) s = 0;
|
||||
var tX = this.x;
|
||||
this.x = (-s * this.y);
|
||||
this.y = s * tX;
|
||||
};
|
||||
Vec2.prototype.MinV = function (b) {
|
||||
this.x = this.x < b.x ? this.x : b.x;
|
||||
this.y = this.y < b.y ? this.y : b.y;
|
||||
};
|
||||
Vec2.prototype.MaxV = function (b) {
|
||||
this.x = this.x > b.x ? this.x : b.x;
|
||||
this.y = this.y > b.y ? this.y : b.y;
|
||||
};
|
||||
Vec2.prototype.Abs = function () {
|
||||
if (this.x < 0) this.x = (-this.x);
|
||||
if (this.y < 0) this.y = (-this.y);
|
||||
};
|
||||
Vec2.prototype.Length = function () {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
};
|
||||
Vec2.prototype.LengthSquared = function () {
|
||||
return (this.x * this.x + this.y * this.y);
|
||||
};
|
||||
Vec2.prototype.Normalize = function () {
|
||||
var length = Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
if (length < Number.MIN_VALUE) {
|
||||
return 0.0;
|
||||
}
|
||||
var invLength = 1.0 / length;
|
||||
this.x *= invLength;
|
||||
this.y *= invLength;
|
||||
return length;
|
||||
};
|
||||
Vec2.IsValid = function (x) {
|
||||
if (x === undefined) x = 0;
|
||||
return isFinite(x);
|
||||
};
|
||||
Vec2.prototype.IsValid = function () {
|
||||
return Vec2.IsValid(this.x) && Vec2.IsValid(this.y);
|
||||
};
|
||||
|
||||
// AABB
|
||||
var AABB = b2.AABB = function () {
|
||||
this.lowerBound = new Vec2();
|
||||
this.upperBound = new Vec2();
|
||||
};
|
||||
AABB.prototype.IsValid = function () {
|
||||
var dX = this.upperBound.x - this.lowerBound.x;
|
||||
var dY = this.upperBound.y - this.lowerBound.y;
|
||||
var valid = dX >= 0.0 && dY >= 0.0;
|
||||
valid = valid && this.lowerBound.IsValid() && this.upperBound.IsValid();
|
||||
return valid;
|
||||
}
|
||||
AABB.prototype.GetCenter = function () {
|
||||
return new Vec2((this.lowerBound.x + this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2);
|
||||
}
|
||||
AABB.prototype.GetExtents = function () {
|
||||
return new Vec2((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2);
|
||||
}
|
||||
AABB.prototype.Contains = function (aabb) {
|
||||
var result = true;
|
||||
result = result && this.lowerBound.x <= aabb.lowerBound.x;
|
||||
result = result && this.lowerBound.y <= aabb.lowerBound.y;
|
||||
result = result && aabb.upperBound.x <= this.upperBound.x;
|
||||
result = result && aabb.upperBound.y <= this.upperBound.y;
|
||||
return result;
|
||||
}
|
||||
AABB.prototype.RayCast = function (output, input) {
|
||||
var tmin = (-Number.MAX_VALUE);
|
||||
var tmax = Number.MAX_VALUE;
|
||||
var pX = input.p1.x;
|
||||
var pY = input.p1.y;
|
||||
var dX = input.p2.x - input.p1.x;
|
||||
var dY = input.p2.y - input.p1.y;
|
||||
var absDX = Math.abs(dX);
|
||||
var absDY = Math.abs(dY);
|
||||
var normal = output.normal;
|
||||
var inv_d = 0;
|
||||
var t1 = 0;
|
||||
var t2 = 0;
|
||||
var t3 = 0;
|
||||
var s = 0; {
|
||||
if (absDX < Number.MIN_VALUE) {
|
||||
if (pX < this.lowerBound.x || this.upperBound.x < pX) return false;
|
||||
}
|
||||
else {
|
||||
inv_d = 1.0 / dX;
|
||||
t1 = (this.lowerBound.x - pX) * inv_d;
|
||||
t2 = (this.upperBound.x - pX) * inv_d;
|
||||
s = (-1.0);
|
||||
if (t1 > t2) {
|
||||
t3 = t1;
|
||||
t1 = t2;
|
||||
t2 = t3;
|
||||
s = 1.0;
|
||||
}
|
||||
if (t1 > tmin) {
|
||||
normal.x = s;
|
||||
normal.y = 0;
|
||||
tmin = t1;
|
||||
}
|
||||
tmax = Math.min(tmax, t2);
|
||||
if (tmin > tmax) return false;
|
||||
}
|
||||
} {
|
||||
if (absDY < Number.MIN_VALUE) {
|
||||
if (pY < this.lowerBound.y || this.upperBound.y < pY) return false;
|
||||
}
|
||||
else {
|
||||
inv_d = 1.0 / dY;
|
||||
t1 = (this.lowerBound.y - pY) * inv_d;
|
||||
t2 = (this.upperBound.y - pY) * inv_d;
|
||||
s = (-1.0);
|
||||
if (t1 > t2) {
|
||||
t3 = t1;
|
||||
t1 = t2;
|
||||
t2 = t3;
|
||||
s = 1.0;
|
||||
}
|
||||
if (t1 > tmin) {
|
||||
normal.y = s;
|
||||
normal.x = 0;
|
||||
tmin = t1;
|
||||
}
|
||||
tmax = Math.min(tmax, t2);
|
||||
if (tmin > tmax) return false;
|
||||
}
|
||||
}
|
||||
output.fraction = tmin;
|
||||
return true;
|
||||
}
|
||||
AABB.prototype.TestOverlap = function (other) {
|
||||
var d1X = other.lowerBound.x - this.upperBound.x;
|
||||
var d1Y = other.lowerBound.y - this.upperBound.y;
|
||||
var d2X = this.lowerBound.x - other.upperBound.x;
|
||||
var d2Y = this.lowerBound.y - other.upperBound.y;
|
||||
if (d1X > 0.0 || d1Y > 0.0) return false;
|
||||
if (d2X > 0.0 || d2Y > 0.0) return false;
|
||||
return true;
|
||||
}
|
||||
AABB.Combine = function (aabb1, aabb2) {
|
||||
var aabb = new AABB();
|
||||
aabb.Combine(aabb1, aabb2);
|
||||
return aabb;
|
||||
}
|
||||
AABB.prototype.Combine = function (aabb1, aabb2) {
|
||||
this.lowerBound.x = Math.min(aabb1.lowerBound.x, aabb2.lowerBound.x);
|
||||
this.lowerBound.y = Math.min(aabb1.lowerBound.y, aabb2.lowerBound.y);
|
||||
this.upperBound.x = Math.max(aabb1.upperBound.x, aabb2.upperBound.x);
|
||||
this.upperBound.y = Math.max(aabb1.upperBound.y, aabb2.upperBound.y);
|
||||
}
|
||||
|
||||
// FilterData
|
||||
var FilterData = b2.FilterData = function () {
|
||||
this.categoryBits = 0x0001;
|
||||
this.maskBits = 0xFFFF;
|
||||
this.groupIndex = 0;
|
||||
};
|
||||
FilterData.prototype.Copy = function () {
|
||||
var copy = new FilterData();
|
||||
copy.categoryBits = this.categoryBits;
|
||||
copy.maskBits = this.maskBits;
|
||||
copy.groupIndex = this.groupIndex;
|
||||
return copy;
|
||||
};
|
||||
|
||||
// FixtureDef
|
||||
b2.FixtureDef = function () {
|
||||
this.filter = new FilterData();
|
||||
|
||||
this.shape = null;
|
||||
this.userData = null;
|
||||
this.friction = 0.2;
|
||||
this.restitution = 0.0;
|
||||
this.density = 0.0;
|
||||
this.isSensor = false;
|
||||
};
|
||||
|
||||
// b2BodyDef
|
||||
b2.BodyDef = function () {
|
||||
this.position = new Vec2(0, 0);
|
||||
this.linearVelocity = new Vec2(0, 0);
|
||||
|
||||
this.userData = null;
|
||||
this.angle = 0.0;
|
||||
this.angularVelocity = 0.0;
|
||||
this.linearDamping = 0.0;
|
||||
this.angularDamping = 0.0;
|
||||
this.allowSleep = true;
|
||||
this.awake = true;
|
||||
this.fixedRotation = false;
|
||||
this.bullet = false;
|
||||
this.type = b2.Body.b2_staticBody;
|
||||
this.active = true;
|
||||
this.inertiaScale = 1.0;
|
||||
this.gravityScale = 1.0;
|
||||
};
|
||||
|
||||
b2.JointDef = function () {
|
||||
this.type = b2.Joint.e_unknownJoint;
|
||||
this.userData = null;
|
||||
this.bodyA = null;
|
||||
this.bodyB = null;
|
||||
this.collideConnected = false;
|
||||
};
|
||||
|
||||
|
||||
b2.DistanceJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_distanceJoint;
|
||||
this.localAnchorA = new Vec2();
|
||||
this.localAnchorB = new Vec2();
|
||||
this.length = 1.0;
|
||||
this.frequencyHz = 0.0;
|
||||
this.dampingRatio = 0.0;
|
||||
};
|
||||
|
||||
b2.FrictionJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_frictionJoint;
|
||||
this.localAnchorA = new Vec2();
|
||||
this.localAnchorB = new Vec2();
|
||||
this.maxForce = 0.0;
|
||||
this.maxTorque = 0.0;
|
||||
};
|
||||
|
||||
b2.GearJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_gearJoint;
|
||||
this.joint1 = null;
|
||||
this.joint2 = null;
|
||||
this.ratio = 1.0;
|
||||
};
|
||||
|
||||
b2.MotorJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_motorJoint;
|
||||
this.linearOffset = new Vec2();
|
||||
this.angularOffset = 0.0;
|
||||
this.maxForce = 1.0;
|
||||
this.maxTorque = 1.0;
|
||||
this.correctionFactor = 0.3;
|
||||
};
|
||||
|
||||
b2.MouseJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_mouseJoint;
|
||||
this.target = new Vec2();
|
||||
this.maxForce = 0.0;
|
||||
this.frequencyHz = 5.0;
|
||||
this.dampingRatio = 0.7;
|
||||
};
|
||||
|
||||
b2.PrismaticJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_prismaticJoint;
|
||||
this.localAnchorA = new Vec2();
|
||||
this.localAnchorB = new Vec2();
|
||||
this.localAxisA = new Vec2(1.0, 0.0);
|
||||
this.referenceAngle = 0.0;
|
||||
this.enableLimit = false;
|
||||
this.lowerTranslation = 0.0;
|
||||
this.upperTranslation = 0.0;
|
||||
this.enableMotor = false;
|
||||
this.maxMotorForce = 0.0;
|
||||
this.motorSpeed = 0.0;
|
||||
};
|
||||
|
||||
b2.PulleyJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_pulleyJoint;
|
||||
this.groundAnchorA = new Vec2(-1.0, 1.0);
|
||||
this.groundAnchorB = new Vec2(1.0, 1.0);
|
||||
this.localAnchorA = new Vec2(-1.0, 0.0);
|
||||
this.localAnchorB = new Vec2(1.0, 0.0);
|
||||
this.lengthA = 0.0;
|
||||
this.lengthB = 0.0;
|
||||
this.ratio = 1.0;
|
||||
this.collideConnected = true;
|
||||
};
|
||||
|
||||
b2.RevoluteJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_revoluteJoint;
|
||||
this.localAnchorA = new Vec2(0.0, 0.0);
|
||||
this.localAnchorB = new Vec2(0.0, 0.0);
|
||||
this.referenceAngle = 0.0;
|
||||
this.lowerAngle = 0.0;
|
||||
this.upperAngle = 0.0;
|
||||
this.maxMotorTorque = 0.0;
|
||||
this.motorSpeed = 0.0;
|
||||
this.enableLimit = false;
|
||||
this.enableMotor = false;
|
||||
};
|
||||
|
||||
b2.RopeJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_ropeJoint;
|
||||
this.localAnchorA = new Vec2(-1.0, 0.0);
|
||||
this.localAnchorB = new Vec2(1.0, 0.0);
|
||||
this.maxLength = 0.0;
|
||||
};
|
||||
|
||||
b2.WeldJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_weldJoint;
|
||||
this.localAnchorA = new Vec2(0.0, 0.0);
|
||||
this.localAnchorB = new Vec2(0.0, 0.0);
|
||||
this.referenceAngle = 0.0;
|
||||
this.frequencyHz = 0.0;
|
||||
this.dampingRatio = 0.0;
|
||||
};
|
||||
|
||||
b2.WheelJointDef = function () {
|
||||
b2.JointDef.apply(this, arguments);
|
||||
|
||||
this.type = b2.Joint.e_wheelJoint;
|
||||
this.localAnchorA = new Vec2();
|
||||
this.localAnchorB = new Vec2();
|
||||
this.localAxisA = new Vec2(1.0, 0.0);
|
||||
this.enableMotor = false;
|
||||
this.maxMotorTorque = 0.0;
|
||||
this.motorSpeed = 0.0;
|
||||
this.frequencyHz = 2.0;
|
||||
this.dampingRatio = 0.7;
|
||||
};
|
||||
|
||||
b2.WorldManifold = function ()
|
||||
{
|
||||
this.normal = new b2.Vec2(); ///< world vector pointing from A to B
|
||||
this.points = []; ///< world contact point (point of intersection)
|
||||
this.separations = []; ///< a negative value indicates overlap, in meters
|
||||
}
|
||||
|
||||
// b2Shape
|
||||
var _p = b2.Shape.prototype;
|
||||
cc.defineGetterSetter(_p, 'm_radius', _p.GetRadius, _p.SetRadius);
|
||||
|
||||
// b2CircleShape
|
||||
_p = b2.CircleShape.prototype;
|
||||
cc.defineGetterSetter(_p, 'm_p', _p.GetPosition, _p.SetPosition);
|
||||
|
||||
// b2Body Type
|
||||
b2.Body.b2_staticBody = 0;
|
||||
b2.Body.b2_kinematicBody = 1;
|
||||
b2.Body.b2_dynamicBody = 2;
|
||||
|
||||
// b2Draw
|
||||
b2.Draw.e_shapeBit = 0x0001; ///< draw shapes
|
||||
b2.Draw.e_jointBit = 0x0002; ///< draw joint connections
|
||||
b2.Draw.e_aabbBit = 0x0004; ///< draw axis aligned bounding boxes
|
||||
b2.Draw.e_pairBit = 0x0008; ///< draw broad-phase pairs
|
||||
b2.Draw.e_centerOfMassBit = 0x0010; ///< draw center of mass frame
|
||||
|
||||
// b2Joint
|
||||
b2.Joint.e_unknownJoint = 0;
|
||||
b2.Joint.e_revoluteJoint = 1;
|
||||
b2.Joint.e_prismaticJoint = 2;
|
||||
b2.Joint.e_distanceJoint = 3;
|
||||
b2.Joint.e_pulleyJoint = 4;
|
||||
b2.Joint.e_mouseJoint = 5;
|
||||
b2.Joint.e_gearJoint = 6;
|
||||
b2.Joint.e_wheelJoint = 7;
|
||||
b2.Joint.e_weldJoint = 8;
|
||||
b2.Joint.e_frictionJoint = 9;
|
||||
b2.Joint.e_ropeJoint = 10;
|
||||
b2.Joint.e_motorJoint = 11;
|
||||
|
||||
b2.Joint.e_inactiveLimit = 0;
|
||||
b2.Joint.e_atLowerLimit = 1;
|
||||
b2.Joint.e_atUpperLimit = 2;
|
||||
b2.Joint.e_equalLimits = 3;
|
||||
|
||||
b2.maxPolygonVertices = 8;
|
||||
b2.maxManifoldPoints = 2;
|
||||
|
||||
})();
|
||||
@@ -1,539 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
var AutoReleaseUtils = require('../cocos2d/core/load-pipeline/auto-release-utils');
|
||||
var ComponentScheduler = require('../cocos2d/core/component-scheduler');
|
||||
var NodeActivator = require('../cocos2d/core/node-activator');
|
||||
var EventListeners = require('../cocos2d/core/event/event-listeners');
|
||||
|
||||
cc.director._purgeDirector = cc.director.purgeDirector;
|
||||
|
||||
// cc.director
|
||||
cc.js.mixin(cc.director, {
|
||||
/**
|
||||
* Manage all init process shared between the web engine and jsb engine.
|
||||
* All platform independent init process should be occupied here.
|
||||
*/
|
||||
sharedInit: function () {
|
||||
this._compScheduler = new ComponentScheduler();
|
||||
this._nodeActivator = new NodeActivator();
|
||||
|
||||
var scheduler = this.getScheduler();
|
||||
|
||||
// Animation manager
|
||||
if (cc.AnimationManager) {
|
||||
this._animationManager = new cc.AnimationManager();
|
||||
scheduler.scheduleUpdate(this._animationManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
else {
|
||||
this._animationManager = null;
|
||||
}
|
||||
|
||||
// collider manager
|
||||
if (cc.CollisionManager) {
|
||||
this._collisionManager = new cc.CollisionManager();
|
||||
scheduler.scheduleUpdate(this._collisionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
else {
|
||||
this._collisionManager = null;
|
||||
}
|
||||
|
||||
// physics manager
|
||||
if (cc.PhysicsManager) {
|
||||
this._physicsManager = new cc.PhysicsManager();
|
||||
this.getScheduler().scheduleUpdate(this._physicsManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
else {
|
||||
this._physicsManager = null;
|
||||
}
|
||||
|
||||
// WidgetManager
|
||||
cc._widgetManager.init(this);
|
||||
|
||||
cc.loader.init(this);
|
||||
},
|
||||
|
||||
purgeDirector: function () {
|
||||
this._compScheduler.unscheduleAll();
|
||||
this._nodeActivator.reset();
|
||||
this._purgeDirector();
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the cc.director, can be used to restart the director after purge
|
||||
*/
|
||||
reset: function () {
|
||||
this.purgeDirector();
|
||||
|
||||
if (cc.eventManager)
|
||||
cc.eventManager.setEnabled(true);
|
||||
|
||||
// Animation manager
|
||||
if (this._animationManager) {
|
||||
this.getScheduler().scheduleUpdate(this._animationManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
|
||||
// Collision manager
|
||||
if (this._collisionManager) {
|
||||
this.getScheduler().scheduleUpdate(this._collisionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
|
||||
// Physics manager
|
||||
if (this._physicsManager) {
|
||||
this.getScheduler().scheduleUpdate(this._physicsManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
|
||||
this.startAnimation();
|
||||
},
|
||||
|
||||
getActionManager: function () {
|
||||
return this._actionManager;
|
||||
},
|
||||
|
||||
setActionManager: function (actionManager) {
|
||||
if (this._actionManager !== actionManager) {
|
||||
if (this._actionManager) {
|
||||
this._scheduler.unscheduleUpdate(this._actionManager);
|
||||
}
|
||||
this._actionManager = actionManager;
|
||||
this._scheduler.scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the cc.AnimationManager associated with this director.
|
||||
* @method getAnimationManager
|
||||
* @return {AnimationManager}
|
||||
*/
|
||||
getAnimationManager: function () {
|
||||
return this._animationManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the cc.CollisionManager associated with this director.
|
||||
* @method getCollisionManager
|
||||
* @return {CollisionManager}
|
||||
*/
|
||||
getCollisionManager: function () {
|
||||
return this._collisionManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the cc.PhysicsManager associated with this director.
|
||||
* @method getPhysicsManager
|
||||
* @return {PhysicsManager}
|
||||
*/
|
||||
getPhysicsManager: function () {
|
||||
return this._physicsManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns current running Scene. Director can only run one Scene at the time.
|
||||
* @method getScene
|
||||
* @return {Scene}
|
||||
*/
|
||||
getScene: function () {
|
||||
return this._scene;
|
||||
},
|
||||
|
||||
/**
|
||||
* Run a scene. Replaces the running scene with a new one or enter the first scene.
|
||||
* The new scene will be launched immediately.
|
||||
* @method runScene
|
||||
* @param {Scene} scene - The need run scene.
|
||||
* @param {Function} [onBeforeLoadScene] - The function invoked at the scene before loading.
|
||||
* @param {Function} [onLaunched] - The function invoked at the scene after launch.
|
||||
*/
|
||||
runSceneImmediate: function (scene, onBeforeLoadScene, onLaunched) {
|
||||
const console = window.console; // should mangle
|
||||
const INIT_SCENE = CC_DEBUG ? 'InitScene' : 'I';
|
||||
const AUTO_RELEASE = CC_DEBUG ? 'AutoRelease' : 'AR';
|
||||
const DESTROY = CC_DEBUG ? 'Destroy' : 'D';
|
||||
const ATTACH_PERSIST = CC_DEBUG ? 'AttachPersist' : 'AP';
|
||||
const ACTIVATE = CC_DEBUG ? 'Activate' : 'A';
|
||||
|
||||
if (scene instanceof cc.Scene) {
|
||||
console.time(INIT_SCENE);
|
||||
scene._load(); // ensure scene initialized
|
||||
console.timeEnd(INIT_SCENE);
|
||||
}
|
||||
|
||||
// detach persist nodes
|
||||
var game = cc.game;
|
||||
var persistNodeList = Object.keys(game._persistRootNodes).map(function (x) {
|
||||
return game._persistRootNodes[x];
|
||||
});
|
||||
for (let i = 0; i < persistNodeList.length; i++) {
|
||||
let node = persistNodeList[i];
|
||||
game._ignoreRemovePersistNode = node;
|
||||
node.parent = null;
|
||||
game._ignoreRemovePersistNode = null;
|
||||
}
|
||||
|
||||
var oldScene = this._scene;
|
||||
|
||||
// auto release assets
|
||||
console.time(AUTO_RELEASE);
|
||||
var autoReleaseAssets = oldScene && oldScene.autoReleaseAssets && oldScene.dependAssets;
|
||||
AutoReleaseUtils.autoRelease(autoReleaseAssets, scene.dependAssets, persistNodeList);
|
||||
console.timeEnd(AUTO_RELEASE);
|
||||
|
||||
// unload scene
|
||||
console.time(DESTROY);
|
||||
if (cc.isValid(oldScene)) {
|
||||
oldScene.destroy();
|
||||
}
|
||||
|
||||
this._scene = null;
|
||||
|
||||
// purge destroyed nodes belongs to old scene
|
||||
cc.Object._deferredDestroy();
|
||||
console.timeEnd(DESTROY);
|
||||
|
||||
if (onBeforeLoadScene) {
|
||||
onBeforeLoadScene();
|
||||
}
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, scene);
|
||||
|
||||
var sgScene = scene;
|
||||
|
||||
// Run an Entity Scene
|
||||
if (scene instanceof cc.Scene) {
|
||||
this._scene = scene;
|
||||
sgScene = scene._sgNode;
|
||||
|
||||
// Re-attach or replace persist nodes
|
||||
console.time(ATTACH_PERSIST);
|
||||
for (let i = 0; i < persistNodeList.length; i++) {
|
||||
let node = persistNodeList[i];
|
||||
var existNode = scene.getChildByUuid(node.uuid);
|
||||
if (existNode) {
|
||||
// scene also contains the persist node, select the old one
|
||||
var index = existNode.getSiblingIndex();
|
||||
existNode._destroyImmediate();
|
||||
scene.insertChild(node, index);
|
||||
}
|
||||
else {
|
||||
node.parent = scene;
|
||||
}
|
||||
}
|
||||
console.timeEnd(ATTACH_PERSIST);
|
||||
console.time(ACTIVATE);
|
||||
scene._activate();
|
||||
console.timeEnd(ACTIVATE);
|
||||
}
|
||||
|
||||
// Run or replace rendering scene
|
||||
if (!this.getRunningScene()) {
|
||||
this.runWithScene(sgScene);
|
||||
}
|
||||
else {
|
||||
this.replaceScene(sgScene);
|
||||
}
|
||||
|
||||
if (onLaunched) {
|
||||
onLaunched(null, scene);
|
||||
}
|
||||
this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene);
|
||||
},
|
||||
|
||||
/**
|
||||
* Run a scene. Replaces the running scene with a new one or enter the first scene.
|
||||
* The new scene will be launched at the end of the current frame.
|
||||
* @method runScene
|
||||
* @param {Scene} scene - The need run scene.
|
||||
* @param {Function} [onBeforeLoadScene] - The function invoked at the scene before loading.
|
||||
* @param {Function} [onLaunched] - The function invoked at the scene after launch.
|
||||
*/
|
||||
runScene: function (scene, onBeforeLoadScene, onLaunched) {
|
||||
cc.assertID(scene, 1205);
|
||||
if (scene instanceof cc.Scene) {
|
||||
// ensure scene initialized
|
||||
scene._load();
|
||||
}
|
||||
|
||||
// Delay run / replace scene to the end of the frame
|
||||
this.once(cc.Director.EVENT_AFTER_UPDATE, function () {
|
||||
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
|
||||
});
|
||||
},
|
||||
|
||||
// @Scene loading section
|
||||
|
||||
_getSceneUuid: function (key) {
|
||||
var scenes = cc.game._sceneInfos;
|
||||
if (typeof key === 'string') {
|
||||
if (!key.endsWith('.fire')) {
|
||||
key += '.fire';
|
||||
}
|
||||
if (key[0] !== '/' && !key.startsWith('db://assets/')) {
|
||||
key = '/' + key; // 使用全名匹配
|
||||
}
|
||||
// search scene
|
||||
for (var i = 0; i < scenes.length; i++) {
|
||||
var info = scenes[i];
|
||||
if (info.url.endsWith(key)) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof key === 'number') {
|
||||
if (0 <= key && key < scenes.length) {
|
||||
return scenes[key];
|
||||
}
|
||||
else {
|
||||
cc.errorID(1211, key);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cc.errorID(1212, key);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
setRuntimeLaunchScene: function (sceneName) {
|
||||
// should not preload launch scene in runtime
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
this._launchSceneUuid = info.uuid;
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads the scene by its name.
|
||||
* @method loadScene
|
||||
* @param {String} sceneName - The name of the scene to load.
|
||||
* @param {Function} [onLaunched] - callback, will be called after scene launched.
|
||||
* @param {Function} [onUnloaded] - callback, will be called when the previous scene was unloaded.
|
||||
* @return {Boolean} if error, return false
|
||||
*/
|
||||
loadScene: function (sceneName, onLaunched, _onUnloaded) {
|
||||
if (this._loadingScene) {
|
||||
cc.errorID(1213, sceneName, this._loadingScene);
|
||||
return false;
|
||||
}
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
if (info) {
|
||||
var uuid = info.uuid;
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
this._loadingScene = sceneName;
|
||||
if (CC_JSB && cc.runtime && uuid !== this._launchSceneUuid) {
|
||||
var self = this;
|
||||
var groupName = cc.path.basename(info.url) + '_' + info.uuid;
|
||||
console.log('==> start preload: ' + groupName);
|
||||
var ensureAsync = false;
|
||||
cc.LoaderLayer.preload([groupName], function () {
|
||||
console.log('==> end preload: ' + groupName);
|
||||
if (ensureAsync) {
|
||||
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}
|
||||
else {
|
||||
setTimeout(function () {
|
||||
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
ensureAsync = true;
|
||||
}
|
||||
else {
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
cc.errorID(1214, sceneName);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
preloadScene: function (sceneName, onLoaded) {
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
if (info) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
cc.loader.load({ uuid: info.uuid, type: 'uuid' }, function (error, asset) {
|
||||
if (error) {
|
||||
cc.errorID(1215, sceneName, error.message);
|
||||
}
|
||||
if (onLoaded) {
|
||||
onLoaded(error, asset);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
var error = 'Can not preload the scene "' + sceneName + '" because it is not in the build settings.';
|
||||
onLoaded(new Error(error));
|
||||
cc.error('preloadScene: ' + error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads the scene by its uuid.
|
||||
* @method _loadSceneByUuid
|
||||
* @param {String} uuid - the uuid of the scene asset to load
|
||||
* @param {Function} [onLaunched]
|
||||
* @param {Function} [onUnloaded]
|
||||
* @param {Boolean} [dontRunScene] - Just download and initialize the scene but will not launch it,
|
||||
* only take effect in the Editor.
|
||||
* @private
|
||||
*/
|
||||
_loadSceneByUuid: function (uuid, onLaunched, onUnloaded, dontRunScene) {
|
||||
if (CC_EDITOR) {
|
||||
if (typeof onLaunched === 'boolean') {
|
||||
dontRunScene = onLaunched;
|
||||
onLaunched = null;
|
||||
}
|
||||
if (typeof onUnloaded === 'boolean') {
|
||||
dontRunScene = onUnloaded;
|
||||
onUnloaded = null;
|
||||
}
|
||||
}
|
||||
//cc.AssetLibrary.unloadAsset(uuid); // force reload
|
||||
console.time('LoadScene ' + uuid);
|
||||
cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) {
|
||||
console.timeEnd('LoadScene ' + uuid);
|
||||
var self = cc.director;
|
||||
self._loadingScene = '';
|
||||
if (error) {
|
||||
error = 'Failed to load scene: ' + error;
|
||||
cc.error(error);
|
||||
}
|
||||
else {
|
||||
if (sceneAsset instanceof cc.SceneAsset) {
|
||||
var scene = sceneAsset.scene;
|
||||
scene._id = sceneAsset._uuid;
|
||||
scene._name = sceneAsset._name;
|
||||
if (CC_EDITOR) {
|
||||
if (!dontRunScene) {
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
else {
|
||||
scene._load();
|
||||
if (onLaunched) {
|
||||
onLaunched(null, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.runSceneImmediate(scene, onUnloaded, onLaunched);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
error = 'The asset ' + uuid + ' is not a scene';
|
||||
cc.error(error);
|
||||
}
|
||||
}
|
||||
if (onLaunched) {
|
||||
onLaunched(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
__fastOn: function (type, callback, target) {
|
||||
var listeners = this._bubblingListeners;
|
||||
if (!listeners) {
|
||||
listeners = this._bubblingListeners = new EventListeners();
|
||||
}
|
||||
listeners.add(type, callback, target);
|
||||
this._addEventFlag(type, listeners, false);
|
||||
},
|
||||
|
||||
__fastOff: function (type, callback, target) {
|
||||
var listeners = this._bubblingListeners;
|
||||
if (listeners) {
|
||||
listeners.remove(type, callback, target);
|
||||
this._purgeEventFlag(type, listeners, false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
cc.defineGetterSetter(cc.director, "actionManager", cc.director.getActionManager, cc.director.setActionManager);
|
||||
|
||||
cc.EventTarget.call(cc.director);
|
||||
cc.js.addon(cc.director, cc.EventTarget.prototype);
|
||||
|
||||
cc.Director.EVENT_PROJECTION_CHANGED = 'director_projection_changed';
|
||||
cc.Director.EVENT_AFTER_DRAW = 'director_after_draw';
|
||||
cc.Director.EVENT_BEFORE_VISIT = 'director_before_visit';
|
||||
cc.Director.EVENT_AFTER_VISIT = 'director_after_visit';
|
||||
cc.Director.EVENT_BEFORE_UPDATE = 'director_before_update';
|
||||
cc.Director.EVENT_AFTER_UPDATE = 'director_after_update';
|
||||
cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading";
|
||||
cc.Director.EVENT_BEFORE_SCENE_LAUNCH = 'director_before_scene_launch';
|
||||
cc.Director.EVENT_AFTER_SCENE_LAUNCH = "director_after_scene_launch";
|
||||
cc.Director._EVENT_NEXT_TICK = '_director_next_tick';
|
||||
|
||||
// Register listener objects in cc.Director to avoid possible crash caused by cc.eventManager.addCustomListener.
|
||||
// For reasons that we don't understand yet, JSFunctionWrapper couldn't very well hold function reference in cc.eventManager.
|
||||
cc.Director._beforeUpdateListener = cc.EventListener.create({
|
||||
event: cc.EventListener.CUSTOM,
|
||||
eventName: cc.Director.EVENT_BEFORE_UPDATE,
|
||||
callback: function () {
|
||||
// cocos-creator/fireball#5157
|
||||
cc.director.emit(cc.Director._EVENT_NEXT_TICK);
|
||||
// User can use this event to do things before update
|
||||
cc.director.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Call start for new added components
|
||||
cc.director._compScheduler.startPhase();
|
||||
// Update for components
|
||||
var dt = cc.director.getDeltaTime();
|
||||
cc.director._compScheduler.updatePhase(dt);
|
||||
}
|
||||
});
|
||||
cc.Director._afterUpdateListener = cc.EventListener.create({
|
||||
event: cc.EventListener.CUSTOM,
|
||||
eventName: cc.Director.EVENT_AFTER_UPDATE,
|
||||
callback: function () {
|
||||
// Late update for components
|
||||
var dt = cc.director.getDeltaTime();
|
||||
cc.director._compScheduler.lateUpdatePhase(dt);
|
||||
// User can use this event to do things after update
|
||||
cc.director.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
|
||||
cc.director.emit(cc.Director.EVENT_BEFORE_VISIT, this);
|
||||
}
|
||||
});
|
||||
cc.Director._afterVisitListener = cc.EventListener.create({
|
||||
event: cc.EventListener.CUSTOM,
|
||||
eventName: cc.Director.EVENT_AFTER_VISIT,
|
||||
callback: function () {
|
||||
cc.director.emit(cc.Director.EVENT_AFTER_VISIT, this);
|
||||
}
|
||||
});
|
||||
cc.Director._afterDrawListener = cc.EventListener.create({
|
||||
event: cc.EventListener.CUSTOM,
|
||||
eventName: cc.Director.EVENT_AFTER_DRAW,
|
||||
callback: function () {
|
||||
cc.director.emit(cc.Director.EVENT_AFTER_DRAW, this);
|
||||
}
|
||||
});
|
||||
|
||||
cc.eventManager.addEventListenerWithFixedPriority(cc.Director._beforeUpdateListener, 1);
|
||||
cc.eventManager.addEventListenerWithFixedPriority(cc.Director._afterUpdateListener, 1);
|
||||
cc.eventManager.addEventListenerWithFixedPriority(cc.Director._afterVisitListener, 1);
|
||||
cc.eventManager.addEventListenerWithFixedPriority(cc.Director._afterDrawListener, 1);
|
||||
@@ -1,76 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var proto = dragonBones.CCArmatureDisplay.prototype;
|
||||
|
||||
cc.js.mixin(proto, cc.EventTarget.prototype);
|
||||
|
||||
proto.addEvent = function(type, listener, target) {
|
||||
if (!this.hasEventCallback()) {
|
||||
var self = this;
|
||||
this.setEventCallback(function (eventObject) {
|
||||
self.emit(eventObject.type, eventObject);
|
||||
});
|
||||
}
|
||||
this.on(type, listener, target);
|
||||
};
|
||||
|
||||
var dragonEventTypes = [
|
||||
dragonBones.EventObject.START,
|
||||
dragonBones.EventObject.LOOP_COMPLETE,
|
||||
dragonBones.EventObject.COMPLETE,
|
||||
dragonBones.EventObject.FADE_IN,
|
||||
dragonBones.EventObject.FADE_IN_COMPLETE,
|
||||
dragonBones.EventObject.FADE_OUT,
|
||||
dragonBones.EventObject.FADE_OUT_COMPLETE,
|
||||
dragonBones.EventObject.FRAME_EVENT,
|
||||
dragonBones.EventObject.SOUND_EVENT
|
||||
];
|
||||
|
||||
proto.removeEvent = function(type, listener, target) {
|
||||
this.off(type, listener, target);
|
||||
|
||||
var noListeners = true;
|
||||
for (var i = 0, n = dragonEventTypes.length; i < n; i++) {
|
||||
var checkType = dragonEventTypes[i];
|
||||
if (this.hasEventListener(checkType)) {
|
||||
noListeners = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (noListeners) {
|
||||
this.clearEventCallback();
|
||||
}
|
||||
};
|
||||
|
||||
var armatureProto = dragonBones.Armature.prototype;
|
||||
armatureProto.addEventListener = function (type, listener, target) {
|
||||
this.display.addEvent(type, listener, target);
|
||||
};
|
||||
|
||||
armatureProto.removeEventListener = function (type, listener, target) {
|
||||
this.display.removeEvent(type, listener, target);
|
||||
};
|
||||
@@ -1,157 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
var _p = cc.EditBox.prototype;
|
||||
|
||||
_p._setMaxLength = _p.setMaxLength;
|
||||
_p.setMaxLength = function(maxLength) {
|
||||
if (maxLength < 0) {
|
||||
maxLength = 65535;
|
||||
}
|
||||
this._setMaxLength(maxLength);
|
||||
};
|
||||
|
||||
cc.defineGetterSetter(_p, 'font', null, _p.setFont);
|
||||
cc.defineGetterSetter(_p, 'fontName', null, _p.setFontName);
|
||||
cc.defineGetterSetter(_p, 'fontSize', null, _p.setFontSize);
|
||||
cc.defineGetterSetter(_p, 'fontColor', null, _p.setFontColor);
|
||||
cc.defineGetterSetter(_p, 'string', _p.getString, _p.setString);
|
||||
cc.defineGetterSetter(_p, 'maxLength', _p.getMaxLength, _p.setMaxLength);
|
||||
cc.defineGetterSetter(_p, 'placeholder', _p.getPlaceHolder, _p.setPlaceHolder);
|
||||
cc.defineGetterSetter(_p, 'placeholderFont', null, _p.setPlaceholderFont);
|
||||
cc.defineGetterSetter(_p, 'placeholderFontName', null, _p.setPlaceholderFontName);
|
||||
cc.defineGetterSetter(_p, 'placeholderFontSize', null, _p.setPlaceholderFontSize);
|
||||
cc.defineGetterSetter(_p, 'placeholderFontColor', null, _p.setPlaceholderFontColor);
|
||||
cc.defineGetterSetter(_p, 'inputFlag', null, _p.setInputFlag);
|
||||
cc.defineGetterSetter(_p, 'delegate', null, _p.setDelegate);
|
||||
cc.defineGetterSetter(_p, 'inputMode', null, _p.setInputMode);
|
||||
cc.defineGetterSetter(_p, 'returnType', null, _p.setReturnType);
|
||||
|
||||
|
||||
_p.setLineHeight = function () {};
|
||||
|
||||
_p.setTabIndex = function () {};
|
||||
_p.getTabIndex = function () { return -1; };
|
||||
_p.setFocus = function () {};
|
||||
_p.isFocused = function () { return false; };
|
||||
_p.stayOnTop = function () {};
|
||||
|
||||
|
||||
|
||||
cc.EditBox.InputMode = cc.Enum({
|
||||
|
||||
ANY: 0,
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an e-mail address.
|
||||
*/
|
||||
EMAIL_ADDR: 1,
|
||||
|
||||
/**
|
||||
* The user is allowed to enter an integer value.
|
||||
*/
|
||||
NUMERIC: 2,
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a phone number.
|
||||
*/
|
||||
PHONE_NUMBER: 3,
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a URL.
|
||||
*/
|
||||
URL: 4,
|
||||
|
||||
/**
|
||||
* The user is allowed to enter a real number value.
|
||||
* This extends kEditBoxInputModeNumeric by allowing a decimal point.
|
||||
*/
|
||||
DECIMAL: 5,
|
||||
|
||||
/**
|
||||
* The user is allowed to enter any text, except for line breaks.
|
||||
*/
|
||||
SINGLE_LINE: 6
|
||||
});
|
||||
|
||||
/**
|
||||
* Enum for the EditBox's input flags
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
* @memberof cc.EditBox
|
||||
*/
|
||||
cc.EditBox.InputFlag = cc.Enum({
|
||||
/**
|
||||
* Indicates that the text entered is confidential data that should be
|
||||
* obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
|
||||
*/
|
||||
PASSWORD: 0,
|
||||
|
||||
/**
|
||||
* Indicates that the text entered is sensitive data that the
|
||||
* implementation must never store into a dictionary or table for use
|
||||
* in predictive, auto-completing, or other accelerated input schemes.
|
||||
* A credit card number is an example of sensitive data.
|
||||
*/
|
||||
SENSITIVE: 1,
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing,
|
||||
* the initial letter of each word should be capitalized.
|
||||
*/
|
||||
INITIAL_CAPS_WORD: 2,
|
||||
|
||||
/**
|
||||
* This flag is a hint to the implementation that during text editing,
|
||||
* the initial letter of each sentence should be capitalized.
|
||||
*/
|
||||
INITIAL_CAPS_SENTENCE: 3,
|
||||
|
||||
/**
|
||||
* Capitalize all characters automatically.
|
||||
*/
|
||||
INITIAL_CAPS_ALL_CHARACTERS: 4,
|
||||
|
||||
/**
|
||||
* Don't do anything with the input text.
|
||||
*/
|
||||
DEFAULT: 5
|
||||
});
|
||||
|
||||
/**
|
||||
* Enum for keyboard return types
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
cc.EditBox.KeyboardReturnType = cc.Enum({
|
||||
DEFAULT: 0,
|
||||
DONE: 1,
|
||||
SEND: 2,
|
||||
SEARCH: 3,
|
||||
GO: 4
|
||||
});
|
||||
-193
@@ -1,193 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
cc.sys.now = function () {
|
||||
return Date.now();
|
||||
};
|
||||
|
||||
var NORMALIZE_RE = /[^\.\/]+\/\.\.\//;
|
||||
|
||||
// cc.path
|
||||
cc.js.mixin(cc.path, {
|
||||
//todo make public after verification
|
||||
_normalize: function (url) {
|
||||
var oldUrl = url = String(url);
|
||||
|
||||
//removing all ../
|
||||
do {
|
||||
oldUrl = url;
|
||||
url = url.replace(NORMALIZE_RE, '');
|
||||
} while (oldUrl.length !== url.length);
|
||||
return url;
|
||||
},
|
||||
|
||||
// The platform-specific file separator. '\\' or '/'.
|
||||
sep: (cc.sys.os === cc.sys.OS_WINDOWS ? '\\' : '/'),
|
||||
|
||||
// @param {string} path
|
||||
stripSep (path) {
|
||||
return path.replace(/[\/\\]$/, '');
|
||||
}
|
||||
});
|
||||
|
||||
// Node
|
||||
var nodeProto = cc.Node.prototype;
|
||||
cc.defineGetterSetter(nodeProto, "_parent", nodeProto.getParent, nodeProto.setParent);
|
||||
|
||||
// View
|
||||
cc.view.isViewReady = cc.view.isOpenGLReady;
|
||||
cc.view.setOrientation = function () {};
|
||||
|
||||
// setTimeout, setInterval, clearTimeout, clearInteval
|
||||
var _windowTimeIntervalId = 0;
|
||||
var _windowTimeFunHash = {};
|
||||
var WindowTimeFun = function (code) {
|
||||
this.__instanceId = cc.ClassManager.getNewInstanceId();
|
||||
this._intervalId = _windowTimeIntervalId++;
|
||||
this._code = code;
|
||||
};
|
||||
|
||||
WindowTimeFun.prototype.fun = function () {
|
||||
if (!this._code) return;
|
||||
var code = this._code;
|
||||
if (typeof code === 'string') {
|
||||
Function(code)();
|
||||
}
|
||||
else if (typeof code === 'function') {
|
||||
code.apply(null, this._args);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's setTimeout
|
||||
@param {String|Function} code
|
||||
@param {number} delay
|
||||
@return {number}
|
||||
*/
|
||||
window.setTimeout = function (code, delay) {
|
||||
var target = new WindowTimeFun(code);
|
||||
if (arguments.length > 2)
|
||||
target._args = Array.prototype.slice.call(arguments, 2);
|
||||
var original = target.fun;
|
||||
target.fun = function () {
|
||||
original.apply(this, arguments);
|
||||
clearTimeout(target._intervalId);
|
||||
};
|
||||
cc.director.getScheduler().schedule(target.fun, target, delay / 1000, 0, 0, false);
|
||||
_windowTimeFunHash[target._intervalId] = target;
|
||||
return target._intervalId;
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's setInterval
|
||||
@param {String|Function} code
|
||||
@param {number} delay
|
||||
@return {number}
|
||||
*/
|
||||
window.setInterval = function (code, delay) {
|
||||
var target = new WindowTimeFun(code);
|
||||
if (arguments.length > 2)
|
||||
target._args = Array.prototype.slice.call(arguments, 2);
|
||||
|
||||
cc.director.getScheduler().schedule(target.fun, target, delay / 1000, cc.macro.REPEAT_FOREVER, 0, false);
|
||||
_windowTimeFunHash[target._intervalId] = target;
|
||||
return target._intervalId;
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's clearInterval
|
||||
@param {number} intervalId
|
||||
*/
|
||||
window.clearInterval = function (intervalId) {
|
||||
var target = _windowTimeFunHash[intervalId];
|
||||
if (target) {
|
||||
cc.director.getScheduler().unschedule(target.fun, target);
|
||||
delete _windowTimeFunHash[intervalId];
|
||||
}
|
||||
};
|
||||
window.clearTimeout = clearInterval;
|
||||
|
||||
// SocketIO
|
||||
if (window.SocketIO) {
|
||||
window.io = window.SocketIO;
|
||||
SocketIO.prototype._jsbEmit = SocketIO.prototype.emit;
|
||||
SocketIO.prototype.emit = function (uri, delegate) {
|
||||
if (typeof delegate === 'object') {
|
||||
delegate = JSON.stringify(delegate);
|
||||
}
|
||||
this._jsbEmit(uri, delegate);
|
||||
};
|
||||
}
|
||||
|
||||
cc.Node.prototype.setIgnoreAnchorPointForPosition = cc.Node.prototype.ignoreAnchorPointForPosition;
|
||||
|
||||
// ccsg
|
||||
window._ccsg = {
|
||||
Node: cc.Node,
|
||||
Scene: cc.Scene,
|
||||
Sprite: cc.Sprite,
|
||||
ParticleSystem: cc.ParticleSystem,
|
||||
Label: cc.Label,
|
||||
EditBox: cc.EditBox,
|
||||
VideoPlayer: cc.VideoPlayer,
|
||||
WebView: cc.WebView,
|
||||
TMXTiledMap: cc.TMXTiledMap,
|
||||
TMXObjectGroup: cc.TMXObjectGroup,
|
||||
TMXObject: cc.TMXObject,
|
||||
TMXObjectImage: cc.TMXObjetImage,
|
||||
TMXObjectShape: cc.TMXObjectShape,
|
||||
TMXLayer: cc.TMXLayer,
|
||||
MotionStreak: cc.MotionStreak,
|
||||
CameraNode: cc.CameraNode
|
||||
};
|
||||
|
||||
// fix cc.formatStr (#2630)
|
||||
cc.formatStr = cc.js.formatStr;
|
||||
|
||||
// disabled premultiplied alpha for png
|
||||
if (cc.Image && cc.Image.setPNGPremultipliedAlphaEnabled) {
|
||||
cc.Image.setPNGPremultipliedAlphaEnabled(false);
|
||||
}
|
||||
|
||||
// __errorHandler
|
||||
// window.__errorHandler = function (filename, lineno, message, stack) {
|
||||
// };
|
||||
|
||||
// global cleanup. Dangerous!!! please do not invoke this function, it's used internally by the restart process
|
||||
window.__cleanup = function () {
|
||||
// Destroy scene
|
||||
cc.director.getScene().destroy();
|
||||
cc.Object._deferredDestroy();
|
||||
// Reset other js caches
|
||||
cc.js._registeredClassIds = {};
|
||||
cc.js._registeredClassNames = {};
|
||||
// Cleanup loader
|
||||
cc.loader.releaseAll();
|
||||
// Cleanup textureCache
|
||||
cc.textureCache.removeAllTextures();
|
||||
};
|
||||
@@ -1,156 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
var Pool = require('../cocos2d/core/platform/js').Pool;
|
||||
var Event = require('../cocos2d/core/event/event');
|
||||
require('../cocos2d/core/event-manager/CCEvent');
|
||||
|
||||
Event.EventMouse.pool = new Pool(5);
|
||||
Event.EventMouse.pool.get = function (fromEvt, eventType) {
|
||||
var event = this._get() || new Event.EventMouse(eventType, true);
|
||||
event._button = fromEvt.getButton();
|
||||
var loc = fromEvt.getLocation();
|
||||
event._x = loc.x;
|
||||
event._y = loc.y;
|
||||
var listener = fromEvt._listener;
|
||||
if (listener) {
|
||||
event._prevX = listener._previousX;
|
||||
event._prevY = listener._previousY;
|
||||
}
|
||||
event._scrollX = fromEvt.getScrollX();
|
||||
event._scrollY = fromEvt.getScrollY();
|
||||
|
||||
event._target = null;
|
||||
event._currentTarget = null;
|
||||
event.eventPhase = cc.Event.NONE;
|
||||
event._propagationStopped = false;
|
||||
event._propagationImmediateStopped = false;
|
||||
return event;
|
||||
};
|
||||
|
||||
Event.EventTouch.pool = new Pool(5);
|
||||
Event.EventTouch.pool.get = function (fromEvt) {
|
||||
var touchArr = fromEvt.getTouches();
|
||||
var event = this._get() || new Event.EventTouch(touchArr, true);
|
||||
event.eventPhase = cc.Event.NONE;
|
||||
event._eventCode = fromEvt.getEventCode();
|
||||
event._touches = touchArr;
|
||||
event._target = null;
|
||||
event._currentTarget = null;
|
||||
event._propagationStopped = false;
|
||||
event._propagationImmediateStopped = false;
|
||||
return event;
|
||||
}
|
||||
|
||||
// cc.eventManager.addListener
|
||||
cc.eventManager.addListener = function(listener, nodeOrPriority) {
|
||||
if(!(listener instanceof cc.EventListener)) {
|
||||
listener = cc.EventListener.create(listener);
|
||||
}
|
||||
|
||||
if (typeof nodeOrPriority === 'number') {
|
||||
if (nodeOrPriority === 0) {
|
||||
cc.logID(3500);
|
||||
return;
|
||||
}
|
||||
|
||||
cc.eventManager.addEventListenerWithFixedPriority(listener, nodeOrPriority);
|
||||
} else {
|
||||
var node = nodeOrPriority;
|
||||
if (nodeOrPriority instanceof cc._BaseNode) {
|
||||
node = nodeOrPriority._sgNode;
|
||||
}
|
||||
else if (!(node instanceof _ccsg.Node)) {
|
||||
cc.warnID(3506);
|
||||
return;
|
||||
}
|
||||
cc.eventManager.addEventListenerWithSceneGraphPriority(listener, node);
|
||||
}
|
||||
|
||||
return listener;
|
||||
};
|
||||
cc.eventManager._removeListeners = cc.eventManager.removeListeners;
|
||||
cc.eventManager.removeListeners = function (target, recursive) {
|
||||
if (target instanceof cc._BaseNode) {
|
||||
target = target._sgNode;
|
||||
}
|
||||
|
||||
if (target instanceof _ccsg.Node || cc.js.isNumber(target)) {
|
||||
this._removeListeners(target, recursive || false);
|
||||
}
|
||||
else {
|
||||
cc.warnID(3506);
|
||||
}
|
||||
};
|
||||
cc.eventManager._pauseTarget = cc.eventManager.pauseTarget;
|
||||
cc.eventManager.pauseTarget = function (target, recursive) {
|
||||
var sgTarget = target;
|
||||
target._eventPaused = true;
|
||||
if (target instanceof cc._BaseNode) {
|
||||
sgTarget = target._sgNode;
|
||||
}
|
||||
else if (!(sgTarget instanceof _ccsg.Node)) {
|
||||
cc.warnID(3506);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sgTarget !== target && !sgTarget.isRunning()) {
|
||||
var originOnEnter = sgTarget.onEnter;
|
||||
sgTarget.onEnter = function () {
|
||||
originOnEnter.call(this);
|
||||
if (target._eventPaused) {
|
||||
cc.eventManager._pauseTarget(this, recursive || false);
|
||||
}
|
||||
this.onEnter = originOnEnter;
|
||||
};
|
||||
}
|
||||
this._pauseTarget(sgTarget, recursive || false);
|
||||
};
|
||||
cc.eventManager._resumeTarget = cc.eventManager.resumeTarget;
|
||||
cc.eventManager.resumeTarget = function (target, recursive) {
|
||||
target._eventPaused = false;
|
||||
if (target instanceof cc._BaseNode) {
|
||||
target = target._sgNode;
|
||||
}
|
||||
else if (!(target instanceof _ccsg.Node)) {
|
||||
cc.warnID(3506);
|
||||
return;
|
||||
}
|
||||
this._resumeTarget(target, recursive || false);
|
||||
};
|
||||
|
||||
cc._EventListenerKeyboard = cc.EventListenerKeyboard;
|
||||
cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard";
|
||||
cc._EventListenerAcceleration = cc.EventListenerAcceleration;
|
||||
cc._EventListenerAcceleration.LISTENER_ID = "__cc_acceleration";
|
||||
cc._EventListenerTouchAllAtOnce = cc.EventListenerTouchAllAtOnce;
|
||||
cc._EventListenerTouchAllAtOnce.LISTENER_ID = "__cc_touch_all_at_once";
|
||||
cc._EventListenerTouchOneByOne = cc.EventListenerTouchOneByOne;
|
||||
cc._EventListenerTouchOneByOne.LISTENER_ID = "__cc_touch_one_by_one";
|
||||
cc._EventListenerMouse = cc.EventListenerMouse;
|
||||
cc._EventListenerMouse.LISTENER_ID = "__cc_mouse";
|
||||
-323
@@ -1,323 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
// cc.game
|
||||
cc.game = {
|
||||
|
||||
EVENT_HIDE: "game_on_hide",
|
||||
EVENT_SHOW: "game_on_show",
|
||||
EVENT_RESIZE: "game_on_resize",
|
||||
|
||||
_onShowListener: null,
|
||||
_onHideListener: null,
|
||||
|
||||
// states
|
||||
_paused: false, //whether the game is paused
|
||||
_prepareCalled: false,//whether the prepare function has been called
|
||||
_prepared: false,//whether the engine has prepared
|
||||
|
||||
/**
|
||||
* Config of game
|
||||
* @type {Object}
|
||||
*/
|
||||
config: null,
|
||||
|
||||
/**
|
||||
* Callback when the scripts of engine have been load.
|
||||
* @type {Function}
|
||||
*/
|
||||
onStart: null,
|
||||
|
||||
// Scenes list
|
||||
_sceneInfos: [],
|
||||
|
||||
_persistRootNodes: {},
|
||||
_ignoreRemovePersistNode: null,
|
||||
|
||||
RENDER_TYPE_CANVAS: 0,
|
||||
RENDER_TYPE_WEBGL: 1,
|
||||
RENDER_TYPE_OPENGL: 2,
|
||||
|
||||
EVENT_GAME_INITED: "game_inited",
|
||||
|
||||
CONFIG_KEY: {
|
||||
width: 'width',
|
||||
height: 'height',
|
||||
// engineDir: 'engineDir',
|
||||
modules: 'modules',
|
||||
debugMode: 'debugMode',
|
||||
showFPS: 'showFPS',
|
||||
frameRate: 'frameRate',
|
||||
id: 'id',
|
||||
renderMode: 'renderMode',
|
||||
registerSystemEvent: 'registerSystemEvent',
|
||||
jsList: 'jsList',
|
||||
scenes: 'scenes'
|
||||
},
|
||||
|
||||
//@Public Methods
|
||||
|
||||
// @Game play control
|
||||
/**
|
||||
* Set frameRate of game.
|
||||
* @param frameRate
|
||||
*/
|
||||
setFrameRate: function (frameRate) {
|
||||
var self = this, config = self.config, CONFIG_KEY = self.CONFIG_KEY;
|
||||
config[CONFIG_KEY.frameRate] = frameRate;
|
||||
cc.director.setAnimationInterval(1.0/frameRate);
|
||||
},
|
||||
|
||||
/**
|
||||
* Run the game frame by frame.
|
||||
*/
|
||||
step: function () {
|
||||
cc.director.mainLoop();
|
||||
},
|
||||
|
||||
/**
|
||||
* Pause the game.
|
||||
*/
|
||||
pause: function () {
|
||||
this._paused = true;
|
||||
cc.director.pause();
|
||||
},
|
||||
|
||||
/**
|
||||
* Resume the game from pause.
|
||||
*/
|
||||
resume: function () {
|
||||
this._paused = false;
|
||||
cc.director.resume();
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether the game is paused.
|
||||
*/
|
||||
isPaused: function () {
|
||||
return this._paused;
|
||||
},
|
||||
|
||||
/**
|
||||
* Restart game.
|
||||
*/
|
||||
restart: function () {
|
||||
__restartVM();
|
||||
},
|
||||
|
||||
/**
|
||||
* End game, it will close the game window
|
||||
*/
|
||||
end: function () {
|
||||
close();
|
||||
},
|
||||
|
||||
prepare: function (cb) {
|
||||
var self = this,
|
||||
config = self.config,
|
||||
CONFIG_KEY = self.CONFIG_KEY;
|
||||
|
||||
this._loadConfig();
|
||||
|
||||
// Already prepared
|
||||
if (this._prepared) {
|
||||
if (cb) cb();
|
||||
return;
|
||||
}
|
||||
// Prepare called, but not done yet
|
||||
if (this._prepareCalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare never called and engine ready
|
||||
this._prepareCalled = true;
|
||||
|
||||
// Additional step in JSB
|
||||
cc.game.renderType = cc.game.RENDER_TYPE_OPENGL;
|
||||
cc.director.sharedInit();
|
||||
|
||||
// Load game scripts
|
||||
var jsList = config[CONFIG_KEY.jsList];
|
||||
if (jsList) {
|
||||
cc.loader.load(jsList, function (err) {
|
||||
if (err) throw new Error(JSON.stringify(err));
|
||||
self._prepared = true;
|
||||
if (cb) cb();
|
||||
self.emit(self.EVENT_GAME_INITED);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (cb) cb();
|
||||
self.emit(self.EVENT_GAME_INITED);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Run game with configuration object and onStart function.
|
||||
* @param {Object|Function} [config] Pass configuration object or onStart function
|
||||
* @param {onStart} [onStart] onStart function to be executed after game initialized
|
||||
*/
|
||||
run: function (config, onStart) {
|
||||
if (typeof config === 'function') {
|
||||
cc.game.onStart = config;
|
||||
}
|
||||
else {
|
||||
if (config) {
|
||||
cc.game.config = config;
|
||||
}
|
||||
if (typeof onStart === 'function') {
|
||||
cc.game.onStart = onStart;
|
||||
}
|
||||
}
|
||||
cc.director.startAnimation();
|
||||
this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game));
|
||||
},
|
||||
|
||||
// @ Persist root node section
|
||||
/**
|
||||
* !#en
|
||||
* Add a persistent root node to the game, the persistent node won't be destroyed during scene transition.<br/>
|
||||
* The target node must be placed in the root level of hierarchy, otherwise this API won't have any effect.
|
||||
* !#zh
|
||||
* 声明常驻根节点,该节点不会被在场景切换中被销毁。<br/>
|
||||
* 目标节点必须位于为层级的根节点,否则无效。
|
||||
* @method addPersistRootNode
|
||||
* @param {Node} node - The node to be made persistent
|
||||
*/
|
||||
addPersistRootNode: function (node) {
|
||||
if (!cc.Node.isNode(node) || !node.uuid) {
|
||||
cc.warnID(3803);
|
||||
return;
|
||||
}
|
||||
var id = node.uuid;
|
||||
if (!this._persistRootNodes[id]) {
|
||||
var scene = cc.director._scene;
|
||||
if (cc.isValid(scene)) {
|
||||
if (!node.parent) {
|
||||
node.parent = scene;
|
||||
}
|
||||
else if ( !(node.parent instanceof cc.Scene) ) {
|
||||
cc.warnID(3801);
|
||||
return;
|
||||
}
|
||||
else if (node.parent !== scene) {
|
||||
cc.warnID(3802);
|
||||
return;
|
||||
}
|
||||
this._persistRootNodes[id] = node;
|
||||
node._persistNode = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a persistent root node
|
||||
* @method removePersistRootNode
|
||||
* @param {ENode} node - The node to be removed from persistent node list
|
||||
*/
|
||||
removePersistRootNode: function (node) {
|
||||
if (node !== this._ignoreRemovePersistNode) {
|
||||
var id = node._id || '';
|
||||
if (node === this._persistRootNodes[id]) {
|
||||
delete this._persistRootNodes[id];
|
||||
node._persistNode = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether the node is a persistent root node
|
||||
* @method isPersistRootNode
|
||||
* @param {ENode} node - The node to be checked
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isPersistRootNode: function (node) {
|
||||
return node._persistNode;
|
||||
},
|
||||
|
||||
//@Private Methods
|
||||
|
||||
_loadConfig: function () {
|
||||
// Load config
|
||||
// Already loaded
|
||||
if (this.config) {
|
||||
this._initConfig(this.config);
|
||||
}
|
||||
// Load from project.json
|
||||
else {
|
||||
try {
|
||||
var txt = jsb.fileUtils.getStringFromFile('project.json');
|
||||
var data = JSON.parse(txt);
|
||||
this._initConfig(data || {});
|
||||
} catch (e) {
|
||||
console.log('Failed to read or parse project.json');
|
||||
this._initConfig({});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_initConfig: function (config) {
|
||||
var CONFIG_KEY = this.CONFIG_KEY;
|
||||
|
||||
// Configs adjustment
|
||||
if (typeof config[CONFIG_KEY.debugMode] !== 'number') {
|
||||
config[CONFIG_KEY.debugMode] = 0;
|
||||
}
|
||||
if (typeof config[CONFIG_KEY.frameRate] !== 'number') {
|
||||
config[CONFIG_KEY.frameRate] = 60;
|
||||
}
|
||||
if (typeof config[CONFIG_KEY.renderMode] !== 'number') {
|
||||
config[CONFIG_KEY.renderMode] = 0;
|
||||
}
|
||||
config[CONFIG_KEY.showFPS] = (CONFIG_KEY.showFPS in config) ? (!!config[CONFIG_KEY.showFPS]) : true;
|
||||
// config[CONFIG_KEY.engineDir] = config[CONFIG_KEY.engineDir] || 'frameworks/cocos2d-html5';
|
||||
|
||||
// Group List and Collide Map
|
||||
this.groupList = config.groupList || [];
|
||||
this.collisionMatrix = config.collisionMatrix || [];
|
||||
|
||||
// Scene parser
|
||||
this._sceneInfos = config[CONFIG_KEY.scenes] || [];
|
||||
|
||||
cc.director.setDisplayStats(config[CONFIG_KEY.showFPS]);
|
||||
cc.director.setAnimationInterval(1.0/config[CONFIG_KEY.frameRate]);
|
||||
cc._initDebugSetting(config[CONFIG_KEY.debugMode]);
|
||||
|
||||
this.config = config;
|
||||
}
|
||||
};
|
||||
|
||||
cc.EventTarget.call(cc.game);
|
||||
cc.js.addon(cc.game, cc.EventTarget.prototype);
|
||||
|
||||
cc.game._onHideListener = cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function () {
|
||||
cc.game.emit(cc.game.EVENT_HIDE, cc.game);
|
||||
});
|
||||
cc.game._onShowListener = cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () {
|
||||
cc.game.emit(cc.game.EVENT_SHOW, cc.game);
|
||||
});
|
||||
@@ -1,312 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
// cc.Label
|
||||
var jsbLabel = cc.Label;
|
||||
// v3.3 bug fix
|
||||
if (!jsbLabel.createWithTTF && jsbLabel.prototype.createWithTTF) {
|
||||
jsbLabel.createWithTTF = jsbLabel.prototype.createWithTTF;
|
||||
}
|
||||
jsbLabel.prototype.setHorizontalAlign = jsbLabel.prototype.setHorizontalAlignment;
|
||||
jsbLabel.prototype.setVerticalAlign = jsbLabel.prototype.setVerticalAlignment;
|
||||
//for back compatibility
|
||||
if (!jsbLabel.prototype.setBMFontSize) {
|
||||
jsbLabel.prototype.setBMFontSize = function(){};
|
||||
}
|
||||
if (!jsbLabel.prototype.getBMFontSize) {
|
||||
jsbLabel.prototype.getBMFontSize = function(){};
|
||||
}
|
||||
if (!jsbLabel.prototype.setOverflow) {
|
||||
jsbLabel.prototype.setOverflow = function(){};
|
||||
}
|
||||
if (!jsbLabel.prototype.getOverflow) {
|
||||
jsbLabel.prototype.getOverflow = function(){};
|
||||
}
|
||||
|
||||
//fix jsb system font overflow
|
||||
jsbLabel.prototype._setOverflow = jsbLabel.prototype.setOverflow;
|
||||
jsbLabel.prototype.setOverflow = function(overflow) {
|
||||
this._overFlow = overflow;
|
||||
this._setOverflow(this._overFlow);
|
||||
};
|
||||
|
||||
jsbLabel.prototype.getOverflow = function() {
|
||||
return this._overFlow;
|
||||
};
|
||||
|
||||
jsbLabel.prototype._enableBold = jsbLabel.prototype.enableBold;
|
||||
jsbLabel.prototype.enableBold = function(enabled) {
|
||||
if (enabled) {
|
||||
this._enableBold();
|
||||
} else {
|
||||
this.disableEffect(5);
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype._enableItalics = jsbLabel.prototype.enableItalics;
|
||||
jsbLabel.prototype.enableItalics = function(enabled) {
|
||||
if (enabled) {
|
||||
this._enableItalics();
|
||||
} else {
|
||||
this.disableEffect(4);
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype._enableUnderline = jsbLabel.prototype.enableUnderline;
|
||||
jsbLabel.prototype.enableUnderline = function(enabled) {
|
||||
if (enabled) {
|
||||
this._enableUnderline();
|
||||
} else {
|
||||
this.disableEffect(6);
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setFontSize = function (size) {
|
||||
this._fontSize = size;
|
||||
if (this._labelType === _ccsg.Label.Type.SystemFont) {
|
||||
this.setSystemFontSize(size);
|
||||
}
|
||||
else if (this._labelType === _ccsg.Label.Type.BMFont) {
|
||||
this.setBMFontSize(size);
|
||||
}
|
||||
else if (this._labelType === _ccsg.Label.Type.TTF) {
|
||||
var ttfConfig = this.getTTFConfig();
|
||||
ttfConfig.fontSize = size;
|
||||
this.setTTFConfig(ttfConfig);
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype.getFontSize = function () {
|
||||
return this._fontSize;
|
||||
};
|
||||
|
||||
jsbLabel.prototype.enableWrapText = jsbLabel.prototype.enableWrap || function(){};
|
||||
jsbLabel.prototype.isWrapTextEnabled = jsbLabel.prototype.isWrapEnabled || function(){};
|
||||
|
||||
jsbLabel.prototype._setLineHeight = jsbLabel.prototype.setLineHeight;
|
||||
jsbLabel.prototype.setLineHeight = function (height) {
|
||||
if (this._labelType !== _ccsg.Label.Type.SystemFont) {
|
||||
this._setLineHeight(height);
|
||||
}
|
||||
else {
|
||||
// Todo support setLineHeight for Native
|
||||
if (40 !== height) {
|
||||
cc.warnID(4013);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype._setColor = jsbLabel.prototype.setColor;
|
||||
|
||||
jsbLabel.prototype.setColor = function(color) {
|
||||
if (this._labelType === _ccsg.Label.Type.BMFont) {
|
||||
this._setColor(color);
|
||||
} else {
|
||||
this.setTextColor(color);
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setSpacingX = jsbLabel.prototype.setAdditionalKerning;
|
||||
|
||||
jsbLabel.prototype._setTTFConfig = jsbLabel.prototype.setTTFConfig;
|
||||
jsbLabel.prototype.setTTFConfig = function (config) {
|
||||
this._setTTFConfig(config);
|
||||
this._ttfConfig = config;
|
||||
};
|
||||
|
||||
jsbLabel.prototype.getTTFConfig = function () {
|
||||
return this._ttfConfig;
|
||||
};
|
||||
|
||||
jsbLabel.prototype._setContentSize = jsbLabel.prototype.setContentSize;
|
||||
jsbLabel.prototype.setContentSize = function (size, height) {
|
||||
var newWidth = (typeof size.width === 'number') ? size.width : size;
|
||||
var newHeight = (typeof size.height === 'number') ? size.height : height;
|
||||
|
||||
if (this.getOverflow() === cc.Label.Overflow.NONE) {
|
||||
newWidth = 0;
|
||||
newHeight = 0;
|
||||
} else {
|
||||
this._setContentSize(newWidth, newHeight);
|
||||
}
|
||||
this.setDimensions(newWidth, newHeight);
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setFontAsset = function (fontAsset) {
|
||||
this._fontAsset = fontAsset;
|
||||
var isAsset = fontAsset instanceof cc.Font;
|
||||
if (!isAsset) {
|
||||
this.setFontFamily('Arial');
|
||||
return;
|
||||
}
|
||||
var fontHandle = isAsset ? fontAsset.nativeUrl : '';
|
||||
var extName = cc.path.extname(fontHandle);
|
||||
|
||||
if (extName === '.ttf') {
|
||||
var outlineWidth = this.isOutlined() ? this.getOutlineWidth() : 0;
|
||||
if (!this._ttfConfig) {
|
||||
this._ttfConfig = {
|
||||
fontFilePath: fontHandle,
|
||||
fontSize: this._fontSize,
|
||||
outlineSize: outlineWidth,
|
||||
glyphs: 0,
|
||||
customGlyphs: "",
|
||||
distanceFieldEnable: false
|
||||
};
|
||||
}
|
||||
else {
|
||||
this._ttfConfig.outlineSize = outlineWidth;
|
||||
this._ttfConfig.fontFilePath = fontHandle;
|
||||
}
|
||||
this._labelType = _ccsg.Label.Type.TTF;
|
||||
this.setTTFConfig(this._ttfConfig);
|
||||
} else if (fontAsset.spriteFrame) {
|
||||
this._labelType = _ccsg.Label.Type.BMFont;
|
||||
this.setBMFontFilePath(JSON.stringify(fontAsset._fntConfig), fontAsset.spriteFrame);
|
||||
this.setFontSize(this.getFontSize());
|
||||
}
|
||||
//FIXME: hack for bmfont crash. remove this line when it fixed in native
|
||||
this.getContentSize();
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setFontFamily = function (fontFamily) {
|
||||
fontFamily = fontFamily || '';
|
||||
this._labelType = _ccsg.Label.Type.SystemFont;
|
||||
this.setSystemFontName(fontFamily);
|
||||
this._isSystemFontUsed = true;
|
||||
//FIXME: hack for bmfont crash. remove this line when it fixed in native
|
||||
this.getContentSize();
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setOutlined = function(value) {
|
||||
this._outlined = !!value;
|
||||
if (this._outlined) {
|
||||
this.enableOutline(this.getOutlineColor(), this.getOutlineWidth());
|
||||
} else {
|
||||
//1 equals cpp outline effect
|
||||
this.disableEffect(1);
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setOutlineWidth = function(value) {
|
||||
this._outlineWidth = value;
|
||||
if (this._outlined) {
|
||||
var outlineWidth = this.getOutlineWidth();
|
||||
if (this._labelType === _ccsg.Label.Type.TTF) {
|
||||
var ttfConfig = this.getTTFConfig();
|
||||
if (ttfConfig.outlineSize !== outlineWidth) {
|
||||
ttfConfig.outlineSize = outlineWidth;
|
||||
this.setTTFConfig(ttfConfig);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.enableOutline(this.getOutlineColor(), outlineWidth);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setOutlineColor = function(value) {
|
||||
this._outlineColor = cc.color(value);
|
||||
if (this._outlined) {
|
||||
this.enableOutline(this.getOutlineColor(), this.getOutlineWidth());
|
||||
}
|
||||
};
|
||||
|
||||
jsbLabel.prototype.setMargin = function() {
|
||||
//add an empty here, needed to be implemented by native
|
||||
};
|
||||
|
||||
jsbLabel.prototype.isOutlined = function() {
|
||||
return this._outlined;
|
||||
};
|
||||
|
||||
jsbLabel.prototype.getOutlineWidth = function() {
|
||||
return this._outlineWidth || 1;
|
||||
};
|
||||
|
||||
jsbLabel.prototype.getOutlineColor = function() {
|
||||
return this._outlineColor || cc.color(255,255,255,255);
|
||||
};
|
||||
|
||||
|
||||
cc.Label = function (string, fontHandle, spriteFrame, fontSize) {
|
||||
fontHandle = fontHandle || "Arial";
|
||||
var extName = cc.path.extname(fontHandle);
|
||||
|
||||
var type = _ccsg.Label.Type.TTF;
|
||||
this._fontSize = fontSize;
|
||||
|
||||
var label;
|
||||
if (extName === ".ttf") {
|
||||
var ttfConfig = {
|
||||
fontFilePath: fontHandle,
|
||||
fontSize: this._fontSize,
|
||||
outlineSize: 0,
|
||||
glyphs: 0,
|
||||
customGlyphs: "",
|
||||
distanceFieldEnable: false
|
||||
};
|
||||
label = jsbLabel.createWithTTF(ttfConfig, string);
|
||||
label._ttfConfig = ttfConfig;
|
||||
}
|
||||
else if (spriteFrame) {
|
||||
label = jsbLabel.createWithBMFont(fontHandle, string, spriteFrame);
|
||||
type = _ccsg.Label.Type.BMFont;
|
||||
}
|
||||
else {
|
||||
label = jsbLabel.createWithSystemFont(string || '', fontHandle, this._fontSize);
|
||||
type = _ccsg.Label.Type.SystemFont;
|
||||
label._isSystemFontUsed = true;
|
||||
}
|
||||
label._labelType = type;
|
||||
return label;
|
||||
};
|
||||
cc.Label.Type = cc.Enum({
|
||||
TTF: 0,
|
||||
BMFont: 1,
|
||||
SystemFont: 2
|
||||
});
|
||||
cc.Label.Overflow = cc.Enum({
|
||||
NONE: 0,
|
||||
CLAMP: 1,
|
||||
SHRINK: 2,
|
||||
RESIZE_HEIGHT: 3
|
||||
});
|
||||
|
||||
cc.Label.pool = new cc.js.Pool(0);
|
||||
//Note: The pool.get method only used for creating TTF and SystemFont
|
||||
cc.Label.pool.get = function (string, fontAsset, spriteFrame, fontSize) {
|
||||
this._fontAsset = fontAsset;
|
||||
fontSize = fontSize || 40;
|
||||
var isAsset = fontAsset instanceof cc.Font;
|
||||
if (!isAsset) {
|
||||
return new _ccsg.Label(string, null, null, fontSize);
|
||||
}
|
||||
var fontHandle = isAsset ? fontAsset.nativeUrl : '';
|
||||
return new _ccsg.Label(string, fontHandle, spriteFrame, fontSize);
|
||||
};
|
||||
+65
-68
@@ -6,7 +6,7 @@
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
@@ -40,21 +40,30 @@ function downloadAudio (item, callback) {
|
||||
return item.url;
|
||||
}
|
||||
|
||||
function downloadImage(item, callback) {
|
||||
let img = new Image();
|
||||
img.src = item.url;
|
||||
img.onload = function(info) {
|
||||
callback(null, img);
|
||||
}
|
||||
// Don't return anything to use async loading.
|
||||
}
|
||||
|
||||
cc.loader.addDownloadHandlers({
|
||||
// JS
|
||||
'js' : downloadScript,
|
||||
'jsc' : downloadScript,
|
||||
|
||||
// Images
|
||||
'png' : loadImage,
|
||||
'jpg' : loadImage,
|
||||
'bmp' : loadImage,
|
||||
'jpeg' : loadImage,
|
||||
'gif' : loadImage,
|
||||
'ico' : loadImage,
|
||||
'tiff' : loadImage,
|
||||
'webp' : loadImage,
|
||||
'image' : loadImage,
|
||||
'png' : downloadImage,
|
||||
'jpg' : downloadImage,
|
||||
'bmp' : downloadImage,
|
||||
'jpeg' : downloadImage,
|
||||
'gif' : downloadImage,
|
||||
'ico' : downloadImage,
|
||||
'tiff' : downloadImage,
|
||||
'webp' : downloadImage,
|
||||
'image' : downloadImage,
|
||||
|
||||
// Audio
|
||||
'mp3' : downloadAudio,
|
||||
@@ -72,64 +81,52 @@ cc.loader.addDownloadHandlers({
|
||||
'ttc' : empty,
|
||||
});
|
||||
|
||||
//cjh FIXME: remote image should still use jsb.loadRemoteImage.
|
||||
|
||||
function loadImage (item, callback) {
|
||||
var url = item.url;
|
||||
var isRemote = jsb.urlRegExp.test(url);
|
||||
var loadByDeserializedTexture = item._owner instanceof cc.Texture2D;
|
||||
if (loadByDeserializedTexture) {
|
||||
// load Image
|
||||
var loader = isRemote ? jsb.initRemoteImg : jsb.initTextureAsync;
|
||||
loader(item._owner, url, function(succeed) {
|
||||
if (succeed) {
|
||||
callback && callback(null);
|
||||
}
|
||||
else {
|
||||
callback && callback(new Error('Load image failed: ' + url));
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
var cachedTex = cc.textureCache.getTextureForKey(url);
|
||||
if (cachedTex) {
|
||||
return cachedTex;
|
||||
}
|
||||
else if (isRemote) {
|
||||
jsb.loadRemoteImg(url, function(succeed, tex) {
|
||||
if (succeed) {
|
||||
tex.url = url;
|
||||
callback && callback(null, tex);
|
||||
}
|
||||
else {
|
||||
callback && callback(new Error('Load image failed: ' + url));
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
cc.textureCache._addImageAsync(url, function (tex) {
|
||||
if (tex instanceof cc.Texture2D) {
|
||||
tex.url = url;
|
||||
callback && callback(null, tex);
|
||||
}
|
||||
else {
|
||||
callback && callback(new Error('Load image failed: ' + url));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//function loadImage (item, callback) {
|
||||
// var url = item.url;
|
||||
//
|
||||
// var cachedTex = cc.textureCache.getTextureForKey(url);
|
||||
// if (cachedTex) {
|
||||
// return cachedTex;
|
||||
// }
|
||||
// else if (url.match(jsb.urlRegExp)) {
|
||||
// jsb.loadRemoteImg(url, function(succeed, tex) {
|
||||
// if (succeed) {
|
||||
// tex.url = url;
|
||||
// callback && callback(null, tex);
|
||||
// }
|
||||
// else {
|
||||
// callback && callback(new Error('Load image failed: ' + url));
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// else {
|
||||
// var addImageCallback = function (tex) {
|
||||
// if (tex instanceof cc.Texture2D) {
|
||||
// tex.url = url;
|
||||
// callback && callback(null, tex);
|
||||
// }
|
||||
// else {
|
||||
// callback && callback(new Error('Load image failed: ' + url));
|
||||
// }
|
||||
// };
|
||||
// cc.textureCache._addImageAsync(url, addImageCallback);
|
||||
// }
|
||||
//}
|
||||
|
||||
cc.loader.addLoadHandlers({
|
||||
// Images
|
||||
'png' : empty,
|
||||
'jpg' : empty,
|
||||
'bmp' : empty,
|
||||
'jpeg' : empty,
|
||||
'gif' : empty,
|
||||
'ico' : empty,
|
||||
'tiff' : empty,
|
||||
'webp' : empty,
|
||||
'image' : empty,
|
||||
//cc.loader.addLoadHandlers({
|
||||
// // Images
|
||||
// 'png' : loadImage,
|
||||
// 'jpg' : loadImage,
|
||||
// 'bmp' : loadImage,
|
||||
// 'jpeg' : loadImage,
|
||||
// 'gif' : loadImage,
|
||||
// 'ico' : loadImage,
|
||||
// 'tiff' : loadImage,
|
||||
// 'webp' : loadImage,
|
||||
// 'image' : loadImage,
|
||||
//
|
||||
// 'default' : empty
|
||||
//});
|
||||
|
||||
'default' : empty
|
||||
});
|
||||
@@ -1,106 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
cc.ParticleSystem.Mode = cc.Enum({
|
||||
/** The gravity mode (A mode) */
|
||||
GRAVITY: 0,
|
||||
/** The radius mode (B mode) */
|
||||
RADIUS: 1
|
||||
});
|
||||
|
||||
|
||||
cc.ParticleSystem.Type = cc.Enum({
|
||||
/**
|
||||
* Living particles are attached to the world and are unaffected by emitter repositioning.
|
||||
*/
|
||||
FREE: 0,
|
||||
|
||||
/**
|
||||
* Living particles are attached to the world but will follow the emitter repositioning.<br/>
|
||||
* Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite.
|
||||
*/
|
||||
RELATIVE: 1,
|
||||
|
||||
/**
|
||||
* Living particles are attached to the emitter and are translated along with it.
|
||||
*/
|
||||
GROUPED: 2
|
||||
});
|
||||
|
||||
var funcNames = [
|
||||
{
|
||||
'tangentialAccel' : 'setTangentialAccel',
|
||||
'tangentialAccelVar' : 'setTangentialAccelVar',
|
||||
'radialAccel' : 'setRadialAccel',
|
||||
'radialAccelVar' : 'setRadialAccelVar',
|
||||
'rotationIsDir' : 'setRotationIsDir',
|
||||
'gravity' : 'setGravity',
|
||||
'speed' : 'setSpeed',
|
||||
'speedVar' : 'setSpeedVar'
|
||||
},
|
||||
{
|
||||
'startRadius' : 'setStartRadius',
|
||||
'startRadiusVar' : 'setStartRadiusVar',
|
||||
'endRadius' : 'setEndRadius',
|
||||
'endRadiusVar' : 'setEndRadiusVar',
|
||||
'rotatePerS' : 'setRotatePerSecond',
|
||||
'rotatePerSVar' : 'setRotatePerSecondVar'
|
||||
}
|
||||
];
|
||||
|
||||
function getReplacer (oldFunc, mode) {
|
||||
return function (value) {
|
||||
if (this.getEmitterMode() === mode) {
|
||||
oldFunc.call(this, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var proto = cc.ParticleSystem.prototype;
|
||||
|
||||
proto._initWithFile = proto.initWithFile;
|
||||
proto.initWithFile = function (plistFile) {
|
||||
var md5Pipe = cc.loader.md5Pipe;
|
||||
if (md5Pipe) {
|
||||
plistFile = md5Pipe.transformURL(plistFile);
|
||||
}
|
||||
this._initWithFile(plistFile);
|
||||
};
|
||||
|
||||
for (var mode = 0; mode < funcNames.length; mode++) {
|
||||
var modeFuncs = funcNames[mode];
|
||||
for (var propName in modeFuncs) {
|
||||
var funcName = modeFuncs[propName];
|
||||
var func = proto[funcName];
|
||||
proto[funcName] = getReplacer(func, mode);
|
||||
|
||||
var getter = funcName.replace('set', 'get');
|
||||
cc.defineGetterSetter(proto, propName, proto[getter], proto[funcName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
// cc.Scale9Sprite
|
||||
|
||||
var v2Found = false;
|
||||
if (cc.Scale9SpriteV2) {
|
||||
v2Found = true;
|
||||
cc.Scale9Sprite = cc.Scale9SpriteV2;
|
||||
}
|
||||
|
||||
cc.Scale9Sprite.state = {NORMAL: 0, GRAY: 1, DISTORTION: 2};
|
||||
|
||||
/**
|
||||
* Enum for sprite type
|
||||
* @enum SpriteType
|
||||
*/
|
||||
cc.Scale9Sprite.RenderingType = cc.Enum({
|
||||
/**
|
||||
* @property {Number} SIMPLE
|
||||
*/
|
||||
SIMPLE: 0,
|
||||
/**
|
||||
* @property {Number} SLICED
|
||||
*/
|
||||
SLICED: 1,
|
||||
/*
|
||||
* @property {Number} TILED
|
||||
*/
|
||||
TILED: 2,
|
||||
/*
|
||||
* @property {Number} FILLED
|
||||
*/
|
||||
FILLED: 3
|
||||
});
|
||||
|
||||
cc.Scale9Sprite.FillType = cc.Enum({
|
||||
Horizontal: 0,
|
||||
Vertical: 1,
|
||||
//todo implement this
|
||||
RADIAL:2,
|
||||
});
|
||||
|
||||
var s9sPrototype = cc.Scale9Sprite.prototype;
|
||||
|
||||
if (v2Found) {
|
||||
var _jsbSetContentSize = s9sPrototype.setContentSize;
|
||||
s9sPrototype.setContentSize = function (size, height) {
|
||||
if (void 0 !== height) {
|
||||
size = new cc.Size(size, height);
|
||||
}
|
||||
_jsbSetContentSize.call(this, size);
|
||||
};
|
||||
var _jsbSetAnchorPoint = s9sPrototype.setAnchorPoint;
|
||||
s9sPrototype.setAnchorPoint = function (anchorPoint, y) {
|
||||
if (void 0 !== y) {
|
||||
anchorPoint = new cc.Vec2(anchorPoint, y);
|
||||
}
|
||||
_jsbSetAnchorPoint.call(this, anchorPoint);
|
||||
};
|
||||
}
|
||||
else {
|
||||
s9sPrototype.setFillType = function () {};
|
||||
s9sPrototype.setFillCenter = function () {};
|
||||
s9sPrototype.setFillStart = function () {};
|
||||
s9sPrototype.setFillRange = function () {};
|
||||
s9sPrototype.enableTrimmedContentSize = function () {};
|
||||
|
||||
s9sPrototype._lazyInit = function () {
|
||||
if (this._onceInit) return;
|
||||
this._onceInit = true;
|
||||
this._insets = {left: 0, right: 0, top: 0, bottom: 0};
|
||||
this._trim = {left: 0, right: 0, top: 0, bottom: 0};
|
||||
this._contentSizeTrimmed = new cc.Size(0, 0);
|
||||
this._anchorPointTrimmed = new cc.Vec2(0, 0);
|
||||
this._sizeAfterTrimmed = new cc.Size(0, 0);
|
||||
};
|
||||
|
||||
s9sPrototype._applyInsetsContentAnchor = function () {
|
||||
var renderingType = this._renderingType || (this.getRenderingType && this.getRenderingType());
|
||||
var trimScaleX = 1;
|
||||
var trimScaleY = 1;
|
||||
if (renderingType === cc.Scale9Sprite.RenderingType.SIMPLE) {
|
||||
trimScaleX = this._contentSizeTrimmed.width / this._sizeAfterTrimmed.width;
|
||||
trimScaleY = this._contentSizeTrimmed.height / this._sizeAfterTrimmed.height;
|
||||
}
|
||||
//apply contentSize
|
||||
var contentSize = new cc.Size(0, 0);
|
||||
contentSize.width = this._contentSizeTrimmed.width + (this._trim.left + this._trim.right) * trimScaleX;
|
||||
contentSize.height = this._contentSizeTrimmed.height + (this._trim.top + this._trim.bottom) * trimScaleY;
|
||||
this._setContentSize(contentSize);
|
||||
|
||||
//apply anchorpoint
|
||||
var anchorPoint = new cc.Vec2(0, 0);
|
||||
anchorPoint.x = (this._contentSizeTrimmed.width * this._anchorPointTrimmed.x) + this._trim.left * trimScaleX;
|
||||
anchorPoint.y = (this._contentSizeTrimmed.height * this._anchorPointTrimmed.y) + this._trim.bottom * trimScaleY;
|
||||
anchorPoint.x = anchorPoint.x / contentSize.width;
|
||||
anchorPoint.y = anchorPoint.y / contentSize.height;
|
||||
|
||||
this._setAnchorPoint(anchorPoint);
|
||||
|
||||
//apply capinsets
|
||||
var capinsets = new cc.Rect(0, 0, 0, 0);
|
||||
capinsets.x = this._trim.left + this._insets.left;
|
||||
capinsets.y = this._trim.top + this._insets.top;
|
||||
capinsets.width = this._sizeAfterTrimmed.width - this._insets.left - this._insets.right;
|
||||
capinsets.height = this._sizeAfterTrimmed.height - this._insets.top - this._insets.bottom;
|
||||
this.setCapInsets(capinsets);
|
||||
};
|
||||
|
||||
s9sPrototype._setBlendFunc = s9sPrototype.setBlendFunc;
|
||||
s9sPrototype.setBlendFunc = function (blendFunc, dst) {
|
||||
if (void 0 !== dst) {
|
||||
blendFunc = {
|
||||
src: blendFunc,
|
||||
dst: dst
|
||||
};
|
||||
}
|
||||
//in v3.3 blendFunc is not present
|
||||
if(this._setBlendFunc)
|
||||
this._setBlendFunc(blendFunc);
|
||||
};
|
||||
s9sPrototype._getContentSize = s9sPrototype.getContentSize;
|
||||
s9sPrototype.getContentSize = function () {
|
||||
return new cc.Size(this._contentSizeTrimmed);
|
||||
};
|
||||
|
||||
s9sPrototype._setContentSize = s9sPrototype.setContentSize;
|
||||
s9sPrototype.setContentSize = function (size, height) {
|
||||
this._lazyInit();
|
||||
if (void 0 !== height) {
|
||||
size = new cc.Size(size, height);
|
||||
}
|
||||
this._contentSizeTrimmed = new cc.Size(size);
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
|
||||
s9sPrototype._getAnchorPoint = s9sPrototype.getAnchorPoint;
|
||||
s9sPrototype.getAnchorPoint = function () {
|
||||
return new cc.Vec2(this._anchorPointTrimmed);
|
||||
};
|
||||
|
||||
s9sPrototype._setAnchorPoint = s9sPrototype.setAnchorPoint;
|
||||
s9sPrototype.setAnchorPoint = function (anchorPoint, y) {
|
||||
this._lazyInit();
|
||||
if (void 0 !== y) {
|
||||
anchorPoint = new cc.Vec2(anchorPoint, y);
|
||||
}
|
||||
this._anchorPointTrimmed = new cc.Vec2(anchorPoint);
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
|
||||
s9sPrototype._getInsetLeft = s9sPrototype.getInsetLeft;
|
||||
s9sPrototype._getInsetRight = s9sPrototype.getInsetRight;
|
||||
s9sPrototype._getInsetBottom = s9sPrototype.getInsetBottom;
|
||||
s9sPrototype._getInsetTop = s9sPrototype.getInsetTop;
|
||||
s9sPrototype.getInsetLeft = function () {
|
||||
return this._insets.left;
|
||||
};
|
||||
s9sPrototype.getInsetRight = function () {
|
||||
return this._insets.right;
|
||||
};
|
||||
s9sPrototype.getInsetBottom = function () {
|
||||
return this._insets.bottom;
|
||||
};
|
||||
s9sPrototype.getInsetTop = function () {
|
||||
return this._insets.top;
|
||||
};
|
||||
|
||||
s9sPrototype._setInsetLeft = s9sPrototype.setInsetLeft;
|
||||
s9sPrototype.setInsetLeft = function (insetLeft) {
|
||||
this._lazyInit();
|
||||
this._insets.left = insetLeft;
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
|
||||
s9sPrototype._setInsetRight = s9sPrototype.setInsetRight;
|
||||
s9sPrototype.setInsetRight = function (insetRight) {
|
||||
this._lazyInit();
|
||||
this._insets.right = insetRight;
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
|
||||
s9sPrototype._setInsetTop = s9sPrototype.setInsetTop;
|
||||
s9sPrototype.setInsetTop = function (insetTop) {
|
||||
this._lazyInit();
|
||||
this._insets.top = insetTop;
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
|
||||
s9sPrototype._setInsetBottom = s9sPrototype.setInsetBottom;
|
||||
s9sPrototype.setInsetBottom = function (insetBottom) {
|
||||
this._lazyInit();
|
||||
this._insets.bottom = insetBottom;
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
|
||||
s9sPrototype._setSpriteFrame = s9sPrototype.setSpriteFrame;
|
||||
s9sPrototype.setSpriteFrame = function (spriteFrame) {
|
||||
this._lazyInit();
|
||||
var originalSize = spriteFrame.getOriginalSize();
|
||||
var spriteRect = spriteFrame.getRect();
|
||||
var offset = spriteFrame.getOffset();
|
||||
var leftTrim = (originalSize.width + (2 * offset.x) - spriteRect.width) / 2;
|
||||
var rightTrim = originalSize.width - leftTrim - spriteRect.width;
|
||||
var bottomTrim = (originalSize.height + (2 * offset.y) - spriteRect.height) / 2;
|
||||
var topTrim = originalSize.height - bottomTrim - spriteRect.height;
|
||||
this._trim.left = leftTrim;
|
||||
this._trim.right = rightTrim;
|
||||
this._trim.top = topTrim;
|
||||
this._trim.bottom = bottomTrim;
|
||||
this._sizeAfterTrimmed = new cc.Size(spriteRect.width, spriteRect.height);
|
||||
this._setSpriteFrame(spriteFrame);
|
||||
this._applyInsetsContentAnchor();
|
||||
};
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
|
||||
require('../cocos2d/core/platform/CCClass');
|
||||
require('../cocos2d/core/assets/CCAsset');
|
||||
var WebTexture = require('../cocos2d/core/textures/CCTexture2D');
|
||||
var WebSpriteFrame = require('../cocos2d/core/sprites/CCSpriteFrame');
|
||||
|
||||
cc.js.unregisterClass(WebTexture, WebSpriteFrame);
|
||||
|
||||
// TextureCache addImage/addImageAsync
|
||||
|
||||
var prototype = cc.TextureCache.prototype;
|
||||
|
||||
if (!prototype._addImageAsync) {
|
||||
prototype._addImageAsync = prototype.addImageAsync;
|
||||
}
|
||||
prototype.addImageAsync = function (url, cb, target) {
|
||||
var localTex = null;
|
||||
cc.loader.load(url, function(err, tex) {
|
||||
if (err) tex = null;
|
||||
if (cb) {
|
||||
cb.call(target, tex);
|
||||
}
|
||||
localTex = tex;
|
||||
});
|
||||
return localTex;
|
||||
};
|
||||
if (!prototype._addImage) {
|
||||
prototype._addImage = prototype.addImage;
|
||||
}
|
||||
prototype.addImage = function (url, cb, target) {
|
||||
if (CC_DEBUG && url instanceof cc.Texture2D) {
|
||||
// TODO - remove at 2.0
|
||||
cc.warn('textureCache.addImage(url) - The type of the url should be string, not Texture2D. You don\'t need to call addImage if you already have the texture object.');
|
||||
url = url.url;
|
||||
}
|
||||
|
||||
var md5Pipe = cc.loader.md5Pipe;
|
||||
if (md5Pipe) {
|
||||
url = md5Pipe.transformURL(url);
|
||||
}
|
||||
|
||||
if (typeof cb === "function") {
|
||||
return this.addImageAsync(url, cb, target);
|
||||
}
|
||||
else {
|
||||
if (cb) {
|
||||
return this._addImage(url, cb);
|
||||
}
|
||||
else {
|
||||
return this._addImage(url);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// cc.textureCache
|
||||
|
||||
cc.textureCache._textures = {};
|
||||
cc.textureCache.cacheImage = function (key, texture) {
|
||||
if (texture instanceof cc.Texture2D) {
|
||||
this._textures[key] = texture;
|
||||
}
|
||||
};
|
||||
cc.textureCache._getTextureForKey = cc.textureCache.getTextureForKey;
|
||||
cc.textureCache.getTextureForKey = function (key) {
|
||||
return this._getTextureForKey(key) || this._textures[key] || null;
|
||||
};
|
||||
cc.textureCache._removeTextureForKey = cc.textureCache.removeTextureForKey;
|
||||
cc.textureCache.removeTextureForKey = function (key) {
|
||||
if (CC_DEBUG && key instanceof cc.Texture2D) {
|
||||
// TODO - remove at 2.0
|
||||
cc.warn('textureCache.removeTextureForKey(key) - The type of the key should be string, not Texture2D. You should call texture.destroy() if you already have the texture object.');
|
||||
key = key.url;
|
||||
}
|
||||
|
||||
delete this._textures[key];
|
||||
this._removeTextureForKey(key);
|
||||
};
|
||||
|
||||
// cc.Texture2D
|
||||
|
||||
cc.Class._fastDefine('cc.Texture2D', cc.Texture2D, []);
|
||||
cc.Texture2D.$super = cc.Asset;
|
||||
|
||||
[
|
||||
'WrapMode',
|
||||
'PixelFormat',
|
||||
'Filter',
|
||||
'extnames',
|
||||
'preventDeferredLoadDependents',
|
||||
'preventPreloadNativeObject',
|
||||
].forEach(function (key) {
|
||||
cc.Texture2D[key] = WebTexture[key];
|
||||
});
|
||||
|
||||
prototype = cc.Texture2D.prototype;
|
||||
prototype._releaseTexture = prototype.releaseTexture;
|
||||
|
||||
cc.js.addon(prototype, WebTexture.prototype);
|
||||
|
||||
prototype._ctor = function () {
|
||||
cc.Asset.call(this);
|
||||
this.url = "";
|
||||
};
|
||||
|
||||
prototype.loaded = true;
|
||||
prototype.update = function (options) {
|
||||
var updateTexParam = false;
|
||||
var genMipmap = false;
|
||||
if (options) {
|
||||
if (options.minFilter !== undefined) {
|
||||
this._minFilter = options.minFilter;
|
||||
updateTexParam = true;
|
||||
}
|
||||
if (options.magFilter !== undefined) {
|
||||
this._magFilter = options.magFilter;
|
||||
updateTexParam = true;
|
||||
}
|
||||
if (options.wrapS !== undefined) {
|
||||
this._wrapS = options.wrapS;
|
||||
updateTexParam = true;
|
||||
}
|
||||
if (options.wrapT !== undefined) {
|
||||
this._wrapT = options.wrapT;
|
||||
updateTexParam = true;
|
||||
}
|
||||
if (options.mipmap !== undefined) {
|
||||
genMipmap = this._hasMipmap = options.mipmap;
|
||||
}
|
||||
}
|
||||
if (updateTexParam) {
|
||||
this.setTexParameters(options);
|
||||
}
|
||||
if (genMipmap) {
|
||||
this.generateMipmap();
|
||||
}
|
||||
};
|
||||
prototype.description = prototype.getDescription;
|
||||
cc.js.get(prototype, 'width', prototype.getPixelsWide);
|
||||
cc.js.get(prototype, 'height', prototype.getPixelsHigh);
|
||||
cc.js.get(prototype, '_glID', prototype.getName);
|
||||
|
||||
// cc.SpriteFrame
|
||||
|
||||
cc.Class._fastDefine('cc.SpriteFrame', cc.SpriteFrame, []);
|
||||
cc.SpriteFrame.$super = cc.Asset;
|
||||
|
||||
prototype = cc.SpriteFrame.prototype;
|
||||
prototype._setTexture = prototype.setTexture;
|
||||
|
||||
cc.js.mixin(prototype, cc.EventTarget.prototype);
|
||||
|
||||
prototype._ctor = function (filename, rect, rotated, offset, originalSize) {
|
||||
this.insetTop = 0;
|
||||
this.insetBottom = 0;
|
||||
this.insetLeft = 0;
|
||||
this.insetRight = 0;
|
||||
this._name = '';
|
||||
this._texture = null;
|
||||
if (filename !== undefined) {
|
||||
this.initWithTexture(filename, rect, rotated, offset, originalSize);
|
||||
}
|
||||
};
|
||||
|
||||
prototype.textureLoaded = function () {
|
||||
return this.getTexture() !== null;
|
||||
};
|
||||
|
||||
prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) {
|
||||
if (rect) {
|
||||
this.setRect(rect);
|
||||
}
|
||||
if (offset) {
|
||||
this.setOffset(offset);
|
||||
}
|
||||
if (originalSize) {
|
||||
this.setOriginalSize(originalSize);
|
||||
}
|
||||
|
||||
this.setRotated(rotated || false);
|
||||
|
||||
// loading texture
|
||||
var texture = textureOrTextureFile;
|
||||
if (typeof texture === 'string' && texture) {
|
||||
texture = cc.textureCache.addImage(texture);
|
||||
}
|
||||
if (texture instanceof cc.Texture2D && this.getTexture() !== texture) {
|
||||
this._refreshTexture(texture);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
prototype.initWithTexture = prototype.setTexture;
|
||||
|
||||
prototype.ensureLoadTexture = function () {
|
||||
if (this._texture) {
|
||||
if (!this._texture.loaded) {
|
||||
// load exists texture
|
||||
this._refreshTexture(this._texture);
|
||||
this._texture.load();
|
||||
}
|
||||
}
|
||||
else if (this._textureFilename) {
|
||||
// load new texture
|
||||
var texture = cc.textureCache.addImage(this._textureFilename);
|
||||
this._refreshTexture(texture);
|
||||
}
|
||||
};
|
||||
|
||||
prototype.clearTexture = function () {
|
||||
this._setTexture(null);
|
||||
};
|
||||
|
||||
prototype._refreshTexture = function (texture) {
|
||||
var w = texture.width, h = texture.height;
|
||||
|
||||
var rect = this.getRect();
|
||||
if (rect.width === 0 || rect.height === 0) {
|
||||
this.setRect(cc.rect(0, 0, w, h));
|
||||
}
|
||||
else {
|
||||
this._checkRect(texture);
|
||||
}
|
||||
|
||||
var originalSize = this.getOriginalSize();
|
||||
if (originalSize.width === 0 || originalSize.height === 0) {
|
||||
this.setOriginalSize(cc.size(w, h));
|
||||
}
|
||||
|
||||
this._setTexture(texture);
|
||||
|
||||
//dispatch 'load' event of cc.SpriteFrame
|
||||
this.emit("load");
|
||||
};
|
||||
|
||||
prototype._deserialize = function (data, handle) {
|
||||
var rect = data.rect;
|
||||
if (rect) {
|
||||
this.setRect(new cc.Rect(rect[0], rect[1], rect[2], rect[3]));
|
||||
}
|
||||
if (data.offset) {
|
||||
this.setOffset(new cc.Vec2(data.offset[0], data.offset[1]));
|
||||
}
|
||||
if (data.originalSize) {
|
||||
this.setOriginalSize(new cc.Size(data.originalSize[0], data.originalSize[1]));
|
||||
}
|
||||
|
||||
this.setRotated(data.rotated === 1);
|
||||
|
||||
this._name = data.name;
|
||||
var capInsets = data.capInsets;
|
||||
if (capInsets) {
|
||||
this.insetLeft = capInsets[0];
|
||||
this.insetTop = capInsets[1];
|
||||
this.insetRight = capInsets[2];
|
||||
this.insetBottom = capInsets[3];
|
||||
}
|
||||
|
||||
// load texture via _textureSetter
|
||||
var textureUuid = data.texture;
|
||||
if (textureUuid) {
|
||||
handle.result.push(this, '_textureSetter', textureUuid);
|
||||
}
|
||||
};
|
||||
prototype._checkRect = function (texture) {
|
||||
var rect = this.getRect();
|
||||
var maxX = rect.x, maxY = rect.y;
|
||||
if (this.isRotated()) {
|
||||
maxX += rect.height;
|
||||
maxY += rect.width;
|
||||
}
|
||||
else {
|
||||
maxX += rect.width;
|
||||
maxY += rect.height;
|
||||
}
|
||||
if (maxX > texture.width) {
|
||||
cc.errorID(3300, texture.url);
|
||||
}
|
||||
if (maxY > texture.height) {
|
||||
cc.errorID(3400, texture.url);
|
||||
}
|
||||
};
|
||||
|
||||
prototype._getTexture = prototype.getTexture;
|
||||
prototype.getTexture = function () {
|
||||
var tex = this._getTexture();
|
||||
this._texture = tex;
|
||||
return tex;
|
||||
};
|
||||
|
||||
prototype._clone = prototype.clone;
|
||||
prototype.clone = function () {
|
||||
var cloned = this._clone();
|
||||
cloned._name = this._name;
|
||||
cloned.insetTop = this.insetTop;
|
||||
cloned.insetBottom = this.insetBottom;
|
||||
cloned.insetLeft = this.insetLeft;
|
||||
cloned.insetRight = this.insetRight;
|
||||
return cloned;
|
||||
};
|
||||
|
||||
cc.js.getset(prototype, 'texture', prototype.getTexture, prototype.setTexture);
|
||||
cc.js.addon(prototype, WebSpriteFrame.prototype);
|
||||
@@ -1,39 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
'use strict';
|
||||
if (!cc.runtime) {
|
||||
var _p = cc.TMXObject.prototype;
|
||||
cc.defineGetterSetter(_p, 'type', _p.getType, null);
|
||||
cc.defineGetterSetter(_p, 'name', _p.getObjectName, _p.setObjectName);
|
||||
cc.defineGetterSetter(_p, 'id', _p.getId, null);
|
||||
cc.defineGetterSetter(_p, 'gid', _p.getGid, null);
|
||||
cc.defineGetterSetter(_p, 'offset', _p.getOffset, null);
|
||||
cc.defineGetterSetter(_p, 'objectSize', _p.getObjectSize, null);
|
||||
cc.defineGetterSetter(_p, 'objectVisible', _p.getObjectVisible, null);
|
||||
cc.defineGetterSetter(_p, 'objectRotation', _p.getObjectRotation, null);
|
||||
cc.defineGetterSetter(_p, 'sgNode', _p.getNode, null);
|
||||
}
|
||||
@@ -0,0 +1,734 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
(function(){
|
||||
|
||||
var sys = cc.sys;
|
||||
var platform = sys.platform;
|
||||
|
||||
// Only android and iOS support cocos analytics
|
||||
if (platform === sys.ANDROID) {
|
||||
|
||||
cocosAnalytics = {};
|
||||
|
||||
var cls_CAAccount = "com/cocos/analytics/CAAccount";
|
||||
var cls_CAAgent = "com/cocos/analytics/CAAgent";
|
||||
var cls_CAEvent = "com/cocos/analytics/CAEvent";
|
||||
var cls_CAItem = "com/cocos/analytics/CAItem";
|
||||
var cls_CALevels = "com/cocos/analytics/CALevels";
|
||||
var cls_CAPayment = "com/cocos/analytics/CAPayment";
|
||||
var cls_CATask = "com/cocos/analytics/CATask";
|
||||
var cls_CAVirtual = "com/cocos/analytics/CAVirtual";
|
||||
|
||||
var cls_CAAgentWrapper = "org/cocos2dx/lib/CAAgentWrapper";
|
||||
|
||||
cocosAnalytics.init = function(info) {
|
||||
|
||||
if (!info.channel) {
|
||||
var anysdkChannelID = jsb.reflection.callStaticMethod(cls_CAAgentWrapper, "getChannelID", "()Ljava/lang/String;");
|
||||
console.log("Found AnySDK channel ID: " + anysdkChannelID);
|
||||
info.channel = anysdkChannelID;
|
||||
}
|
||||
|
||||
if (info && info.appID && info.appSecret && info.channel) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAgentWrapper,
|
||||
"init", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
info.channel, info.appID, info.appSecret);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.init are wrong!");
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.enableDebug = function(enabled) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAgent,
|
||||
"enableDebug", "(Z)V",
|
||||
enabled);
|
||||
};
|
||||
|
||||
cocosAnalytics.CAAccount = {
|
||||
loginStart: function() {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "loginStart", "()V");
|
||||
},
|
||||
|
||||
loginSuccess: function(info) {
|
||||
if (info && info.userID) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "loginSuccess", "(Ljava/lang/String;)V", info.userID);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAAccount.loginSuccess are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
loginFailed: function() {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "loginFailed", "()V");
|
||||
},
|
||||
|
||||
logout: function(info) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "logout", "()V");
|
||||
},
|
||||
|
||||
setAccountType: function(type) {
|
||||
if (type) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setAccountType", "(Ljava/lang/String;)V", type);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAAccount.setAccountType are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
setAge: function(age) {
|
||||
if (age) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setAge", "(I)V", age);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAAccount.setAge is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
setGender: function(gender) {
|
||||
if (gender) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setGender", "(I)V", gender);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAAccount.setGender is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
setLevel: function(level) {
|
||||
if (level) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setLevel", "(I)V", level);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAAccount.setLevel is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
createRole: function(info) {
|
||||
if (info && info.roleID && info.userName && info.race && info['class'] && info.gameServer) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount,
|
||||
"createRole", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
info.roleID, info.userName, info.race, info['class'], info.gameServer);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAAccount.createRole are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAEvent = {
|
||||
onEvent: function(info) {
|
||||
if (info && info.eventName) {
|
||||
jsb.reflection.callStaticMethod(cls_CAEvent, "onEvent", "(Ljava/lang/String;)V", info.eventName);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAEvent.onEvent is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
onEventStart: function(info) {
|
||||
if (info && info.eventName) {
|
||||
jsb.reflection.callStaticMethod(cls_CAEvent, "onEventStart", "(Ljava/lang/String;)V", info.eventName);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAEvent.onEventStart is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
onEventEnd: function(info) {
|
||||
if (info && info.eventName) {
|
||||
jsb.reflection.callStaticMethod(cls_CAEvent, "onEventEnd", "(Ljava/lang/String;)V", info.eventName);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAEvent.onEventEnd is wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAPayment = {
|
||||
payBegin: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"payBegin", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.payBegin are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
paySuccess: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"paySuccess", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.paySuccess are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
payFailed: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"payFailed", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.payFailed are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
payCanceled: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"payCanceled", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.payCanceled are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CALevels = {
|
||||
begin: function(info) {
|
||||
if (info && info.level) {
|
||||
jsb.reflection.callStaticMethod(cls_CALevels, "begin", "(Ljava/lang/String;)V", info.level);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CALevels.begin is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
complete: function(info) {
|
||||
if (info && info.level) {
|
||||
jsb.reflection.callStaticMethod(cls_CALevels, "complete", "(Ljava/lang/String;)V", info.level);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CALevels.complete is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
failed: function(info) {
|
||||
if (info && info.level) {
|
||||
info.reason = info.reason || "";
|
||||
jsb.reflection.callStaticMethod(cls_CALevels, "failed", "(Ljava/lang/String;Ljava/lang/String;)V", info.level, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CALevels.failed are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CATaskType = {
|
||||
GuideLine: 1,
|
||||
MainLine: 2,
|
||||
BranchLine: 3,
|
||||
Daily: 4,
|
||||
Activity: 5,
|
||||
Other: 100
|
||||
};
|
||||
|
||||
cocosAnalytics.CATask = {
|
||||
|
||||
begin: function(info) {
|
||||
if (info && info.taskID && info.type) {
|
||||
jsb.reflection.callStaticMethod(cls_CATask, "begin", "(Ljava/lang/String;I)V", info.taskID, info.type);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CATask.begin are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
complete: function(info) {
|
||||
if (info && info.taskID) {
|
||||
jsb.reflection.callStaticMethod(cls_CATask, "complete", "(Ljava/lang/String;)V", info.taskID);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CATask.complete is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
failed: function(info) {
|
||||
if (info && info.taskID) {
|
||||
info.reason = info.reason || "";
|
||||
jsb.reflection.callStaticMethod(cls_CATask, "failed", "(Ljava/lang/String;Ljava/lang/String;)V", info.taskID, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CATask.failed are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAItem = {
|
||||
buy: function(info) {
|
||||
if (info && info.itemID && info.itemType && info.itemCount && info.virtualCoin && info.virtualType && info.consumePoint) {
|
||||
jsb.reflection.callStaticMethod(cls_CAItem, "buy", "(Ljava/lang/String;Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V",
|
||||
info.itemID, info.itemType, info.itemCount, info.virtualCoin, info.virtualType, info.consumePoint);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAItem.buy are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
get: function(info) {
|
||||
if (info && info.itemID && info.itemType && info.itemCount && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAItem, "get", "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V",
|
||||
info.itemID, info.itemType, info.itemCount, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAItem.get are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
consume: function(info) {
|
||||
if (info && info.itemID && info.itemType && info.itemCount && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAItem, "consume", "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V",
|
||||
info.itemID, info.itemType, info.itemCount, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAItem.consume are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAVirtual = {
|
||||
setVirtualNum: function(info) {
|
||||
if (info && info.type && info.count) {
|
||||
jsb.reflection.callStaticMethod(cls_CAVirtual, "setVirtualNum", "(Ljava/lang/String;J)V",
|
||||
info.type, info.count);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAVirtual.setVirtualNum are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
get: function(info) {
|
||||
if (info && info.type && info.count && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAVirtual, "get", "(Ljava/lang/String;JLjava/lang/String;)V",
|
||||
info.type, info.count, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAVirtual.get are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
consume: function(info) {
|
||||
if (info && info.type && info.count && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAVirtual, "consume", "(Ljava/lang/String;JLjava/lang/String;)V",
|
||||
info.type, info.count, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAVirtual.consume are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} else if (platform === sys.IPAD || platform === sys.IPHONE) {
|
||||
cocosAnalytics = {};
|
||||
|
||||
var cls_CAAccount = "CAAccount";
|
||||
var cls_CAAgent = "CAAgent";
|
||||
var cls_CAEvent = "CAEvent";
|
||||
var cls_CAItem = "CAItem";
|
||||
var cls_CALevels = "CALevels";
|
||||
var cls_CAPayment = "CAPeiment";
|
||||
var cls_CATask = "CATask";
|
||||
var cls_CAVirtual = "CAVirtual";
|
||||
var cls_JSB_PlatformIOS = "JSB_PlatformIOS";
|
||||
|
||||
cocosAnalytics.init = function(info) {
|
||||
|
||||
if (!info.channel) {
|
||||
var anysdkChannelID = jsb.reflection.callStaticMethod(cls_JSB_PlatformIOS, "getChannelID");
|
||||
console.log("Found AnySDK channel ID: " + anysdkChannelID);
|
||||
info.channel = anysdkChannelID;
|
||||
}
|
||||
|
||||
if (info && info.appID && info.appSecret && info.channel) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAgent,
|
||||
"init:appID:appSecret:",
|
||||
info.channel, info.appID, info.appSecret);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.init are wrong!");
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.enableDebug = function(enabled) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAgent,
|
||||
"enableDebug:",
|
||||
enabled);
|
||||
};
|
||||
|
||||
cocosAnalytics.CAAccount = {
|
||||
|
||||
loginStart: function() {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "loginStart");
|
||||
},
|
||||
|
||||
loginSuccess: function(info) {
|
||||
if (info && info.userID) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "loginSuccess:", info.userID);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAAccount.loginSuccess are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
loginFailed: function() {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "loginFailed");
|
||||
},
|
||||
|
||||
logout: function(info) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "logout");
|
||||
},
|
||||
|
||||
setAccountType: function(type) {
|
||||
if (type) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setAccountType:", type);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAAccount.setAccountType are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
setAge: function(age) {
|
||||
if (age) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setAge:", age);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAAccount.setAge is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
setGender: function(gender) {
|
||||
if (gender) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setGender:", gender);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAAccount.setGender is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
setLevel: function(level) {
|
||||
if (level) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount, "setLevel:", level);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAAccount.setLevel is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
createRole: function(info) {
|
||||
if (info && info.roleID && info.userName && info.race && info['class'] && info.gameServer) {
|
||||
jsb.reflection.callStaticMethod(cls_CAAccount,
|
||||
"createRole:userName:race:roleClass:gameServer:",
|
||||
info.roleID, info.userName, info.race, info['class'], info.gameServer);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAAccount.createRole are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAEvent = {
|
||||
onEvent: function(info) {
|
||||
if (info && info.eventName) {
|
||||
jsb.reflection.callStaticMethod(cls_CAEvent, "onEvent:", info.eventName);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAEvent.onEvent is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
onEventStart: function(info) {
|
||||
if (info && info.eventName) {
|
||||
jsb.reflection.callStaticMethod(cls_CAEvent, "onEventStart:", info.eventName);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAEvent.onEventStart is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
onEventEnd: function(info) {
|
||||
if (info && info.eventName) {
|
||||
jsb.reflection.callStaticMethod(cls_CAEvent, "onEventEnd:", info.eventName);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CAEvent.onEventEnd is wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAPayment = {
|
||||
payBegin: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"peiBegin:orderID:peiType:pppID:currencyType:",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.payBegin are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
paySuccess: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"peiSuccess:orderID:peiType:pppID:currencyType:",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.paySuccess are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
payFailed: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"peiFailed:orderID:peiType:pppID:currencyType:",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.payFailed are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
payCanceled: function(info) {
|
||||
if (info && info.amount && info.orderID && info.payType && info.iapID && info.currencyType) {
|
||||
jsb.reflection.callStaticMethod(cls_CAPayment,
|
||||
"peiCanceled:orderID:peiType:pppID:currencyType:",
|
||||
info.amount, info.orderID, info.payType, info.iapID, info.currencyType);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAPayment.payCanceled are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CALevels = {
|
||||
begin: function(info) {
|
||||
if (info && info.level) {
|
||||
jsb.reflection.callStaticMethod(cls_CALevels, "begin:", info.level);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CALevels.begin is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
complete: function(info) {
|
||||
if (info && info.level) {
|
||||
jsb.reflection.callStaticMethod(cls_CALevels, "complete:", info.level);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CALevels.complete is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
failed: function(info) {
|
||||
if (info && info.level) {
|
||||
info.reason = info.reason || "";
|
||||
jsb.reflection.callStaticMethod(cls_CALevels, "failed:reason:", info.level, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CALevels.failed are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CATaskType = {
|
||||
GuideLine: 1,
|
||||
MainLine: 2,
|
||||
BranchLine: 3,
|
||||
Daily: 4,
|
||||
Activity: 5,
|
||||
Other: 100
|
||||
};
|
||||
|
||||
cocosAnalytics.CATask = {
|
||||
|
||||
begin: function(info) {
|
||||
if (info && info.taskID && info.type) {
|
||||
jsb.reflection.callStaticMethod(cls_CATask, "begin:taskType:", info.taskID, info.type);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CATask.begin are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
complete: function(info) {
|
||||
if (info && info.taskID) {
|
||||
jsb.reflection.callStaticMethod(cls_CATask, "complete:", info.taskID);
|
||||
} else {
|
||||
console.error("The argument passed to cocosAnalytics.CATask.complete is wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
failed: function(info) {
|
||||
if (info && info.taskID) {
|
||||
info.reason = info.reason || "";
|
||||
jsb.reflection.callStaticMethod(cls_CATask, "failed:reason:", info.taskID, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CATask.failed are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAItem = {
|
||||
buy: function(info) {
|
||||
if (info && info.itemID && info.itemType && info.itemCount && info.virtualCoin && info.virtualType && info.consumePoint) {
|
||||
jsb.reflection.callStaticMethod(cls_CAItem, "buy:type:count:virtualCoin:virtualType:consumePoint:",
|
||||
info.itemID, info.itemType, info.itemCount, info.virtualCoin, info.virtualType, info.consumePoint);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAItem.buy are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
get: function(info) {
|
||||
if (info && info.itemID && info.itemType && info.itemCount && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAItem, "get:type:count:reason:",
|
||||
info.itemID, info.itemType, info.itemCount, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAItem.get are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
consume: function(info) {
|
||||
if (info && info.itemID && info.itemType && info.itemCount && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAItem, "consume:type:count:reason:",
|
||||
info.itemID, info.itemType, info.itemCount, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAItem.consume are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAVirtual = {
|
||||
setVirtualNum: function(info) {
|
||||
if (info && info.type && info.count) {
|
||||
jsb.reflection.callStaticMethod(cls_CAVirtual, "setVirtualNum:count:",
|
||||
info.type, info.count);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAVirtual.setVirtualNum are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
get: function(info) {
|
||||
if (info && info.type && info.count && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAVirtual, "get:count:reason:",
|
||||
info.type, info.count, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAVirtual.get are wrong!");
|
||||
}
|
||||
},
|
||||
|
||||
consume: function(info) {
|
||||
if (info && info.type && info.count && info.reason) {
|
||||
jsb.reflection.callStaticMethod(cls_CAVirtual, "consume:count:reason:",
|
||||
info.type, info.count, info.reason);
|
||||
} else {
|
||||
console.error("The arguments passed to cocosAnalytics.CAVirtual.consume are wrong!");
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// Empty implementation for other platforms
|
||||
cocosAnalytics = {};
|
||||
|
||||
cocosAnalytics.init = function(info) {
|
||||
console.log("Cocos Analytics module isn't available on this platform!");
|
||||
};
|
||||
|
||||
cocosAnalytics.enableDebug = function(enabled) {
|
||||
};
|
||||
|
||||
cocosAnalytics.CAAccount = {
|
||||
loginStart: function() {
|
||||
},
|
||||
|
||||
loginSuccess: function(info) {
|
||||
},
|
||||
|
||||
loginFailed: function() {
|
||||
},
|
||||
|
||||
logout: function(info) {
|
||||
},
|
||||
|
||||
setAccountType: function(type) {
|
||||
},
|
||||
|
||||
setAge: function(age) {
|
||||
},
|
||||
|
||||
setGender: function(gender) {
|
||||
},
|
||||
|
||||
setLevel: function(level) {
|
||||
},
|
||||
|
||||
createRole: function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAEvent = {
|
||||
onEvent: function(info) {
|
||||
},
|
||||
|
||||
onEventStart: function(info) {
|
||||
},
|
||||
|
||||
onEventEnd: function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAPayment = {
|
||||
payBegin: function(info) {
|
||||
},
|
||||
|
||||
paySuccess: function(info) {
|
||||
},
|
||||
|
||||
payFailed: function(info) {
|
||||
},
|
||||
|
||||
payCanceled: function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CALevels = {
|
||||
begin: function(info) {
|
||||
},
|
||||
|
||||
complete: function(info) {
|
||||
},
|
||||
|
||||
failed: function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CATaskType = {
|
||||
GuideLine: 1,
|
||||
MainLine: 2,
|
||||
BranchLine: 3,
|
||||
Daily: 4,
|
||||
Activity: 5,
|
||||
Other: 100
|
||||
};
|
||||
|
||||
cocosAnalytics.CATask = {
|
||||
|
||||
begin: function(info) {
|
||||
},
|
||||
|
||||
complete: function(info) {
|
||||
},
|
||||
|
||||
failed: function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAItem = {
|
||||
buy: function(info) {
|
||||
},
|
||||
|
||||
get: function(info) {
|
||||
},
|
||||
|
||||
consume: function(info) {
|
||||
}
|
||||
};
|
||||
|
||||
cocosAnalytics.CAVirtual = {
|
||||
setVirtualNum: function(info) {
|
||||
},
|
||||
|
||||
get: function(info) {
|
||||
},
|
||||
|
||||
consume: function(info) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// projection
|
||||
renderer.PROJ_PERSPECTIVE = 0;
|
||||
renderer.PROJ_ORTHO = 1;
|
||||
|
||||
// lights
|
||||
renderer.LIGHT_DIRECTIONAL = 0;
|
||||
renderer.LIGHT_POINT = 1;
|
||||
renderer.LIGHT_SPOT = 2;
|
||||
|
||||
// shadows
|
||||
renderer.SHADOW_NONE = 0;
|
||||
renderer.SHADOW_HARD = 1;
|
||||
renderer.SHADOW_SOFT = 2;
|
||||
|
||||
// parameter type
|
||||
renderer.PARAM_INT = 0;
|
||||
renderer.PARAM_INT2 = 1;
|
||||
renderer.PARAM_INT3 = 2;
|
||||
renderer.PARAM_INT4 = 3;
|
||||
renderer.PARAM_FLOAT = 4;
|
||||
renderer.PARAM_FLOAT2 = 5;
|
||||
renderer.PARAM_FLOAT3 = 6;
|
||||
renderer.PARAM_FLOAT4 = 7;
|
||||
renderer.PARAM_COLOR3 = 8;
|
||||
renderer.PARAM_COLOR4 = 9;
|
||||
renderer.PARAM_MAT2 = 10;
|
||||
renderer.PARAM_MAT3 = 11;
|
||||
renderer.PARAM_MAT4 = 12;
|
||||
renderer.PARAM_TEXTURE_2D = 13;
|
||||
renderer.PARAM_TEXTURE_CUBE = 14;
|
||||
|
||||
// clear flags
|
||||
renderer.CLEAR_COLOR = 1;
|
||||
renderer.CLEAR_DEPTH = 2;
|
||||
renderer.CLEAR_STENCIL = 4;
|
||||
|
||||
renderer.addStage = renderer.Config.addStage;
|
||||
|
||||
// ForwardRenderer adapter
|
||||
var _p;
|
||||
|
||||
_p = renderer.ForwardRenderer.prototype;
|
||||
_p._ctor = function(device, builtin) {
|
||||
this.init(device, builtin.programTemplates, builtin.defaultTexture, canvas.width, canvas.height);
|
||||
};
|
||||
|
||||
// InputAssembler adapter
|
||||
_p = renderer.InputAssembler.prototype;
|
||||
_p._ctor = function(vb, ib, pt = gfx.PT_TRIANGLES) {
|
||||
this.init(vb, ib, pt);
|
||||
};
|
||||
|
||||
cc.defineGetterSetter(_p, "_vertexBuffer", _p.getVertexBuffer, _p.setVertexBuffer);
|
||||
cc.defineGetterSetter(_p, "_indexBuffer", _p.getIndexBuffer, _p.setIndexBuffer);
|
||||
cc.defineGetterSetter(_p, "_primitiveType", _p.getPrimitiveType, _p.setPrimitiveType);
|
||||
cc.defineGetterSetter(_p, "_start", _p.getStart, _p.setStart);
|
||||
cc.defineGetterSetter(_p, "_count", _p.getCount, _p.setCount);
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
let {attrTypeBytes} = require("./enums");
|
||||
|
||||
// ====================
|
||||
// exports
|
||||
// ====================
|
||||
|
||||
class VertexFormat {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Array} infos
|
||||
*
|
||||
* @example
|
||||
* let vertexFmt = new VertexFormat([
|
||||
* { name: gfx.ATTR_POSITION, type: gfx.ATTR_TYPE_FLOAT32, num: 3 },
|
||||
* { name: gfx.ATTR_UV0, type: gfx.ATTR_TYPE_FLOAT32, num: 2 },
|
||||
* { name: gfx.ATTR_COLOR, type: gfx.ATTR_TYPE_FLOAT32, num: 4, normalize: true },
|
||||
* ])
|
||||
*/
|
||||
constructor(infos) {
|
||||
this._attr2el = {};
|
||||
this._elements = [];
|
||||
this._bytes = 0;
|
||||
|
||||
let offset = 0;
|
||||
for (let i = 0, len = infos.length; i < len; ++i) {
|
||||
let info = infos[i];
|
||||
let el = {
|
||||
name: info.name,
|
||||
offset: offset,
|
||||
stride: 0,
|
||||
stream: -1,
|
||||
type: info.type,
|
||||
num: info.num,
|
||||
normalize: (info.normalize === undefined) ? false : info.normalize,
|
||||
bytes: info.num * attrTypeBytes(info.type),
|
||||
};
|
||||
// log('info.num is:' + info.num + ' attrTypeBytes(info.type) is:' + attrTypeBytes(info.type));
|
||||
|
||||
this._attr2el[el.name] = el;
|
||||
this._elements.push(el);
|
||||
|
||||
this._bytes += el.bytes;
|
||||
offset += el.bytes;
|
||||
}
|
||||
|
||||
for (let i = 0, len = this._elements.length; i < len; ++i) {
|
||||
let el = this._elements[i];
|
||||
el.stride = this._bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method element
|
||||
* @param {string} attrName
|
||||
*/
|
||||
element(attrName) {
|
||||
return this._attr2el[attrName];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VertexFormat
|
||||
+1
-1
@@ -52,4 +52,4 @@
|
||||
"vinyl-source-stream": "1.0.0",
|
||||
"watchify": "^3.7.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -135,7 +135,11 @@ defineMacro('CC_JSB', defined('jsb'));
|
||||
defineMacro('CC_BUILD', false);
|
||||
defineMacro('CC_WECHATGAME', false);
|
||||
defineMacro('CC_QQPLAY', false);
|
||||
defineMacro('CC_SUPPORT_JIT', !(CC_WECHATGAME || CC_QQPLAY));
|
||||
if (CC_JSB) {
|
||||
defineMacro('CC_SUPPORT_JIT', true); //FIXME: cjh close it since safety issues.
|
||||
} else {
|
||||
defineMacro('CC_SUPPORT_JIT', !(CC_WECHATGAME || CC_QQPLAY));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
Reference in New Issue
Block a user