From e5e8ade1bd2648843aa6c78b4fbdcde0ca2de4da Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 3 Feb 2016 11:17:26 +0800 Subject: [PATCH] Fix JSB issues --- .jshintrc | 1 + extensions/spine/Skeleton.js | 4 +- extensions/spine/SkeletonAnimation.js | 4 +- extensions/spine/SkeletonCanvasRenderCmd.js | 4 +- extensions/spine/SkeletonWebGLRenderCmd.js | 4 +- extensions/spine/index.js | 2 +- gulp/tasks/build.js | 12 ++- gulpfile.js | 1 + index.js | 3 +- jsb/index.js | 6 +- jsb/jsb-director.js | 4 +- jsb/jsb-enums.js | 2 +- jsb/jsb-etc.js | 2 +- jsb/jsb-scale9sprite.js | 102 ++++++++++++++------ jsb/versions/jsb-polyfill-v3.9.js | 2 +- 15 files changed, 104 insertions(+), 49 deletions(-) diff --git a/.jshintrc b/.jshintrc index 8e9fd98055..028b0a4e77 100644 --- a/.jshintrc +++ b/.jshintrc @@ -36,6 +36,7 @@ "expect", "it", "cc", + "CC_JSB", "CC_EDITOR", "CC_DEV", "CC_TEST", diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index 8cadc1f618..8f7af3015e 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -25,7 +25,9 @@ THE SOFTWARE. ****************************************************************************/ -var spine = require('./spine-exported'); +if (!CC_JSB) { + var spine = require('./spine-exported'); +} /** * @module sp diff --git a/extensions/spine/SkeletonAnimation.js b/extensions/spine/SkeletonAnimation.js index edfc167f02..9256ea215e 100644 --- a/extensions/spine/SkeletonAnimation.js +++ b/extensions/spine/SkeletonAnimation.js @@ -25,7 +25,9 @@ THE SOFTWARE. ****************************************************************************/ -var spine = require('./spine-exported'); +if (!CC_JSB) { + var spine = require('./spine-exported'); +} /** * @module sp diff --git a/extensions/spine/SkeletonCanvasRenderCmd.js b/extensions/spine/SkeletonCanvasRenderCmd.js index 5f33707590..72790a904b 100644 --- a/extensions/spine/SkeletonCanvasRenderCmd.js +++ b/extensions/spine/SkeletonCanvasRenderCmd.js @@ -22,7 +22,9 @@ THE SOFTWARE. ****************************************************************************/ -var spine = require('./spine-exported'); +if (!CC_JSB) { + var spine = require('./spine-exported'); +} /** * @module sp diff --git a/extensions/spine/SkeletonWebGLRenderCmd.js b/extensions/spine/SkeletonWebGLRenderCmd.js index 78a9363775..d254349cb5 100644 --- a/extensions/spine/SkeletonWebGLRenderCmd.js +++ b/extensions/spine/SkeletonWebGLRenderCmd.js @@ -22,7 +22,9 @@ THE SOFTWARE. ****************************************************************************/ -var spine = require('./spine-exported'); +if (!CC_JSB) { + var spine = require('./spine-exported'); +} /** * @module sp diff --git a/extensions/spine/index.js b/extensions/spine/index.js index 0bb1cdf240..454cf2e0e6 100644 --- a/extensions/spine/index.js +++ b/extensions/spine/index.js @@ -30,7 +30,7 @@ sp = {}; -if (!CC_EDITOR || !Editor.isCoreLevel) { +if (!CC_JSB && (!CC_EDITOR || !Editor.isCoreLevel)) { require('./Skeleton'); require('./SkeletonCanvasRenderCmd'); require('./SkeletonWebGLRenderCmd'); diff --git a/gulp/tasks/build.js b/gulp/tasks/build.js index c54b438ac8..cadc3eaa35 100644 --- a/gulp/tasks/build.js +++ b/gulp/tasks/build.js @@ -66,14 +66,16 @@ function rebundle(bundler) { var dev = uglify(getUglifyOptions(false, { CC_EDITOR: false, CC_DEV: false, - CC_TEST: false + CC_TEST: false, + CC_JSB: false })); var min = rename({ suffix: '-min' }); min.pipe(uglify(getUglifyOptions(true, { CC_EDITOR: false, CC_DEV: false, - CC_TEST: false + CC_TEST: false, + CC_JSB: false }))); return bundler.bundle() @@ -107,7 +109,8 @@ function rebundle_test(bundler, suffix) { bundle = bundle.pipe(uglify(getUglifyOptions(false, { CC_EDITOR: TestEditorExtends, CC_DEV: TestEditorExtends || true, - CC_TEST: true + CC_TEST: true, + CC_JSB: false }))); if (SourceMap) { bundle = bundle.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true})); @@ -179,7 +182,8 @@ function rebundle_jsb(bundler, minify, suffix) { bundle = bundle.pipe(uglify(getUglifyOptions(minify, { CC_EDITOR: false, CC_DEV: false, - CC_TEST: false + CC_TEST: false, + CC_JSB: true }))); if (SourceMap) { bundle = bundle.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true})); diff --git a/gulpfile.js b/gulpfile.js index 2dea6199df..4bcad6fbbc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,6 +23,7 @@ paths = { '../../cocos2d/core/platform/CCLoader', '../../cocos2d/core/platform/CCLoaders', '../../cocos2d/core/event/event', + '../../extensions/spine/spine-exported', ], test: { diff --git a/index.js b/index.js index 8e2f2d762b..768b9599c0 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,8 @@ eval( 'if(typeof CC_EDITOR=="undefined")' + 'CC_EDITOR=typeof Editor=="object"&&typeof process=="object"&&"electron" in process.versions;' + 'if(typeof CC_DEV=="undefined")' + - 'CC_DEV=CC_EDITOR||CC_TEST;' + 'CC_DEV=CC_EDITOR||CC_TEST;' + + 'CC_JSB=false;' ); // PREDEFINE diff --git a/jsb/index.js b/jsb/index.js index 456e8517a5..5be79c7cbb 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -50,9 +50,9 @@ if (_engineNumberVersion) { } } -var originLog = console.log; -var log = console.log = function () { - originLog.call(console, cc.formatStr.apply(null, arguments)); +// var originLog = console.log; +var log = function () { + console.log.call(console, cc.formatStr.apply(null, arguments)); }; cc.log = log; diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index 61471966b6..6983d31efd 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -299,14 +299,14 @@ cc.Director.EVENT_COMPONENT_UPDATE = 'director_component_update'; cc.Director.EVENT_COMPONENT_LATE_UPDATE = 'director_component_late_update'; cc.eventManager.addCustomListener(cc.Director.EVENT_BEFORE_UPDATE, function () { - var dt = 1 / cc.game.config[cc.game.CONFIG_KEY.frameRate]; + var dt = 1 / 60; // Call start for new added components cc.director.emit(cc.Director.EVENT_BEFORE_UPDATE); // Update for components cc.director.emit(cc.Director.EVENT_COMPONENT_UPDATE, dt); }); cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_UPDATE, function () { - var dt = 1 / cc.game.config[cc.game.CONFIG_KEY.frameRate]; + var dt = 1 / 60; // Late update for components cc.director.emit(cc.Director.EVENT_COMPONENT_LATE_UPDATE, dt); // User can use this event to do things after update diff --git a/jsb/jsb-enums.js b/jsb/jsb-enums.js index 459c4aa61a..25677b203c 100644 --- a/jsb/jsb-enums.js +++ b/jsb/jsb-enums.js @@ -113,7 +113,7 @@ cc.EditBox.InputFlag = cc.Enum({ * @readonly * @enum {number} */ -cc.KeyboardReturnType = cc.Enum({ +cc.EditBox.KeyboardReturnType = cc.Enum({ DEFAULT: 0, DONE: 1, SEND: 2, diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 33f35d48f1..b7bc76e563 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -260,7 +260,7 @@ window._ccsg = { Sprite: cc.Sprite, ParticleSystem: cc.ParticleSystem, Label: cc.Label, - + EditBox: cc.EditBox }; // rename cc.Class to cc._Class diff --git a/jsb/jsb-scale9sprite.js b/jsb/jsb-scale9sprite.js index f78cb6e5cc..231c9cae4d 100644 --- a/jsb/jsb-scale9sprite.js +++ b/jsb/jsb-scale9sprite.js @@ -26,7 +26,47 @@ // cc.Scale9Sprite -cc.Scale9Sprite.prototype._lazyInit = function () { +cc.Scale9Sprite.state = {NORMAL: 0, GRAY: 1}; + +/** + * 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; + +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}; @@ -36,11 +76,11 @@ cc.Scale9Sprite.prototype._lazyInit = function () { this._sizeAfterTrimmed = new cc.Size(0, 0); }; -cc.Scale9Sprite.prototype._applyInsetsContentAnchor = function () { +s9sPrototype._applyInsetsContentAnchor = function () { var renderingType = this._renderingType || (this.getRenderingType && this.getRenderingType()); var trimScaleX = 1; var trimScaleY = 1; - if (renderingType === cc.SpriteType.SIMPLE) { + if (renderingType === cc.Scale9Sprite.RenderingType.SIMPLE) { trimScaleX = this._contentSizeTrimmed.width / this._sizeAfterTrimmed.width; trimScaleY = this._contentSizeTrimmed.height / this._sizeAfterTrimmed.height; } @@ -68,8 +108,8 @@ cc.Scale9Sprite.prototype._applyInsetsContentAnchor = function () { this.setCapInsets(capinsets); }; -cc.Scale9Sprite.prototype._setBlendFunc = cc.Scale9Sprite.prototype.setBlendFunc; -cc.Scale9Sprite.prototype.setBlendFunc = function (blendFunc, dst) { +s9sPrototype._setBlendFunc = s9sPrototype.setBlendFunc; +s9sPrototype.setBlendFunc = function (blendFunc, dst) { if (void 0 !== dst) { blendFunc = { src: blendFunc, @@ -78,13 +118,13 @@ cc.Scale9Sprite.prototype.setBlendFunc = function (blendFunc, dst) { } this._setBlendFunc(blendFunc); }; -cc.Scale9Sprite.prototype._getContentSize = cc.Scale9Sprite.prototype.getContentSize; -cc.Scale9Sprite.prototype.getContentSize = function () { +s9sPrototype._getContentSize = s9sPrototype.getContentSize; +s9sPrototype.getContentSize = function () { return new cc.Size(this._contentSizeTrimmed); }; -cc.Scale9Sprite.prototype._setContentSize = cc.Scale9Sprite.prototype.setContentSize; -cc.Scale9Sprite.prototype.setContentSize = function (size, height) { +s9sPrototype._setContentSize = s9sPrototype.setContentSize; +s9sPrototype.setContentSize = function (size, height) { this._lazyInit(); if (void 0 !== height) { size = new cc.Size(size, height); @@ -93,13 +133,13 @@ cc.Scale9Sprite.prototype.setContentSize = function (size, height) { this._applyInsetsContentAnchor(); }; -cc.Scale9Sprite.prototype._getAnchorPoint = cc.Scale9Sprite.prototype.getAnchorPoint; -cc.Scale9Sprite.prototype.getAnchorPoint = function () { +s9sPrototype._getAnchorPoint = s9sPrototype.getAnchorPoint; +s9sPrototype.getAnchorPoint = function () { return new cc.Vec2(this._anchorPointTrimmed); }; -cc.Scale9Sprite.prototype._setAnchorPoint = cc.Scale9Sprite.prototype.setAnchorPoint; -cc.Scale9Sprite.prototype.setAnchorPoint = function (anchorPoint, y) { +s9sPrototype._setAnchorPoint = s9sPrototype.setAnchorPoint; +s9sPrototype.setAnchorPoint = function (anchorPoint, y) { this._lazyInit(); if (void 0 !== y) { anchorPoint = new cc.Vec2(anchorPoint, y); @@ -108,53 +148,53 @@ cc.Scale9Sprite.prototype.setAnchorPoint = function (anchorPoint, y) { this._applyInsetsContentAnchor(); }; -cc.Scale9Sprite.prototype._getInsetLeft = cc.Scale9Sprite.prototype.getInsetLeft; -cc.Scale9Sprite.prototype._getInsetRight = cc.Scale9Sprite.prototype.getInsetRight; -cc.Scale9Sprite.prototype._getInsetBottom = cc.Scale9Sprite.prototype.getInsetBottom; -cc.Scale9Sprite.prototype._getInsetTop = cc.Scale9Sprite.prototype.getInsetTop; -cc.Scale9Sprite.prototype.getInsetLeft = function () { +s9sPrototype._getInsetLeft = s9sPrototype.getInsetLeft; +s9sPrototype._getInsetRight = s9sPrototype.getInsetRight; +s9sPrototype._getInsetBottom = s9sPrototype.getInsetBottom; +s9sPrototype._getInsetTop = s9sPrototype.getInsetTop; +s9sPrototype.getInsetLeft = function () { return this._insets.left; }; -cc.Scale9Sprite.prototype.getInsetRight = function () { +s9sPrototype.getInsetRight = function () { return this._insets.right; }; -cc.Scale9Sprite.prototype.getInsetBottom = function () { +s9sPrototype.getInsetBottom = function () { return this._insets.bottom; }; -cc.Scale9Sprite.prototype.getInsetTop = function () { +s9sPrototype.getInsetTop = function () { return this._insets.top; }; -cc.Scale9Sprite.prototype._setInsetLeft = cc.Scale9Sprite.prototype.setInsetLeft; -cc.Scale9Sprite.prototype.setInsetLeft = function (insetLeft) { +s9sPrototype._setInsetLeft = s9sPrototype.setInsetLeft; +s9sPrototype.setInsetLeft = function (insetLeft) { this._lazyInit(); this._insets.left = insetLeft; this._applyInsetsContentAnchor(); }; -cc.Scale9Sprite.prototype._setInsetRight = cc.Scale9Sprite.prototype.setInsetRight; -cc.Scale9Sprite.prototype.setInsetRight = function (insetRight) { +s9sPrototype._setInsetRight = s9sPrototype.setInsetRight; +s9sPrototype.setInsetRight = function (insetRight) { this._lazyInit(); this._insets.right = insetRight; this._applyInsetsContentAnchor(); }; -cc.Scale9Sprite.prototype._setInsetTop = cc.Scale9Sprite.prototype.setInsetTop; -cc.Scale9Sprite.prototype.setInsetTop = function (insetTop) { +s9sPrototype._setInsetTop = s9sPrototype.setInsetTop; +s9sPrototype.setInsetTop = function (insetTop) { this._lazyInit(); this._insets.top = insetTop; this._applyInsetsContentAnchor(); }; -cc.Scale9Sprite.prototype._setInsetBottom = cc.Scale9Sprite.prototype.setInsetBottom; -cc.Scale9Sprite.prototype.setInsetBottom = function (insetBottom) { +s9sPrototype._setInsetBottom = s9sPrototype.setInsetBottom; +s9sPrototype.setInsetBottom = function (insetBottom) { this._lazyInit(); this._insets.bottom = insetBottom; this._applyInsetsContentAnchor(); }; -cc.Scale9Sprite.prototype._setSpriteFrame = cc.Scale9Sprite.prototype.setSpriteFrame; -cc.Scale9Sprite.prototype.setSpriteFrame = function (spriteFrame) { +s9sPrototype._setSpriteFrame = s9sPrototype.setSpriteFrame; +s9sPrototype.setSpriteFrame = function (spriteFrame) { this._lazyInit(); var originalSize = spriteFrame.getOriginalSize(); var spriteRect = spriteFrame.getRect(); diff --git a/jsb/versions/jsb-polyfill-v3.9.js b/jsb/versions/jsb-polyfill-v3.9.js index 2093161531..0f8c81d2b6 100644 --- a/jsb/versions/jsb-polyfill-v3.9.js +++ b/jsb/versions/jsb-polyfill-v3.9.js @@ -32,7 +32,7 @@ cc.Scale9Sprite.prototype.setRenderingType = function (type) { this.setScale9Enabled(true); } - if (type === cc.SpriteType.SIMPLE) { + if (type === cc.Scale9Sprite.RenderingType.SIMPLE) { // Should modify based on trim size this.setInsetLeft(0); this.setInsetTop(0);